#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 rand();
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/);
int main() {
  int a[100];
  int k, mid, searched_val;
  int val = 1, low = 0, high = 100 - 1;
  srand(time(0));
  for (k = 0; k < 100; ++k) {
    a[k] = val;
    val += rand() % 10;
    printf("%d ", a[k]);
  }
  printf("\nEnter value to find: ");
  scanf("%d", &searched_val);
  while (low <= high) {
    mid = (low + high) / 2;
    if (a[mid] == searched_val)
      break;
    if (a[mid] > searched_val)
      high = mid - 1;
    else
      low = mid + 1;
  }
  if (low > high)
    printf("Not found! %d is not in the list!\n", searched_val);
  else
    printf("a[%d] = %d\n", mid, searched_val);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x1b0(%rbp)
movl   $0x0,-0x1b4(%rbp)
movl   $0x63,-0x1b8(%rbp)
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movl   $0x0,-0x1a4(%rbp)
cmpl   $0x64,-0x1a4(%rbp)
jge    1204 <main+0xb4>
mov    -0x1b0(%rbp),%ecx
movslq -0x1a4(%rbp),%rax
mov    %ecx,-0x1a0(%rbp,%rax,4)
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
add    -0x1b0(%rbp),%edx
mov    %edx,-0x1b0(%rbp)
movslq -0x1a4(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%esi
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a4(%rbp)
jmp    1198 <main+0x48>
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe02(%rip),%rdi
lea    -0x1ac(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x1b4(%rbp),%eax
cmp    -0x1b8(%rbp),%eax
jg     12b2 <main+0x162>
mov    -0x1b4(%rbp),%eax
add    -0x1b8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1a8(%rbp)
movslq -0x1a8(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%eax
cmp    -0x1ac(%rbp),%eax
jne    1270 <main+0x120>
jmp    12b2 <main+0x162>
movslq -0x1a8(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%eax
cmp    -0x1ac(%rbp),%eax
jle    129e <main+0x14e>
mov    -0x1a8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1b8(%rbp)
jmp    12ad <main+0x15d>
mov    -0x1a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1b4(%rbp)
jmp    1225 <main+0xd5>
mov    -0x1b4(%rbp),%eax
cmp    -0x1b8(%rbp),%eax
jle    12dd <main+0x18d>
mov    -0x1ac(%rbp),%esi
lea    0xd4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12f7 <main+0x1a7>
mov    -0x1a8(%rbp),%esi
mov    -0x1ac(%rbp),%edx
lea    0xd51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1a8,%rsp
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x1,%r15d
lea    0xe88(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r15d,0x10(%rsp,%rbx,4)
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%rbp
imul   $0x66666667,%rbp,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebp
add    %r15d,%ebp
mov    %r14,%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
mov    %ebp,%r15d
cmp    $0x64,%rbx
jne    1180 <main+0x30>
lea    0xe36(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe3d(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    $0x63,%eax
mov    0xc(%rsp),%edx
jmp    1209 <main+0xb9>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%esi
mov    %esi,%ebx
cmp    %eax,%ebx
jg     122b <main+0xdb>
lea    (%rax,%rbx,1),%ecx
mov    %ecx,%esi
shr    $0x1f,%esi
add    %ecx,%esi
sar    %esi
movslq %esi,%rcx
mov    0x10(%rsp,%rcx,4),%ecx
cmp    %edx,%ecx
je     123d <main+0xed>
jle    1200 <main+0xb0>
add    $0xffffffff,%esi
mov    %esi,%eax
cmp    %eax,%ebx
jle    1209 <main+0xb9>
lea    0xdec(%rip),%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    124b <main+0xfb>
lea    0xdfd(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x1a8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d \00"
@.str.1 = [23 x i8] c"\0AEnter value to find: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [35 x i8] c"Not found! %d is not in the list!\0A\00"
@.str.4 = [12 x i8] c"a[%d] = %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
%8 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %6
store i32 0, i32* %7
store i32 99, i32* %8
%9 = call i32 @time(i32 0)
%10 = call i32 @srand(i32 %9)
store i32 0, i32* %3
br label %11
11: ; preds = %28, %0
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 100
br i1 %13, label %14, label %31
14: ; preds = %11
%15 = load i32, i32* %6
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %17
store i32 %15, i32* %18
%19 = call i32 (...) @rand()
%20 = srem i32 %19, 10
%21 = load i32, i32* %6
%22 = add nsw i32 %21, %20
store i32 %22, i32* %6
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %14
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 1
store i32 %30, i32* %3
br label %11
31: ; preds = %11
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%33 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
br label %34
34: ; preds = %63, %31
%35 = load i32, i32* %7
%36 = load i32, i32* %8
%37 = icmp sle i32 %35, %36
br i1 %37, label %38, label %64
38: ; preds = %34
%39 = load i32, i32* %7
%40 = load i32, i32* %8
%41 = add nsw i32 %39, %40
%42 = sdiv i32 %41, 2
store i32 %42, i32* %4
%43 = load i32, i32* %4
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %44
%46 = load i32, i32* %45
%47 = load i32, i32* %5
%48 = icmp eq i32 %46, %47
br i1 %48, label %49, label %50
49: ; preds = %38
br label %64
50: ; preds = %38
%51 = load i32, i32* %4
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [100 x i32], [100 x i32]* %2, i64 0, i64 %52
%54 = load i32, i32* %53
%55 = load i32, i32* %5
%56 = icmp sgt i32 %54, %55
br i1 %56, label %57, label %60
57: ; preds = %50
%58 = load i32, i32* %4
%59 = sub nsw i32 %58, 1
store i32 %59, i32* %8
br label %63
60: ; preds = %50
%61 = load i32, i32* %4
%62 = add nsw i32 %61, 1
store i32 %62, i32* %7
br label %63
63: ; preds = %60, %57
br label %34
64: ; preds = %49, %34
%65 = load i32, i32* %7
%66 = load i32, i32* %8
%67 = icmp sgt i32 %65, %66
br i1 %67, label %68, label %71
68: ; preds = %64
%69 = load i32, i32* %5
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %69)
br label %75
71: ; preds = %64
%72 = load i32, i32* %4
%73 = load i32, i32* %5
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %72, i32 %73)
br label %75
75: ; preds = %71, %68
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d \00"
@.str.1 = [23 x i8] c"\0AEnter value to find: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [35 x i8] c"Not found! %d is not in the list!\0A\00"
@.str.4 = [12 x i8] c"a[%d] = %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 = tail call i32 @time(i32 0)
%6 = tail call i32 @srand(i32 %5)
br label %7
7: ; preds = %0, %7
%8 = phi i64 [ 0, %0 ], [ %15, %7 ]
%9 = phi i32 [ 1, %0 ], [ %13, %7 ]
%10 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %8
store i32 %9, i32* %10
%11 = tail call i32 (...) @rand()
%12 = srem i32 %11, 10
%13 = add nsw i32 %12, %9
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %9)
%15 = add nuw nsw i64 %8, 1
%16 = icmp eq i64 %15, 100
br i1 %16, label %17, label %7
17: ; preds = %7
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%20 = load i32, i32* %2
br label %21
21: ; preds = %17, %30
%22 = phi i32 [ 99, %17 ], [ %35, %30 ]
%23 = phi i32 [ 0, %17 ], [ %34, %30 ]
%24 = add nsw i32 %22, %23
%25 = sdiv i32 %24, 2
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [100 x i32], [100 x i32]* %1, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = icmp eq i32 %28, %20
br i1 %29, label %39, label %30
30: ; preds = %21
%31 = icmp sgt i32 %28, %20
%32 = add nsw i32 %25, -1
%33 = add nsw i32 %25, 1
%34 = select i1 %31, i32 %23, i32 %33
%35 = select i1 %31, i32 %32, i32 %22
%36 = icmp sgt i32 %34, %35
br i1 %36, label %37, label %21
37: ; preds = %30
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %20)
br label %41
39: ; preds = %21
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %25, i32 %20)
br label %41
41: ; preds = %39, %37
ret i32 0
}