#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__ str_cmp(char *, char const *);
extern int array_scan(char *keys[], int len, const char *key) {
  int i;
  for (i = 0; i < len; ++i)
    if (str_cmp(keys[i], key) == 0)
      break;
  return i == len ? -1 : i;
}


x86 assembly (clang, -O0):
<array_scan>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    116d <array_scan+0x5d>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <str_cmp@plt>
cmp    $0x0,%rax
jne    115a <array_scan+0x4a>
jmp    116d <array_scan+0x5d>
jmp    115f <array_scan+0x4f>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112a <array_scan+0x1a>
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    1186 <array_scan+0x76>
mov    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    118c <array_scan+0x7c>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<array_scan>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
test   %esi,%esi
jle    1150 <array_scan+0x40>
mov    %rdx,%r15
mov    %rdi,%rbp
mov    %r14d,%r12d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    0x0(%rbp,%rbx,8),%rdi
mov    %r15,%rsi
call   1030 <str_cmp@plt>
test   %rax,%rax
je     1152 <array_scan+0x42>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1130 <array_scan+0x20>
mov    %r12d,%ebx
jmp    1152 <array_scan+0x42>
xor    %ebx,%ebx
cmp    %r14d,%ebx
mov    $0xffffffff,%eax
cmovne %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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