#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 opt_arg_scan(const char *array, const char *tokens[]) {
  if (array == NULL)
    return -1;
  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):
<opt_arg_scan>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1137 <opt_arg_scan+0x27>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <opt_arg_scan+0xd2>
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x1d(%rbp)
je     1189 <opt_arg_scan+0x79>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe88(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
xor    $0xff,%al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1199 <opt_arg_scan+0x89>
jmp    11a7 <opt_arg_scan+0x97>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113e <opt_arg_scan+0x2e>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe46(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11d6 <opt_arg_scan+0xc6>
mov    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    11dc <opt_arg_scan+0xcc>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<opt_arg_scan>:
test   %rdi,%rdi
je     118d <opt_arg_scan+0x7d>
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 <opt_arg_scan+0x59>
lea    0xec6(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    (%rbx),%rdi
mov    %r15,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1169 <opt_arg_scan+0x59>
add    $0x1,%r12
mov    0x8(%rbx),%rsi
add    $0x8,%rbx
mov    %r14,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
jne    1140 <opt_arg_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
mov    $0xffffffff,%eax
ret

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

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