#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 /*<<< orphan*/ foo(int *);
int rand();
int main() {
  int i, j, x[32] = {0, 1, 2, 4, 2, 2, 1, 0};
  foo(x);
  for (i = 0; i < 32; i++) {
    for (j = 0; j < 32; j++)
      x[j] = rand() & 3;
    x[rand() & 31] = 4;
    foo(x);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1030 <memset@plt>
movl   $0x1,-0x8c(%rbp)
movl   $0x2,-0x88(%rbp)
movl   $0x4,-0x84(%rbp)
movl   $0x2,-0x80(%rbp)
movl   $0x2,-0x7c(%rbp)
movl   $0x1,-0x78(%rbp)
lea    -0x90(%rbp),%rdi
call   1040 <foo@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x20,-0x8(%rbp)
jge    120c <main+0xdc>
movl   $0x0,-0xc(%rbp)
cmpl   $0x20,-0xc(%rbp)
jge    11db <main+0xab>
mov    $0x0,%al
call   1050 <rand@plt>
mov    %eax,%ecx
and    $0x3,%ecx
movslq -0xc(%rbp),%rax
mov    %ecx,-0x90(%rbp,%rax,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11ac <main+0x7c>
mov    $0x0,%al
call   1050 <rand@plt>
and    $0x1f,%eax
cltq
movl   $0x4,-0x90(%rbp,%rax,4)
lea    -0x90(%rbp),%rdi
call   1040 <foo@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    119b <main+0x6b>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps 0xea4(%rip),%xmm0
movups %xmm0,0x4(%rsp)
movabs $0x100000002,%rax
mov    %rax,0x14(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
call   1030 <foo@plt>
xor    %ebp,%ebp
nopl   (%rax)
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <rand@plt>
and    $0x3,%eax
mov    %eax,(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x20,%rbx
jne    1190 <main+0x70>
xor    %eax,%eax
call   1040 <rand@plt>
and    $0x1f,%eax
movl   $0x4,(%rsp,%rax,4)
mov    %r14,%rdi
call   1030 <foo@plt>
add    $0x1,%ebp
cmp    $0x20,%ebp
jne    1180 <main+0x60>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @main() {
%1 = alloca [32 x i32]
%2 = bitcast [32 x i32]* %1 to i8*
%3 = getelementptr inbounds [32 x i32], [32 x i32]* %1, i64 0, i64 1
%4 = bitcast i32* %3 to <4 x i32>*
store <4 x i32> <i32 1, i32 2, i32 4, i32 2>, <4 x i32>* %4
%5 = getelementptr inbounds [32 x i32], [32 x i32]* %1, i64 0, i64 5
store i32 2, i32* %5
%6 = getelementptr inbounds [32 x i32], [32 x i32]* %1, i64 0, i64 6
store i32 1, i32* %6
%7 = getelementptr inbounds [32 x i32], [32 x i32]* %1, i64 0, i64 0
%8 = call i32 @foo(i32* %7)
br label %9
9: ; preds = %0, %18
%10 = phi i32 [ 0, %0 ], [ %24, %18 ]
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ 0, %9 ], [ %16, %11 ]
%13 = call i32 (...) @rand()
%14 = and i32 %13, 3
%15 = getelementptr inbounds [32 x i32], [32 x i32]* %1, i64 0, i64 %12
store i32 %14, i32* %15
%16 = add nuw nsw i64 %12, 1
%17 = icmp eq i64 %16, 32
br i1 %17, label %18, label %11
18: ; preds = %11
%19 = call i32 (...) @rand()
%20 = and i32 %19, 31
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds [32 x i32], [32 x i32]* %1, i64 0, i64 %21
store i32 4, i32* %22
%23 = call i32 @foo(i32* %7)
%24 = add nuw nsw i32 %10, 1
%25 = icmp eq i32 %24, 32
br i1 %25, label %26, label %9
26: ; preds = %18
ret i32 0
}