int ArrayToSum(void) {
  int A[100], i;
  for (i = 0; i < 100; ++i)
    A[i] = i * 4;
  return A[A[0]];
}


x86 assembly (clang, -O0):
<ArrayToSum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x194(%rbp)
cmpl   $0x64,-0x194(%rbp)
jge    114d <ArrayToSum+0x4d>
mov    -0x194(%rbp),%ecx
shl    $0x2,%ecx
movslq -0x194(%rbp),%rax
mov    %ecx,-0x190(%rbp,%rax,4)
mov    -0x194(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x194(%rbp)
jmp    1115 <ArrayToSum+0x15>
movslq -0x190(%rbp),%rax
mov    -0x190(%rbp,%rax,4),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ArrayToSum>:
sub    $0x118,%rsp
movaps 0xef2(%rip),%xmm0
movaps %xmm0,-0x80(%rsp)
movaps 0xef6(%rip),%xmm0
movaps %xmm0,-0x70(%rsp)
movaps 0xefa(%rip),%xmm0
movaps %xmm0,-0x60(%rsp)
movaps 0xefe(%rip),%xmm0
movaps %xmm0,-0x50(%rsp)
movaps 0xf02(%rip),%xmm0
movaps %xmm0,-0x40(%rsp)
movaps 0xf06(%rip),%xmm0
movaps %xmm0,-0x30(%rsp)
movaps 0xf0a(%rip),%xmm0
movaps %xmm0,-0x20(%rsp)
movaps 0xf0e(%rip),%xmm0
movaps %xmm0,-0x10(%rsp)
movaps 0xf12(%rip),%xmm0
movaps %xmm0,(%rsp)
movaps 0xf17(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xf1b(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xf1f(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xf23(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xf27(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xf2b(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xf2f(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xf33(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xf34(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movaps 0xf35(%rip),%xmm0
movaps %xmm0,0xa0(%rsp)
movaps 0xf36(%rip),%xmm0
movaps %xmm0,0xb0(%rsp)
movaps 0xf37(%rip),%xmm0
movaps %xmm0,0xc0(%rsp)
movaps 0xf38(%rip),%xmm0
movaps %xmm0,0xd0(%rsp)
movaps 0xf39(%rip),%xmm0
movaps %xmm0,0xe0(%rsp)
movaps 0xf3a(%rip),%xmm0
movaps %xmm0,0xf0(%rsp)
movaps 0xf3b(%rip),%xmm0
movaps %xmm0,0x100(%rsp)
movslq -0x80(%rsp),%rax
mov    -0x80(%rsp,%rax,4),%eax
add    $0x118,%rsp
ret

LLVM IR (-O0):
define i32 @ArrayToSum() {
%1 = alloca [100 x i32]
%2 = alloca i32
store i32 0, i32* %2
br label %3
3: ; preds = %12, %0
%4 = load i32, i32* %2
%5 = icmp slt i32 %4, 100
br i1 %5, label %6, label %15
6: ; preds = %3
%7 = load i32, i32* %2
%8 = mul nsw i32 %7, 4
%9 = load i32, i32* %2
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %10
store i32 %8, i32* %11
br label %12
12: ; preds = %6
%13 = load i32, i32* %2
%14 = add nsw i32 %13, 1
store i32 %14, i32* %2
br label %3
15: ; preds = %3
%16 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 0
%17 = load i32, i32* %16
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %18
%20 = load i32, i32* %19
ret i32 %20
}

LLVM IR (-O2):
define i32 @ArrayToSum() {
%1 = alloca [100 x i32]
%2 = bitcast [100 x i32]* %1 to i8*
%3 = bitcast [100 x i32]* %1 to <4 x i32>*
store <4 x i32> <i32 0, i32 4, i32 8, i32 12>, <4 x i32>* %3
%4 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 4
%5 = bitcast i32* %4 to <4 x i32>*
store <4 x i32> <i32 16, i32 20, i32 24, i32 28>, <4 x i32>* %5
%6 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 8
%7 = bitcast i32* %6 to <4 x i32>*
store <4 x i32> <i32 32, i32 36, i32 40, i32 44>, <4 x i32>* %7
%8 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 12
%9 = bitcast i32* %8 to <4 x i32>*
store <4 x i32> <i32 48, i32 52, i32 56, i32 60>, <4 x i32>* %9
%10 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 16
%11 = bitcast i32* %10 to <4 x i32>*
store <4 x i32> <i32 64, i32 68, i32 72, i32 76>, <4 x i32>* %11
%12 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 20
%13 = bitcast i32* %12 to <4 x i32>*
store <4 x i32> <i32 80, i32 84, i32 88, i32 92>, <4 x i32>* %13
%14 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 24
%15 = bitcast i32* %14 to <4 x i32>*
store <4 x i32> <i32 96, i32 100, i32 104, i32 108>, <4 x i32>* %15
%16 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 28
%17 = bitcast i32* %16 to <4 x i32>*
store <4 x i32> <i32 112, i32 116, i32 120, i32 124>, <4 x i32>* %17
%18 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 32
%19 = bitcast i32* %18 to <4 x i32>*
store <4 x i32> <i32 128, i32 132, i32 136, i32 140>, <4 x i32>* %19
%20 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 36
%21 = bitcast i32* %20 to <4 x i32>*
store <4 x i32> <i32 144, i32 148, i32 152, i32 156>, <4 x i32>* %21
%22 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 40
%23 = bitcast i32* %22 to <4 x i32>*
store <4 x i32> <i32 160, i32 164, i32 168, i32 172>, <4 x i32>* %23
%24 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 44
%25 = bitcast i32* %24 to <4 x i32>*
store <4 x i32> <i32 176, i32 180, i32 184, i32 188>, <4 x i32>* %25
%26 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 48
%27 = bitcast i32* %26 to <4 x i32>*
store <4 x i32> <i32 192, i32 196, i32 200, i32 204>, <4 x i32>* %27
%28 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 52
%29 = bitcast i32* %28 to <4 x i32>*
store <4 x i32> <i32 208, i32 212, i32 216, i32 220>, <4 x i32>* %29
%30 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 56
%31 = bitcast i32* %30 to <4 x i32>*
store <4 x i32> <i32 224, i32 228, i32 232, i32 236>, <4 x i32>* %31
%32 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 60
%33 = bitcast i32* %32 to <4 x i32>*
store <4 x i32> <i32 240, i32 244, i32 248, i32 252>, <4 x i32>* %33
%34 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 64
%35 = bitcast i32* %34 to <4 x i32>*
store <4 x i32> <i32 256, i32 260, i32 264, i32 268>, <4 x i32>* %35
%36 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 68
%37 = bitcast i32* %36 to <4 x i32>*
store <4 x i32> <i32 272, i32 276, i32 280, i32 284>, <4 x i32>* %37
%38 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 72
%39 = bitcast i32* %38 to <4 x i32>*
store <4 x i32> <i32 288, i32 292, i32 296, i32 300>, <4 x i32>* %39
%40 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 76
%41 = bitcast i32* %40 to <4 x i32>*
store <4 x i32> <i32 304, i32 308, i32 312, i32 316>, <4 x i32>* %41
%42 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 80
%43 = bitcast i32* %42 to <4 x i32>*
store <4 x i32> <i32 320, i32 324, i32 328, i32 332>, <4 x i32>* %43
%44 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 84
%45 = bitcast i32* %44 to <4 x i32>*
store <4 x i32> <i32 336, i32 340, i32 344, i32 348>, <4 x i32>* %45
%46 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 88
%47 = bitcast i32* %46 to <4 x i32>*
store <4 x i32> <i32 352, i32 356, i32 360, i32 364>, <4 x i32>* %47
%48 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 92
%49 = bitcast i32* %48 to <4 x i32>*
store <4 x i32> <i32 368, i32 372, i32 376, i32 380>, <4 x i32>* %49
%50 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 96
%51 = bitcast i32* %50 to <4 x i32>*
store <4 x i32> <i32 384, i32 388, i32 392, i32 396>, <4 x i32>* %51
%52 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 0
%53 = load i32, i32* %52
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %54
%56 = load i32, i32* %55
ret i32 %56
}