#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int fscanf(int /*<<< orphan*/ *, char *, int *);
int arraySearch(FILE *in, int size, int needle) {
  int array[size];
  for (int i = 0; i < size && fscanf(in, "%d", &array[i]) == 1; i++) {
    if (array[i] == needle) {
      return i;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<arraySearch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%ecx
xor    %eax,%eax
cmp    -0x14(%rbp),%ecx
mov    %al,-0x39(%rbp)
jge    1189 <arraySearch+0x79>
mov    -0x38(%rbp),%rdx
mov    -0x10(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xe85(%rip),%rsi
call   1030 <fscanf@plt>
cmp    $0x1,%eax
sete   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    1199 <arraySearch+0x89>
jmp    11d2 <arraySearch+0xc2>
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x18(%rbp),%eax
jne    11bf <arraySearch+0xaf>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    11e0 <arraySearch+0xd0>
jmp    11c4 <arraySearch+0xb4>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1150 <arraySearch+0x40>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arraySearch>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rsp,%rbx
lea    0xf(,%r15,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    $0xffffffff,%eax
test   %esi,%esi
jle    1186 <arraySearch+0x76>
mov    %edx,%r14d
mov    %rdi,%r12
neg    %r15
xor    %r13d,%r13d
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
lea    0xea6(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fscanf@plt>
cmp    $0x1,%eax
jne    1179 <arraySearch+0x69>
cmp    %r14d,(%rbx)
je     1180 <arraySearch+0x70>
add    $0xffffffffffffffff,%r13
add    $0x4,%rbx
cmp    %r13,%r15
jne    1150 <arraySearch+0x40>
mov    $0xffffffff,%eax
jmp    1186 <arraySearch+0x76>
neg    %r13d
mov    %r13d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @arraySearch(i32* nocapture %0, i32 %1, i32 %2) {
%4 = zext i32 %1 to i64
%5 = alloca i32, i64 %4
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %20
7: ; preds = %3, %15
%8 = phi i64 [ %16, %15 ], [ 0, %3 ]
%9 = getelementptr inbounds i32, i32* %5, i64 %8
%10 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %9)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %20
12: ; preds = %7
%13 = load i32, i32* %9
%14 = icmp eq i32 %13, %2
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = add nuw nsw i64 %8, 1
%17 = icmp eq i64 %16, %4
br i1 %17, label %20, label %7
18: ; preds = %12
%19 = trunc i64 %8 to i32
br label %20
20: ; preds = %7, %15, %18, %3
%21 = phi i32 [ -1, %3 ], [ %19, %18 ], [ -1, %15 ], [ -1, %7 ]
ret i32 %21
}