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

    <tr>
        <th>Summary</th>
        <td>
            `opt -O3` is not treating names correctly.
        </td>
    </tr>

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

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

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

<pre>
    I have a machine generated `.ll` file that can be compiled correctly by `llc`. However, if I first optimize the program using `opt`, and then compile using `llc`, the compiler will complain `multiple definition of local value named`. I would think that there is either a bug in `opt` or in `llc`. As the program is machine generated by my compiler, I do not have a reduced test case yet. 

I suspect the issue is that `opt` is inserting an incorrect amount of `.i` when trying to make sure the names do not clash, and unfortunately, it failed.

Steps to reproduce,
1. Download the attached `runtest.ll.txt` and rename it to `runtest.ll`
2. Run `llc -o runtest.o runtest.ll` and confirm it is successful
3. Run `opt -O3 -o runtest.opt.ll runtest.ll` and confirm it is successful. The `-O3` is crucial here.
4. Run `llc -o runtest.opt.o runtest.opt.ll` and see the name clash. 

 
[runtest.ll.txt](https://github.com/llvm/llvm-project/files/11362662/runtest.ll.txt)

Version information:
`opt --version`
```
Homebrew LLVM version 15.0.7
 Optimized build.
  Default target: x86_64-apple-darwin22.1.0
  Host CPU: skylake
```
`llc --version`
```
Homebrew LLVM version 15.0.7
  Optimized build.
  Default target: x86_64-apple-darwin22.1.0
  Host CPU: skylake

  Registered Targets:
    aarch64    - AArch64 (little endian)
    aarch64_32 - AArch64 (little endian ILP32)
    aarch64_be - AArch64 (big endian)
 amdgcn     - AMD GCN GPUs
    arm        - ARM
    arm64      - ARM64 (little endian)
    arm64_32   - ARM64 (little endian ILP32)
    armeb - ARM (big endian)
    avr        - Atmel AVR Microcontroller
 bpf        - BPF (host endian)
    bpfeb      - BPF (big endian)
 bpfel      - BPF (little endian)
    hexagon    - Hexagon
    lanai - Lanai
    mips       - MIPS (32-bit big endian)
    mips64     - MIPS (64-bit big endian)
    mips64el   - MIPS (64-bit little endian)
 mipsel     - MIPS (32-bit little endian)
    msp430     - MSP430 [experimental]
    nvptx      - NVIDIA PTX 32-bit
    nvptx64    - NVIDIA PTX 64-bit
    ppc32      - PowerPC 32
    ppc32le    - PowerPC 32 LE
    ppc64      - PowerPC 64
    ppc64le    - PowerPC 64 LE
 r600       - AMD GPUs HD2XXX-HD6XXX
    riscv32    - 32-bit RISC-V
 riscv64    - 64-bit RISC-V
    sparc      - Sparc
    sparcel    - Sparc LE
    sparcv9    - Sparc V9
    systemz    - SystemZ
 thumb      - Thumb
    thumbeb    - Thumb (big endian)
    ve         - VE
    wasm32     - WebAssembly 32-bit
    wasm64     - WebAssembly 64-bit
    x86        - 32-bit X86: Pentium-Pro and above
    x86-64 - 64-bit X86: EM64T and AMD64
    xcore      - XCore
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8V1tv4joQ_jXhZZQoOCGlDzzQst0itbuot4POy8pJBvCpY0e2A2V__dHkQoC2u1rp6FRViTvffPPNxTBwa8VaIU680ZU3mg145TbaTJ6lEwV3uEA-SHW-n8xhw7cIHAqebYRCWKNCwx3m4CVhIKWXhLASEsFtuIOMK0gRMl2UQmIOmTYGMyf3kO7JQcqM3OBW73CLxmPXIFYwh5Uw1oEunSjET-JCKI1eG15AZYVak68unZeE5MJVThDVxekxDT9hiKI1G9gJKeuT5EIRrqikE6VEyHEllHBCK9ArkDrjErZcVgiKF5jXYuew05WkkEK9Nnm6DRoEYQEFPQKHtFpDw93oBG3ac5fz1J7kJewHNU33UOwPuimPOeQalHZdHwzmVYY5OLRUbouwRxeAF868cNr8nYOtbIlZLROEtVUttRbe6xMWhLJoHJWOKxCqbRbwQlfKUT1ItyDwjqrtzJ6wTkPBXxFsZZpOUaVsJzOT3G66JlVqpY2rFHco93WzHaw4TUZwLPjRYWmJ12BpNOXnsevGNAxgpndKal63HLhzPN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