#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 strcmp(char *, char *);
int binarySearch(char A[][30], char *key, int low, int high) {
  int mid;
  int result;
  if (low > high)
    return -1;
  mid = (high + low) / 2;
  result = strcmp(A[mid], key);
  if (result == 0)
    return mid;
  else if (result > 0)
    return binarySearch(A, key, low, mid - 1);
  else
    return binarySearch(A, key, mid + 1, high);
}


x86 assembly (clang, -O0):
<binarySearch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jle    114e <binarySearch+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d0 <binarySearch+0xb0>
mov    -0x20(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x24(%rbp),%rax
imul   $0x1e,%rax,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcmp@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    118f <binarySearch+0x6f>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d0 <binarySearch+0xb0>
cmpl   $0x0,-0x28(%rbp)
jle    11b7 <binarySearch+0x97>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
call   1040 <binarySearch@plt>
mov    %eax,-0x4(%rbp)
jmp    11d0 <binarySearch+0xb0>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
add    $0x1,%edx
mov    -0x20(%rbp),%ecx
call   1040 <binarySearch@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binarySearch>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xffffffff,%r14d
cmp    %ecx,%edx
jg     1176 <binarySearch+0x66>
mov    %ecx,%ebp
mov    %edx,%r13d
mov    %rsi,%r15
mov    %rdi,%r12
lea    0x0(%rbp,%r13,1),%eax
mov    %eax,%ebx
shr    $0x1f,%ebx
add    %eax,%ebx
sar    %ebx
movslq %ebx,%rax
mov    %rax,%rdi
shl    $0x5,%rdi
sub    %rax,%rdi
sub    %rax,%rdi
add    %r12,%rdi
mov    %r15,%rsi
call   1030 <strcmp@plt>
test   %eax,%eax
je     1173 <binarySearch+0x63>
jle    1169 <binarySearch+0x59>
lea    -0x1(%rbx),%ebp
cmp    %ebx,%r13d
jl     1130 <binarySearch+0x20>
jmp    1176 <binarySearch+0x66>
lea    0x1(%rbx),%r13d
cmp    %ebp,%ebx
jl     1130 <binarySearch+0x20>
jmp    1176 <binarySearch+0x66>
mov    %ebx,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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