#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 binsearch(int, int *, int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int ret = 0;
  int x = 45;
  int v[] = {1, 4, 6, 31, 43, 45, 56, 67, 76};
  int n = 9;
  int location = 0;
  printf("\n Finding the position of %d in the vertex: ", x);
  location = binsearch(x, v, n);
  if (location > 0)
    printf("\n\t The index of %d in v is %d\n", x, location + 1);
  else
    printf("The element doesn't exist in v\n");
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x2d,-0xc(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xea8(%rip),%rsi
mov    $0x24,%edx
call   1050 <memcpy@plt>
movl   $0x9,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0xc(%rbp),%esi
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1030 <binsearch@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jle    11b9 <main+0x89>
mov    -0xc(%rbp),%esi
mov    -0x38(%rbp),%edx
add    $0x1,%edx
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11c7 <main+0x97>
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
mov    0xee6(%rip),%eax
mov    %eax,0x20(%rsp)
movaps 0xecb(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeaf(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xec8(%rip),%rdi
mov    $0x2d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rsi
mov    $0x2d,%edi
mov    $0x9,%edx
call   1030 <binsearch@plt>
test   %eax,%eax
jle    1198 <main+0x68>
add    $0x1,%eax
lea    0xec9(%rip),%rdi
mov    $0x2d,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11a4 <main+0x74>
lea    0xed1(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x28,%rsp
ret

LLVM IR (-O0):
@__const.main.v = [9 x i32] [i32 1, i32 4, i32 6, i32 31, i32 43, i32 45, i32 56, i32 67, i32 76]
@.str = [45 x i8] c"\0A Finding the position of %d in the vertex: \00"
@.str.1 = [31 x i8] c"\0A\09 The index of %d in v is %d\0A\00"
@.str.2 = [32 x i8] c"The element doesn't exist in v\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [9 x i32]
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 45, i32* %3
%7 = bitcast [9 x i32]* %4 to i8*
store i32 9, i32* %5
store i32 0, i32* %6
%8 = load i32, i32* %3
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = load i32, i32* %3
%11 = getelementptr inbounds [9 x i32], [9 x i32]* %4, i64 0, i64 0
%12 = load i32, i32* %5
%13 = call i32 @binsearch(i32 %10, i32* %11, i32 %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %0
%17 = load i32, i32* %3
%18 = load i32, i32* %6
%19 = add nsw i32 %18, 1
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %19)
br label %23
21: ; preds = %0
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %21, %16
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@__const.main.v = [9 x i32] [i32 1, i32 4, i32 6, i32 31, i32 43, i32 45, i32 56, i32 67, i32 76]
@.str = [45 x i8] c"\0A Finding the position of %d in the vertex: \00"
@.str.1 = [31 x i8] c"\0A\09 The index of %d in v is %d\0A\00"
@str = [31 x i8] c"The element doesn't exist in v\00"
define i32 @main() {
%1 = alloca [9 x i32]
%2 = bitcast [9 x i32]* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 45)
%4 = getelementptr inbounds [9 x i32], [9 x i32]* %1, i64 0, i64 0
%5 = call i32 @binsearch(i32 45, i32* %4, i32 9)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = add nuw nsw i32 %5, 1
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 45, i32 %8)
br label %12
10: ; preds = %0
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
ret i32 0
}