#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 */
scalar_t__ strcmp(char const *, char *);
int lookup(const char *tab[], char *s, int tableLength) {
  int found = 0;
  int i = tableLength;
  while (!found && --i >= 0) {
    found = (0 == strcmp(tab[i], s));
  }
  return i;
}


x86 assembly (clang, -O0):
<lookup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x18(%rbp)
mov    %al,-0x1d(%rbp)
jne    1151 <lookup+0x41>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
setge  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1161 <lookup+0x51>
jmp    118e <lookup+0x7e>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x18(%rbp)
jmp    1130 <lookup+0x20>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lookup>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%ebx
mov    %rbx,%r12
test   %r12d,%r12d
jle    1140 <lookup+0x30>
lea    -0x1(%r12),%rbx
mov    %ebx,%eax
mov    (%r15,%rax,8),%rdi
mov    %r14,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
jne    1120 <lookup+0x10>
add    $0xffffffff,%r12d
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @lookup(i8** %0, i8* %1, i32 %2) {
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
%9 = load i32, i32* %6
store i32 %9, i32* %8
br label %10
10: ; preds = %19, %3
%11 = load i32, i32* %7
%12 = icmp ne i32 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = load i32, i32* %8
%15 = add nsw i32 %14, -1
store i32 %15, i32* %8
%16 = icmp sge i32 %15, 0
br label %17
17: ; preds = %13, %10
%18 = phi i1 [ false, %10 ], [ %16, %13 ]
br i1 %18, label %19, label %29
19: ; preds = %17
%20 = load i8**, i8*** %4
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
%24 = load i8*, i8** %23
%25 = load i8*, i8** %5
%26 = call i64 @strcmp(i8* %24, i8* %25)
%27 = icmp eq i64 0, %26
%28 = zext i1 %27 to i32
store i32 %28, i32* %7
br label %10
29: ; preds = %17
%30 = load i32, i32* %8
ret i32 %30
}

LLVM IR (-O2):
define i32 @lookup(i8** nocapture %0, i8* %1, i32 %2) {
%4 = zext i32 %2 to i64
br label %5
5: ; preds = %3, %10
%6 = phi i64 [ %4, %3 ], [ %7, %10 ]
%7 = add nsw i64 %6, -1
%8 = trunc i64 %6 to i32
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %5
%11 = and i64 %7, 4294967295
%12 = getelementptr inbounds i8*, i8** %0, i64 %11
%13 = load i8*, i8** %12
%14 = tail call i64 @strcmp(i8* %13, i8* %1)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %5
16: ; preds = %10, %5
%17 = trunc i64 %7 to i32
ret i32 %17
}