#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*/ do_parse(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ do_validate_grammar(int /*<<< orphan*/ *);
int /*<<< orphan*/ do_validate_lex(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int /*<<< orphan*/ stderr;
int main(int argc, char *const *argv) {
  FILE *fp1 = NULL, *fp2 = NULL;
  const char *src = "scanner_output", *out = "parser_output";
  const char *usage = "Usage: parse-java [SOURCE]\n"
                      "If SOURCE is not specified, 'scanner_output' "
                      "will be used\n\n";
  char err_msg[512];
  if (argc > 2) {
    fprintf(stderr, "%s", usage);
    goto error;
  } else if (argc == 2) {
    src = argv[1];
  }
  if ((fp1 = fopen(src, "r")) == NULL) {
    snprintf(err_msg, 512, "parse-java: cannot open '%s'", src);
    perror(err_msg);
    goto error;
  }
  if (!do_validate_lex(fp1)) {
    fprintf(stderr, "parse-java: invalid lexical analysis output "
                    "file\n");
    goto error;
  }
  if (!do_validate_grammar(fp1)) {
    fprintf(stderr, "parse-java: grammar error\n");
    goto error;
  }
  if ((fp2 = fopen(out, "w")) == NULL) {
    snprintf(err_msg, 512, "parse-java: cannot open '%s'", out);
    perror(err_msg);
    goto error;
  }
  do_parse(fp1, fp2);
  fclose(fp1);
  fclose(fp2);
  return 0;
error:
  if (fp1 != NULL) {
    fclose(fp1);
  }
  if (fp2 != NULL) {
    fclose(fp2);
  }
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xe50(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe54(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe57(%rip),%rax
mov    %rax,-0x38(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11f4 <main+0x74>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
lea    0xe8c(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    132c <main+0x1ac>
cmpl   $0x2,-0x8(%rbp)
jne    120a <main+0x8a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    120f <main+0x8f>
mov    -0x28(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    125a <main+0xda>
lea    -0x240(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x200,%esi
lea    0xe35(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x240(%rbp),%rdi
call   10a0 <perror@plt>
jmp    132c <main+0x1ac>
mov    -0x18(%rbp),%rdi
call   1040 <do_validate_lex@plt>
cmp    $0x0,%eax
jne    1288 <main+0x108>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    132c <main+0x1ac>
mov    -0x18(%rbp),%rdi
call   1060 <do_validate_grammar@plt>
cmp    $0x0,%eax
jne    12b6 <main+0x136>
mov    0x2d3f(%rip),%rax
mov    (%rax),%edi
lea    0xe1e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    132c <main+0x1ac>
mov    -0x30(%rbp),%rdi
lea    0xe22(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1301 <main+0x181>
lea    -0x240(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x200,%esi
lea    0xd8e(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x240(%rbp),%rdi
call   10a0 <perror@plt>
jmp    132c <main+0x1ac>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <do_parse@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    135b <main+0x1db>
cmpq   $0x0,-0x18(%rbp)
je     1340 <main+0x1c0>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmpq   $0x0,-0x20(%rbp)
je     1354 <main+0x1d4>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x208,%rsp
cmp    $0x3,%edi
jl     11b2 <main+0x32>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    0xed5(%rip),%rsi
lea    0xe77(%rip),%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1266 <main+0xe6>
cmp    $0x2,%edi
jne    11bd <main+0x3d>
mov    0x8(%rsi),%r14
jmp    11c4 <main+0x44>
lea    0xe3c(%rip),%r14
lea    0xeac(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1276 <main+0xf6>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <do_validate_lex@plt>
test   %eax,%eax
je     1235 <main+0xb5>
mov    %rbx,%rdi
call   1060 <do_validate_grammar@plt>
test   %eax,%eax
je     1247 <main+0xc7>
lea    0xe11(%rip),%rdi
lea    0xede(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     129a <main+0x11a>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %rax,%rsi
call   1080 <do_parse@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    126b <main+0xeb>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
jmp    1257 <main+0xd7>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
lea    0xe71(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdfc(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x200,%esi
mov    %r14,%rcx
call   1050 <snprintf@plt>
mov    %rbx,%rdi
call   10a0 <perror@plt>
jmp    1266 <main+0xe6>
lea    0xdd8(%rip),%rdx
lea    0xd67(%rip),%rcx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x200,%esi
call   1050 <snprintf@plt>
mov    %r14,%rdi
call   10a0 <perror@plt>
jmp    125e <main+0xde>

LLVM IR (-O0):
@.str = [15 x i8] c"scanner_output\00"
@.str.1 = [14 x i8] c"parser_output\00"
@.str.2 = [87 x i8] c"Usage: parse-java [SOURCE]\0AIf SOURCE is not specified, 'scanner_output' will be used\0A\0A\00"
@stderr = global i32 0
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [29 x i8] c"parse-java: cannot open '%s'\00"
@.str.6 = [50 x i8] c"parse-java: invalid lexical analysis output file\0A\00"
@.str.7 = [27 x i8] c"parse-java: grammar error\0A\00"
@.str.8 = [2 x i8] c"w\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca [512 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
store i32* null, i32** %7
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %8
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8** %9
store i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.2, i64 0, i64 0), i8** %10
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 2
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %10
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %16)
br label %68
18: ; preds = %2
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, 2
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %8
br label %25
25: ; preds = %21, %18
br label %26
26: ; preds = %25
%27 = load i8*, i8** %8
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %28, i32** %6
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %36
30: ; preds = %26
%31 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%32 = load i8*, i8** %8
%33 = call i32 @snprintf(i8* %31, i32 512, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %32)
%34 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%35 = call i32 @perror(i8* %34)
br label %68
36: ; preds = %26
%37 = load i32*, i32** %6
%38 = call i32 @do_validate_lex(i32* %37)
%39 = icmp ne i32 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %36
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.6, i64 0, i64 0))
br label %68
43: ; preds = %36
%44 = load i32*, i32** %6
%45 = call i32 @do_validate_grammar(i32* %44)
%46 = icmp ne i32 %45, 0
br i1 %46, label %50, label %47
47: ; preds = %43
%48 = load i32, i32* @stderr
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
br label %68
50: ; preds = %43
%51 = load i8*, i8** %9
%52 = call i32* @fopen(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
store i32* %52, i32** %7
%53 = icmp eq i32* %52, null
br i1 %53, label %54, label %60
54: ; preds = %50
%55 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%56 = load i8*, i8** %9
%57 = call i32 @snprintf(i8* %55, i32 512, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %56)
%58 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%59 = call i32 @perror(i8* %58)
br label %68
60: ; preds = %50
%61 = load i32*, i32** %6
%62 = load i32*, i32** %7
%63 = call i32 @do_parse(i32* %61, i32* %62)
%64 = load i32*, i32** %6
%65 = call i32 @fclose(i32* %64)
%66 = load i32*, i32** %7
%67 = call i32 @fclose(i32* %66)
store i32 0, i32* %3
br label %81
68: ; preds = %54, %47, %40, %30, %14
%69 = load i32*, i32** %6
%70 = icmp ne i32* %69, null
br i1 %70, label %71, label %74
71: ; preds = %68
%72 = load i32*, i32** %6
%73 = call i32 @fclose(i32* %72)
br label %74
74: ; preds = %71, %68
%75 = load i32*, i32** %7
%76 = icmp ne i32* %75, null
br i1 %76, label %77, label %80
77: ; preds = %74
%78 = load i32*, i32** %7
%79 = call i32 @fclose(i32* %78)
br label %80
80: ; preds = %77, %74
store i32 1, i32* %3
br label %81
81: ; preds = %80, %60
%82 = load i32, i32* %3
ret i32 %82
}

LLVM IR (-O2):
@.str = [15 x i8] c"scanner_output\00"
@.str.1 = [14 x i8] c"parser_output\00"
@.str.2 = [87 x i8] c"Usage: parse-java [SOURCE]\0AIf SOURCE is not specified, 'scanner_output' will be used\0A\0A\00"
@stderr = global i32 0
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [29 x i8] c"parse-java: cannot open '%s'\00"
@.str.6 = [50 x i8] c"parse-java: invalid lexical analysis output file\0A\00"
@.str.7 = [27 x i8] c"parse-java: grammar error\0A\00"
@.str.8 = [2 x i8] c"w\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %0, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.2, i64 0, i64 0))
br label %45
9: ; preds = %2
%10 = icmp eq i32 %0, 2
br i1 %10, label %11, label %14
11: ; preds = %9
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
br label %14
14: ; preds = %9, %11
%15 = phi i8* [ %13, %11 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %9 ]
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = call i32 @snprintf(i8* %4, i32 512, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %15)
%20 = call i32 @perror(i8* %4)
br label %45
21: ; preds = %14
%22 = tail call i32 @do_validate_lex(i32* %16)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.6, i64 0, i64 0))
br label %43
27: ; preds = %21
%28 = tail call i32 @do_validate_grammar(i32* %16)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load i32, i32* @stderr
%32 = tail call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
br label %43
33: ; preds = %27
%34 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = call i32 @snprintf(i8* %4, i32 512, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%38 = call i32 @perror(i8* %4)
br label %43
39: ; preds = %33
%40 = tail call i32 @do_parse(i32* %16, i32* %34)
%41 = tail call i32 @fclose(i32* %16)
%42 = tail call i32 @fclose(i32* %34)
br label %45
43: ; preds = %36, %30, %24
%44 = call i32 @fclose(i32* %16)
br label %45
45: ; preds = %6, %18, %43, %39
%46 = phi i32 [ 0, %39 ], [ 1, %43 ], [ 1, %18 ], [ 1, %6 ]
ret i32 %46
}