#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 */
struct tms {
  scalar_t__ tms_stime;
  scalar_t__ tms_utime;
};

/* Variables and functions */
int /*<<< orphan*/ free(int *);
int knr_binsearch(int, int *, int);
int *malloc(int);
int our_binsearch(int, int *, int);
int printf(char *, ...);
int /*<<< orphan*/ times(struct tms *);
int main() {
  int ret = 0;
  int x = 0;
  int *v = NULL;
  int location = 0;
  int i = 0;
  struct tms time_b4_sort, time_aftr_sort;
  v = malloc(sizeof(int) * 400000000);
  if (!v)
    return printf("malloc issue\n");
  for (i = 0; i < 400000000; i++)
    v[i] = 2 * i + 1;
  times(&time_b4_sort);
  location = our_binsearch(x, v, 400000000);
  times(&time_aftr_sort);
  printf("The resources usage for our search on %d elements are:\nUser Time: "
         "%ld\nSystem Time: %ld\n",
         400000000, time_aftr_sort.tms_utime - time_b4_sort.tms_utime,
         time_aftr_sort.tms_stime - time_b4_sort.tms_stime);
  times(&time_b4_sort);
  location = knr_binsearch(x, v, 400000000);
  times(&time_aftr_sort);
  printf("The resources usage for KNR search on %d elements are:\nUser Time: "
         "%ld\nSystem Time: %ld\n",
         400000000, time_aftr_sort.tms_utime - time_b4_sort.tms_utime,
         time_aftr_sort.tms_stime - time_b4_sort.tms_stime);
  if (location > 0)
    printf("\n\t The index of %d in v is %d\n", x, location);
  else
    printf("\n\t The element doesn't exist in v\n");
  free(v);
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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    11c2 <main+0x62>
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    %eax,-0x4(%rbp)
jmp    12ca <main+0x16a>
movl   $0x0,-0x20(%rbp)
cmpl   $0x17d78400,-0x20(%rbp)
jge    11f8 <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    11c9 <main+0x69>
lea    -0x30(%rbp),%rdi
call   1080 <times@plt>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x17d78400,%edx
call   1050 <our_binsearch@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x40(%rbp),%rdi
call   1080 <times@plt>
mov    -0x38(%rbp),%rdx
sub    -0x28(%rbp),%rdx
mov    -0x40(%rbp),%rcx
sub    -0x30(%rbp),%rcx
lea    0xdd9(%rip),%rdi
mov    $0x17d78400,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
call   1080 <times@plt>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x17d78400,%edx
call   1070 <knr_binsearch@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x40(%rbp),%rdi
call   1080 <times@plt>
mov    -0x38(%rbp),%rdx
sub    -0x28(%rbp),%rdx
mov    -0x40(%rbp),%rcx
sub    -0x30(%rbp),%rcx
lea    0xde8(%rip),%rdi
mov    $0x17d78400,%esi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x1c(%rbp)
jle    12ad <main+0x14d>
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12bb <main+0x15b>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    $0x5f5e1000,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     12cc <main+0x15c>
mov    %rax,%rbx
movdqa 0xe68(%rip),%xmm0
mov    $0xc,%eax
movdqa 0xe6a(%rip),%xmm8
movdqa 0xe72(%rip),%xmm2
movdqa 0xe7a(%rip),%xmm3
movdqa 0xe82(%rip),%xmm4
movdqa 0xe8a(%rip),%xmm5
cs nopw 0x0(%rax,%rax,1)
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    11d0 <main+0x60>
lea    0x18(%rsp),%r14
mov    %r14,%rdi
call   1090 <times@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x17d78400,%edx
call   1060 <our_binsearch@plt>
lea    0x8(%rsp),%r15
mov    %r15,%rdi
call   1090 <times@plt>
mov    0x8(%rsp),%rcx
mov    0x10(%rsp),%rdx
sub    0x20(%rsp),%rdx
sub    0x18(%rsp),%rcx
lea    0xe0e(%rip),%rdi
mov    $0x17d78400,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1090 <times@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x17d78400,%edx
call   1080 <knr_binsearch@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1090 <times@plt>
mov    0x8(%rsp),%rcx
mov    0x10(%rsp),%rdx
sub    0x20(%rsp),%rdx
sub    0x18(%rsp),%rcx
lea    0xe1e(%rip),%rdi
mov    $0x17d78400,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebp,%ebp
jle    12e4 <main+0x174>
lea    0xe5f(%rip),%rdi
xor    %esi,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    12f0 <main+0x180>
lea    0xd8d(%rip),%rdi
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <printf@plt>
lea    0xe52(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tms = type { i64, i64 }
@.str = [14 x i8] c"malloc issue\0A\00"
@.str.1 = [88 x i8] c"The resources usage for our search on %d elements are:\0AUser Time: %ld\0ASystem Time: %ld\0A\00"
@.str.2 = [88 x i8] c"The resources usage for KNR search on %d elements are:\0AUser Time: %ld\0ASystem Time: %ld\0A\00"
@.str.3 = [31 x i8] c"\0A\09 The index of %d in v is %d\0A\00"
@.str.4 = [35 x i8] c"\0A\09 The 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
%7 = alloca %struct.tms
%8 = alloca %struct.tms
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
%9 = call i32* @malloc(i32 1600000000)
store i32* %9, i32** %4
%10 = load i32*, i32** %4
%11 = icmp ne i32* %10, null
br i1 %11, label %14, label %12
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 %13, i32* %1
br label %74
14: ; preds = %0
store i32 0, i32* %6
br label %15
15: ; preds = %26, %14
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 400000000
br i1 %17, label %18, label %29
18: ; preds = %15
%19 = load i32, i32* %6
%20 = mul nsw i32 2, %19
%21 = add nsw i32 %20, 1
%22 = load i32*, i32** %4
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
store i32 %21, i32* %25
br label %26
26: ; preds = %18
%27 = load i32, i32* %6
%28 = add nsw i32 %27, 1
store i32 %28, i32* %6
br label %15
29: ; preds = %15
%30 = call i32 @times(%struct.tms* %7)
%31 = load i32, i32* %3
%32 = load i32*, i32** %4
%33 = call i32 @our_binsearch(i32 %31, i32* %32, i32 400000000)
store i32 %33, i32* %5
%34 = call i32 @times(%struct.tms* %8)
%35 = getelementptr inbounds %struct.tms, %struct.tms* %8, i32 0, i32 1
%36 = load i64, i64* %35
%37 = getelementptr inbounds %struct.tms, %struct.tms* %7, i32 0, i32 1
%38 = load i64, i64* %37
%39 = sub nsw i64 %36, %38
%40 = getelementptr inbounds %struct.tms, %struct.tms* %8, i32 0, i32 0
%41 = load i64, i64* %40
%42 = getelementptr inbounds %struct.tms, %struct.tms* %7, i32 0, i32 0
%43 = load i64, i64* %42
%44 = sub nsw i64 %41, %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([88 x i8], [88 x i8]* @.str.1, i64 0, i64 0), i32 400000000, i64 %39, i64 %44)
%46 = call i32 @times(%struct.tms* %7)
%47 = load i32, i32* %3
%48 = load i32*, i32** %4
%49 = call i32 @knr_binsearch(i32 %47, i32* %48, i32 400000000)
store i32 %49, i32* %5
%50 = call i32 @times(%struct.tms* %8)
%51 = getelementptr inbounds %struct.tms, %struct.tms* %8, i32 0, i32 1
%52 = load i64, i64* %51
%53 = getelementptr inbounds %struct.tms, %struct.tms* %7, i32 0, i32 1
%54 = load i64, i64* %53
%55 = sub nsw i64 %52, %54
%56 = getelementptr inbounds %struct.tms, %struct.tms* %8, i32 0, i32 0
%57 = load i64, i64* %56
%58 = getelementptr inbounds %struct.tms, %struct.tms* %7, i32 0, i32 0
%59 = load i64, i64* %58
%60 = sub nsw i64 %57, %59
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([88 x i8], [88 x i8]* @.str.2, i64 0, i64 0), i32 400000000, i64 %55, i64 %60)
%62 = load i32, i32* %5
%63 = icmp sgt i32 %62, 0
br i1 %63, label %64, label %68
64: ; preds = %29
%65 = load i32, i32* %3
%66 = load i32, i32* %5
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %65, i32 %66)
br label %70
68: ; preds = %29
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
br label %70
70: ; preds = %68, %64
%71 = load i32*, i32** %4
%72 = call i32 @free(i32* %71)
%73 = load i32, i32* %2
store i32 %73, i32* %1
br label %74
74: ; preds = %70, %12
%75 = load i32, i32* %1
ret i32 %75
}

LLVM IR (-O2):
%struct.tms = type { i64, i64 }
@.str = [14 x i8] c"malloc issue\0A\00"
@.str.1 = [88 x i8] c"The resources usage for our search on %d elements are:\0AUser Time: %ld\0ASystem Time: %ld\0A\00"
@.str.2 = [88 x i8] c"The resources usage for KNR search on %d elements are:\0AUser Time: %ld\0ASystem Time: %ld\0A\00"
@.str.3 = [31 x i8] c"\0A\09 The index of %d in v is %d\0A\00"
@str = [34 x i8] c"\0A\09 The element doesn't exist in v\00"
define i32 @main() {
%1 = alloca %struct.tms
%2 = alloca %struct.tms
%3 = bitcast %struct.tms* %1 to i8*
%4 = bitcast %struct.tms* %2 to i8*
%5 = tail call i32* @malloc(i32 1600000000)
%6 = icmp eq i32* %5, null
br i1 %6, label %33, label %7
7: ; preds = %0, %7
%8 = phi i64 [ %30, %7 ], [ 0, %0 ]
%9 = phi <4 x i32> [ %31, %7 ], [ <i32 0, i32 1, i32 2, i32 3>, %0 ]
%10 = getelementptr inbounds i32, i32* %5, i64 %8
%11 = shl <4 x i32> %9, <i32 1, i32 1, i32 1, i32 1>
%12 = shl <4 x i32> %9, <i32 1, i32 1, i32 1, i32 1>
%13 = add <4 x i32> %12, <i32 8, i32 8, i32 8, i32 8>
%14 = or <4 x i32> %11, <i32 1, i32 1, i32 1, i32 1>
%15 = or <4 x i32> %13, <i32 1, i32 1, i32 1, i32 1>
%16 = bitcast i32* %10 to <4 x i32>*
store <4 x i32> %14, <4 x i32>* %16
%17 = getelementptr inbounds i32, i32* %10, i64 4
%18 = bitcast i32* %17 to <4 x i32>*
store <4 x i32> %15, <4 x i32>* %18
%19 = or i64 %8, 8
%20 = add <4 x i32> %9, <i32 8, i32 8, i32 8, i32 8>
%21 = getelementptr inbounds i32, i32* %5, i64 %19
%22 = shl <4 x i32> %20, <i32 1, i32 1, i32 1, i32 1>
%23 = shl <4 x i32> %20, <i32 1, i32 1, i32 1, i32 1>
%24 = add <4 x i32> %23, <i32 8, i32 8, i32 8, i32 8>
%25 = or <4 x i32> %22, <i32 1, i32 1, i32 1, i32 1>
%26 = or <4 x i32> %24, <i32 1, i32 1, i32 1, i32 1>
%27 = bitcast i32* %21 to <4 x i32>*
store <4 x i32> %25, <4 x i32>* %27
%28 = getelementptr inbounds i32, i32* %21, i64 4
%29 = bitcast i32* %28 to <4 x i32>*
store <4 x i32> %26, <4 x i32>* %29
%30 = add nuw nsw i64 %8, 16
%31 = add <4 x i32> %9, <i32 16, i32 16, i32 16, i32 16>
%32 = icmp eq i64 %30, 400000000
br i1 %32, label %35, label %7
33: ; preds = %0
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %67
35: ; preds = %7
%36 = call i32 @times(%struct.tms* %1)
%37 = tail call i32 @our_binsearch(i32 0, i32* %5, i32 400000000)
%38 = call i32 @times(%struct.tms* %2)
%39 = getelementptr inbounds %struct.tms, %struct.tms* %2, i64 0, i32 1
%40 = load i64, i64* %39
%41 = getelementptr inbounds %struct.tms, %struct.tms* %1, i64 0, i32 1
%42 = load i64, i64* %41
%43 = sub nsw i64 %40, %42
%44 = getelementptr inbounds %struct.tms, %struct.tms* %2, i64 0, i32 0
%45 = load i64, i64* %44
%46 = getelementptr inbounds %struct.tms, %struct.tms* %1, i64 0, i32 0
%47 = load i64, i64* %46
%48 = sub nsw i64 %45, %47
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([88 x i8], [88 x i8]* @.str.1, i64 0, i64 0), i32 400000000, i64 %43, i64 %48)
%50 = call i32 @times(%struct.tms* %1)
%51 = tail call i32 @knr_binsearch(i32 0, i32* %5, i32 400000000)
%52 = call i32 @times(%struct.tms* %2)
%53 = load i64, i64* %39
%54 = load i64, i64* %41
%55 = sub nsw i64 %53, %54
%56 = load i64, i64* %44
%57 = load i64, i64* %46
%58 = sub nsw i64 %56, %57
%59 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([88 x i8], [88 x i8]* @.str.2, i64 0, i64 0), i32 400000000, i64 %55, i64 %58)
%60 = icmp sgt i32 %51, 0
br i1 %60, label %61, label %63
61: ; preds = %35
%62 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 0, i32 %51)
br label %65
63: ; preds = %35
%64 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
br label %65
65: ; preds = %63, %61
%66 = tail call i32 @free(i32* %5)
br label %67
67: ; preds = %65, %33
%68 = phi i32 [ 0, %65 ], [ %34, %33 ]
ret i32 %68
}