#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*/ check_syntax(char *);
int /*<<< orphan*/ compile(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ make_template_bottom(int /*<<< orphan*/ *);
int /*<<< orphan*/ make_template_top(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ system(char *);
int main(int argc, char *argv[]) {
  char brainfuck[4000];
  FILE *in = fopen(argv[1], "r");
  FILE *out = fopen(argv[2], "w");
  fread(brainfuck, 4000, 1, in);
  fclose(in);
  if (!check_syntax(brainfuck)) {
    return -1;
  }
  make_template_top(out, argv[1]);
  compile(brainfuck, out);
  make_template_bottom(out);
  fclose(out);
  if (argv[3]) {
    char command[80];
    sprintf(command, "gcc %s -o %s", argv[2], argv[3]);
    system(command);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1010,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe48(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0xfb8(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe2f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0xfc0(%rbp)
lea    -0xfb0(%rbp),%rdi
mov    -0xfb8(%rbp),%rcx
mov    $0xfa0,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0xfb8(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0xfb0(%rbp),%rdi
call   1070 <check_syntax@plt>
cmp    $0x0,%eax
jne    1229 <main+0x99>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a6 <main+0x116>
mov    -0xfc0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   10a0 <make_template_top@plt>
lea    -0xfb0(%rbp),%rdi
mov    -0xfc0(%rbp),%rsi
call   1060 <compile@plt>
mov    -0xfc0(%rbp),%rdi
call   1080 <make_template_bottom@plt>
mov    -0xfc0(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x18(%rax)
je     12a6 <main+0x116>
lea    -0x1010(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rcx
lea    0xd6f(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x1010(%rbp),%rdi
call   1050 <system@plt>
mov    -0x4(%rbp),%eax
add    $0x1010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xff8,%rsp
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
lea    0xe54(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    0x10(%r14),%rdi
lea    0xe43(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r15
lea    0x50(%rsp),%r12
mov    %r12,%rdi
mov    $0xfa0,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
call   1070 <check_syntax@plt>
test   %eax,%eax
je     1249 <main+0xb9>
mov    0x8(%r14),%rsi
mov    %r15,%rdi
call   10a0 <make_template_top@plt>
lea    0x50(%rsp),%rdi
mov    %r15,%rsi
call   1060 <compile@plt>
mov    %r15,%rdi
call   1080 <make_template_bottom@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    0x18(%r14),%rcx
xor    %ebx,%ebx
test   %rcx,%rcx
je     124e <main+0xbe>
mov    0x10(%r14),%rdx
lea    0xdd0(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
call   10b0 <sprintf@plt>
mov    %r14,%rdi
call   1050 <system@plt>
jmp    124e <main+0xbe>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0xff8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [13 x i8] c"gcc %s -o %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4000 x i8]
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca [80 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %7
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 2
%16 = load i8*, i8** %15
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %8
%18 = getelementptr inbounds [4000 x i8], [4000 x i8]* %6, i64 0, i64 0
%19 = load i32*, i32** %7
%20 = call i32 @fread(i8* %18, i32 4000, i32 1, i32* %19)
%21 = load i32*, i32** %7
%22 = call i32 @fclose(i32* %21)
%23 = getelementptr inbounds [4000 x i8], [4000 x i8]* %6, i64 0, i64 0
%24 = call i32 @check_syntax(i8* %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %2
store i32 -1, i32* %3
br label %55
27: ; preds = %2
%28 = load i32*, i32** %8
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @make_template_top(i32* %28, i8* %31)
%33 = getelementptr inbounds [4000 x i8], [4000 x i8]* %6, i64 0, i64 0
%34 = load i32*, i32** %8
%35 = call i32 @compile(i8* %33, i32* %34)
%36 = load i32*, i32** %8
%37 = call i32 @make_template_bottom(i32* %36)
%38 = load i32*, i32** %8
%39 = call i32 @fclose(i32* %38)
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 3
%42 = load i8*, i8** %41
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %55
44: ; preds = %27
%45 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 2
%48 = load i8*, i8** %47
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 3
%51 = load i8*, i8** %50
%52 = call i32 @sprintf(i8* %45, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %48, i8* %51)
%53 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%54 = call i32 @system(i8* %53)
br label %55
55: ; preds = %26, %44, %27
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [13 x i8] c"gcc %s -o %s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4000 x i8]
%4 = alloca [80 x i8]
%5 = getelementptr inbounds [4000 x i8], [4000 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @fread(i8* %5, i32 4000, i32 1, i32* %8)
%13 = tail call i32 @fclose(i32* %8)
%14 = call i32 @check_syntax(i8* %5)
%15 = icmp eq i32 %14, 0
br i1 %15, label %30, label %16
16: ; preds = %2
%17 = load i8*, i8** %6
%18 = call i32 @make_template_top(i32* %11, i8* %17)
%19 = call i32 @compile(i8* %5, i32* %11)
%20 = call i32 @make_template_bottom(i32* %11)
%21 = call i32 @fclose(i32* %11)
%22 = getelementptr inbounds i8*, i8** %1, i64 3
%23 = load i8*, i8** %22
%24 = icmp eq i8* %23, null
br i1 %24, label %30, label %25
25: ; preds = %16
%26 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%27 = load i8*, i8** %9
%28 = call i32 @sprintf(i8* %26, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %27, i8* %23)
%29 = call i32 @system(i8* %26)
br label %30
30: ; preds = %16, %25, %2
%31 = phi i32 [ -1, %2 ], [ 0, %25 ], [ 0, %16 ]
ret i32 %31
}