#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 const *, char const *);
int jsY_findword(const char *s, const char **list, int num) {
  int l = 0;
  int r = num - 1;
  while (l <= r) {
    int m = (l + r) >> 1;
    int c = strcmp(s, list[m]);
    if (c < 0)
      r = m - 1;
    else if (c > 0)
      l = m + 1;
    else
      return m;
  }
  return -1;
}


x86 assembly (clang, -O0):
<jsY_findword>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jg     11a8 <jsY_findword+0x98>
mov    -0x20(%rbp),%eax
add    -0x24(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcmp@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    117b <jsY_findword+0x6b>
mov    -0x28(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a3 <jsY_findword+0x93>
cmpl   $0x0,-0x2c(%rbp)
jle    1193 <jsY_findword+0x83>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    119e <jsY_findword+0x8e>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11af <jsY_findword+0x9f>
jmp    11a3 <jsY_findword+0x93>
jmp    1133 <jsY_findword+0x23>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @jsY_findword(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 ], [ 0, %5 ]
%9 = phi i32 [ %24, %23 ], [ %6, %5 ]
%10 = add nsw i32 %8, %9
%11 = ashr i32 %10, 1
%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 = %17, %21
%24 = phi i32 [ %18, %17 ], [ %9, %21 ]
%25 = phi i32 [ %8, %17 ], [ %22, %21 ]
%26 = icmp sgt i32 %25, %24
br i1 %26, label %27, label %7
27: ; preds = %23, %19, %3
%28 = phi i32 [ -1, %3 ], [ %11, %19 ], [ -1, %23 ]
ret i32 %28
}