#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_lex(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *const, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
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 *usage = "Usage: lex-java <SOURCE>\n\n";
  char err_msg[4096];
  if (argc != 2) {
    fprintf(stderr, "%s", usage);
    goto error;
  }
  if ((fp1 = fopen(argv[1], "r")) == NULL) {
    snprintf(err_msg, 4096, "lex-java: cannot open '%s'", argv[1]);
    perror(err_msg);
    goto error;
  }
  if ((fp2 = fopen("scanner_output", "w")) == NULL) {
    perror("lex-java: cannot open 'scanner_output'");
    goto error;
  }
  do_lex(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    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xe70(%rip),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11bc <main+0x5c>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xe69(%rip),%rsi
call   1060 <fprintf@plt>
jmp    126c <main+0x10c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe53(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    120f <main+0xaf>
lea    -0x1030(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    $0x1000,%esi
lea    0xe27(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x1030(%rbp),%rdi
call   1080 <perror@plt>
jmp    126c <main+0x10c>
lea    0xe25(%rip),%rdi
lea    0xe2d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1241 <main+0xe1>
lea    0xe15(%rip),%rdi
call   1080 <perror@plt>
jmp    126c <main+0x10c>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <do_lex@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    129b <main+0x13b>
cmpq   $0x0,-0x18(%rbp)
je     1280 <main+0x120>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x20(%rbp)
je     1294 <main+0x134>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x1008,%rsp
cmp    $0x2,%edi
jne    11c4 <main+0x64>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xea1(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11f0 <main+0x90>
mov    %rax,%r14
lea    0xeaa(%rip),%rdi
lea    0xeb2(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1215 <main+0xb5>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <do_lex@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    11e5 <main+0x85>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
lea    0xe25(%rip),%rdx
call   1060 <fprintf@plt>
mov    $0x1,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r14
ret
mov    0x8(%rbx),%rcx
lea    0xe25(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x1000,%esi
call   1050 <snprintf@plt>
mov    %rbx,%rdi
call   1080 <perror@plt>
jmp    11e0 <main+0x80>
lea    0xe30(%rip),%rdi
call   1080 <perror@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    11e0 <main+0x80>

LLVM IR (-O0):
@.str = [27 x i8] c"Usage: lex-java <SOURCE>\0A\0A\00"
@stderr = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [27 x i8] c"lex-java: cannot open '%s'\00"
@.str.4 = [15 x i8] c"scanner_output\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [39 x i8] c"lex-java: cannot open 'scanner_output'\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 [4096 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 ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8** %8
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %8
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %43
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %20, i32** %6
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %30
22: ; preds = %16
%23 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @snprintf(i8* %23, i32 4096, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %26)
%28 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%29 = call i32 @perror(i8* %28)
br label %43
30: ; preds = %16
%31 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %31, i32** %7
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0))
br label %43
35: ; preds = %30
%36 = load i32*, i32** %6
%37 = load i32*, i32** %7
%38 = call i32 @do_lex(i32* %36, i32* %37)
%39 = load i32*, i32** %6
%40 = call i32 @fclose(i32* %39)
%41 = load i32*, i32** %7
%42 = call i32 @fclose(i32* %41)
store i32 0, i32* %3
br label %56
43: ; preds = %33, %22, %12
%44 = load i32*, i32** %6
%45 = icmp ne i32* %44, null
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = load i32*, i32** %6
%48 = call i32 @fclose(i32* %47)
br label %49
49: ; preds = %46, %43
%50 = load i32*, i32** %7
%51 = icmp ne i32* %50, null
br i1 %51, label %52, label %55
52: ; preds = %49
%53 = load i32*, i32** %7
%54 = call i32 @fclose(i32* %53)
br label %55
55: ; preds = %52, %49
store i32 1, i32* %3
br label %56
56: ; preds = %55, %35
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str = [27 x i8] c"Usage: lex-java <SOURCE>\0A\0A\00"
@stderr = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [27 x i8] c"lex-java: cannot open '%s'\00"
@.str.4 = [15 x i8] c"scanner_output\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [39 x i8] c"lex-java: cannot open 'scanner_output'\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %28
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i8*, i8** %10
%16 = call i32 @snprintf(i8* %4, i32 4096, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %15)
%17 = call i32 @perror(i8* %4)
br label %28
18: ; preds = %9
%19 = tail call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = tail call i32 @do_lex(i32* %12, i32* %19)
%23 = tail call i32 @fclose(i32* %12)
%24 = tail call i32 @fclose(i32* %19)
br label %28
25: ; preds = %18
%26 = tail call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0))
%27 = tail call i32 @fclose(i32* %12)
br label %28
28: ; preds = %14, %6, %25, %21
%29 = phi i32 [ 0, %21 ], [ 1, %25 ], [ 1, %6 ], [ 1, %14 ]
ret i32 %29
}