#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 /*<<< orphan*/ bubbleSort(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ println(int *, int);
int rand();
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(void) {
  int i;
  int key = 0;
  int a[20];
  srand(time(NULL));
  for (i = 0; i < 20; i++)
    a[i] = rand() % 100;
  bubbleSort(a, 20);
  println(a, 20);
  printf("key: ");
  scanf("%d", &key);
  int index = binary_search(a, 20, key);
  if (index == -1)
    printf("not found!\n");
  else
    printf("found:a[%d]:%d\n", index, a[index]);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x14,-0x8(%rbp)
jge    11dc <main+0x5c>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
movslq -0x8(%rbp),%rax
mov    %edx,-0x60(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11ad <main+0x2d>
lea    -0x60(%rbp),%rdi
mov    $0x14,%esi
call   1040 <bubbleSort@plt>
lea    -0x60(%rbp),%rdi
mov    $0x14,%esi
call   1050 <println@plt>
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdf9(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1090 <scanf@plt>
lea    -0x60(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    $0x14,%esi
call   1080 <binary_search@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0xffffffff,-0x64(%rbp)
jne    1247 <main+0xc7>
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1260 <main+0xe0>
mov    -0x64(%rbp),%esi
movslq -0x64(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%edx
lea    0xdbc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x60,%rsp
movl   $0x0,0xc(%rsp)
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
xor    %ebx,%ebx
nopl   (%rax)
xor    %eax,%eax
call   10b0 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x10(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x14,%rbx
jne    11b0 <main+0x20>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x14,%esi
call   1050 <bubbleSort@plt>
mov    %rbx,%rdi
mov    $0x14,%esi
call   1060 <println@plt>
lea    0xdfa(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdf2(%rip),%rdi
lea    0xc(%rsp),%rsi
call   10a0 <scanf@plt>
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
mov    $0x14,%esi
call   1090 <binary_search@plt>
cmp    $0xffffffff,%eax
je     124d <main+0xbd>
movslq %eax,%rcx
mov    0x10(%rsp,%rcx,4),%edx
lea    0xdc7(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1259 <main+0xc9>
lea    0xdc5(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"key: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [12 x i8] c"not found!\0A\00"
@.str.3 = [16 x i8] c"found:a[%d]:%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [20 x i32]
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%6 = call i32 @time(i32* null)
%7 = call i32 @srand(i32 %6)
store i32 0, i32* %2
br label %8
8: ; preds = %17, %0
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 20
br i1 %10, label %11, label %20
11: ; preds = %8
%12 = call i32 (...) @rand()
%13 = srem i32 %12, 100
%14 = load i32, i32* %2
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [20 x i32], [20 x i32]* %4, i64 0, i64 %15
store i32 %13, i32* %16
br label %17
17: ; preds = %11
%18 = load i32, i32* %2
%19 = add nsw i32 %18, 1
store i32 %19, i32* %2
br label %8
20: ; preds = %8
%21 = getelementptr inbounds [20 x i32], [20 x i32]* %4, i64 0, i64 0
%22 = call i32 @bubbleSort(i32* %21, i32 20)
%23 = getelementptr inbounds [20 x i32], [20 x i32]* %4, i64 0, i64 0
%24 = call i32 @println(i32* %23, i32 20)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%26 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%27 = getelementptr inbounds [20 x i32], [20 x i32]* %4, i64 0, i64 0
%28 = load i32, i32* %3
%29 = call i32 @binary_search(i32* %27, i32 20, i32 %28)
store i32 %29, i32* %5
%30 = load i32, i32* %5
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %20
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %41
34: ; preds = %20
%35 = load i32, i32* %5
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [20 x i32], [20 x i32]* %4, i64 0, i64 %37
%39 = load i32, i32* %38
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %35, i32 %39)
br label %41
41: ; preds = %34, %32
%42 = load i32, i32* %1
ret i32 %42
}

LLVM IR (-O2):
@.str = [6 x i8] c"key: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [16 x i8] c"found:a[%d]:%d\0A\00"
@str = [11 x i8] c"not found!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i32]
%3 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%4 = bitcast [20 x i32]* %2 to i8*
%5 = tail call i32 @time(i32* null)
%6 = tail call i32 @srand(i32 %5)
br label %7
7: ; preds = %0, %7
%8 = phi i64 [ 0, %0 ], [ %12, %7 ]
%9 = tail call i32 (...) @rand()
%10 = srem i32 %9, 100
%11 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %8
store i32 %10, i32* %11
%12 = add nuw nsw i64 %8, 1
%13 = icmp eq i64 %12, 20
br i1 %13, label %14, label %7
14: ; preds = %7
%15 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%16 = call i32 @bubbleSort(i32* %15, i32 20)
%17 = call i32 @println(i32* %15, i32 20)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%20 = load i32, i32* %1
%21 = call i32 @binary_search(i32* %15, i32 20, i32 %20)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %14
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
br label %30
25: ; preds = %14
%26 = sext i32 %21 to i64
%27 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %21, i32 %28)
br label %30
30: ; preds = %25, %23
ret i32 0
}