#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ _file(int /*<<< orphan*/ *);
int /*<<< orphan*/ _mods(char const *);
int /*<<< orphan*/ _path(char const *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char const *, char *);
int main(int argc, char const *argv[]) {
  printf("db-ticket test tool 0.3\n\n");
  if (argc < 2) {
    fprintf(stderr,
            "Invalid parameters.\nUsage: %s file [mods|file|path]\n (default "
            "mode is 'mods')\n",
            argv[0]);
    return 1;
  }
  short mode = 0;
  if (argc == 3) {
    if (strcmp(argv[2], "file") == 0)
      mode = 1;
    else if (strcmp(argv[2], "path") == 0)
      mode = 2;
  }
  printf("File: %s\n\n", argv[1]);
  if (mode == 0) {
    _mods(argv[1]);
  } else if (mode == 1) {
    FILE *fptr = fopen(argv[1], "rb");
    _file(fptr);
    fclose(fptr);
  } else if (mode == 2) {
    _path(argv[1]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x2,-0x8(%rbp)
jge    11d6 <main+0x56>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe55(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d9 <main+0x159>
movw   $0x0,-0x12(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    123d <main+0xbd>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe74(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    120f <main+0x8f>
movw   $0x1,-0x12(%rbp)
jmp    1238 <main+0xb8>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe50(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1233 <main+0xb3>
movw   $0x2,-0x12(%rbp)
jmp    1238 <main+0xb8>
jmp    123d <main+0xbd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movswl -0x12(%rbp),%eax
cmp    $0x0,%eax
jne    1272 <main+0xf2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <_mods@plt>
jmp    12d2 <main+0x152>
movswl -0x12(%rbp),%eax
cmp    $0x1,%eax
jne    12ae <main+0x12e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdf0(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1090 <_file@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
jmp    12cd <main+0x14d>
movswl -0x12(%rbp),%eax
cmp    $0x2,%eax
jne    12c8 <main+0x148>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <_path@plt>
jmp    12cd <main+0x14d>
jmp    12d2 <main+0x152>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xec7(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x1,%ebp
jg     11cc <main+0x3c>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe43(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%ebp
jmp    1279 <main+0xe9>
cmp    $0x3,%ebp
jne    1220 <main+0x90>
mov    0x10(%rbx),%rdi
lea    0xe73(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1242 <main+0xb2>
mov    0x10(%rbx),%rdi
lea    0xe63(%rip),%rsi
call   1070 <strcmp@plt>
mov    %rax,%r14
mov    0x8(%rbx),%rsi
add    $0x8,%rbx
lea    0xe51(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <printf@plt>
test   %r14,%r14
jne    1236 <main+0xa6>
mov    (%rbx),%rdi
call   1060 <_path@plt>
jmp    1279 <main+0xe9>
mov    0x8(%rbx),%rsi
add    $0x8,%rbx
lea    0xe2a(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%rdi
call   1080 <_mods@plt>
xor    %ebp,%ebp
jmp    1279 <main+0xe9>
mov    0x8(%rbx),%rsi
lea    0xe0c(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbx),%rdi
lea    0xe03(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   10a0 <_file@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"db-ticket test tool 0.3\0A\0A\00"
@stderr = global i32 0
@.str.1 = [79 x i8] c"Invalid parameters.\0AUsage: %s file [mods|file|path]\0A (default mode is 'mods')\0A\00"
@.str.2 = [5 x i8] c"file\00"
@.str.3 = [5 x i8] c"path\00"
@.str.4 = [11 x i8] c"File: %s\0A\0A\00"
@.str.5 = [3 x i8] c"rb\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i16
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.1, i64 0, i64 0), i8* %15)
store i32 1, i32* %3
br label %74
17: ; preds = %2
store i16 0, i16* %6
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 3
br i1 %19, label %20, label %36
20: ; preds = %17
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
%24 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %20
store i16 1, i16* %6
br label %35
27: ; preds = %20
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %27
store i16 2, i16* %6
br label %34
34: ; preds = %33, %27
br label %35
35: ; preds = %34, %26
br label %36
36: ; preds = %35, %17
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %39)
%41 = load i16, i16* %6
%42 = sext i16 %41 to i32
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %49
44: ; preds = %36
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = call i32 @_mods(i8* %47)
br label %73
49: ; preds = %36
%50 = load i16, i16* %6
%51 = sext i16 %50 to i32
%52 = icmp eq i32 %51, 1
br i1 %52, label %53, label %62
53: ; preds = %49
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 1
%56 = load i8*, i8** %55
%57 = call i32* @fopen(i8* %56, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %57, i32** %7
%58 = load i32*, i32** %7
%59 = call i32 @_file(i32* %58)
%60 = load i32*, i32** %7
%61 = call i32 @fclose(i32* %60)
br label %72
62: ; preds = %49
%63 = load i16, i16* %6
%64 = sext i16 %63 to i32
%65 = icmp eq i32 %64, 2
br i1 %65, label %66, label %71
66: ; preds = %62
%67 = load i8**, i8*** %5
%68 = getelementptr inbounds i8*, i8** %67, i64 1
%69 = load i8*, i8** %68
%70 = call i32 @_path(i8* %69)
br label %71
71: ; preds = %66, %62
br label %72
72: ; preds = %71, %53
br label %73
73: ; preds = %72, %44
store i32 0, i32* %3
br label %74
74: ; preds = %73, %11
%75 = load i32, i32* %3
ret i32 %75
}

LLVM IR (-O2):
@stderr = global i32 0
@.str.1 = [79 x i8] c"Invalid parameters.\0AUsage: %s file [mods|file|path]\0A (default mode is 'mods')\0A\00"
@.str.2 = [5 x i8] c"file\00"
@.str.3 = [5 x i8] c"path\00"
@.str.4 = [11 x i8] c"File: %s\0A\0A\00"
@.str.5 = [3 x i8] c"rb\00"
@str = [25 x i8] c"db-ticket test tool 0.3\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([79 x i8], [79 x i8]* @.str.1, i64 0, i64 0), i8* %7)
br label %42
9: ; preds = %2
%10 = icmp eq i32 %0, 3
br i1 %10, label %15, label %11
11: ; preds = %9
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %13)
br label %27
15: ; preds = %9
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %31, label %20
20: ; preds = %15
%21 = load i8*, i8** %16
%22 = tail call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = load i8*, i8** %24
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %25)
br i1 %23, label %39, label %27
27: ; preds = %11, %20
%28 = phi i8** [ %12, %11 ], [ %24, %20 ]
%29 = load i8*, i8** %28
%30 = tail call i32 @_mods(i8* %29)
br label %42
31: ; preds = %15
%32 = getelementptr inbounds i8*, i8** %1, i64 1
%33 = load i8*, i8** %32
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %33)
%35 = load i8*, i8** %32
%36 = tail call i32* @fopen(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%37 = tail call i32 @_file(i32* %36)
%38 = tail call i32 @fclose(i32* %36)
br label %42
39: ; preds = %20
%40 = load i8*, i8** %24
%41 = tail call i32 @_path(i8* %40)
br label %42
42: ; preds = %27, %39, %31, %5
%43 = phi i32 [ 1, %5 ], [ 0, %31 ], [ 0, %39 ], [ 0, %27 ]
ret i32 %43
}