#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 getIntArray(int *, int, int /*<<< orphan*/);
int linear(int *, int, int);
int /*<<< orphan*/ printIntArray(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int x[10];
  int hmny;
  int who;
  int where;
  hmny = getIntArray(x, 10, 0);
  printf("The array was: \n");
  printIntArray(x, hmny);
  printf("Now we do linear searches on this data\n");
  do {
    printf("Enter integer to search for [0 to terminate] : ");
    scanf("%d", &who);
    if (who == 0)
      break;
    where = linear(x, hmny, who);
    if (where < 0) {
      printf("Sorry, %d is not in the array\n", who);
    } else
      printf("%d is at position %d\n", who, where);
  } while (1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0xa,%esi
xor    %edx,%edx
call   1070 <getIntArray@plt>
mov    %eax,-0x34(%rbp)
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1060 <printIntArray@plt>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeba(%rip),%rdi
lea    -0x38(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,-0x38(%rbp)
jne    11c7 <main+0x77>
jmp    1221 <main+0xd1>
lea    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x38(%rbp),%edx
call   1040 <linear@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    11f9 <main+0xa9>
mov    -0x38(%rbp),%esi
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    120d <main+0xbd>
mov    -0x38(%rbp),%esi
mov    -0x3c(%rbp),%edx
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1212 <main+0xc2>
mov    $0x1,%al
test   $0x1,%al
jne    119a <main+0x4a>
jmp    1221 <main+0xd1>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0xa,%esi
xor    %edx,%edx
call   1080 <getIntArray@plt>
mov    %eax,%ebx
lea    0xedd(%rip),%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
mov    %ebx,%esi
call   1070 <printIntArray@plt>
lea    0xed7(%rip),%rdi
call   1030 <puts@plt>
lea    0xe53(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe75(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%edx
test   %edx,%edx
je     123b <main+0xdb>
lea    0x10(%rsp),%r14
lea    0xe27(%rip),%r12
lea    0xe50(%rip),%r13
lea    0xc(%rsp),%rbp
lea    0xe66(%rip),%r15
jmp    1219 <main+0xb9>
xchg   %ax,%ax
mov    %r15,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%edx
test   %edx,%edx
je     123b <main+0xdb>
mov    %r14,%rdi
mov    %ebx,%esi
call   1050 <linear@plt>
mov    0xc(%rsp),%esi
test   %eax,%eax
jns    11f0 <main+0x90>
lea    0xe01(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11fc <main+0x9c>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"The array was: \0A\00"
@.str.1 = [40 x i8] c"Now we do linear searches on this data\0A\00"
@.str.2 = [48 x i8] c"Enter integer to search for [0 to terminate] : \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [31 x i8] c"Sorry, %d is not in the array\0A\00"
@.str.5 = [22 x i8] c"%d is at position %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%7 = call i32 @getIntArray(i32* %6, i32 10, i32 0)
store i32 %7, i32* %3
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%10 = load i32, i32* %3
%11 = call i32 @printIntArray(i32* %9, i32 %10)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %34, %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %13
br label %35
19: ; preds = %13
%20 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%21 = load i32, i32* %3
%22 = load i32, i32* %4
%23 = call i32 @linear(i32* %20, i32 %21, i32 %22)
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %19
%27 = load i32, i32* %4
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %27)
br label %33
29: ; preds = %19
%30 = load i32, i32* %4
%31 = load i32, i32* %5
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i32 %30, i32 %31)
br label %33
33: ; preds = %29, %26
br label %34
34: ; preds = %33
br i1 true, label %13, label %35
35: ; preds = %34, %18
%36 = load i32, i32* %1
ret i32 %36
}

LLVM IR (-O2):
@.str.2 = [48 x i8] c"Enter integer to search for [0 to terminate] : \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [31 x i8] c"Sorry, %d is not in the array\0A\00"
@.str.5 = [22 x i8] c"%d is at position %d\0A\00"
@str = [16 x i8] c"The array was: \00"
@str.6 = [39 x i8] c"Now we do linear searches on this data\00"
define i32 @main() {
%1 = alloca [10 x i32]
%2 = alloca i32
%3 = bitcast [10 x i32]* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
%6 = call i32 @getIntArray(i32* %5, i32 10, i32 0)
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%8 = call i32 @printIntArray(i32* %5, i32 %6)
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.6, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%12 = load i32, i32* %2
%13 = icmp eq i32 %12, 0
br i1 %13, label %28, label %14
14: ; preds = %0, %23
%15 = phi i32 [ %26, %23 ], [ %12, %0 ]
%16 = call i32 @linear(i32* %5, i32 %6, i32 %15)
%17 = icmp slt i32 %16, 0
%18 = load i32, i32* %2
br i1 %17, label %19, label %21
19: ; preds = %14
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %18)
br label %23
21: ; preds = %14
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i32 %18, i32 %16)
br label %23
23: ; preds = %19, %21
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%26 = load i32, i32* %2
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %14
28: ; preds = %23, %0
ret i32 0
}