#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 */
typedef int /*<<< orphan*/ arr;

/* Variables and functions */
int EXIT_SUCCESS;
int binary_search(int, int *, int);
int /*<<< orphan*/ printf(char *, int, ...);
int main(void) {
  int arr[] = {10, 12, 24, 21, 34, 37, 41, 48,  54,  59,  61,  68,  72,  77,
               80, 85, 88, 91, 92, 94, 98, 100, 101, 102, 120, 130, 130, 178};
  int value = 72;
  int result = binary_search(value, arr, (sizeof(arr) / sizeof(arr[0])));
  if (result == -1)
    printf("Element %d is not present\n", value);
  else
    printf("Element '%d' has index: '%d'\n", value, result);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x80(%rbp),%rdi
lea    0xeb3(%rip),%rsi
mov    $0x70,%edx
call   1040 <memcpy@plt>
movl   $0x48,-0x84(%rbp)
mov    -0x84(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x1c,%edx
call   1050 <binary_search@plt>
mov    %eax,-0x88(%rbp)
cmpl   $0xffffffff,-0x88(%rbp)
jne    11a1 <main+0x71>
mov    -0x84(%rbp),%esi
lea    0xedb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11bb <main+0x8b>
mov    -0x84(%rbp),%esi
mov    -0x88(%rbp),%edx
lea    0xed7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x78,%rsp
movaps 0xf35(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xf19(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xefd(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xee1(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xec5(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xea9(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe8d(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rsi
mov    $0x48,%edi
mov    $0x1c,%edx
call   1040 <binary_search@plt>
cmp    $0xffffffff,%eax
je     11a5 <main+0x85>
lea    0xef6(%rip),%rdi
mov    $0x48,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11b8 <main+0x98>
lea    0xec4(%rip),%rdi
mov    $0x48,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%eax
add    $0x78,%rsp
ret

LLVM IR (-O0):
@__const.main.arr = [28 x i32] [i32 10, i32 12, i32 24, i32 21, i32 34, i32 37, i32 41, i32 48, i32 54, i32 59, i32 61, i32 68, i32 72, i32 77, i32 80, i32 85, i32 88, i32 91, i32 92, i32 94, i32 98, i32 100, i32 101, i32 102, i32 120, i32 130, i32 130, i32 178]
@.str = [27 x i8] c"Element %d is not present\0A\00"
@.str.1 = [30 x i8] c"Element '%d' has index: '%d'\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [28 x i32]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [28 x i32]* %2 to i8*
store i32 72, i32* %3
%6 = load i32, i32* %3
%7 = getelementptr inbounds [28 x i32], [28 x i32]* %2, i64 0, i64 0
%8 = call i32 @binary_search(i32 %6, i32* %7, i32 28)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = load i32, i32* %3
%13 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %18
14: ; preds = %0
%15 = load i32, i32* %3
%16 = load i32, i32* %4
%17 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %16)
br label %18
18: ; preds = %14, %11
%19 = load i32, i32* @EXIT_SUCCESS
ret i32 %19
}

LLVM IR (-O2):
@__const.main.arr = [28 x i32] [i32 10, i32 12, i32 24, i32 21, i32 34, i32 37, i32 41, i32 48, i32 54, i32 59, i32 61, i32 68, i32 72, i32 77, i32 80, i32 85, i32 88, i32 91, i32 92, i32 94, i32 98, i32 100, i32 101, i32 102, i32 120, i32 130, i32 130, i32 178]
@.str = [27 x i8] c"Element %d is not present\0A\00"
@.str.1 = [30 x i8] c"Element '%d' has index: '%d'\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [28 x i32]
%2 = bitcast [28 x i32]* %1 to i8*
%3 = getelementptr inbounds [28 x i32], [28 x i32]* %1, i64 0, i64 0
%4 = call i32 @binary_search(i32 72, i32* %3, i32 28)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 72)
br label %10
8: ; preds = %0
%9 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 72, i32 %4)
br label %10
10: ; preds = %8, %6
%11 = load i32, i32* @EXIT_SUCCESS
ret i32 %11
}