#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 angel_char_array_lookup(char *v[], char *tofind) {
  int ret = -1;
  int i;
  for (i = 0; ((v[i] != NULL) && (ret == -1)); i++) {
    if (strcmp(v[i], tofind) == 0)
      ret = 0;
  }
  return ret;
}


x86 assembly (clang, -O0):
<angel_char_array_lookup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rcx
movslq -0x18(%rbp),%rdx
xor    %eax,%eax
cmpq   $0x0,(%rcx,%rdx,8)
mov    %al,-0x19(%rbp)
je     1150 <angel_char_array_lookup+0x40>
cmpl   $0xffffffff,-0x14(%rbp)
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1160 <angel_char_array_lookup+0x50>
jmp    1199 <angel_char_array_lookup+0x89>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1186 <angel_char_array_lookup+0x76>
movl   $0x0,-0x14(%rbp)
jmp    118b <angel_char_array_lookup+0x7b>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112e <angel_char_array_lookup+0x1e>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<angel_char_array_lookup>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%rdi
test   %rdi,%rdi
je     1150 <angel_char_array_lookup+0x40>
mov    %rsi,%r14
add    $0x8,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1149 <angel_char_array_lookup+0x39>
mov    (%rbx),%rdi
add    $0x8,%rbx
test   %rdi,%rdi
jne    1130 <angel_char_array_lookup+0x20>
neg    %rax
sbb    %eax,%eax
jmp    1155 <angel_char_array_lookup+0x45>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @angel_char_array_lookup(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8** %0, i8*** %3
store i8* %1, i8** %4
store i32 -1, i32* %5
store i32 0, i32* %6
br label %7
7: ; preds = %30, %2
%8 = load i8**, i8*** %3
%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 %17
14: ; preds = %7
%15 = load i32, i32* %5
%16 = icmp eq i32 %15, -1
br label %17
17: ; preds = %14, %7
%18 = phi i1 [ false, %7 ], [ %16, %14 ]
br i1 %18, label %19, label %33
19: ; preds = %17
%20 = load i8**, i8*** %3
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
%24 = load i8*, i8** %23
%25 = load i8*, i8** %4
%26 = call i64 @strcmp(i8* %24, i8* %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %19
store i32 0, i32* %5
br label %29
29: ; preds = %28, %19
br label %30
30: ; preds = %29
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %7
33: ; preds = %17
%34 = load i32, i32* %5
ret i32 %34
}

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