#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 bs(char *query, char **against, int len) {
  int cond;
  int low, high, mid;
  low = 0;
  high = len - 1;
  while (low <= high) {
    mid = (low + high) / 2;
    if ((cond = strcmp(query, *(against + mid))) < 0)
      high = mid - 1;
    else if (cond > 0)
      low = mid + 1;
    else
      return mid;
  }
  return -1;
}


x86 assembly (clang, -O0):
<bs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jg     11ac <bs+0x9c>
mov    -0x24(%rbp),%eax
add    -0x28(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcmp@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    117f <bs+0x6f>
mov    -0x2c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11a7 <bs+0x97>
cmpl   $0x0,-0x20(%rbp)
jle    1197 <bs+0x87>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a2 <bs+0x92>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b3 <bs+0xa3>
jmp    11a7 <bs+0x97>
jmp    1133 <bs+0x23>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bs>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xffffffff,%r14d
test   %edx,%edx
jle    117d <bs+0x6d>
mov    %edx,%r13d
mov    %rsi,%r15
mov    %rdi,%r12
add    $0xffffffff,%r13d
xor    %ebp,%ebp
jmp    114b <bs+0x3b>
cs nopw 0x0(%rax,%rax,1)
add    $0xffffffff,%ebx
mov    %ebx,%r13d
cmp    %r13d,%ebp
jg     117d <bs+0x6d>
lea    0x0(%r13,%rbp,1),%eax
mov    %eax,%ebx
shr    $0x1f,%ebx
add    %eax,%ebx
sar    %ebx
movslq %ebx,%rax
mov    (%r15,%rax,8),%rsi
mov    %r12,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
js     1140 <bs+0x30>
je     117a <bs+0x6a>
add    $0x1,%ebx
mov    %ebx,%ebp
cmp    %r13d,%ebp
jle    114b <bs+0x3b>
jmp    117d <bs+0x6d>
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 @bs(i8* %0, i8** %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i32 %2, i32* %7
store i32 0, i32* %9
%12 = load i32, i32* %7
%13 = sub nsw i32 %12, 1
store i32 %13, i32* %10
br label %14
14: ; preds = %43, %3
%15 = load i32, i32* %9
%16 = load i32, i32* %10
%17 = icmp sle i32 %15, %16
br i1 %17, label %18, label %44
18: ; preds = %14
%19 = load i32, i32* %9
%20 = load i32, i32* %10
%21 = add nsw i32 %19, %20
%22 = sdiv i32 %21, 2
store i32 %22, i32* %11
%23 = load i8*, i8** %5
%24 = load i8**, i8*** %6
%25 = load i32, i32* %11
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%28 = load i8*, i8** %27
%29 = call i32 @strcmp(i8* %23, i8* %28)
store i32 %29, i32* %8
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %18
%32 = load i32, i32* %11
%33 = sub nsw i32 %32, 1
store i32 %33, i32* %10
br label %43
34: ; preds = %18
%35 = load i32, i32* %8
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = load i32, i32* %11
%39 = add nsw i32 %38, 1
store i32 %39, i32* %9
br label %42
40: ; preds = %34
%41 = load i32, i32* %11
store i32 %41, i32* %4
br label %45
42: ; preds = %37
br label %43
43: ; preds = %42, %31
br label %14
44: ; preds = %14
store i32 -1, i32* %4
br label %45
45: ; preds = %44, %40
%46 = load i32, i32* %4
ret i32 %46
}

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