#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*/ strcmp(char *, char *);
int sym_lookup(char **table, int table_size, char *look) {
  int i = 0;
  while (i < table_size)
    if (!strcmp(table[i++], look))
      return i - 1;
  return -1;
}


x86 assembly (clang, -O0):
<sym_lookup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1171 <sym_lookup+0x61>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x24(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    116c <sym_lookup+0x5c>
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1178 <sym_lookup+0x68>
jmp    112a <sym_lookup+0x1a>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sym_lookup>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%r12
xor    %ebx,%ebx
test   %esi,%esi
cmovle %ebx,%r15d
nopl   0x0(%rax)
cmp    %rbx,%r15
je     114e <sym_lookup+0x3e>
mov    (%r12,%rbx,8),%rdi
add    $0x1,%rbx
mov    %r14,%rsi
call   1030 <strcmp@plt>
test   %eax,%eax
jne    1130 <sym_lookup+0x20>
add    $0xffffffff,%ebx
jmp    1153 <sym_lookup+0x43>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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