#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 atoi(char *);
int binary_search(int, int *, int);
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(int argc, char *argv[]) {
  int size, i, search, result;
  size = argc - 1;
  printf("%d\n", size);
  int *array;
  array = malloc(size * sizeof(int));
  for (i = 1; i < argc; i++) {
    array[i - 1] = atoi(argv[i]);
  }
  printf("Enter the number you wish to look for:");
  scanf("%d", &search);
  result = binary_search(search, array, size);
  if (result == -1) {
    printf("Number not found.\n");
  } else {
    printf("Number at index %d.\n", result);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11d7 <main+0x87>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1070 <atoi@plt>
mov    %eax,%edx
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    119a <main+0x4a>
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe3f(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <binary_search@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    1224 <main+0xd4>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1235 <main+0xe5>
mov    -0x20(%rbp),%esi
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %edi,%r15d
lea    -0x1(%r15),%r14d
lea    0xe84(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    -0x4(,%r15,4),%edi
ff
call   1050 <malloc@plt>
mov    %rax,%r13
cmp    $0x2,%r15d
jl     11c8 <main+0x68>
mov    %r15d,%ebp
add    $0xffffffffffffffff,%rbp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x8(%r12,%rbx,8),%rdi
call   1080 <atoi@plt>
mov    %eax,0x0(%r13,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11b0 <main+0x50>
lea    0xe35(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe4e(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
mov    0x4(%rsp),%edi
mov    %r13,%rsi
mov    %r14d,%edx
call   1060 <binary_search@plt>
cmp    $0xffffffff,%eax
je     120d <main+0xad>
lea    0xe2c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1219 <main+0xb9>
lea    0xe2f(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [39 x i8] c"Enter the number you wish to look for:\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [19 x i8] c"Number not found.\0A\00"
@.str.4 = [21 x i8] c"Number at index %d.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = sub nsw i32 %11, 1
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = mul i64 %16, 4
%18 = trunc i64 %17 to i32
%19 = call i32* @malloc(i32 %18)
store i32* %19, i32** %10
store i32 1, i32* %7
br label %20
20: ; preds = %36, %2
%21 = load i32, i32* %7
%22 = load i32, i32* %4
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %39
24: ; preds = %20
%25 = load i8**, i8*** %5
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %25, i64 %27
%29 = load i8*, i8** %28
%30 = call i32 @atoi(i8* %29)
%31 = load i32*, i32** %10
%32 = load i32, i32* %7
%33 = sub nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %31, i64 %34
store i32 %30, i32* %35
br label %36
36: ; preds = %24
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %20
39: ; preds = %20
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%41 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %8)
%42 = load i32, i32* %8
%43 = load i32*, i32** %10
%44 = load i32, i32* %6
%45 = call i32 @binary_search(i32 %42, i32* %43, i32 %44)
store i32 %45, i32* %9
%46 = load i32, i32* %9
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %50
48: ; preds = %39
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %53
50: ; preds = %39
%51 = load i32, i32* %9
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %51)
br label %53
53: ; preds = %50, %48
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [39 x i8] c"Enter the number you wish to look for:\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.4 = [21 x i8] c"Number at index %d.\0A\00"
@str = [18 x i8] c"Number not found.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = add nsw i32 %0, -1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = shl i32 %5, 2
%8 = tail call i32* @malloc(i32 %7)
%9 = icmp sgt i32 %0, 1
br i1 %9, label %10, label %21
10: ; preds = %2
%11 = zext i32 %0 to i64
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ 1, %10 ], [ %19, %12 ]
%14 = getelementptr inbounds i8*, i8** %1, i64 %13
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = add nsw i64 %13, -1
%18 = getelementptr inbounds i32, i32* %8, i64 %17
store i32 %16, i32* %18
%19 = add nuw nsw i64 %13, 1
%20 = icmp eq i64 %19, %11
br i1 %20, label %21, label %12
21: ; preds = %12, %2
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%24 = load i32, i32* %3
%25 = call i32 @binary_search(i32 %24, i32* %8, i32 %5)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %21
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %31
29: ; preds = %21
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %25)
br label %31
31: ; preds = %29, %27
ret i32 0
}