#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 /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int arr[10] = {1, 2, 3, 9, 11, 13, 17, 25, 57, 90};
  int mid = 0, lower = 0, upper = 10 - 1, key = 0, found = 0;
  printf("Enter number to search for: ");
  scanf("%d", &key);
  for (mid = (lower + upper) / 2; lower <= upper; mid = (lower + upper) / 2) {
    if (arr[mid] == key) {
      printf("Your number is at position %d of our array\n", mid);
      found = 1;
      break;
    }
    if (arr[mid] > key)
      upper = mid - 1;
    else
      lower = mid + 1;
  }
  if (!found)
    printf("%d is not in the array\n", key);
  return 0;
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xeb6(%rip),%rsi
mov    $0x28,%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x9,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb9(%rip),%rdi
lea    -0x40(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x38(%rbp),%eax
add    -0x3c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x34(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jg     1223 <main+0xf3>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
cmp    -0x40(%rbp),%eax
jne    11e0 <main+0xb0>
mov    -0x34(%rbp),%esi
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x44(%rbp)
jmp    1223 <main+0xf3>
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
cmp    -0x40(%rbp),%eax
jle    11ff <main+0xcf>
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1208 <main+0xd8>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    120d <main+0xdd>
mov    -0x38(%rbp),%eax
add    -0x3c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x34(%rbp)
jmp    11a6 <main+0x76>
cmpl   $0x0,-0x44(%rbp)
jne    123e <main+0x10e>
mov    -0x40(%rbp),%esi
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
lea    0xef4(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf01(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    $0x4,%eax
mov    $0x9,%ecx
mov    0xc(%rsp),%esi
lea    0xe9d(%rip),%r8
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movslq %eax,%rdi
mov    (%r8,%rdi,4),%edi
cmp    %esi,%edi
je     11a2 <main+0x82>
lea    -0x1(%rax),%edx
add    $0x1,%eax
cmp    %esi,%edi
cmovle %eax,%ebx
cmovg  %edx,%ecx
lea    (%rbx,%rcx,1),%edx
mov    %edx,%eax
shr    $0x1f,%eax
add    %edx,%eax
sar    %eax
cmp    %ecx,%ebx
jle    1170 <main+0x50>
lea    0xed4(%rip),%rdi
jmp    11ab <main+0x8b>
lea    0xe9f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.arr = [10 x i32] [i32 1, i32 2, i32 3, i32 9, i32 11, i32 13, i32 17, i32 25, i32 57, i32 90]
@.str = [29 x i8] c"Enter number to search for: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [44 x i8] c"Your number is at position %d of our array\0A\00"
@.str.3 = [24 x i8] c"%d is not in the array\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = bitcast [10 x i32]* %2 to i8*
store i32 0, i32* %3
store i32 0, i32* %4
store i32 9, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%11 = load i32, i32* %4
%12 = load i32, i32* %5
%13 = add nsw i32 %11, %12
%14 = sdiv i32 %13, 2
store i32 %14, i32* %3
br label %15
15: ; preds = %43, %0
%16 = load i32, i32* %4
%17 = load i32, i32* %5
%18 = icmp sle i32 %16, %17
br i1 %18, label %19, label %48
19: ; preds = %15
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %21
%23 = load i32, i32* %22
%24 = load i32, i32* %6
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %29
26: ; preds = %19
%27 = load i32, i32* %3
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 %27)
store i32 1, i32* %7
br label %48
29: ; preds = %19
%30 = load i32, i32* %3
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %31
%33 = load i32, i32* %32
%34 = load i32, i32* %6
%35 = icmp sgt i32 %33, %34
br i1 %35, label %36, label %39
36: ; preds = %29
%37 = load i32, i32* %3
%38 = sub nsw i32 %37, 1
store i32 %38, i32* %5
br label %42
39: ; preds = %29
%40 = load i32, i32* %3
%41 = add nsw i32 %40, 1
store i32 %41, i32* %4
br label %42
42: ; preds = %39, %36
br label %43
43: ; preds = %42
%44 = load i32, i32* %4
%45 = load i32, i32* %5
%46 = add nsw i32 %44, %45
%47 = sdiv i32 %46, 2
store i32 %47, i32* %3
br label %15
48: ; preds = %26, %15
%49 = load i32, i32* %7
%50 = icmp ne i32 %49, 0
br i1 %50, label %54, label %51
51: ; preds = %48
%52 = load i32, i32* %6
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %52)
br label %54
54: ; preds = %51, %48
ret i32 0
}

LLVM IR (-O2):
@__const.main.arr = [10 x i32] [i32 1, i32 2, i32 3, i32 9, i32 11, i32 13, i32 17, i32 25, i32 57, i32 90]
@.str = [29 x i8] c"Enter number to search for: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [44 x i8] c"Your number is at position %d of our array\0A\00"
@.str.3 = [24 x i8] c"%d is not in the array\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
br label %6
6: ; preds = %0, %16
%7 = phi i32 [ 9, %0 ], [ %21, %16 ]
%8 = phi i32 [ 0, %0 ], [ %20, %16 ]
%9 = phi i32 [ 4, %0 ], [ %23, %16 ]
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [10 x i32], [10 x i32]* @__const.main.arr, i64 0, i64 %10
%12 = load i32, i32* %11
%13 = icmp eq i32 %12, %5
br i1 %13, label %14, label %16
14: ; preds = %6
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 %9)
br label %27
16: ; preds = %6
%17 = icmp sgt i32 %12, %5
%18 = add nsw i32 %9, -1
%19 = add nsw i32 %9, 1
%20 = select i1 %17, i32 %8, i32 %19
%21 = select i1 %17, i32 %18, i32 %7
%22 = add nsw i32 %20, %21
%23 = sdiv i32 %22, 2
%24 = icmp sgt i32 %20, %21
br i1 %24, label %25, label %6
25: ; preds = %16
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %5)
br label %27
27: ; preds = %14, %25
ret i32 0
}