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

    <tr>
        <th>Summary</th>
        <td>
            Wrong code at -Os on x86_64-linux_gnu (LoopFlattenPass)
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          shao-hua-li
      </td>
    </tr>
</table>

<pre>
    ```console
% clang-tk -v
clang version 16.0.0 (https://github.com/llvm/llvm-project.git faf0e1fbf90f14a92042a83f6cb1239791674412)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /zdata/shaoli/compilers/ccbuilder-compilers
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Candidate multilib: .;@m64
Selected multilib: .;@m64
%
% clang-tk -w -O0 a.c && ./a.out
6
% clang-tk -w -Os a.c && ./a.out
1
% cat a.c
void printf();
int c;
int a(int b) {
    int t = 0;
    while (t < 7 && b) t++;
    return t;
}
int e() {
    int l;
    for (l = 0; l < 6; l = l + 1)
        for (c = 0; c < 6; c = (a(6) ^ 7) + c + 1)
            ;
}
int main() {
    e();
    printf("%d\n", c);
}
%
```
Compiler explorer: https://godbolt.org/z/x1jvrPj9a
`opt-bisect-limit` suggests that the issue might be in `LoopFlattenPass`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytVN2P3CYQ_2vsF2QLsM3aD37o7WajSJUaqZX6GGGMbS4srADvXfvXd7C9H7lcI0WKhQzM52-Gmels_0-bMLwuYY23Wib4kODfElohobkZs_AVZZeVuBDQRTqvrEGE5TjHKKH1FMLZJwUoHWGNKkxzlwt7govWl-uWnZ19liLkIIAGPmBJhm5o8EBK3lBcUl4XA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