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

    <tr>
        <th>Summary</th>
        <td>
            Does the print statement influence code optimization and debug information's generation?
        </td>
    </tr>

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

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

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

<pre>
    This test case is derived from #107443 and #107449. Is there anything we can do to improve? How can we minimize the effect of print statements on debug information generation and code optimization?


If we comment out line 34, which contains printf("Hello, world!\n");, does it affect the generated code via the same compiling option "-g -O3", even just printing ""Hello, world!\n" "? You can compare the results on [Godbolt with printf](https://godbolt.org/z/7vzoqe3dT) and[ Godbot without printf](https://godbolt.org/z/YGn8Mahde) .

Without print statement, `local_ptr` is optimized out and we cannot get its debug information.  We can reproduce this in LLVM 18.1.8, 17.06, and 16.0.3.
```
(lldb) file 434_O3.out
(lldb) b main
(lldb) r
* thread #1, name = '434_O3.out', stop reason = breakpoint 1.1
    frame #0: 0x0000555555555130 434_O3.out`main [inlined] get_union_value at 434.c:25:29
   22   static const union U3 get_union_value(void) {
   23       long int *local_ptr = &g_values[7];
   24       
-> 25            *g_value_ptr = (249UL < g_flag); // Set value based on comparison
   26       *local_ptr = 0; // Reset the value at index 7
   27       *g_ptr_wrapper = &local_ptr;     // Update reference
   28   

(lldb) p *local_ptr
error: Couldn't apply expression side effects : Couldn't dematerialize a result variable: couldn't read its memory
(lldb) s
(lldb) p *local_ptr
error: Couldn't materialize: couldn't get the value of variable local_ptr: variable not available
error: errored out in DoExecute, couldn't PrepareToExecuteJITExpression
```


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVk1z2zYQ_TXQZcccEiBF8aCDZEVJOsmk0zrN5OQBiaWEFARYAJTs_PrOkvqy3R5aj4eisMDbt28_IBmC3lnEJSvWrNjM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