#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 */
int /*<<< orphan*/ exit(int);
int input_set_file(char const *);
int /*<<< orphan*/ input_set_interactive();
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char const *, char *);
int parse_switches(const int argc, const char *argv[]) {
  const char *filename = NULL;
  for (int argi = 1; argi < argc; argi++) {
    const char *arg = argv[argi];
    if (arg[0] == '-') {
      if (arg[1] == '-') {
        if (strcmp(arg + 2, "in") == 0) {
          goto SWITCH_FILEIN;
        } else {
          goto SWITCH_INVALID;
        }
      } else {
        switch (arg[1]) {
        case 'i':
        SWITCH_FILEIN:
          if (argi + 1 >= argc) {
            printf("-i/--in switch needs an argument\n");
            return -1;
          }
          argi++;
          filename = argv[argi];
          break;
        default:
          goto SWITCH_INVALID;
        }
      }
    } else {
    SWITCH_INVALID:
      printf("Invalid switch %s\n", arg);
      exit(-1);
    }
  }
  if (filename == NULL)
    input_set_interactive();
  else {
    if (input_set_file(filename) == false)
      return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_switches>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1276 <parse_switches+0x126>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1242 <parse_switches+0xf2>
mov    -0x28(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2d,%eax
jne    11d3 <parse_switches+0x83>
mov    -0x28(%rbp),%rdi
add    $0x2,%rdi
lea    0xe46(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11ce <parse_switches+0x7e>
jmp    11ec <parse_switches+0x9c>
jmp    1247 <parse_switches+0xf7>
mov    -0x28(%rbp),%rax
mov    0x1(%rax),%al
sub    $0x69,%al
jne    1233 <parse_switches+0xe3>
jmp    11e7 <parse_switches+0x97>
jmp    11ec <parse_switches+0x9c>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cmp    -0x8(%rbp),%eax
jl     1215 <parse_switches+0xc5>
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b7 <parse_switches+0x167>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x18(%rbp)
jmp    1238 <parse_switches+0xe8>
jmp    1247 <parse_switches+0xf7>
jmp    123d <parse_switches+0xed>
jmp    1263 <parse_switches+0x113>
jmp    1247 <parse_switches+0xf7>
mov    -0x28(%rbp),%rsi
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
jmp    1268 <parse_switches+0x118>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116e <parse_switches+0x1e>
cmpq   $0x0,-0x18(%rbp)
jne    128d <parse_switches+0x13d>
mov    $0x0,%al
call   1060 <input_set_interactive@plt>
jmp    12b0 <parse_switches+0x160>
mov    -0x18(%rbp),%rdi
call   1030 <input_set_file@plt>
cmp    $0x0,%eax
jne    12ab <parse_switches+0x15b>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b7 <parse_switches+0x167>
jmp    12b0 <parse_switches+0x160>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_switches>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x2,%edi
jl     11cf <parse_switches+0x6f>
mov    %rsi,%r15
mov    %edi,%r12d
xor    %ebp,%ebp
lea    0xe84(%rip),%r14
nopl   0x0(%rax)
mov    0x8(%r15,%rbp,8),%rbx
cmpb   $0x2d,(%rbx)
jne    11f4 <parse_switches+0x94>
movzbl 0x1(%rbx),%eax
cmp    $0x69,%al
je     11a7 <parse_switches+0x47>
cmp    $0x2d,%al
jne    11f4 <parse_switches+0x94>
lea    0x2(%rbx),%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11f4 <parse_switches+0x94>
lea    0x2(%rbp),%eax
cmp    %r12d,%eax
jge    11da <parse_switches+0x7a>
add    $0x2,%rbp
lea    0x1(%rbp),%eax
cmp    %r12d,%eax
jl     1180 <parse_switches+0x20>
mov    (%r15,%rbp,8),%rdi
test   %rdi,%rdi
je     11cf <parse_switches+0x6f>
call   1040 <input_set_file@plt>
test   %eax,%eax
jne    11d6 <parse_switches+0x76>
jmp    11e6 <parse_switches+0x86>
xor    %eax,%eax
call   1070 <input_set_interactive@plt>
xor    %eax,%eax
jmp    11eb <parse_switches+0x8b>
lea    0xe35(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe08(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"in\00"
@.str.1 = [34 x i8] c"-i/--in switch needs an argument\0A\00"
@.str.2 = [19 x i8] c"Invalid switch %s\0A\00"
define i32 @parse_switches(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i32 1, i32* %7
br label %9
9: ; preds = %67, %2
%10 = load i32, i32* %7
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %70
13: ; preds = %9
%14 = load i8**, i8*** %5
%15 = load i32, i32* %7
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %14, i64 %16
%18 = load i8*, i8** %17
store i8* %18, i8** %8
%19 = load i8*, i8** %8
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 45
br i1 %23, label %24, label %61
24: ; preds = %13
%25 = load i8*, i8** %8
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 45
br i1 %29, label %30, label %37
30: ; preds = %24
%31 = load i8*, i8** %8
%32 = getelementptr inbounds i8, i8* %31, i64 2
%33 = call i64 @strcmp(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %30
br label %43
36: ; preds = %30
br label %62
37: ; preds = %24
%38 = load i8*, i8** %8
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
switch i32 %41, label %58 [
i32 105, label %42
]
42: ; preds = %37
br label %43
43: ; preds = %42, %35
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
%46 = load i32, i32* %4
%47 = icmp sge i32 %45, %46
br i1 %47, label %48, label %50
48: ; preds = %43
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %82
50: ; preds = %43
%51 = load i32, i32* %7
%52 = add nsw i32 %51, 1
store i32 %52, i32* %7
%53 = load i8**, i8*** %5
%54 = load i32, i32* %7
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8*, i8** %53, i64 %55
%57 = load i8*, i8** %56
store i8* %57, i8** %6
br label %59
58: ; preds = %37
br label %62
59: ; preds = %50
br label %60
60: ; preds = %59
br label %66
61: ; preds = %13
br label %62
62: ; preds = %61, %58, %36
%63 = load i8*, i8** %8
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %63)
%65 = call i32 @exit(i32 -1)
unreachable
66: ; preds = %60
br label %67
67: ; preds = %66
%68 = load i32, i32* %7
%69 = add nsw i32 %68, 1
store i32 %69, i32* %7
br label %9
70: ; preds = %9
%71 = load i8*, i8** %6
%72 = icmp eq i8* %71, null
br i1 %72, label %73, label %75
73: ; preds = %70
%74 = call i32 (...) @input_set_interactive()
br label %81
75: ; preds = %70
%76 = load i8*, i8** %6
%77 = call i32 @input_set_file(i8* %76)
%78 = icmp eq i32 %77, 0
br i1 %78, label %79, label %80
79: ; preds = %75
store i32 -1, i32* %3
br label %82
80: ; preds = %75
br label %81
81: ; preds = %80, %73
store i32 0, i32* %3
br label %82
82: ; preds = %81, %79, %48
%83 = load i32, i32* %3
ret i32 %83
}

LLVM IR (-O2):
@.str = [3 x i8] c"in\00"
@.str.2 = [19 x i8] c"Invalid switch %s\0A\00"
@str = [33 x i8] c"-i/--in switch needs an argument\00"
define i32 @parse_switches(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %34
4: ; preds = %2, %26
%5 = phi i64 [ %27, %26 ], [ 1, %2 ]
%6 = getelementptr inbounds i8*, i8** %1, i64 %5
%7 = load i8*, i8** %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 45
br i1 %9, label %10, label %21
10: ; preds = %4
%11 = getelementptr inbounds i8, i8* %7, i64 1
%12 = load i8, i8* %11
switch i8 %12, label %21 [
i8 45, label %13
i8 105, label %17
]
13: ; preds = %10
%14 = getelementptr inbounds i8, i8* %7, i64 2
%15 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %10, %13
%18 = add nuw nsw i64 %5, 1
%19 = trunc i64 %18 to i32
%20 = icmp slt i32 %19, %0
br i1 %20, label %26, label %24
21: ; preds = %10, %4, %13
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%23 = tail call i32 @exit(i32 -1)
unreachable
24: ; preds = %17
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
br label %40
26: ; preds = %17
%27 = add nuw i64 %5, 2
%28 = trunc i64 %27 to i32
%29 = icmp slt i32 %28, %0
br i1 %29, label %4, label %30
30: ; preds = %26
%31 = getelementptr inbounds i8*, i8** %1, i64 %18
%32 = load i8*, i8** %31
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %36
34: ; preds = %2, %30
%35 = tail call i32 (...) @input_set_interactive()
br label %39
36: ; preds = %30
%37 = tail call i32 @input_set_file(i8* %32)
%38 = icmp eq i32 %37, 0
br i1 %38, label %40, label %39
39: ; preds = %36, %34
br label %40
40: ; preds = %24, %36, %39
%41 = phi i32 [ 0, %39 ], [ -1, %36 ], [ -1, %24 ]
ret i32 %41
}