#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 */
scalar_t__ binary_search_array(int *, int, int);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int size = 10;
  int val = 40;
  int array[10] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
  if (binary_search_array(array, size, val)) {
    printf("val->%d found in array\n", val);
  } else {
    printf("val->%d NOT found in array\n", val);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xa,-0x8(%rbp)
movl   $0x28,-0xc(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xea8(%rip),%rsi
mov    $0x28,%edx
call   1050 <memcpy@plt>
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1040 <binary_search_array@plt>
cmp    $0x0,%rax
je     118f <main+0x5f>
mov    -0xc(%rbp),%esi
lea    0xea3(%rip),%rdi
call   1030 <printf@plt>
jmp    119e <main+0x6e>
mov    -0xc(%rbp),%esi
lea    0xea7(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
mov    0xef5(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0xed9(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xebd(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
mov    $0xa,%esi
mov    $0x28,%edx
call   1040 <binary_search_array@plt>
test   %rax,%rax
lea    0xedd(%rip),%rax
lea    0xebe(%rip),%rdi
cmove  %rax,%rdi
mov    $0x28,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
ret

LLVM IR (-O0):
@__const.main.array = [10 x i32] [i32 10, i32 20, i32 30, i32 40, i32 50, i32 60, i32 70, i32 80, i32 90, i32 100]
@.str = [24 x i8] c"val->%d found in array\0A\00"
@.str.1 = [28 x i8] c"val->%d NOT found in array\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [10 x i32]
store i32 0, i32* %1
store i32 10, i32* %2
store i32 40, i32* %3
%5 = bitcast [10 x i32]* %4 to i8*
%6 = getelementptr inbounds [10 x i32], [10 x i32]* %4, i64 0, i64 0
%7 = load i32, i32* %2
%8 = load i32, i32* %3
%9 = call i64 @binary_search_array(i32* %6, i32 %7, i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = load i32, i32* %3
%13 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %17
14: ; preds = %0
%15 = load i32, i32* %3
%16 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %14, %11
ret i32 0
}

LLVM IR (-O2):
@__const.main.array = [10 x i32] [i32 10, i32 20, i32 30, i32 40, i32 50, i32 60, i32 70, i32 80, i32 90, i32 100]
@.str = [24 x i8] c"val->%d found in array\0A\00"
@.str.1 = [28 x i8] c"val->%d NOT found in array\0A\00"
define i32 @main() {
%1 = alloca [10 x i32]
%2 = bitcast [10 x i32]* %1 to i8*
%3 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
%4 = call i64 @binary_search_array(i32* %3, i32 10, i32 40)
%5 = icmp eq i64 %4, 0
%6 = select i1 %5, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0)
%7 = call i32 @printf(i8* %6, i32 40)
ret i32 0
}