#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 neg(int);
size_t sub_one(int);
int main() {
  int i, j, x, y;
  int a[10] = {};
  j = 0;
  for (i = 0; i < 10; i++) {
    if (i % 2 != 0)
      j++;
    else
      j--;
    a[sub_one(i)] = j;
  }
  x = neg(5);
  y = a[x];
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jge    11b5 <main+0x85>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1189 <main+0x59>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1192 <main+0x62>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <sub_one@plt>
mov    -0x44(%rbp),%ecx
mov    %ecx,-0x40(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    115d <main+0x2d>
mov    $0x5,%edi
call   1030 <neg@plt>
mov    %eax,-0x10(%rbp)
movslq -0x10(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %edi,%edi
call   1040 <sub_one@plt>
mov    $0x1,%edi
call   1040 <sub_one@plt>
mov    $0x2,%edi
call   1040 <sub_one@plt>
mov    $0x3,%edi
call   1040 <sub_one@plt>
mov    $0x4,%edi
call   1040 <sub_one@plt>
mov    $0x5,%edi
call   1040 <sub_one@plt>
mov    $0x6,%edi
call   1040 <sub_one@plt>
mov    $0x7,%edi
call   1040 <sub_one@plt>
mov    $0x8,%edi
call   1040 <sub_one@plt>
mov    $0x9,%edi
call   1040 <sub_one@plt>
mov    $0x5,%edi
call   1030 <neg@plt>
xor    %eax,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
define i32 @main() {
%1 = tail call i64 @sub_one(i32 0)
%2 = tail call i64 @sub_one(i32 1)
%3 = tail call i64 @sub_one(i32 2)
%4 = tail call i64 @sub_one(i32 3)
%5 = tail call i64 @sub_one(i32 4)
%6 = tail call i64 @sub_one(i32 5)
%7 = tail call i64 @sub_one(i32 6)
%8 = tail call i64 @sub_one(i32 7)
%9 = tail call i64 @sub_one(i32 8)
%10 = tail call i64 @sub_one(i32 9)
%11 = tail call i32 @neg(i32 5)
ret i32 0
}