#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*/ printf(char *, int, ...);
int inArray(int test, int array[], int size) {
  printf("array[1] is %d, test term is %d", array[1], test);
  int res = 0, array_max, i;
  array_max = size;
  printf("array max is %d\n", array_max);
  for (i = 0; i < array_max; i++) {
    printf("i = %d\n", i);
    if (test == array[i]) {
      res++;
    }
  }
  if (res > 0) {
    return (1);
  } else {
    return (0);
  }
}


x86 assembly (clang, -O0):
<inArray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x8(%rbp),%edx
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xecf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11ac <inArray+0x9c>
mov    -0x20(%rbp),%esi
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    -0x10(%rbp),%rcx
movslq -0x20(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jne    1199 <inArray+0x89>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    119e <inArray+0x8e>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    115f <inArray+0x4f>
cmpl   $0x0,-0x18(%rbp)
jle    11c2 <inArray+0xb2>
movl   $0x1,-0x4(%rbp)
jmp    11c9 <inArray+0xb9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inArray>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
mov    %edi,%r12d
mov    0x4(%rsi),%esi
lea    0xed2(%rip),%rdi
xor    %ebx,%ebx
mov    %r12d,%edx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xedf(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
test   %r14d,%r14d
jle    1187 <inArray+0x77>
mov    %r14d,%r13d
lea    0xed7(%rip),%r14
xor    %ebx,%ebx
xor    %ebp,%ebp
xchg   %ax,%ax
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
cmp    %r12d,(%r15,%rbx,4)
sete   %al
add    %eax,%ebp
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1160 <inArray+0x50>
xor    %ebx,%ebx
test   %ebp,%ebp
setne  %bl
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"array[1] is %d, test term is %d\00"
@.str.1 = [17 x i8] c"array max is %d\0A\00"
@.str.2 = [8 x i8] c"i = %d\0A\00"
define i32 @inArray(i32 %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%11 = load i32*, i32** %6
%12 = getelementptr inbounds i32, i32* %11, i64 1
%13 = load i32, i32* %12
%14 = load i32, i32* %5
%15 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %14)
store i32 0, i32* %8
%16 = load i32, i32* %7
store i32 %16, i32* %9
%17 = load i32, i32* %9
%18 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %17)
store i32 0, i32* %10
br label %19
19: ; preds = %37, %3
%20 = load i32, i32* %10
%21 = load i32, i32* %9
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %40
23: ; preds = %19
%24 = load i32, i32* %10
%25 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %5
%27 = load i32*, i32** %6
%28 = load i32, i32* %10
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = load i32, i32* %30
%32 = icmp eq i32 %26, %31
br i1 %32, label %33, label %36
33: ; preds = %23
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
store i32 %35, i32* %8
br label %36
36: ; preds = %33, %23
br label %37
37: ; preds = %36
%38 = load i32, i32* %10
%39 = add nsw i32 %38, 1
store i32 %39, i32* %10
br label %19
40: ; preds = %19
%41 = load i32, i32* %8
%42 = icmp sgt i32 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %40
store i32 1, i32* %4
br label %45
44: ; preds = %40
store i32 0, i32* %4
br label %45
45: ; preds = %44, %43
%46 = load i32, i32* %4
ret i32 %46
}

LLVM IR (-O2):
@.str = [32 x i8] c"array[1] is %d, test term is %d\00"
@.str.1 = [17 x i8] c"array max is %d\0A\00"
@.str.2 = [8 x i8] c"i = %d\0A\00"
define i32 @inArray(i32 %0, i32* nocapture %1, i32 %2) {
%4 = getelementptr inbounds i32, i32* %1, i64 1
%5 = load i32, i32* %4
%6 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %0)
%7 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%8 = icmp sgt i32 %2, 0
br i1 %8, label %9, label %26
9: ; preds = %3
%10 = zext i32 %2 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ 0, %9 ], [ %21, %11 ]
%13 = phi i32 [ 0, %9 ], [ %20, %11 ]
%14 = trunc i64 %12 to i32
%15 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = getelementptr inbounds i32, i32* %1, i64 %12
%17 = load i32, i32* %16
%18 = icmp eq i32 %17, %0
%19 = zext i1 %18 to i32
%20 = add nuw nsw i32 %13, %19
%21 = add nuw nsw i64 %12, 1
%22 = icmp eq i64 %21, %10
br i1 %22, label %23, label %11
23: ; preds = %11
%24 = icmp ne i32 %20, 0
%25 = zext i1 %24 to i32
br label %26
26: ; preds = %23, %3
%27 = phi i32 [ 0, %3 ], [ %25, %23 ]
ret i32 %27
}