#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*/ printf(char *, int);
int binary_search_with_less_comp(int a[], int l, int r, int key) {
  printf("Searching for %d\n", key);
  int m = 0;
  while (r - l > 1) {
    m = l + (r - l) / 2;
    if (key < a[m])
      r = m;
    else
      l = m;
  }
  if (key == a[l])
    return l;
  return -1;
}


x86 assembly (clang, -O0):
<binary_search_with_less_comp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xed1(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
cmp    $0x1,%eax
jle    1192 <binary_search_with_less_comp+0x82>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x10(%rbp),%rcx
movslq -0x20(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jge    1187 <binary_search_with_less_comp+0x77>
mov    -0x20(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    118d <binary_search_with_less_comp+0x7d>
mov    -0x20(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    113b <binary_search_with_less_comp+0x2b>
mov    -0x1c(%rbp),%eax
mov    -0x10(%rbp),%rcx
movslq -0x14(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jne    11b1 <binary_search_with_less_comp+0xa1>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b8 <binary_search_with_less_comp+0xa8>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binary_search_with_less_comp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %edx,%ebx
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xed8(%rip),%rdi
mov    %ecx,%esi
call   1030 <printf@plt>
mov    %ebx,%eax
sub    %ebp,%eax
cmp    $0x2,%eax
jge    116b <binary_search_with_less_comp+0x5b>
movslq %ebp,%rax
cmp    %r15d,(%r14,%rax,4)
mov    $0xffffffff,%ecx
cmovne %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %eax,%ebp
mov    %ebx,%eax
sub    %ebp,%eax
cmp    $0x1,%eax
jle    1138 <binary_search_with_less_comp+0x28>
shr    %eax
add    %ebp,%eax
movslq %eax,%rcx
cmp    %r15d,(%r14,%rcx,4)
jle    1160 <binary_search_with_less_comp+0x50>
mov    %eax,%ebx
jmp    1164 <binary_search_with_less_comp+0x54>

LLVM IR (-O0):
@.str = [18 x i8] c"Searching for %d\0A\00"
define i32 @binary_search_with_less_comp(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* %9
%12 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 0, i32* %10
br label %13
13: ; preds = %36, %4
%14 = load i32, i32* %8
%15 = load i32, i32* %7
%16 = sub nsw i32 %14, %15
%17 = icmp sgt i32 %16, 1
br i1 %17, label %18, label %37
18: ; preds = %13
%19 = load i32, i32* %7
%20 = load i32, i32* %8
%21 = load i32, i32* %7
%22 = sub nsw i32 %20, %21
%23 = sdiv i32 %22, 2
%24 = add nsw i32 %19, %23
store i32 %24, i32* %10
%25 = load i32, i32* %9
%26 = load i32*, i32** %6
%27 = load i32, i32* %10
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
%30 = load i32, i32* %29
%31 = icmp slt i32 %25, %30
br i1 %31, label %32, label %34
32: ; preds = %18
%33 = load i32, i32* %10
store i32 %33, i32* %8
br label %36
34: ; preds = %18
%35 = load i32, i32* %10
store i32 %35, i32* %7
br label %36
36: ; preds = %34, %32
br label %13
37: ; preds = %13
%38 = load i32, i32* %9
%39 = load i32*, i32** %6
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
%43 = load i32, i32* %42
%44 = icmp eq i32 %38, %43
br i1 %44, label %45, label %47
45: ; preds = %37
%46 = load i32, i32* %7
store i32 %46, i32* %5
br label %48
47: ; preds = %37
store i32 -1, i32* %5
br label %48
48: ; preds = %47, %45
%49 = load i32, i32* %5
ret i32 %49
}

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