#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 const *);
int str_in_array(char *s, const char *a[], size_t size) {
  unsigned int i = 0;
  while (i < size) {
    if (strcmp(s, a[i]) == 0) {
      return i;
    }
    ++i;
  }
  return -1;
}


x86 assembly (clang, -O0):
<str_in_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%rax
jae    116f <str_in_array+0x5f>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1161 <str_in_array+0x51>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1176 <str_in_array+0x66>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    112b <str_in_array+0x1b>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_in_array>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0xffffffff,%r14d
test   %rdx,%rdx
je     114e <str_in_array+0x3e>
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r12
xor    %ebp,%ebp
xchg   %ax,%ax
mov    (%r15,%rbp,8),%rsi
mov    %r12,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     114b <str_in_array+0x3b>
add    $0x1,%ebp
cmp    %rbx,%rbp
jb     1130 <str_in_array+0x20>
jmp    114e <str_in_array+0x3e>
mov    %ebp,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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