<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/90047>90047</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            User defined SIN function is not called with O3 opt level
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          ararmine
      </td>
    </tr>
</table>

<pre>
    When compiling the following example with clang -O3 opt level, the program does not print the expected output, the user defined sin function is not called and the sin library function is called instead. While with -O0 level it works as expected.
Steps to reproduce:
```
cat bug.cpp 
#include <stdio.h>

extern "C" double sin(double x) {
  printf ("Inside the sin function\n");
 return 0.0;
}

int main() {
  printf ("Call 1 %f\n", sin(3.3));
  printf ("Call 2 %f\n", ::sin(3.3));
}
```
With clang 18.1.0
```
clang++ -O0 bug.cpp
./a.out
Inside the sin function
Call 1 0.000000
Inside the sin function
Call 2 0.000000

clang++ -O3 bug.cpp
./a.out
Inside the sin function
Call 1 -0.157746
Inside the sin function
Call 2 -0.157746
```

When compiling the program with GCC 13.2 , the output is expected with both opt. levels.
```
g++ -O0 bug.cpp
./a.out
Inside the sin function
Call 1 0.000000
Inside the sin function
Call 2 0.000000

g++ -O3 bug.cpp
./a.out
Inside the sin function
Call 1 0.000000
Inside the sin function
Call 2 0.000000
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVU2P4ygQ_TX4UgrCYMfJwYfu9GY1l53DaNVnDJWYXQwW4Omef78ydtIfm16N1HuYKEqEqx71eOVXyBjN2SG2pL4n9UMhp9T70Mogw2AcFp3XP9rHHh0oP4zGGneG1COcvLX-aV7hsxxGi_BkUg_KSneGzVcBfkxg8Ttawg8ZMQZ_DnIA7TGC8wnGYFzKIXweUSXU4Kc0TumCmCIG0HgyDjVE4-A0OZWMd2CWHZS0FjVIp3P-nGJNF2T48SZ1TTMuJpSawmNvLnw3X9nCEkyCJx_-jiDjlQ8l7IGwu28JxwjJQ8AxeD0pJOJuCZEtW795qWSCbjpTNY6wJnBhnLKTRiDiEJM2nvZE_LZG8y8-JwwOCOcHwjloP3U2n4bw3bp4JnwPpLlfALBodwLCd4TzLy4ajVcJLkcn9cERzgnfE3EBBkxTcMAouz4jzcNrMnNPBplr_1fNg7QWSiC8Pl3rHFbOgoq56Ou6N8D8PXgWVdx9tMULzbeSP768duWOlpTdbsycQPg94fe552uTliAl_Cipn9Ky_EjOHFzPzSjLn59F8HeIW6zEp1ltGC3rpqm2P0_rHeSdbKvE_7b_xczZRL8fDlAKOjd0Me5i49l6V2fnxM6nfh4MdPFcpDeL_np9-j979GlGb8UqdCv0XuxlgW3ZlBWrWbWtir7dcs2kanZ115Ri26ASSmx3TVM2jarEaVuYljNesYrXpWBNxeleVyhQC4Z7rFXdkIrhII2l1n4fqA_nwsQ4YbtnrGoKKzu0MV8bnDt8ghycrVw_FKGdMZtuOkdSMWtiii-7JJMstn--Hu7fvvzx0XDPL87r-6SYgm37lMY4Dwx-JPx4NqmfOqr8QPhxrrP-bcbg_0KVCD9mdpHwY2b_TwAAAP__A3gPeg">