#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*/ free(int *);
int *malloc(int);
int printf(char *, ...);
int main() {
  int ret = 0;
  int x = 0;
  int *v = NULL;
  int location = 0;
  int i = 0;
  v = malloc(sizeof(int) * 400000000);
  if (!v)
    return printf("malloc issue\n");
  for (i = 0; i < 400000000; i++)
    v[i] = 2 * i + 1;
  printf("\n Finding the position of %d in the vertex: ", x);
  location = binsearch(x, v, 400000000);
  if (location > 0)
    printf("\n\t The index of %d in v is %d\n", x, location + 1);
  else
    printf("\n\tThe element doesn't exist in v\n");
  free(v);
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    $0x5f5e1000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a2 <main+0x62>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    %eax,-0x4(%rbp)
jmp    1240 <main+0x100>
movl   $0x0,-0x20(%rbp)
cmpl   $0x17d78400,-0x20(%rbp)
jge    11d8 <main+0x98>
mov    -0x20(%rbp),%edx
shl    $0x1,%edx
add    $0x1,%edx
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11a9 <main+0x69>
mov    -0xc(%rbp),%esi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x17d78400,%edx
call   1040 <binsearch@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    1223 <main+0xe3>
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1231 <main+0xf1>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x5f5e1000,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1226 <main+0xd6>
mov    %rax,%rbx
movdqa 0xe91(%rip),%xmm0
mov    $0xc,%eax
movdqa 0xe93(%rip),%xmm8
movdqa 0xe9b(%rip),%xmm2
movdqa 0xea3(%rip),%xmm3
movdqa 0xeab(%rip),%xmm4
movdqa 0xeb3(%rip),%xmm5
nopl   (%rax)
movdqa %xmm0,%xmm6
paddd  %xmm0,%xmm6
movdqa %xmm6,%xmm7
por    %xmm8,%xmm7
movdqa %xmm6,%xmm1
paddd  %xmm2,%xmm1
movdqu %xmm7,-0x30(%rbx,%rax,4)
movdqu %xmm1,-0x20(%rbx,%rax,4)
movdqa %xmm6,%xmm1
paddd  %xmm3,%xmm1
paddd  %xmm4,%xmm6
movdqu %xmm1,-0x10(%rbx,%rax,4)
movdqu %xmm6,(%rbx,%rax,4)
paddd  %xmm5,%xmm0
add    $0x10,%rax
cmp    $0x17d7840c,%rax
jne    11a0 <main+0x50>
lea    0xe7b(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x17d78400,%edx
call   1040 <binsearch@plt>
test   %eax,%eax
jle    1235 <main+0xe5>
add    $0x1,%eax
lea    0xe82(%rip),%rdi
xor    %esi,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1241 <main+0xf1>
lea    0xe33(%rip),%rdi
xor    %eax,%eax
pop    %rbx
jmp    1060 <printf@plt>
lea    0xe7e(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"malloc issue\0A\00"
@.str.1 = [45 x i8] c"\0A Finding the position of %d in the vertex: \00"
@.str.2 = [31 x i8] c"\0A\09 The index of %d in v is %d\0A\00"
@.str.3 = [34 x i8] c"\0A\09The element doesn't exist in v\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i32* null, i32** %4
store i32 0, i32* %5
store i32 0, i32* %6
%7 = call i32* @malloc(i32 1600000000)
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = icmp ne i32* %8, null
br i1 %9, label %12, label %10
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 %11, i32* %1
br label %46
12: ; preds = %0
store i32 0, i32* %6
br label %13
13: ; preds = %24, %12
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 400000000
br i1 %15, label %16, label %27
16: ; preds = %13
%17 = load i32, i32* %6
%18 = mul nsw i32 2, %17
%19 = add nsw i32 %18, 1
%20 = load i32*, i32** %4
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
store i32 %19, i32* %23
br label %24
24: ; preds = %16
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
store i32 %26, i32* %6
br label %13
27: ; preds = %13
%28 = load i32, i32* %3
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %3
%31 = load i32*, i32** %4
%32 = call i32 @binsearch(i32 %30, i32* %31, i32 400000000)
store i32 %32, i32* %5
%33 = load i32, i32* %5
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %27
%36 = load i32, i32* %3
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %36, i32 %38)
br label %42
40: ; preds = %27
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
br label %42
42: ; preds = %40, %35
%43 = load i32*, i32** %4
%44 = call i32 @free(i32* %43)
%45 = load i32, i32* %2
store i32 %45, i32* %1
br label %46
46: ; preds = %42, %10
%47 = load i32, i32* %1
ret i32 %47
}

LLVM IR (-O2):
@.str = [14 x i8] c"malloc issue\0A\00"
@.str.1 = [45 x i8] c"\0A Finding the position of %d in the vertex: \00"
@.str.2 = [31 x i8] c"\0A\09 The index of %d in v is %d\0A\00"
@str = [33 x i8] c"\0A\09The element doesn't exist in v\00"
define i32 @main() {
%1 = tail call i32* @malloc(i32 1600000000)
%2 = icmp eq i32* %1, null
br i1 %2, label %29, label %3
3: ; preds = %0, %3
%4 = phi i64 [ %26, %3 ], [ 0, %0 ]
%5 = phi <4 x i32> [ %27, %3 ], [ <i32 0, i32 1, i32 2, i32 3>, %0 ]
%6 = getelementptr inbounds i32, i32* %1, i64 %4
%7 = shl <4 x i32> %5, <i32 1, i32 1, i32 1, i32 1>
%8 = shl <4 x i32> %5, <i32 1, i32 1, i32 1, i32 1>
%9 = add <4 x i32> %8, <i32 8, i32 8, i32 8, i32 8>
%10 = or <4 x i32> %7, <i32 1, i32 1, i32 1, i32 1>
%11 = or <4 x i32> %9, <i32 1, i32 1, i32 1, i32 1>
%12 = bitcast i32* %6 to <4 x i32>*
store <4 x i32> %10, <4 x i32>* %12
%13 = getelementptr inbounds i32, i32* %6, i64 4
%14 = bitcast i32* %13 to <4 x i32>*
store <4 x i32> %11, <4 x i32>* %14
%15 = or i64 %4, 8
%16 = add <4 x i32> %5, <i32 8, i32 8, i32 8, i32 8>
%17 = getelementptr inbounds i32, i32* %1, i64 %15
%18 = shl <4 x i32> %16, <i32 1, i32 1, i32 1, i32 1>
%19 = shl <4 x i32> %16, <i32 1, i32 1, i32 1, i32 1>
%20 = add <4 x i32> %19, <i32 8, i32 8, i32 8, i32 8>
%21 = or <4 x i32> %18, <i32 1, i32 1, i32 1, i32 1>
%22 = or <4 x i32> %20, <i32 1, i32 1, i32 1, i32 1>
%23 = bitcast i32* %17 to <4 x i32>*
store <4 x i32> %21, <4 x i32>* %23
%24 = getelementptr inbounds i32, i32* %17, i64 4
%25 = bitcast i32* %24 to <4 x i32>*
store <4 x i32> %22, <4 x i32>* %25
%26 = add nuw nsw i64 %4, 16
%27 = add <4 x i32> %5, <i32 16, i32 16, i32 16, i32 16>
%28 = icmp eq i64 %26, 400000000
br i1 %28, label %31, label %3
29: ; preds = %0
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %42
31: ; preds = %3
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 0)
%33 = tail call i32 @binsearch(i32 0, i32* %1, i32 400000000)
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = add nuw nsw i32 %33, 1
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 0, i32 %36)
br label %40
38: ; preds = %31
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
br label %40
40: ; preds = %38, %35
%41 = tail call i32 @free(i32* %1)
br label %42
42: ; preds = %40, %29
%43 = phi i32 [ 0, %40 ], [ %30, %29 ]
ret i32 %43
}