#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 const *, char const *);
int scan(const char *array, const char *tokens[]) {
  int index = 0;
  while (strcmp(array, tokens[index]) != 0 &&
         !(strcmp(tokens[index], "\0") == 0))
    ++index;
  return (strcmp(tokens[index], "\0") == 0) ? -1 : index;
}


x86 assembly (clang, -O0):
<scan>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x15(%rbp)
je     1172 <scan+0x62>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe9f(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
xor    $0xff,%al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1182 <scan+0x72>
jmp    1190 <scan+0x80>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1127 <scan+0x17>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe5d(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11bf <scan+0xaf>
mov    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c5 <scan+0xb5>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    (%rsi),%rsi
call   1030 <strcmp@plt>
xor    %r12d,%r12d
test   %rax,%rax
je     1169 <scan+0x59>
lea    0xecb(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rbx),%rdi
mov    %r15,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1169 <scan+0x59>
add    $0x1,%r12
mov    0x8(%rbx),%rsi
add    $0x8,%rbx
mov    %r14,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
jne    1140 <scan+0x30>
mov    (%rbx),%rdi
lea    0xe8d(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x1,%rax
sbb    %eax,%eax
or     %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] zeroinitializer
define i32 @scan(i8* %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = tail call i64 @strcmp(i8* %0, i8* %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %22, label %6
6: ; preds = %2, %12
%7 = phi i64 [ %13, %12 ], [ 0, %2 ]
%8 = phi i8** [ %14, %12 ], [ %1, %2 ]
%9 = load i8*, i8** %8
%10 = tail call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %18, label %12
12: ; preds = %6
%13 = add nuw i64 %7, 1
%14 = getelementptr inbounds i8*, i8** %1, i64 %13
%15 = load i8*, i8** %14
%16 = tail call i64 @strcmp(i8* %0, i8* %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %6
18: ; preds = %12, %6
%19 = phi i64 [ %7, %6 ], [ %13, %12 ]
%20 = phi i8** [ %8, %6 ], [ %14, %12 ]
%21 = trunc i64 %19 to i32
br label %22
22: ; preds = %18, %2
%23 = phi i32 [ 0, %2 ], [ %21, %18 ]
%24 = phi i8** [ %1, %2 ], [ %20, %18 ]
%25 = load i8*, i8** %24
%26 = tail call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
%28 = select i1 %27, i32 -1, i32 %23
ret i32 %28
}