#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int, int);
int /*<<< orphan*/ stderr;
int binary_search_ints_helper(int v, int a[], int lb, int ub) {
  fprintf(stderr, "binary_search_ints_helper (%d, a[], %d, %d)\n", v, lb, ub);
  int index = (lb + ub) / 2;
  if (lb == ub) {
    return -1;
  }
  if (a[index] == v) {
    return index;
  } else if (v > a[index]) {
    return binary_search_ints_helper(v, a, index, ub);
  } else {
    return binary_search_ints_helper(v, a, lb, index);
  }
}


x86 assembly (clang, -O0):
<binary_search_ints_helper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    0x2ea4(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
lea    0xeb1(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    117d <binary_search_ints_helper+0x5d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11df <binary_search_ints_helper+0xbf>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x8(%rbp),%eax
jne    119c <binary_search_ints_helper+0x7c>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11df <binary_search_ints_helper+0xbf>
mov    -0x8(%rbp),%eax
mov    -0x10(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jle    11ca <binary_search_ints_helper+0xaa>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1030 <binary_search_ints_helper@plt>
mov    %eax,-0x4(%rbp)
jmp    11df <binary_search_ints_helper+0xbf>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1030 <binary_search_ints_helper@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binary_search_ints_helper>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edi,%r13d
mov    0x2eb3(%rip),%rax
mov    (%rax),%edi
lea    0xeca(%rip),%rsi
mov    %r13d,%edx
mov    %ebx,%ecx
mov    %r15d,%r8d
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
cmp    %r15d,%ebx
je     11a7 <binary_search_ints_helper+0x97>
lea    (%r15,%rbx,1),%eax
lea    0xea8(%rip),%r12
jmp    1183 <binary_search_ints_helper+0x73>
nopw   0x0(%rax,%rax,1)
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    %r12,%rsi
mov    %r13d,%edx
mov    %ebx,%ecx
mov    %ebp,%r8d
call   1030 <fprintf@plt>
lea    (%rbx,%rbp,1),%eax
mov    %ebp,%r15d
cmp    %ebp,%ebx
je     119e <binary_search_ints_helper+0x8e>
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
movslq %ebp,%rax
cmp    %r13d,(%r14,%rax,4)
je     11a5 <binary_search_ints_helper+0x95>
jge    1160 <binary_search_ints_helper+0x50>
mov    %ebp,%ebx
mov    %r15d,%ebp
jmp    1160 <binary_search_ints_helper+0x50>
mov    $0xffffffff,%eax
jmp    11a7 <binary_search_ints_helper+0x97>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [45 x i8] c"binary_search_ints_helper (%d, a[], %d, %d)\0A\00"
define i32 @binary_search_ints_helper(i32 %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%11 = load i32, i32* @stderr
%12 = load i32, i32* %6
%13 = load i32, i32* %8
%14 = load i32, i32* %9
%15 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %13, i32 %14)
%16 = load i32, i32* %8
%17 = load i32, i32* %9
%18 = add nsw i32 %16, %17
%19 = sdiv i32 %18, 2
store i32 %19, i32* %10
%20 = load i32, i32* %8
%21 = load i32, i32* %9
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %4
store i32 -1, i32* %5
br label %54
24: ; preds = %4
%25 = load i32*, i32** %7
%26 = load i32, i32* %10
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
%29 = load i32, i32* %28
%30 = load i32, i32* %6
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %34
32: ; preds = %24
%33 = load i32, i32* %10
store i32 %33, i32* %5
br label %54
34: ; preds = %24
%35 = load i32, i32* %6
%36 = load i32*, i32** %7
%37 = load i32, i32* %10
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %36, i64 %38
%40 = load i32, i32* %39
%41 = icmp sgt i32 %35, %40
br i1 %41, label %42, label %48
42: ; preds = %34
%43 = load i32, i32* %6
%44 = load i32*, i32** %7
%45 = load i32, i32* %10
%46 = load i32, i32* %9
%47 = call i32 @binary_search_ints_helper(i32 %43, i32* %44, i32 %45, i32 %46)
store i32 %47, i32* %5
br label %54
48: ; preds = %34
%49 = load i32, i32* %6
%50 = load i32*, i32** %7
%51 = load i32, i32* %8
%52 = load i32, i32* %10
%53 = call i32 @binary_search_ints_helper(i32 %49, i32* %50, i32 %51, i32 %52)
store i32 %53, i32* %5
br label %54
54: ; preds = %48, %42, %32, %23
%55 = load i32, i32* %5
ret i32 %55
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [45 x i8] c"binary_search_ints_helper (%d, a[], %d, %d)\0A\00"
define i32 @binary_search_ints_helper(i32 %0, i32* %1, i32 %2, i32 %3) {
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %2, i32 %3)
%7 = icmp eq i32 %2, %3
br i1 %7, label %27, label %8
8: ; preds = %4
%9 = add nsw i32 %3, %2
br label %10
10: ; preds = %8, %19
%11 = phi i32 [ %25, %19 ], [ %9, %8 ]
%12 = phi i32 [ %22, %19 ], [ %3, %8 ]
%13 = phi i32 [ %21, %19 ], [ %2, %8 ]
%14 = sdiv i32 %11, 2
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %1, i64 %15
%17 = load i32, i32* %16
%18 = icmp eq i32 %17, %0
br i1 %18, label %27, label %19
19: ; preds = %10
%20 = icmp slt i32 %17, %0
%21 = select i1 %20, i32 %14, i32 %13
%22 = select i1 %20, i32 %12, i32 %14
%23 = load i32, i32* @stderr
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %21, i32 %22)
%25 = add nsw i32 %22, %21
%26 = icmp eq i32 %21, %22
br i1 %26, label %27, label %10
27: ; preds = %19, %10, %4
%28 = phi i32 [ -1, %4 ], [ %14, %10 ], [ -1, %19 ]
ret i32 %28
}