#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*/ assert(int *);
int binary_search_recursive(int *arr, int lo, int hi, int target) {
  assert(arr);
  if (lo > hi) {
    return -1;
  }
  int mid = ((hi - lo) / 2) + lo;
  if (target == arr[mid]) {
    return mid;
  } else if (target > arr[mid]) {
    lo = mid + 1;
  } else {
    hi = mid - 1;
  }
  return binary_search_recursive(arr, lo, hi, target);
}


x86 assembly (clang, -O0):
<binary_search_recursive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <assert@plt>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    1156 <binary_search_recursive+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ce <binary_search_recursive+0xae>
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
add    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x10(%rbp),%rcx
movslq -0x20(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jne    1189 <binary_search_recursive+0x69>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ce <binary_search_recursive+0xae>
mov    -0x1c(%rbp),%eax
mov    -0x10(%rbp),%rcx
movslq -0x20(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jle    11ab <binary_search_recursive+0x8b>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b4 <binary_search_recursive+0x94>
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11b9 <binary_search_recursive+0x99>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1040 <binary_search_recursive@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binary_search_recursive>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r15d
mov    %edx,%ebp
mov    %esi,%ebx
mov    %rdi,%r12
call   1030 <assert@plt>
mov    $0xffffffff,%r14d
jmp    113d <binary_search_recursive+0x2d>
nop
add    $0xffffffff,%eax
mov    %eax,%ebp
mov    %r12,%rdi
call   1030 <assert@plt>
cmp    %ebx,%ebp
jl     1168 <binary_search_recursive+0x58>
mov    %ebp,%ecx
sub    %ebx,%ecx
mov    %ecx,%eax
shr    $0x1f,%eax
add    %ecx,%eax
sar    %eax
add    %ebx,%eax
movslq %eax,%rcx
mov    (%r12,%rcx,4),%ecx
cmp    %r15d,%ecx
je     1165 <binary_search_recursive+0x55>
jge    1130 <binary_search_recursive+0x20>
add    $0x1,%eax
mov    %eax,%ebx
jmp    1135 <binary_search_recursive+0x25>
mov    %eax,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @binary_search_recursive(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** %6
%12 = call i32 @assert(i32* %11)
%13 = load i32, i32* %7
%14 = load i32, i32* %8
%15 = icmp sgt i32 %13, %14
br i1 %15, label %16, label %17
16: ; preds = %4
store i32 -1, i32* %5
br label %54
17: ; preds = %4
%18 = load i32, i32* %8
%19 = load i32, i32* %7
%20 = sub nsw i32 %18, %19
%21 = sdiv i32 %20, 2
%22 = load i32, i32* %7
%23 = add nsw i32 %21, %22
store i32 %23, i32* %10
%24 = load i32, i32* %9
%25 = load i32*, i32** %6
%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 = icmp eq i32 %24, %29
br i1 %30, label %31, label %33
31: ; preds = %17
%32 = load i32, i32* %10
store i32 %32, i32* %5
br label %54
33: ; preds = %17
%34 = load i32, i32* %9
%35 = load i32*, i32** %6
%36 = load i32, i32* %10
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
%39 = load i32, i32* %38
%40 = icmp sgt i32 %34, %39
br i1 %40, label %41, label %44
41: ; preds = %33
%42 = load i32, i32* %10
%43 = add nsw i32 %42, 1
store i32 %43, i32* %7
br label %47
44: ; preds = %33
%45 = load i32, i32* %10
%46 = sub nsw i32 %45, 1
store i32 %46, i32* %8
br label %47
47: ; preds = %44, %41
br label %48
48: ; preds = %47
%49 = load i32*, i32** %6
%50 = load i32, i32* %7
%51 = load i32, i32* %8
%52 = load i32, i32* %9
%53 = call i32 @binary_search_recursive(i32* %49, i32 %50, i32 %51, i32 %52)
store i32 %53, i32* %5
br label %54
54: ; preds = %48, %31, %16
%55 = load i32, i32* %5
ret i32 %55
}

LLVM IR (-O2):
define i32 @binary_search_recursive(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = tail call i32 @assert(i32* %0)
%6 = icmp slt i32 %2, %1
br i1 %6, label %25, label %7
7: ; preds = %4, %17
%8 = phi i32 [ %21, %17 ], [ %2, %4 ]
%9 = phi i32 [ %22, %17 ], [ %1, %4 ]
%10 = sub nsw i32 %8, %9
%11 = sdiv i32 %10, 2
%12 = add nsw i32 %11, %9
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i32, i32* %0, i64 %13
%15 = load i32, i32* %14
%16 = icmp eq i32 %15, %3
br i1 %16, label %25, label %17
17: ; preds = %7
%18 = icmp slt i32 %15, %3
%19 = add nsw i32 %12, 1
%20 = add nsw i32 %12, -1
%21 = select i1 %18, i32 %8, i32 %20
%22 = select i1 %18, i32 %19, i32 %9
%23 = tail call i32 @assert(i32* %0)
%24 = icmp slt i32 %21, %22
br i1 %24, label %25, label %7
25: ; preds = %17, %7, %4
%26 = phi i32 [ -1, %4 ], [ %12, %7 ], [ -1, %17 ]
ret i32 %26
}