#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*/ compact_props();
int /*<<< orphan*/ compact_tables();
int /*<<< orphan*/ emit_header(int /*<<< orphan*/ *);
int /*<<< orphan*/ emit_tables(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ init_database();
int /*<<< orphan*/ parse_line(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ process_line(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int main(int argc, char **argv) {
  char buf[1024];
  FILE *in;
  FILE *out;
  if (argc == 4) {
    in = fopen(argv[2], "r");
    if (!in) {
      perror(argv[2]);
      return 1;
    }
    out = fopen(argv[3], "w");
    if (!out) {
      perror(argv[3]);
      return 1;
    }
    if (strcmp(argv[1], "data") == 0) {
      init_database();
      fprintf(stderr, "Parsing...");
      while (fgets(buf, 1024, in)) {
        process_line(parse_line(buf));
      }
      fprintf(stderr, "done\n");
      compact_props();
      compact_tables();
      emit_tables(out);
      fclose(out);
      return 0;
    } else if (strcmp(argv[1], "header") == 0) {
      emit_header(out);
      fclose(out);
      return 0;
    }
  }
  fprintf(stderr, "usage: %s header|data <input-file> <output-file>\n",
          argv[0]);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jne    1382 <main+0x1b2>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe1b(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
jne    1235 <main+0x65>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13a7 <main+0x1d7>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xdbc(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x420(%rbp)
cmpq   $0x0,-0x420(%rbp)
jne    1277 <main+0xa7>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13a7 <main+0x1d7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd7c(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    1336 <main+0x166>
mov    $0x0,%al
call   1080 <init_database@plt>
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
lea    0xd5b(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rdx
mov    $0x400,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12ed <main+0x11d>
lea    -0x410(%rbp),%rdi
call   10b0 <parse_line@plt>
mov    %eax,%edi
call   10f0 <process_line@plt>
jmp    12b3 <main+0xe3>
mov    0x2cec(%rip),%rax
mov    (%rax),%edi
lea    0xd15(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x0,%al
call   10e0 <compact_props@plt>
mov    $0x0,%al
call   1040 <compact_tables@plt>
mov    -0x420(%rbp),%rdi
call   1060 <emit_tables@plt>
mov    -0x420(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    13a7 <main+0x1d7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xcd3(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    1378 <main+0x1a8>
mov    -0x420(%rbp),%rdi
call   1050 <emit_header@plt>
mov    -0x420(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    13a7 <main+0x1d7>
jmp    137d <main+0x1ad>
jmp    1382 <main+0x1b2>
mov    0x2c57(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xc86(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%rbp
cmp    $0x4,%edi
jne    124d <main+0x7d>
mov    0x10(%rbp),%rdi
lea    0xe2b(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1331 <main+0x161>
mov    %rax,%rbx
mov    0x18(%rbp),%rdi
lea    0xdf2(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     133f <main+0x16f>
mov    %rax,%r14
mov    0x8(%rbp),%rdi
lea    0xdd8(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1281 <main+0xb1>
mov    0x8(%rbp),%rdi
lea    0xdd9(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1319 <main+0x149>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xdbe(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r15d,%r15d
xor    %eax,%eax
call   1080 <init_database@plt>
mov    0x2d4e(%rip),%r12
mov    (%r12),%edi
lea    0xd6a(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     12e4 <main+0x114>
mov    %rsp,%rbp
nopl   0x0(%rax)
mov    %rbp,%rdi
call   10b0 <parse_line@plt>
mov    %eax,%edi
call   10f0 <process_line@plt>
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
jne    12c0 <main+0xf0>
mov    (%r12),%edi
lea    0xd23(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
xor    %eax,%eax
call   10e0 <compact_props@plt>
xor    %eax,%eax
call   1040 <compact_tables@plt>
mov    %r14,%rdi
call   1060 <emit_tables@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
jmp    126e <main+0x9e>
mov    %r14,%rdi
call   1050 <emit_header@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %r15d,%r15d
jmp    126e <main+0x9e>
mov    0x10(%rbp),%rdi
call   10d0 <perror@plt>
jmp    1268 <main+0x98>
mov    0x18(%rbp),%rdi
call   10d0 <perror@plt>
jmp    1268 <main+0x98>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [5 x i8] c"data\00"
@stderr = global i32 0
@.str.3 = [11 x i8] c"Parsing...\00"
@.str.4 = [6 x i8] c"done\0A\00"
@.str.5 = [7 x i8] c"header\00"
@.str.6 = [50 x i8] c"usage: %s header|data <input-file> <output-file>\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca i32*
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 4
br i1 %10, label %11, label %76
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 2
%14 = load i8*, i8** %13
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %7
%16 = load i32*, i32** %7
%17 = icmp ne i32* %16, null
br i1 %17, label %23, label %18
18: ; preds = %11
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i32 @perror(i8* %21)
store i32 1, i32* %3
br label %82
23: ; preds = %11
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 3
%26 = load i8*, i8** %25
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %27, i32** %8
%28 = load i32*, i32** %8
%29 = icmp ne i32* %28, null
br i1 %29, label %35, label %30
30: ; preds = %23
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 3
%33 = load i8*, i8** %32
%34 = call i32 @perror(i8* %33)
store i32 1, i32* %3
br label %82
35: ; preds = %23
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call i64 @strcmp(i8* %38, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %63
41: ; preds = %35
%42 = call i32 (...) @init_database()
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %45
45: ; preds = %50, %41
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%47 = load i32*, i32** %7
%48 = call i64 @fgets(i8* %46, i32 1024, i32* %47)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %54
50: ; preds = %45
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%52 = call i32 @parse_line(i8* %51)
%53 = call i32 @process_line(i32 %52)
br label %45
54: ; preds = %45
%55 = load i32, i32* @stderr
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%57 = call i32 (...) @compact_props()
%58 = call i32 (...) @compact_tables()
%59 = load i32*, i32** %8
%60 = call i32 @emit_tables(i32* %59)
%61 = load i32*, i32** %8
%62 = call i32 @fclose(i32* %61)
store i32 0, i32* %3
br label %82
63: ; preds = %35
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 1
%66 = load i8*, i8** %65
%67 = call i64 @strcmp(i8* %66, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%68 = icmp eq i64 %67, 0
br i1 %68, label %69, label %74
69: ; preds = %63
%70 = load i32*, i32** %8
%71 = call i32 @emit_header(i32* %70)
%72 = load i32*, i32** %8
%73 = call i32 @fclose(i32* %72)
store i32 0, i32* %3
br label %82
74: ; preds = %63
br label %75
75: ; preds = %74
br label %76
76: ; preds = %75, %2
%77 = load i32, i32* @stderr
%78 = load i8**, i8*** %5
%79 = getelementptr inbounds i8*, i8** %78, i64 0
%80 = load i8*, i8** %79
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.6, i64 0, i64 0), i8* %80)
store i32 1, i32* %3
br label %82
82: ; preds = %76, %69, %54, %30, %18
%83 = load i32, i32* %3
ret i32 %83
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [5 x i8] c"data\00"
@stderr = global i32 0
@.str.3 = [11 x i8] c"Parsing...\00"
@.str.4 = [6 x i8] c"done\0A\00"
@.str.5 = [7 x i8] c"header\00"
@.str.6 = [50 x i8] c"usage: %s header|data <input-file> <output-file>\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 4
br i1 %5, label %6, label %52
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 2
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = load i8*, i8** %7
%13 = tail call i32 @perror(i8* %12)
br label %56
14: ; preds = %6
%15 = getelementptr inbounds i8*, i8** %1, i64 3
%16 = load i8*, i8** %15
%17 = tail call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i8*, i8** %15
%21 = tail call i32 @perror(i8* %20)
br label %56
22: ; preds = %14
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = tail call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %45
27: ; preds = %22
%28 = tail call i32 (...) @init_database()
%29 = load i32, i32* @stderr
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%31 = call i64 @fgets(i8* %4, i32 1024, i32* %9)
%32 = icmp eq i64 %31, 0
br i1 %32, label %38, label %33
33: ; preds = %27, %33
%34 = call i32 @parse_line(i8* %4)
%35 = call i32 @process_line(i32 %34)
%36 = call i64 @fgets(i8* %4, i32 1024, i32* %9)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %33
38: ; preds = %33, %27
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%41 = call i32 (...) @compact_props()
%42 = call i32 (...) @compact_tables()
%43 = call i32 @emit_tables(i32* %17)
%44 = call i32 @fclose(i32* %17)
br label %56
45: ; preds = %22
%46 = load i8*, i8** %23
%47 = tail call i64 @strcmp(i8* %46, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %45
%50 = tail call i32 @emit_header(i32* %17)
%51 = tail call i32 @fclose(i32* %17)
br label %56
52: ; preds = %45, %2
%53 = load i32, i32* @stderr
%54 = load i8*, i8** %1
%55 = tail call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.6, i64 0, i64 0), i8* %54)
br label %56
56: ; preds = %52, %49, %38, %19, %11
%57 = phi i32 [ 0, %38 ], [ 0, %49 ], [ 1, %52 ], [ 1, %19 ], [ 1, %11 ]
ret i32 %57
}