#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*/ strlen(char *);
int /*<<< orphan*/ strncasecmp(char *, char *, int /*<<< orphan*/);
int find_string(char *s, char *table[]) {
  int i;
  for (i = 0; table[i]; i++) {
    if (!strncasecmp(table[i], s, strlen(table[i])))
      return i;
  }
  return -1;
}


x86 assembly (clang, -O0):
<find_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11a9 <find_string+0x89>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1040 <strncasecmp@plt>
cmp    $0x0,%eax
jne    1196 <find_string+0x76>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b0 <find_string+0x90>
jmp    119b <find_string+0x7b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1137 <find_string+0x17>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_string>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    (%rsi),%rbp
mov    $0xffffffff,%r14d
test   %rbp,%rbp
je     116c <find_string+0x4c>
mov    %rsi,%r12
mov    %rdi,%r15
xor    %ebx,%ebx
xchg   %ax,%ax
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <strncasecmp@plt>
test   %eax,%eax
je     1169 <find_string+0x49>
mov    0x8(%r12,%rbx,8),%rbp
add    $0x1,%rbx
test   %rbp,%rbp
jne    1140 <find_string+0x20>
jmp    116c <find_string+0x4c>
mov    %ebx,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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