#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int rand();
int foo() {
  char arr[10 << 20] = {};
  for (int i = 0; i < 10 << 20; ++i) {
    arr[i] = rand() % 3;
    i += rand() % 100;
  }
  int res = 0;
  while (rand() % 3)
    ++res;
  return res + arr[res % 10 << 20];
}


x86 assembly (clang, -O0):
<foo>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa00010,%rsp
lea    -0xa00000(%rbp),%rdi
xor    %esi,%esi
mov    $0xa00000,%edx
call   1030 <memset@plt>
movl   $0x0,-0xa00004(%rbp)
cmpl   $0xa00000,-0xa00004(%rbp)
jge    11a6 <foo+0x86>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %dl,%cl
movslq -0xa00004(%rbp),%rax
mov    %cl,-0xa00000(%rbp,%rax,1)
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
add    -0xa00004(%rbp),%edx
mov    %edx,-0xa00004(%rbp)
mov    -0xa00004(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa00004(%rbp)
jmp    1148 <foo+0x28>
movl   $0x0,-0xa00008(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     11dc <foo+0xbc>
mov    -0xa00008(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa00008(%rbp)
jmp    11b0 <foo+0x90>
mov    -0xa00008(%rbp),%eax
mov    %eax,-0xa0000c(%rbp)
mov    -0xa00008(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0xa0000c(%rbp),%eax
shl    $0x14,%edx
movslq %edx,%rcx
movsbl -0xa00000(%rbp,%rcx,1),%ecx
ff
add    %ecx,%eax
add    $0xa00010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<foo>:
push   %rbp
push   %rbx
sub    $0xa00008,%rsp
mov    %rsp,%rdi
mov    $0xa00000,%edx
xor    %esi,%esi
call   1030 <memset@plt>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
movslq %ebx,%rbx
mov    %al,(%rsp,%rbx,1)
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
add    %eax,%ebx
add    $0x1,%ebx
cmp    $0xa00000,%ebx
jl     1140 <foo+0x20>
mov    $0xfff00000,%ebx
mov    $0xffffffff,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <rand@plt>
imul   $0xaaaaaaab,%eax,%eax
add    $0x2aaaaaaa,%eax
add    $0x100000,%ebx
add    $0x1,%ebp
cmp    $0x55555554,%eax
ja     11b0 <foo+0x90>
mov    %ebp,%eax
mov    $0xcccccccd,%ecx
imul   %rax,%rcx
shr    $0x23,%rcx
shl    $0x15,%ecx
lea    (%rcx,%rcx,4),%eax
sub    %eax,%ebx
movsbl (%rsp,%rbx,1),%eax
add    %ebp,%eax
add    $0xa00008,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @foo() {
%1 = alloca [10485760 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = bitcast [10485760 x i8]* %1 to i8*
store i32 0, i32* %2
br label %5
5: ; preds = %19, %0
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 10485760
br i1 %7, label %8, label %22
8: ; preds = %5
%9 = call i32 (...) @rand()
%10 = srem i32 %9, 3
%11 = trunc i32 %10 to i8
%12 = load i32, i32* %2
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [10485760 x i8], [10485760 x i8]* %1, i64 0, i64 %13
store i8 %11, i8* %14
%15 = call i32 (...) @rand()
%16 = srem i32 %15, 100
%17 = load i32, i32* %2
%18 = add nsw i32 %17, %16
store i32 %18, i32* %2
br label %19
19: ; preds = %8
%20 = load i32, i32* %2
%21 = add nsw i32 %20, 1
store i32 %21, i32* %2
br label %5
22: ; preds = %5
store i32 0, i32* %3
br label %23
23: ; preds = %27, %22
%24 = call i32 (...) @rand()
%25 = srem i32 %24, 3
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i32, i32* %3
%29 = add nsw i32 %28, 1
store i32 %29, i32* %3
br label %23
30: ; preds = %23
%31 = load i32, i32* %3
%32 = load i32, i32* %3
%33 = srem i32 %32, 10
%34 = shl i32 %33, 20
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [10485760 x i8], [10485760 x i8]* %1, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = add nsw i32 %31, %38
ret i32 %39
}

LLVM IR (-O2):
define i32 @foo() {
%1 = alloca [10485760 x i8]
%2 = getelementptr inbounds [10485760 x i8], [10485760 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %0, %3
%4 = phi i32 [ 0, %0 ], [ %13, %3 ]
%5 = tail call i32 (...) @rand()
%6 = srem i32 %5, 3
%7 = trunc i32 %6 to i8
%8 = sext i32 %4 to i64
%9 = getelementptr inbounds [10485760 x i8], [10485760 x i8]* %1, i64 0, i64 %8
store i8 %7, i8* %9
%10 = tail call i32 (...) @rand()
%11 = srem i32 %10, 100
%12 = add nsw i32 %4, 1
%13 = add i32 %12, %11
%14 = icmp slt i32 %13, 10485760
br i1 %14, label %3, label %15
15: ; preds = %3, %15
%16 = phi i32 [ %20, %15 ], [ 0, %3 ]
%17 = tail call i32 (...) @rand()
%18 = srem i32 %17, 3
%19 = icmp eq i32 %18, 0
%20 = add nuw nsw i32 %16, 1
br i1 %19, label %21, label %15
21: ; preds = %15
%22 = urem i32 %16, 10
%23 = shl nuw nsw i32 %22, 20
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds [10485760 x i8], [10485760 x i8]* %1, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = add nsw i32 %16, %27
ret i32 %28
}