#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 atoi(char *);
int binary_search_ints(int, int *, int);
int /*<<< orphan*/ print_ints(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int v;
  int a[argc - 2];
  int n = argc - 2;
  v = atoi(argv[1]);
  for (int i = 2; i < argc; i++) {
    a[i - 2] = atoi(argv[i]);
  }
  int pos = binary_search_ints(v, a, n);
  if (pos == -1) {
    printf("The value %d could not be found in the array ", v);
    print_ints(a, n);
    printf("\n");
    return 1;
  } else {
    printf("%d appears at position %d in ", v, pos);
    print_ints(a, n);
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0xfffffffe,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
movl   $0x2,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11dd <main+0x9d>
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1060 <atoi@plt>
mov    %eax,%edx
mov    -0x40(%rbp),%rax
mov    -0x30(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11a0 <main+0x60>
mov    -0x40(%rbp),%rsi
mov    -0x14(%rbp),%edi
mov    -0x2c(%rbp),%edx
call   1040 <binary_search_ints@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    1237 <main+0xf7>
mov    -0x14(%rbp),%esi
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x40(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1050 <print_ints@plt>
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x38(%rbp)
jmp    1273 <main+0x133>
mov    -0x14(%rbp),%esi
mov    -0x34(%rbp),%edx
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x40(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1050 <print_ints@plt>
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r13d
lea    -0x2(%r13),%eax
mov    %rsp,%r12
mov    %rax,-0x30(%rbp)
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%r15d
cmp    $0x3,%r13d
jl     11b7 <main+0x67>
mov    %r13d,%r13d
add    $0xfffffffffffffffe,%r13
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    0x10(%r14,%rbx,8),%rdi
call   1070 <atoi@plt>
mov    %eax,(%r12,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r13
jne    11a0 <main+0x50>
mov    %r15d,%edi
mov    %r12,%rsi
mov    -0x30(%rbp),%rbx
mov    %ebx,%edx
call   1050 <binary_search_ints@plt>
cmp    $0xffffffff,%eax
je     11e5 <main+0x95>
lea    0xe5a(%rip),%rdi
xor    %r14d,%r14d
mov    %r15d,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11fc <main+0xac>
lea    0xe14(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r14d
mov    %r12,%rdi
mov    %ebx,%esi
call   1060 <print_ints@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r14d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [46 x i8] c"The value %d could not be found in the array \00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [30 x i8] c"%d appears at position %d in \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = sub nsw i32 %13, 2
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %7
%17 = alloca i32, i64 %15
store i64 %15, i64* %8
%18 = load i32, i32* %4
%19 = sub nsw i32 %18, 2
store i32 %19, i32* %9
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %6
store i32 2, i32* %10
br label %24
24: ; preds = %39, %2
%25 = load i32, i32* %10
%26 = load i32, i32* %4
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %42
28: ; preds = %24
%29 = load i8**, i8*** %5
%30 = load i32, i32* %10
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = call i32 @atoi(i8* %33)
%35 = load i32, i32* %10
%36 = sub nsw i32 %35, 2
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %17, i64 %37
store i32 %34, i32* %38
br label %39
39: ; preds = %28
%40 = load i32, i32* %10
%41 = add nsw i32 %40, 1
store i32 %41, i32* %10
br label %24
42: ; preds = %24
%43 = load i32, i32* %6
%44 = load i32, i32* %9
%45 = call i32 @binary_search_ints(i32 %43, i32* %17, i32 %44)
store i32 %45, i32* %11
%46 = load i32, i32* %11
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %54
48: ; preds = %42
%49 = load i32, i32* %6
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %49)
%51 = load i32, i32* %9
%52 = call i32 @print_ints(i32* %17, i32 %51)
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %12
br label %62
54: ; preds = %42
%55 = load i32, i32* %6
%56 = load i32, i32* %11
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %55, i32 %56)
%58 = load i32, i32* %9
%59 = call i32 @print_ints(i32* %17, i32 %58)
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %61
61: ; preds = %54
store i32 0, i32* %3
store i32 1, i32* %12
br label %62
62: ; preds = %61, %48
%63 = load i8*, i8** %7
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
@.str = [46 x i8] c"The value %d could not be found in the array \00"
@.str.2 = [30 x i8] c"%d appears at position %d in \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = add nsw i32 %0, -2
%4 = zext i32 %3 to i64
%5 = alloca i32, i64 %4
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 @atoi(i8* %7)
%9 = icmp sgt i32 %0, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = zext i32 %0 to i64
br label %15
12: ; preds = %15, %2
%13 = call i32 @binary_search_ints(i32 %8, i32* %5, i32 %3)
%14 = icmp eq i32 %13, -1
br i1 %14, label %24, label %26
15: ; preds = %10, %15
%16 = phi i64 [ 2, %10 ], [ %22, %15 ]
%17 = getelementptr inbounds i8*, i8** %1, i64 %16
%18 = load i8*, i8** %17
%19 = tail call i32 @atoi(i8* %18)
%20 = add nsw i64 %16, -2
%21 = getelementptr inbounds i32, i32* %5, i64 %20
store i32 %19, i32* %21
%22 = add nuw nsw i64 %16, 1
%23 = icmp eq i64 %22, %11
br i1 %23, label %12, label %15
24: ; preds = %12
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %28
26: ; preds = %12
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %8, i32 %13)
br label %28
28: ; preds = %26, %24
%29 = phi i32 [ 1, %24 ], [ 0, %26 ]
%30 = call i32 @print_ints(i32* %5, i32 %3)
%31 = call i32 @putchar(i32 10)
ret i32 %29
}