#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(char *array, const char *tokens[]) {
  int index = 0;
  while ((strcmp(array, tokens[index]) != 0) &&
         !(strcmp(tokens[index], "\0") == 0))
    ++index;
  return 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    -0x14(%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,%r14
mov    %rdi,%r15
mov    (%rsi),%rsi
call   1030 <strcmp@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1167 <scan+0x57>
lea    0xecc(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r14,%rbx,8),%rdi
mov    %r12,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1167 <scan+0x57>
mov    0x8(%r14,%rbx,8),%rsi
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
jne    1140 <scan+0x30>
mov    %ebx,%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 i32, i32* %5
ret i32 %30
}

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 %21, 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 = trunc i64 %19 to i32
br label %21
21: ; preds = %18, %2
%22 = phi i32 [ 0, %2 ], [ %20, %18 ]
ret i32 %22
}