#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*/ printf(char *, ...);
int main() {
  int n = 19;
  int arr[] = {
      0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
  };
  int *ptr;
  int elem;
  ptr = &arr[0];
  elem = arr[9];
  ptr = binary_search(ptr, n, elem);
  if (NULL == ptr)
    printf("cannot found.\n");
  else
    printf("return value = %d\n", *ptr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x13,-0x8(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xeaf(%rip),%rsi
mov    $0x50,%edx
call   1040 <memcpy@plt>
lea    -0x60(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x68(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x6c(%rbp),%edx
call   1050 <binary_search@plt>
mov    %rax,-0x68(%rbp)
xor    %eax,%eax
cmp    -0x68(%rbp),%rax
jne    119b <main+0x6b>
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11af <main+0x7f>
mov    -0x68(%rbp),%rax
mov    (%rax),%esi
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x58,%rsp
movaps 0xf05(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xee9(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xecd(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xeb1(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe95(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
mov    $0x13,%esi
mov    $0x9,%edx
call   1050 <binary_search@plt>
test   %rax,%rax
je     1198 <main+0x68>
mov    (%rax),%esi
lea    0xec1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11a4 <main+0x74>
lea    0xec4(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x58,%rsp
ret

LLVM IR (-O0):
@__const.main.arr = [20 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19]
@.str = [15 x i8] c"cannot found.\0A\00"
@.str.1 = [19 x i8] c"return value = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [20 x i32]
%4 = alloca i32*
%5 = alloca i32
store i32 0, i32* %1
store i32 19, i32* %2
%6 = bitcast [20 x i32]* %3 to i8*
%7 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 0
store i32* %7, i32** %4
%8 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 9
%9 = load i32, i32* %8
store i32 %9, i32* %5
%10 = load i32*, i32** %4
%11 = load i32, i32* %2
%12 = load i32, i32* %5
%13 = call i32* @binary_search(i32* %10, i32 %11, i32 %12)
store i32* %13, i32** %4
%14 = load i32*, i32** %4
%15 = icmp eq i32* null, %14
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %22
18: ; preds = %0
%19 = load i32*, i32** %4
%20 = load i32, i32* %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %18, %16
ret i32 0
}

LLVM IR (-O2):
@__const.main.arr = [20 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19]
@.str.1 = [19 x i8] c"return value = %d\0A\00"
@str = [14 x i8] c"cannot found.\00"
define i32 @main() {
%1 = alloca [20 x i32]
%2 = bitcast [20 x i32]* %1 to i8*
%3 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%4 = call i32* @binary_search(i32* %3, i32 19, i32 9)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %11
8: ; preds = %0
%9 = load i32, i32* %4
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %9)
br label %11
11: ; preds = %8, %6
ret i32 0
}