#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 */
void *atoi(char *);
int /*<<< orphan*/ free(int *);
int *malloc(int const);
int /*<<< orphan*/ printf(char *, ...);
int vk_bsearch(int *, int /*<<< orphan*/, int const, int const);
int main(int argc, char **argv) {
  if (argc <= 2) {
    printf("Usage: %s <value> <arr_1> <arr_2> <...>\n", argv[0]);
    return 1;
  }
  const int value = atoi(argv[1]);
  const int array_size = argc - 2;
  int *array = malloc(array_size * sizeof(int));
  if (array == NULL) {
    printf("Failed to allocate memory\n");
    return 2;
  }
  int i;
  for (i = 0; i < array_size; ++i) {
    array[i] = atoi(argv[i + 2]);
  }
  const int result = vk_bsearch(array, 0, array_size - 1, value);
  printf("Result: %d\n", result);
  free(array);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jg     1191 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    125e <main+0x10e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e2 <main+0x92>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    125e <main+0x10e>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1226 <main+0xd6>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1070 <atoi@plt>
mov    %eax,%edx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11e9 <main+0x99>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%edx
sub    $0x1,%edx
mov    -0x14(%rbp),%ecx
xor    %esi,%esi
call   1040 <vk_bsearch@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%esi
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
cmp    $0x2,%edi
jg     118f <main+0x2f>
mov    0x0(%r13),%rsi
lea    0xe82(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%ebx
jmp    1218 <main+0xb8>
mov    %edi,%r14d
mov    0x8(%r13),%rdi
call   1080 <atoi@plt>
mov    %rax,%r12
lea    -0x8(,%r14,4),%edi
ff
call   1070 <malloc@plt>
test   %rax,%rax
je     1207 <main+0xa7>
mov    %rax,%r15
lea    -0x2(%r14),%eax
mov    %eax,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    0x10(%r13,%rbp,8),%rdi
call   1080 <atoi@plt>
mov    %eax,(%r15,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    11c0 <main+0x60>
add    $0xfffffffd,%r14d
xor    %ebx,%ebx
mov    %r15,%rdi
xor    %esi,%esi
mov    %r14d,%edx
mov    %r12d,%ecx
call   1050 <vk_bsearch@plt>
lea    0xe35(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
jmp    1218 <main+0xb8>
lea    0xe27(%rip),%rdi
call   1040 <puts@plt>
mov    $0x2,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Usage: %s <value> <arr_1> <arr_2> <...>\0A\00"
@.str.1 = [27 x i8] c"Failed to allocate memory\0A\00"
@.str.2 = [12 x i8] c"Result: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp sle i32 %11, 2
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 1, i32* %3
br label %66
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i8* @atoi(i8* %21)
%23 = ptrtoint i8* %22 to i32
store i32 %23, i32* %6
%24 = load i32, i32* %4
%25 = sub nsw i32 %24, 2
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = mul i64 %27, 4
%29 = trunc i64 %28 to i32
%30 = call i32* @malloc(i32 %29)
store i32* %30, i32** %8
%31 = load i32*, i32** %8
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %35
33: ; preds = %18
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %3
br label %66
35: ; preds = %18
store i32 0, i32* %9
br label %36
36: ; preds = %53, %35
%37 = load i32, i32* %9
%38 = load i32, i32* %7
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %56
40: ; preds = %36
%41 = load i8**, i8*** %5
%42 = load i32, i32* %9
%43 = add nsw i32 %42, 2
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8*, i8** %41, i64 %44
%46 = load i8*, i8** %45
%47 = call i8* @atoi(i8* %46)
%48 = ptrtoint i8* %47 to i32
%49 = load i32*, i32** %8
%50 = load i32, i32* %9
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32, i32* %49, i64 %51
store i32 %48, i32* %52
br label %53
53: ; preds = %40
%54 = load i32, i32* %9
%55 = add nsw i32 %54, 1
store i32 %55, i32* %9
br label %36
56: ; preds = %36
%57 = load i32*, i32** %8
%58 = load i32, i32* %7
%59 = sub nsw i32 %58, 1
%60 = load i32, i32* %6
%61 = call i32 @vk_bsearch(i32* %57, i32 0, i32 %59, i32 %60)
store i32 %61, i32* %10
%62 = load i32, i32* %10
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %62)
%64 = load i32*, i32** %8
%65 = call i32 @free(i32* %64)
store i32 0, i32* %3
br label %66
66: ; preds = %56, %33, %13
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
@.str = [41 x i8] c"Usage: %s <value> <arr_1> <arr_2> <...>\0A\00"
@.str.2 = [12 x i8] c"Result: %d\0A\00"
@str = [26 x i8] c"Failed to allocate memory\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %37
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i8* @atoi(i8* %9)
%11 = ptrtoint i8* %10 to i64
%12 = trunc i64 %11 to i32
%13 = add nsw i32 %0, -2
%14 = shl i32 %13, 2
%15 = tail call i32* @malloc(i32 %14)
%16 = icmp eq i32* %15, null
br i1 %16, label %19, label %17
17: ; preds = %7
%18 = zext i32 %13 to i64
br label %21
19: ; preds = %7
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %37
21: ; preds = %17, %21
%22 = phi i64 [ 0, %17 ], [ %30, %21 ]
%23 = add nuw nsw i64 %22, 2
%24 = getelementptr inbounds i8*, i8** %1, i64 %23
%25 = load i8*, i8** %24
%26 = tail call i8* @atoi(i8* %25)
%27 = ptrtoint i8* %26 to i64
%28 = trunc i64 %27 to i32
%29 = getelementptr inbounds i32, i32* %15, i64 %22
store i32 %28, i32* %29
%30 = add nuw nsw i64 %22, 1
%31 = icmp eq i64 %30, %18
br i1 %31, label %32, label %21
32: ; preds = %21
%33 = add nsw i32 %0, -3
%34 = tail call i32 @vk_bsearch(i32* %15, i32 0, i32 %33, i32 %12)
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = tail call i32 @free(i32* %15)
br label %37
37: ; preds = %19, %32, %4
%38 = phi i32 [ 1, %4 ], [ 2, %19 ], [ 0, %32 ]
ret i32 %38
}