#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 */
typedef int /*<<< orphan*/ commands;

/* Variables and functions */
scalar_t__ strcmp(char *, char const *);
int scan_cmd(int start, int argc, char **argv) {
  const char *commands[] = {"-a",     "-e",       "-r",    "--dump",
                            "--make", "--syntax", "--list"};
  for (int i = start; i < argc; i++) {
    for (size_t j = 0; j < (sizeof(commands) / sizeof(commands[0])); j++) {
      if (strcmp(argv[i], commands[j]) == 0)
        return i;
    }
  }
  return argc;
}


x86 assembly (clang, -O0):
<scan_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x50(%rbp),%rdi
lea    0x2ca3(%rip),%rsi
mov    $0x38,%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c4 <scan_cmd+0xa4>
movq   $0x0,-0x60(%rbp)
cmpq   $0x7,-0x60(%rbp)
jae    11b1 <scan_cmd+0x91>
mov    -0x18(%rbp),%rax
movslq -0x54(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x60(%rbp),%rax
mov    -0x50(%rbp,%rax,8),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    119b <scan_cmd+0x7b>
mov    -0x54(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ca <scan_cmd+0xaa>
jmp    11a0 <scan_cmd+0x80>
mov    -0x60(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x60(%rbp)
jmp    1161 <scan_cmd+0x41>
jmp    11b6 <scan_cmd+0x96>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    114d <scan_cmd+0x2d>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_cmd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebp
cmp    %esi,%edi
jge    11e5 <scan_cmd+0xd5>
mov    %edi,%ebx
movslq %edi,%rax
movslq %ebp,%r12
lea    (%rdx,%rax,8),%r15
sub    %rax,%r12
xor    %r13d,%r13d
lea    0xec2(%rip),%r14
mov    (%r15,%r13,8),%rdi
mov    %r14,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     11e0 <scan_cmd+0xd0>
mov    (%r15,%r13,8),%rdi
lea    0xea5(%rip),%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     11e0 <scan_cmd+0xd0>
mov    (%r15,%r13,8),%rdi
lea    0xe93(%rip),%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     11e0 <scan_cmd+0xd0>
mov    (%r15,%r13,8),%rdi
lea    0xe81(%rip),%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     11e0 <scan_cmd+0xd0>
mov    (%r15,%r13,8),%rdi
lea    0xe73(%rip),%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     11e0 <scan_cmd+0xd0>
mov    (%r15,%r13,8),%rdi
lea    0xe65(%rip),%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     11e0 <scan_cmd+0xd0>
mov    (%r15,%r13,8),%rdi
lea    0xe59(%rip),%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     11e0 <scan_cmd+0xd0>
add    $0x1,%r13
cmp    %r13,%r12
jne    113e <scan_cmd+0x2e>
jmp    11e5 <scan_cmd+0xd5>
add    %r13d,%ebx
mov    %ebx,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"-a\00"
@.str.1 = [3 x i8] c"-e\00"
@.str.2 = [3 x i8] c"-r\00"
@.str.3 = [7 x i8] c"--dump\00"
@.str.4 = [7 x i8] c"--make\00"
@.str.5 = [9 x i8] c"--syntax\00"
@.str.6 = [7 x i8] c"--list\00"
@__const.scan_cmd.commands = [7 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i32 0, i32 0)]
define i32 @scan_cmd(i32 %0, i32 %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8**
%8 = alloca [7 x i8*]
%9 = alloca i32
%10 = alloca i64
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
%11 = bitcast [7 x i8*]* %8 to i8*
%12 = load i32, i32* %5
store i32 %12, i32* %9
br label %13
13: ; preds = %39, %3
%14 = load i32, i32* %9
%15 = load i32, i32* %6
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %42
17: ; preds = %13
store i64 0, i64* %10
br label %18
18: ; preds = %35, %17
%19 = load i64, i64* %10
%20 = icmp ult i64 %19, 7
br i1 %20, label %21, label %38
21: ; preds = %18
%22 = load i8**, i8*** %7
%23 = load i32, i32* %9
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = load i64, i64* %10
%28 = getelementptr inbounds [7 x i8*], [7 x i8*]* %8, i64 0, i64 %27
%29 = load i8*, i8** %28
%30 = call i64 @strcmp(i8* %26, i8* %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %21
%33 = load i32, i32* %9
store i32 %33, i32* %4
br label %44
34: ; preds = %21
br label %35
35: ; preds = %34
%36 = load i64, i64* %10
%37 = add i64 %36, 1
store i64 %37, i64* %10
br label %18
38: ; preds = %18
br label %39
39: ; preds = %38
%40 = load i32, i32* %9
%41 = add nsw i32 %40, 1
store i32 %41, i32* %9
br label %13
42: ; preds = %13
%43 = load i32, i32* %6
store i32 %43, i32* %4
br label %44
44: ; preds = %42, %32
%45 = load i32, i32* %4
ret i32 %45
}

LLVM IR (-O2):
@.str = [3 x i8] c"-a\00"
@.str.1 = [3 x i8] c"-e\00"
@.str.2 = [3 x i8] c"-r\00"
@.str.3 = [7 x i8] c"--dump\00"
@.str.4 = [7 x i8] c"--make\00"
@.str.5 = [9 x i8] c"--syntax\00"
@.str.6 = [7 x i8] c"--list\00"
define i32 @scan_cmd(i32 %0, i32 %1, i8** nocapture %2) {
%4 = icmp slt i32 %0, %1
br i1 %4, label %5, label %55
5: ; preds = %3
%6 = sext i32 %0 to i64
%7 = sext i32 %1 to i64
br label %8
8: ; preds = %5, %38
%9 = phi i64 [ %6, %5 ], [ %39, %38 ]
%10 = getelementptr inbounds i8*, i8** %2, i64 %9
%11 = load i8*, i8** %10
%12 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %53, label %14
14: ; preds = %8
%15 = load i8*, i8** %10
%16 = tail call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %51, label %18
18: ; preds = %14
%19 = load i8*, i8** %10
%20 = tail call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %49, label %22
22: ; preds = %18
%23 = load i8*, i8** %10
%24 = tail call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %47, label %26
26: ; preds = %22
%27 = load i8*, i8** %10
%28 = tail call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %45, label %30
30: ; preds = %26
%31 = load i8*, i8** %10
%32 = tail call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %43, label %34
34: ; preds = %30
%35 = load i8*, i8** %10
%36 = tail call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %41, label %38
38: ; preds = %34
%39 = add nsw i64 %9, 1
%40 = icmp eq i64 %39, %7
br i1 %40, label %55, label %8
41: ; preds = %34
%42 = trunc i64 %9 to i32
br label %55
43: ; preds = %30
%44 = trunc i64 %9 to i32
br label %55
45: ; preds = %26
%46 = trunc i64 %9 to i32
br label %55
47: ; preds = %22
%48 = trunc i64 %9 to i32
br label %55
49: ; preds = %18
%50 = trunc i64 %9 to i32
br label %55
51: ; preds = %14
%52 = trunc i64 %9 to i32
br label %55
53: ; preds = %8
%54 = trunc i64 %9 to i32
br label %55
55: ; preds = %38, %41, %43, %45, %47, %49, %51, %53, %3
%56 = phi i32 [ %1, %3 ], [ %42, %41 ], [ %44, %43 ], [ %46, %45 ], [ %48, %47 ], [ %50, %49 ], [ %52, %51 ], [ %54, %53 ], [ %1, %38 ]
ret i32 %56
}