#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() {
  int a[100], x, i;
  for (i = 0; i < 100; i++)
    a[i] = i * 5;
  printf("Enter a number to search: ");
  scanf("%d", &x);
  int mid = 100 / 2, low = 0, high = 100;
  while (1) {
    if (low > high) {
      mid = -1;
      break;
    }
    mid = (low + high) / 2;
    if (x == a[mid])
      break;
    if (x < a[mid]) {
      high = mid - 1;
      continue;
    } else {
      low = mid + 1;
      continue;
    }
  }
  printf("Given number is at position: %d\n", mid);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1a8(%rbp)
cmpl   $0x64,-0x1a8(%rbp)
jge    1172 <main+0x52>
imul   $0x5,-0x1a8(%rbp),%ecx
movslq -0x1a8(%rbp),%rax
mov    %ecx,-0x1a0(%rbp,%rax,4)
mov    -0x1a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a8(%rbp)
jmp    113c <main+0x1c>
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe94(%rip),%rdi
lea    -0x1a4(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x32,-0x1ac(%rbp)
movl   $0x0,-0x1b0(%rbp)
movl   $0x64,-0x1b4(%rbp)
mov    -0x1b0(%rbp),%eax
cmp    -0x1b4(%rbp),%eax
jle    11d2 <main+0xb2>
movl   $0xffffffff,-0x1ac(%rbp)
ff ff ff
jmp    124d <main+0x12d>
mov    -0x1b0(%rbp),%eax
add    -0x1b4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1ac(%rbp)
mov    -0x1a4(%rbp),%eax
movslq -0x1ac(%rbp),%rcx
cmp    -0x1a0(%rbp,%rcx,4),%eax
jne    120b <main+0xeb>
jmp    124d <main+0x12d>
mov    -0x1a4(%rbp),%eax
movslq -0x1ac(%rbp),%rcx
cmp    -0x1a0(%rbp,%rcx,4),%eax
jge    1239 <main+0x119>
mov    -0x1ac(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1b4(%rbp)
jmp    11b1 <main+0x91>
mov    -0x1ac(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1b0(%rbp)
jmp    11b1 <main+0x91>
mov    -0x1ac(%rbp),%esi
lea    0xdc4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x1a0,%rsp
movaps 0xed1(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xed5(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xed9(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xedd(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xee1(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xee5(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xee9(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xeed(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xeee(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movaps 0xeef(%rip),%xmm0
movaps %xmm0,0xa0(%rsp)
movaps 0xef0(%rip),%xmm0
movaps %xmm0,0xb0(%rsp)
movaps 0xef1(%rip),%xmm0
movaps %xmm0,0xc0(%rsp)
movaps 0xef2(%rip),%xmm0
movaps %xmm0,0xd0(%rsp)
movaps 0xef3(%rip),%xmm0
movaps %xmm0,0xe0(%rsp)
movaps 0xef4(%rip),%xmm0
movaps %xmm0,0xf0(%rsp)
movaps 0xef5(%rip),%xmm0
movaps %xmm0,0x100(%rsp)
movaps 0xef6(%rip),%xmm0
movaps %xmm0,0x110(%rsp)
movaps 0xef7(%rip),%xmm0
movaps %xmm0,0x120(%rsp)
movaps 0xef8(%rip),%xmm0
movaps %xmm0,0x130(%rsp)
movaps 0xef9(%rip),%xmm0
movaps %xmm0,0x140(%rsp)
movaps 0xefa(%rip),%xmm0
movaps %xmm0,0x150(%rsp)
movaps 0xefb(%rip),%xmm0
movaps %xmm0,0x160(%rsp)
movaps 0xefc(%rip),%xmm0
movaps %xmm0,0x170(%rsp)
movaps 0xefd(%rip),%xmm0
movaps %xmm0,0x180(%rsp)
movaps 0xefe(%rip),%xmm0
movaps %xmm0,0x190(%rsp)
lea    0xeff(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf0a(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    $0x64,%ecx
mov    0xc(%rsp),%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%rcx,%rbx,1),%edx
mov    %edx,%esi
shr    $0x1f,%esi
add    %edx,%esi
sar    %esi
movslq %esi,%rdx
cmp    0x10(%rsp,%rdx,4),%eax
je     12ec <main+0x1cc>
jge    12e0 <main+0x1c0>
lea    -0x1(%rsi),%ecx
cmp    %esi,%ebx
jl     12c0 <main+0x1a0>
jmp    12e7 <main+0x1c7>
lea    0x1(%rsi),%ebx
cmp    %ecx,%esi
jl     12c0 <main+0x1a0>
mov    $0xffffffff,%esi
lea    0xebb(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x1a0,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [27 x i8] c"Enter a number to search: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [33 x i8] c"Given number is at position: %d\0A\00"
define i32 @main() {
%1 = alloca [100 x i32]
%2 = alloca i32
%3 = bitcast [100 x i32]* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = bitcast [100 x i32]* %1 to <4 x i32>*
store <4 x i32> <i32 0, i32 5, i32 10, i32 15>, <4 x i32>* %5
%6 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 4
%7 = bitcast i32* %6 to <4 x i32>*
store <4 x i32> <i32 20, i32 25, i32 30, i32 35>, <4 x i32>* %7
%8 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 8
%9 = bitcast i32* %8 to <4 x i32>*
store <4 x i32> <i32 40, i32 45, i32 50, i32 55>, <4 x i32>* %9
%10 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 12
%11 = bitcast i32* %10 to <4 x i32>*
store <4 x i32> <i32 60, i32 65, i32 70, i32 75>, <4 x i32>* %11
%12 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 16
%13 = bitcast i32* %12 to <4 x i32>*
store <4 x i32> <i32 80, i32 85, i32 90, i32 95>, <4 x i32>* %13
%14 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 20
%15 = bitcast i32* %14 to <4 x i32>*
store <4 x i32> <i32 100, i32 105, i32 110, i32 115>, <4 x i32>* %15
%16 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 24
%17 = bitcast i32* %16 to <4 x i32>*
store <4 x i32> <i32 120, i32 125, i32 130, i32 135>, <4 x i32>* %17
%18 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 28
%19 = bitcast i32* %18 to <4 x i32>*
store <4 x i32> <i32 140, i32 145, i32 150, i32 155>, <4 x i32>* %19
%20 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 32
%21 = bitcast i32* %20 to <4 x i32>*
store <4 x i32> <i32 160, i32 165, i32 170, i32 175>, <4 x i32>* %21
%22 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 36
%23 = bitcast i32* %22 to <4 x i32>*
store <4 x i32> <i32 180, i32 185, i32 190, i32 195>, <4 x i32>* %23
%24 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 40
%25 = bitcast i32* %24 to <4 x i32>*
store <4 x i32> <i32 200, i32 205, i32 210, i32 215>, <4 x i32>* %25
%26 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 44
%27 = bitcast i32* %26 to <4 x i32>*
store <4 x i32> <i32 220, i32 225, i32 230, i32 235>, <4 x i32>* %27
%28 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 48
%29 = bitcast i32* %28 to <4 x i32>*
store <4 x i32> <i32 240, i32 245, i32 250, i32 255>, <4 x i32>* %29
%30 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 52
%31 = bitcast i32* %30 to <4 x i32>*
store <4 x i32> <i32 260, i32 265, i32 270, i32 275>, <4 x i32>* %31
%32 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 56
%33 = bitcast i32* %32 to <4 x i32>*
store <4 x i32> <i32 280, i32 285, i32 290, i32 295>, <4 x i32>* %33
%34 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 60
%35 = bitcast i32* %34 to <4 x i32>*
store <4 x i32> <i32 300, i32 305, i32 310, i32 315>, <4 x i32>* %35
%36 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 64
%37 = bitcast i32* %36 to <4 x i32>*
store <4 x i32> <i32 320, i32 325, i32 330, i32 335>, <4 x i32>* %37
%38 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 68
%39 = bitcast i32* %38 to <4 x i32>*
store <4 x i32> <i32 340, i32 345, i32 350, i32 355>, <4 x i32>* %39
%40 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 72
%41 = bitcast i32* %40 to <4 x i32>*
store <4 x i32> <i32 360, i32 365, i32 370, i32 375>, <4 x i32>* %41
%42 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 76
%43 = bitcast i32* %42 to <4 x i32>*
store <4 x i32> <i32 380, i32 385, i32 390, i32 395>, <4 x i32>* %43
%44 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 80
%45 = bitcast i32* %44 to <4 x i32>*
store <4 x i32> <i32 400, i32 405, i32 410, i32 415>, <4 x i32>* %45
%46 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 84
%47 = bitcast i32* %46 to <4 x i32>*
store <4 x i32> <i32 420, i32 425, i32 430, i32 435>, <4 x i32>* %47
%48 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 88
%49 = bitcast i32* %48 to <4 x i32>*
store <4 x i32> <i32 440, i32 445, i32 450, i32 455>, <4 x i32>* %49
%50 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 92
%51 = bitcast i32* %50 to <4 x i32>*
store <4 x i32> <i32 460, i32 465, i32 470, i32 475>, <4 x i32>* %51
%52 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 96
%53 = bitcast i32* %52 to <4 x i32>*
store <4 x i32> <i32 480, i32 485, i32 490, i32 495>, <4 x i32>* %53
%54 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%55 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%56 = load i32, i32* %2
br label %57
57: ; preds = %0, %73
%58 = phi i32 [ 100, %0 ], [ %61, %73 ]
%59 = phi i32 [ 0, %0 ], [ %74, %73 ]
br label %60
60: ; preds = %57, %70
%61 = phi i32 [ %58, %57 ], [ %71, %70 ]
%62 = add nsw i32 %61, %59
%63 = sdiv i32 %62, 2
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %64
%66 = load i32, i32* %65
%67 = icmp eq i32 %56, %66
br i1 %67, label %76, label %68
68: ; preds = %60
%69 = icmp slt i32 %56, %66
br i1 %69, label %70, label %73
70: ; preds = %68
%71 = add nsw i32 %63, -1
%72 = icmp slt i32 %59, %63
br i1 %72, label %60, label %76
73: ; preds = %68
%74 = add nsw i32 %63, 1
%75 = icmp slt i32 %63, %61
br i1 %75, label %57, label %76
76: ; preds = %73, %60, %70
%77 = phi i32 [ -1, %70 ], [ %63, %60 ], [ -1, %73 ]
%78 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %77)
ret i32 0
}