int test(int x) {
  const int XX[1000] = {0, 0};
  const char S[1000] = "foo";
  const int array[] = {
      17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49,
      17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49,
      17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49,
      17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49,
      17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49,
      17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49,
      17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49,
      17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49,
      17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49,
      17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49,
      17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49,
      17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49,
      17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49,
      17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49,
      17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49,
      17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49,
      17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49,
      17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49,
      17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49,
      17, 23, 123, 123, 49, 17, 23, 123, 123, 49, 17, 23, 123, 123, 49,
  };
  return array[x];
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1850,%rsp
mov    %edi,-0x4(%rbp)
lea    -0xfb0(%rbp),%rdi
xor    %esi,%esi
mov    $0xfa0,%edx
call   1030 <memset@plt>
lea    -0x13a0(%rbp),%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1030 <memset@plt>
movb   $0x66,-0x13a0(%rbp)
movb   $0x6f,-0x139f(%rbp)
movb   $0x6f,-0x139e(%rbp)
lea    -0x1850(%rbp),%rdi
lea    0xe89(%rip),%rsi
mov    $0x4b0,%edx
call   1040 <memcpy@plt>
movslq -0x4(%rbp),%rax
mov    -0x1850(%rbp,%rax,4),%eax
add    $0x1850,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
movslq %edi,%rax
lea    0xef6(%rip),%rcx
mov    (%rcx,%rax,4),%eax
ret

LLVM IR (-O0):
@__const.test.array = [300 x i32] [i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49]
define i32 @test(i32 %0) {
%2 = alloca i32
%3 = alloca [1000 x i32]
%4 = alloca [1000 x i8]
%5 = alloca [300 x i32]
store i32 %0, i32* %2
%6 = bitcast [1000 x i32]* %3 to i8*
%7 = bitcast [1000 x i8]* %4 to i8*
%8 = bitcast i8* %7 to [1000 x i8]*
%9 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i32 0, i32 0
store i8 102, i8* %9
%10 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i32 0, i32 1
store i8 111, i8* %10
%11 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i32 0, i32 2
store i8 111, i8* %11
%12 = bitcast [300 x i32]* %5 to i8*
%13 = load i32, i32* %2
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [300 x i32], [300 x i32]* %5, i64 0, i64 %14
%16 = load i32, i32* %15
ret i32 %16
}

LLVM IR (-O2):
@__const.test.array = [300 x i32] [i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49, i32 17, i32 23, i32 123, i32 123, i32 49]
define i32 @test(i32 %0) {
%2 = sext i32 %0 to i64
%3 = getelementptr inbounds [300 x i32], [300 x i32]* @__const.test.array, i64 0, i64 %2
%4 = load i32, i32* %3
ret i32 %4
}