#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 *, char *);
int search(char str[32], char sym_table[][32], int entries_in_table) {
  int i;
  for (i = 0; i < entries_in_table; i++) {
    if (strcmp(str, sym_table[i]) == 0) {
      break;
    }
  }
  if (i >= entries_in_table)
    return -1;
  else
    return i;
}


x86 assembly (clang, -O0):
<search>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1170 <search+0x60>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movslq -0x20(%rbp),%rax
shl    $0x5,%rax
add    %rax,%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    115d <search+0x4d>
jmp    1170 <search+0x60>
jmp    1162 <search+0x52>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    112a <search+0x1a>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     1188 <search+0x78>
movl   $0xffffffff,-0x4(%rbp)
jmp    118e <search+0x7e>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<search>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0xffffffff,%r14d
test   %edx,%edx
jle    1152 <search+0x42>
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %edx,%r12d
xor    %ebp,%ebp
nopl   (%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     114f <search+0x3f>
add    $0x1,%rbp
add    $0x20,%rbx
cmp    %rbp,%r12
jne    1130 <search+0x20>
jmp    1152 <search+0x42>
mov    %ebp,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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