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

    <tr>
        <th>Summary</th>
        <td>
            unexpected output results in fusion using -Os
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          Elowen-jjw
      </td>
    </tr>
</table>

<pre>
    For the following two c files, I performed the equivalent transformation of loop from **file1.c** to **file2.c**. I ran these two files respectively using different optimization levels including **-O0**, **-O1**, **-O2**, **-O3**, **-Os**, **-Ofast**. The exact output results(i.e. checksum values) are:
```
                -O0 -O1             -O2             -O3             -Os             -Ofast 
file1.c         F2F952A1        F2F952A1        AAF00380        AAF00380 AAF00380        AAF00380     
file2.c         F2F952A1 F2F952A1        AAF00380        AAF00380        F2F952A1        AAF00380 
```
Please help me to explain why these two files produced different output results when using the same optimization level(i.e. -Os), thank you.

command line:
```
clang <filename.c> <optimization level> -lm -I $CSMITH_HOME/include && ./a.out
```
version: clang+llvm 14.0.0
os: ubuntu 22.04

**file1.c**
```

#include "csmith.h"

static int32_t g_a4[2];
static int64_t g_b4[2];

struct S0 {
  volatile int64_t f0;
  int8_t f1;
 uint8_t f2;
  volatile int16_t f3;
};

union U1 {
  int64_t f0;
  uint8_t f1;
  uint8_t f2;
  const int64_t f3;
  volatile struct S0 f4;
};

static int32_t g_3 = 0xA73D2D67L;
static int32_t *g_5 = (void *)0;
static uint16_t g_16[2] = {0x8D20L, 0x8D20L};
static int32_t **volatile g_18 = &g_5;
static volatile union U1 g_25 = {0xDF34FFDEABFD090DLL};

static int32_t func_1(void);
static int32_t *func_7(void);

static int32_t func_1(void) {
  (*g_18) = func_7();
  return g_16[1];
}

static int32_t *func_7() {
  int32_t *l_17[2][1];
 int i, j;
  int ii_0;
  // fusion
  for (i = 0, ii_0 = 0; i < 2; i++, ii_0++) {
    for (j = 0; j < 1; j++) {
      l_17[i][j] = &g_3;
      g_a4[ii_0] = g_16[0] * g_3 - g_25.f2;
    }
  }
  int jj_0;
  for (jj_0 = 0; jj_0 < 1; jj_0++) {
    g_b4[jj_0] = g_25.f3 * g_a4[jj_0] - g_25.f2;
  }
  return l_17[0][0];
}

int main(void) {
  int i, j, k;
  int print_hash_value = 0;
 platform_main_begin();
  crc32_gentab();
  func_1();
 transparent_crc(g_3, "g_3", print_hash_value);
  for (i = 0; i < 2; i++) {
    transparent_crc(g_16[i], "g_16[i]", print_hash_value);
  }
 transparent_crc(g_25.f0, "g_25.f0", print_hash_value);
  for (i = 0; i < 2; i++) {
    transparent_crc(g_a4[i], "g_a4[i]", print_hash_value);
 }
  for (i = 0; i < 2; i++) {
    transparent_crc(g_b4[i], "g_b4[i]", print_hash_value);
  }
  platform_main_end(crc32_context ^ 0xFFFFFFFFUL, print_hash_value);
  return 0;
}

```

**file2.c**
```

#include "csmith.h"

static int32_t g_a4[2];
static int64_t g_b4[2];

struct S0 {
  volatile int64_t f0;
  int8_t f1;
 uint8_t f2;
  volatile int16_t f3;
};

union U1 {
  int64_t f0;
  uint8_t f1;
  uint8_t f2;
  const int64_t f3;
  volatile struct S0 f4;
};

static int32_t g_3 = 0xA73D2D67L;
static int32_t *g_5 = (void *)0;
static uint16_t g_16[2] = {0x8D20L, 0x8D20L};
static int32_t **volatile g_18 = &g_5;
static volatile union U1 g_25 = {0xDF34FFDEABFD090DLL};

static int32_t func_1(void);
static int32_t *func_7(void);

static int32_t func_1(void) {
  (*g_18) = func_7();
  return g_16[1];
}

static int32_t *func_7() {
  int32_t *l_17[2][1];
 int i, j;
  int ii_0;
  int jj_0;
  int ij_0;
  // fusion
 for (i = 0, ii_0 = 0, jj_0 = 0, ij_0 = 0; ij_0 <= 2; ij_0++) {
    if (ij_0 <= 2 && i < 2) {
      for (j = 0; j < 1; j++) {
 l_17[i][j] = &g_3;
        g_a4[ii_0] = g_16[0] * g_3 - g_25.f2;
 }
      i++;
      ii_0++;
    }
    if (ij_0 <= 1 && jj_0 < 1) {
      g_b4[jj_0] = g_25.f3 * g_a4[jj_0] - g_25.f2;
      jj_0++;
 }
  }
  return l_17[0][0];
}

int main(void) {
  int i, j, k;
  int print_hash_value = 0;
  platform_main_begin();
 crc32_gentab();
  func_1();
  transparent_crc(g_3, "g_3", print_hash_value);
  for (i = 0; i < 2; i++) {
 transparent_crc(g_16[i], "g_16[i]", print_hash_value);
  }
 transparent_crc(g_25.f0, "g_25.f0", print_hash_value);
  for (i = 0; i < 2; i++) {
    transparent_crc(g_a4[i], "g_a4[i]", print_hash_value);
 }
  for (i = 0; i < 2; i++) {
    transparent_crc(g_b4[i], "g_b4[i]", print_hash_value);
  }
  platform_main_end(crc32_context ^ 0xFFFFFFFFUL, print_hash_value);
  return 0;
}

```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWc1u27oSfhp6M7BAkZZ_Fl7YcYQGSJELtF0LtETZdCnRV6Sc5D79Bakfy7KcpKfFOWcRwWg1w-HMN8MZ6bPDtBa7nPMlCtYo2IxYafaqWN5L9czz8eHwPNqq5HUZqgLMnkOqpFTPIt-BeVYQQyok14jcwQMceZGqIuOJM-T_LcWJSZ4bMAXLtV1iRqgcVApSqSOkhcoAkRUiK-vF9-JKAKM6atKoPXiAguXWueYuuosNBddHHhtx4vIVSm2hJSJNeWFDq6MRmfhfFVjyE5caRB7LMrF2lePxE65ubBqNyr9WkWsVvVbpa1XKtGly-G5L88JiA6o0x9JY-KU0GpG58LgH8Z7HP3WZwYnJ0lZ2AazgiK4Q3iC8QlNcf5wIvWv8hGH85Pd0pCfTnqx7ssULVYD6YNrFkISLgKz8W_JqFWJM5_hKvrlgr3MsMhTrw0HeAzVYw_9IzjSHPZdHyLhtPv5ylEzk8Lx_veq2Y6GSMuZJt8cuDhKe9zyv-9DOgWYZH2jD5rxdwyxst5g9y3_Cqyq9Gqb7N1ZZxvIEpMhvdkEsmW1memch5izjX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