#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ globals_free();
scalar_t__ parse_buffer(int /*<<< orphan*/ *, char *, size_t);
int /*<<< orphan*/ printf(char *);
scalar_t__ scan_globals(char *, size_t);
size_t scan_input(char *, char **);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    printf("No input file. Usage: mimasm <infile> [<outfile>]\n");
    printf("Standard output file is out.mima\n");
    return 0;
  }
  FILE *output;
  char *outfile = "out.mima";
  char *buffer = NULL;
  size_t scanned_length = 0;
  if (argc > 2) {
    outfile = argv[2];
  }
  printf("M:MAIN: Scanning input file\n");
  scanned_length = scan_input(argv[1], &buffer);
  if (scanned_length < 2) {
    printf("E:MAIN: Failed to read input file\n");
    free(buffer);
    return EXIT_FAILURE;
  }
  output = fopen(outfile, "wb");
  if (!output) {
    printf("E:MAIN: Could not open output file\n");
    free(buffer);
    return EXIT_FAILURE;
  }
  printf("M:MAIN: Building global table\n");
  if (scan_globals(buffer, scanned_length)) {
    printf("E:MAIN: Global scanning raised errors\n");
    globals_free();
    free(buffer);
    fclose(output);
    return EXIT_FAILURE;
  }
  printf("M:MAIN: Parsing statements\n");
  if (parse_buffer(output, buffer, scanned_length)) {
    printf("E:MAIN: Parser raised irrecoverable error\n");
    globals_free();
    free(buffer);
    fclose(output);
    return EXIT_FAILURE;
  }
  printf("M:MAIN: Cleaning up\n");
  globals_free();
  free(buffer);
  fclose(output);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11c4 <main+0x44>
lea    0xe59(%rip),%rdi
call   1050 <printf@plt>
lea    0xe80(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1373 <main+0x1f3>
lea    0xe8a(%rip),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11f5 <main+0x75>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
lea    0xe62(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x28(%rbp),%rsi
call   1090 <scan_input@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x2,-0x30(%rbp)
jae    1247 <main+0xc7>
lea    0xe53(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1373 <main+0x1f3>
mov    -0x20(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    128c <main+0x10c>
lea    0xe34(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1373 <main+0x1f3>
lea    0xe32(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1060 <scan_globals@plt>
cmp    $0x0,%rax
je     12e5 <main+0x165>
lea    0xe2e(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1080 <globals_free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2d05(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1373 <main+0x1f3>
lea    0xe1f(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1070 <parse_buffer@plt>
cmp    $0x0,%rax
je     1342 <main+0x1c2>
lea    0xe14(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1080 <globals_free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2ca8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1373 <main+0x1f3>
lea    0xe09(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1080 <globals_free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2c6a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     11a8 <main+0x28>
lea    0xf71(%rip),%rdi
call   1040 <puts@plt>
lea    0xf97(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
jmp    1290 <main+0x110>
mov    %rsi,%rbx
movq   $0x0,(%rsp)
cmp    $0x2,%edi
jne    11c1 <main+0x41>
lea    0xf8c(%rip),%r14
jmp    11c5 <main+0x45>
mov    0x10(%rbx),%r14
lea    0xe37(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%rbx),%rdi
mov    %rsp,%rsi
call   1090 <scan_input@plt>
cmp    $0x1,%rax
ja     11ec <main+0x6c>
lea    0xef5(%rip),%rdi
jmp    1233 <main+0xb3>
mov    %rax,%rbx
lea    0xe0a(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     122c <main+0xac>
mov    %rax,%r14
lea    0xe35(%rip),%rdi
call   1040 <puts@plt>
mov    (%rsp),%rdi
mov    %rbx,%rsi
call   1060 <scan_globals@plt>
test   %rax,%rax
je     1243 <main+0xc3>
lea    0xe8f(%rip),%rdi
jmp    126a <main+0xea>
lea    0xdec(%rip),%rdi
call   1040 <puts@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
jmp    1287 <main+0x107>
lea    0xe16(%rip),%rdi
call   1040 <puts@plt>
mov    (%rsp),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1070 <parse_buffer@plt>
test   %rax,%rax
je     1298 <main+0x118>
lea    0xe25(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1080 <globals_free@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    0x2d52(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xddc(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1080 <globals_free@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    0x2d15(%rip),%rax
jmp    128e <main+0x10e>

LLVM IR (-O0):
@.str = [51 x i8] c"No input file. Usage: mimasm <infile> [<outfile>]\0A\00"
@.str.1 = [34 x i8] c"Standard output file is out.mima\0A\00"
@.str.2 = [9 x i8] c"out.mima\00"
@.str.3 = [29 x i8] c"M:MAIN: Scanning input file\0A\00"
@.str.4 = [35 x i8] c"E:MAIN: Failed to read input file\0A\00"
@EXIT_FAILURE = global i32 0
@.str.5 = [3 x i8] c"wb\00"
@.str.6 = [36 x i8] c"E:MAIN: Could not open output file\0A\00"
@.str.7 = [31 x i8] c"M:MAIN: Building global table\0A\00"
@.str.8 = [39 x i8] c"E:MAIN: Global scanning raised errors\0A\00"
@.str.9 = [28 x i8] c"M:MAIN: Parsing statements\0A\00"
@.str.10 = [43 x i8] c"E:MAIN: Parser raised irrecoverable error\0A\00"
@.str.11 = [21 x i8] c"M:MAIN: Cleaning up\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %82
15: ; preds = %2
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8** %7
store i8* null, i8** %8
store i64 0, i64* %9
%16 = load i32, i32* %4
%17 = icmp sgt i32 %16, 2
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
store i8* %21, i8** %7
br label %22
22: ; preds = %18, %15
%23 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i64 @scan_input(i8* %26, i8** %8)
store i64 %27, i64* %9
%28 = load i64, i64* %9
%29 = icmp ult i64 %28, 2
br i1 %29, label %30, label %35
30: ; preds = %22
%31 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
%32 = load i8*, i8** %8
%33 = call i32 @free(i8* %32)
%34 = load i32, i32* @EXIT_FAILURE
store i32 %34, i32* %3
br label %82
35: ; preds = %22
%36 = load i8*, i8** %7
%37 = call i32* @fopen(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %37, i32** %6
%38 = load i32*, i32** %6
%39 = icmp ne i32* %38, null
br i1 %39, label %45, label %40
40: ; preds = %35
%41 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
%42 = load i8*, i8** %8
%43 = call i32 @free(i8* %42)
%44 = load i32, i32* @EXIT_FAILURE
store i32 %44, i32* %3
br label %82
45: ; preds = %35
%46 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0))
%47 = load i8*, i8** %8
%48 = load i64, i64* %9
%49 = call i64 @scan_globals(i8* %47, i64 %48)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %59
51: ; preds = %45
%52 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.8, i64 0, i64 0))
%53 = call i32 (...) @globals_free()
%54 = load i8*, i8** %8
%55 = call i32 @free(i8* %54)
%56 = load i32*, i32** %6
%57 = call i32 @fclose(i32* %56)
%58 = load i32, i32* @EXIT_FAILURE
store i32 %58, i32* %3
br label %82
59: ; preds = %45
%60 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0))
%61 = load i32*, i32** %6
%62 = load i8*, i8** %8
%63 = load i64, i64* %9
%64 = call i64 @parse_buffer(i32* %61, i8* %62, i64 %63)
%65 = icmp ne i64 %64, 0
br i1 %65, label %66, label %74
66: ; preds = %59
%67 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.10, i64 0, i64 0))
%68 = call i32 (...) @globals_free()
%69 = load i8*, i8** %8
%70 = call i32 @free(i8* %69)
%71 = load i32*, i32** %6
%72 = call i32 @fclose(i32* %71)
%73 = load i32, i32* @EXIT_FAILURE
store i32 %73, i32* %3
br label %82
74: ; preds = %59
%75 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0))
%76 = call i32 (...) @globals_free()
%77 = load i8*, i8** %8
%78 = call i32 @free(i8* %77)
%79 = load i32*, i32** %6
%80 = call i32 @fclose(i32* %79)
%81 = load i32, i32* @EXIT_SUCCESS
store i32 %81, i32* %3
br label %82
82: ; preds = %74, %66, %51, %40, %30, %12
%83 = load i32, i32* %3
ret i32 %83
}

LLVM IR (-O2):
@.str.2 = [9 x i8] c"out.mima\00"
@EXIT_FAILURE = global i32 0
@.str.5 = [3 x i8] c"wb\00"
@EXIT_SUCCESS = global i32 0
@str = [28 x i8] c"M:MAIN: Scanning input file\00"
@str.12 = [35 x i8] c"E:MAIN: Could not open output file\00"
@str.13 = [30 x i8] c"M:MAIN: Building global table\00"
@str.14 = [27 x i8] c"M:MAIN: Parsing statements\00"
@str.15 = [20 x i8] c"M:MAIN: Cleaning up\00"
@str.16 = [42 x i8] c"E:MAIN: Parser raised irrecoverable error\00"
@str.17 = [38 x i8] c"E:MAIN: Global scanning raised errors\00"
@str.18 = [34 x i8] c"E:MAIN: Failed to read input file\00"
@str.19 = [50 x i8] c"No input file. Usage: mimasm <infile> [<outfile>]\00"
@str.20 = [33 x i8] c"Standard output file is out.mima\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.19, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.20, i64 0, i64 0))
br label %63
8: ; preds = %2
%9 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%10 = icmp eq i32 %0, 2
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
br label %14
14: ; preds = %11, %8
%15 = phi i8* [ %13, %11 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), %8 ]
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = call i64 @scan_input(i8* %18, i8** %3)
%20 = icmp ult i64 %19, 2
br i1 %20, label %21, label %25
21: ; preds = %14
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.18, i64 0, i64 0))
%23 = load i8*, i8** %3
%24 = call i32 @free(i8* %23)
br label %60
25: ; preds = %14
%26 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.12, i64 0, i64 0))
%30 = load i8*, i8** %3
%31 = call i32 @free(i8* %30)
br label %60
32: ; preds = %25
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.13, i64 0, i64 0))
%34 = load i8*, i8** %3
%35 = call i64 @scan_globals(i8* %34, i64 %19)
%36 = icmp eq i64 %35, 0
br i1 %36, label %43, label %37
37: ; preds = %32
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.17, i64 0, i64 0))
%39 = call i32 (...) @globals_free()
%40 = load i8*, i8** %3
%41 = call i32 @free(i8* %40)
%42 = call i32 @fclose(i32* %26)
br label %60
43: ; preds = %32
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.14, i64 0, i64 0))
%45 = load i8*, i8** %3
%46 = call i64 @parse_buffer(i32* %26, i8* %45, i64 %19)
%47 = icmp eq i64 %46, 0
br i1 %47, label %54, label %48
48: ; preds = %43
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.16, i64 0, i64 0))
%50 = call i32 (...) @globals_free()
%51 = load i8*, i8** %3
%52 = call i32 @free(i8* %51)
%53 = call i32 @fclose(i32* %26)
br label %60
54: ; preds = %43
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.15, i64 0, i64 0))
%56 = call i32 (...) @globals_free()
%57 = load i8*, i8** %3
%58 = call i32 @free(i8* %57)
%59 = call i32 @fclose(i32* %26)
br label %60
60: ; preds = %54, %48, %37, %28, %21
%61 = phi i32* [ @EXIT_FAILURE, %21 ], [ @EXIT_FAILURE, %37 ], [ @EXIT_FAILURE, %48 ], [ @EXIT_SUCCESS, %54 ], [ @EXIT_FAILURE, %28 ]
%62 = load i32, i32* %61
br label %63
63: ; preds = %60, %5
%64 = phi i32 [ 0, %5 ], [ %62, %60 ]
ret i32 %64
}