#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 binary_search(int *, int, int);
int binary_search0(int *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, int *);
int main() {
  int a[128];
  int i, n = 0;
  printf("input: ");
  while (1 == scanf("%d", &a[n])) {
    n++;
  }
  while (1) {
    printf("searching for: ");
    if (1 == scanf("%d", &i)) {
      printf("found at: %d vs %d\n", binary_search(a, n, i),
             binary_search0(a, n, i));
    } else
      break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x218(%rbp)
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x218(%rbp),%rax
lea    -0x210(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe82(%rip),%rdi
call   1060 <scanf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
jne    11ae <main+0x6e>
mov    -0x218(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x218(%rbp)
jmp    116a <main+0x2a>
jmp    11b3 <main+0x73>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe40(%rip),%rdi
lea    -0x214(%rbp),%rsi
call   1060 <scanf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
jne    1234 <main+0xf4>
lea    -0x210(%rbp),%rdi
mov    -0x218(%rbp),%esi
mov    -0x214(%rbp),%edx
call   1050 <binary_search@plt>
mov    %eax,-0x21c(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x218(%rbp),%esi
mov    -0x214(%rbp),%edx
call   1040 <binary_search0@plt>
mov    -0x21c(%rbp),%esi
mov    %eax,%edx
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1239 <main+0xf9>
jmp    123e <main+0xfe>
jmp    11b3 <main+0x73>
xor    %eax,%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
lea    0xea8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%ebx
lea    0x10(%rsp),%rbp
lea    0xe98(%rip),%r14
mov    %r14,%rdi
mov    %rbp,%rsi
call   1060 <scanf@plt>
add    $0x1,%ebx
add    $0x4,%rbp
cmp    $0x1,%eax
je     1170 <main+0x30>
lea    0xe7d(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe6c(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    121c <main+0xdc>
lea    0x10(%rsp),%r14
lea    0xe54(%rip),%r12
lea    0xe4a(%rip),%r13
lea    0xc(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0xc(%rsp),%edx
mov    %r14,%rdi
mov    %ebx,%esi
call   1050 <binary_search@plt>
mov    %eax,%r15d
mov    0xc(%rsp),%edx
mov    %r14,%rdi
mov    %ebx,%esi
call   1040 <binary_search0@plt>
lea    0xe25(%rip),%rdi
mov    %r15d,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
je     11d0 <main+0x90>
xor    %eax,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"input: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [16 x i8] c"searching for: \00"
@.str.3 = [20 x i8] c"found at: %d vs %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [128 x i32]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %12, %0
%7 = load i32, i32* %4
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [128 x i32], [128 x i32]* %2, i64 0, i64 %8
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %9)
%11 = icmp eq i32 1, %10
br i1 %11, label %12, label %15
12: ; preds = %6
%13 = load i32, i32* %4
%14 = add nsw i32 %13, 1
store i32 %14, i32* %4
br label %6
15: ; preds = %6
br label %16
16: ; preds = %15, %31
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%19 = icmp eq i32 1, %18
br i1 %19, label %20, label %30
20: ; preds = %16
%21 = getelementptr inbounds [128 x i32], [128 x i32]* %2, i64 0, i64 0
%22 = load i32, i32* %4
%23 = load i32, i32* %3
%24 = call i32 @binary_search(i32* %21, i32 %22, i32 %23)
%25 = getelementptr inbounds [128 x i32], [128 x i32]* %2, i64 0, i64 0
%26 = load i32, i32* %4
%27 = load i32, i32* %3
%28 = call i32 @binary_search0(i32* %25, i32 %26, i32 %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %24, i32 %28)
br label %31
30: ; preds = %16
br label %32
31: ; preds = %20
br label %16
32: ; preds = %30
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"input: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [16 x i8] c"searching for: \00"
@.str.3 = [20 x i8] c"found at: %d vs %d\0A\00"
define i32 @main() {
%1 = alloca [128 x i32]
%2 = alloca i32
%3 = bitcast [128 x i32]* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %6, %0
%7 = phi i64 [ %11, %6 ], [ 0, %0 ]
%8 = getelementptr inbounds [128 x i32], [128 x i32]* %1, i64 0, i64 %7
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %8)
%10 = icmp eq i32 %9, 1
%11 = add nuw i64 %7, 1
br i1 %10, label %6, label %12
12: ; preds = %6
%13 = trunc i64 %7 to i32
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %28
17: ; preds = %12
%18 = getelementptr inbounds [128 x i32], [128 x i32]* %1, i64 0, i64 0
br label %19
19: ; preds = %17, %19
%20 = load i32, i32* %2
%21 = call i32 @binary_search(i32* %18, i32 %13, i32 %20)
%22 = load i32, i32* %2
%23 = call i32 @binary_search0(i32* %18, i32 %13, i32 %22)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %21, i32 %23)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%27 = icmp eq i32 %26, 1
br i1 %27, label %19, label %28
28: ; preds = %19, %12
ret i32 0
}