#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*/ array;

/* Variables and functions */
int binarySearch(int, int *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int array[] = {2, 3, 4, 10, 40};
  int n = sizeof(array) / sizeof(array[0]);
  int x = 10;
  int result = binarySearch(x, array, 2, n - 1);
  (result == -1) ? printf("Element is not present in array")
                 : printf("Element is present at index %d", result);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xec7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xec5(%rip),%eax
mov    %eax,-0x10(%rbp)
movl   $0x5,-0x24(%rbp)
movl   $0xa,-0x28(%rbp)
mov    -0x28(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x2,%edx
call   1040 <binarySearch@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1193 <main+0x73>
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a4 <main+0x84>
mov    -0x2c(%rbp),%esi
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
mov    0xee6(%rip),%eax
mov    %eax,0x10(%rsp)
movaps 0xecb(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rsi
mov    $0xa,%edi
mov    $0x2,%edx
mov    $0x4,%ecx
call   1040 <binarySearch@plt>
cmp    $0xffffffff,%eax
je     1167 <main+0x47>
lea    0xed8(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1175 <main+0x55>
lea    0xea6(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@__const.main.array = [5 x i32] [i32 2, i32 3, i32 4, i32 10, i32 40]
@.str = [32 x i8] c"Element is not present in array\00"
@.str.1 = [31 x i8] c"Element is present at index %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [5 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast [5 x i32]* %2 to i8*
store i32 5, i32* %3
store i32 10, i32* %4
%7 = load i32, i32* %4
%8 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 0
%9 = load i32, i32* %3
%10 = sub nsw i32 %9, 1
%11 = call i32 @binarySearch(i32 %7, i32* %8, i32 2, i32 %10)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %19
16: ; preds = %0
%17 = load i32, i32* %5
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %16, %14
%20 = phi i32 [ %15, %14 ], [ %18, %16 ]
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@__const.main.array = [5 x i32] [i32 2, i32 3, i32 4, i32 10, i32 40]
@.str = [32 x i8] c"Element is not present in array\00"
@.str.1 = [31 x i8] c"Element is present at index %d\00"
define i32 @main() {
%1 = alloca [5 x i32]
%2 = bitcast [5 x i32]* %1 to i8*
%3 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 0
%4 = call i32 @binarySearch(i32 10, i32* %3, i32 2, i32 4)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %10
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %4)
br label %10
10: ; preds = %8, %6
ret i32 0
}