#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 */
char EOF;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char const *);
int main(int argc, char const *argv[]) {
  if (argc != 3) {
    printf("Usage: %s <file.bf> <output file>\n", argv[0]);
    return EXIT_FAILURE;
  } else {
    FILE *bf_file = fopen(argv[1], "r");
    FILE *c_output = fopen(argv[2], "w");
    char c;
    fputs("/* generated by bf.c */#include <stdio.h>\nint main(void) {char "
          "s[30000]={0};char*sp=s;",
          c_output);
    while ((c = fgetc(bf_file)) != EOF) {
      switch (c) {
      case '>':
        fputs("++sp;", c_output);
        break;
      case '<':
        fputs("--sp;", c_output);
        break;
      case '+':
        fputs("++*sp;", c_output);
        break;
      case '-':
        fputs("--*sp;", c_output);
        break;
      case '.':
        fputs("putchar(*sp);", c_output);
        break;
      case ',':
        fputs("*sp=getchar();", c_output);
        break;
      case '[':
        fputs("while (*sp) {", c_output);
        break;
      case ']':
        fputs("}", c_output);
        break;
      default:
        break;
      }
    }
    fputs("}", c_output);
    fclose(bf_file);
    fclose(c_output);
    printf("Output written to: %s.\n", argv[2]);
  }
  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   $0x3,-0x8(%rbp)
je     1194 <main+0x44>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xf4e(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1313 <main+0x1c3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xf4c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xf36(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xf24(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x21(%rbp)
movsbl %al,%eax
mov    0x2dfe(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     12d1 <main+0x181>
movsbl -0x21(%rbp),%eax
add    $0xffffffd5,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x32,%eax
ja     12c7 <main+0x177>
mov    -0x30(%rbp),%rax
lea    0xdea(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x20(%rbp),%rsi
lea    0xf20(%rip),%rdi
call   1050 <fputs@plt>
jmp    12cc <main+0x17c>
mov    -0x20(%rbp),%rsi
lea    0xf11(%rip),%rdi
call   1050 <fputs@plt>
jmp    12cc <main+0x17c>
mov    -0x20(%rbp),%rsi
lea    0xf02(%rip),%rdi
call   1050 <fputs@plt>
jmp    12cc <main+0x17c>
mov    -0x20(%rbp),%rsi
lea    0xef4(%rip),%rdi
call   1050 <fputs@plt>
jmp    12cc <main+0x17c>
mov    -0x20(%rbp),%rsi
lea    0xee6(%rip),%rdi
call   1050 <fputs@plt>
jmp    12cc <main+0x17c>
mov    -0x20(%rbp),%rsi
lea    0xedf(%rip),%rdi
call   1050 <fputs@plt>
jmp    12cc <main+0x17c>
mov    -0x20(%rbp),%rsi
lea    0xed9(%rip),%rdi
call   1050 <fputs@plt>
jmp    12cc <main+0x17c>
mov    -0x20(%rbp),%rsi
lea    0xed2(%rip),%rdi
call   1050 <fputs@plt>
jmp    12cc <main+0x17c>
jmp    12cc <main+0x17c>
jmp    11d4 <main+0x84>
mov    -0x20(%rbp),%rsi
lea    0xeb3(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe8f(%rip),%rdi
call   1040 <printf@plt>
mov    0x2cc2(%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   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x3,%edi
jne    11fc <main+0x9c>
mov    0x8(%r14),%rdi
lea    0xf6d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    0x10(%r14),%rdi
lea    0xf5c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
lea    0xf4f(%rip),%rdi
mov    $0x56,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    0x2e23(%rip),%r13
cmp    0x0(%r13),%al
jne    1223 <main+0xc3>
add    $0x10,%r14
mov    $0x7d,%edi
mov    %r15,%rsi
call   1060 <fputc@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    0x2ddd(%rip),%rbx
lea    0xf95(%rip),%rdi
jmp    120a <main+0xaa>
mov    0x2dd5(%rip),%rbx
lea    0xec2(%rip),%rdi
mov    (%r14),%rsi
call   1040 <printf@plt>
mov    (%rbx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdd6(%rip),%rbp
lea    0xf50(%rip),%r12
jmp    126a <main+0x10a>
mov    $0x5,%esi
mov    $0x1,%edx
lea    0xf06(%rip),%rdi
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    0x0(%r13),%al
je     11cb <main+0x6b>
movsbl %al,%eax
add    $0xffffffd5,%eax
cmp    $0x32,%eax
ja     1258 <main+0xf8>
movslq 0x0(%rbp,%rax,4),%rax
add    %rbp,%rax
jmp    *%rax
mov    $0x6,%esi
mov    $0x1,%edx
lea    0xec6(%rip),%rdi
jmp    1250 <main+0xf0>
mov    $0xe,%esi
mov    $0x1,%edx
lea    0xecf(%rip),%rdi
jmp    1250 <main+0xf0>
mov    $0x6,%esi
mov    $0x1,%edx
lea    0xea7(%rip),%rdi
jmp    1250 <main+0xf0>
mov    $0xd,%esi
mov    $0x1,%edx
lea    0xe9b(%rip),%rdi
jmp    1250 <main+0xf0>
mov    $0x5,%esi
mov    $0x1,%edx
lea    0xe74(%rip),%rdi
jmp    1250 <main+0xf0>
mov    $0xd,%esi
mov    $0x1,%edx
mov    %r12,%rdi
jmp    1250 <main+0xf0>
mov    $0x7d,%edi
mov    %r15,%rsi
call   1060 <fputc@plt>
jmp    1258 <main+0xf8>

LLVM IR (-O0):
@.str = [35 x i8] c"Usage: %s <file.bf> <output file>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [87 x i8] c"/* generated by bf.c */#include <stdio.h>\0Aint main(void) {char s[30000]={0};char*sp=s;\00"
@EOF = global i8 0
@.str.4 = [6 x i8] c"++sp;\00"
@.str.5 = [6 x i8] c"--sp;\00"
@.str.6 = [7 x i8] c"++*sp;\00"
@.str.7 = [7 x i8] c"--*sp;\00"
@.str.8 = [14 x i8] c"putchar(*sp);\00"
@.str.9 = [15 x i8] c"*sp=getchar();\00"
@.str.10 = [14 x i8] c"while (*sp) {\00"
@.str.11 = [2 x i8] c"}\00"
@.str.12 = [24 x i8] c"Output written to: %s.\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 i32*
%8 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
store i32 %16, i32* %3
br label %77
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %6
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %25, i32** %7
%26 = load i32*, i32** %7
%27 = call i32 @fputs(i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.3, i64 0, i64 0), i32* %26)
br label %28
28: ; preds = %63, %17
%29 = load i32*, i32** %6
%30 = call signext i8 @fgetc(i32* %29)
store i8 %30, i8* %8
%31 = sext i8 %30 to i32
%32 = load i8, i8* @EOF
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %31, %33
br i1 %34, label %35, label %64
35: ; preds = %28
%36 = load i8, i8* %8
%37 = sext i8 %36 to i32
switch i32 %37, label %62 [
i32 62, label %38
i32 60, label %41
i32 43, label %44
i32 45, label %47
i32 46, label %50
i32 44, label %53
i32 91, label %56
i32 93, label %59
]
38: ; preds = %35
%39 = load i32*, i32** %7
%40 = call i32 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32* %39)
br label %63
41: ; preds = %35
%42 = load i32*, i32** %7
%43 = call i32 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32* %42)
br label %63
44: ; preds = %35
%45 = load i32*, i32** %7
%46 = call i32 @fputs(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32* %45)
br label %63
47: ; preds = %35
%48 = load i32*, i32** %7
%49 = call i32 @fputs(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32* %48)
br label %63
50: ; preds = %35
%51 = load i32*, i32** %7
%52 = call i32 @fputs(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i32* %51)
br label %63
53: ; preds = %35
%54 = load i32*, i32** %7
%55 = call i32 @fputs(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i32* %54)
br label %63
56: ; preds = %35
%57 = load i32*, i32** %7
%58 = call i32 @fputs(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0), i32* %57)
br label %63
59: ; preds = %35
%60 = load i32*, i32** %7
%61 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0), i32* %60)
br label %63
62: ; preds = %35
br label %63
63: ; preds = %62, %59, %56, %53, %50, %47, %44, %41, %38
br label %28
64: ; preds = %28
%65 = load i32*, i32** %7
%66 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0), i32* %65)
%67 = load i32*, i32** %6
%68 = call i32 @fclose(i32* %67)
%69 = load i32*, i32** %7
%70 = call i32 @fclose(i32* %69)
%71 = load i8**, i8*** %5
%72 = getelementptr inbounds i8*, i8** %71, i64 2
%73 = load i8*, i8** %72
%74 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.12, i64 0, i64 0), i8* %73)
br label %75
75: ; preds = %64
%76 = load i32, i32* @EXIT_SUCCESS
store i32 %76, i32* %3
br label %77
77: ; preds = %75, %11
%78 = load i32, i32* %3
ret i32 %78
}

LLVM IR (-O2):
@.str = [35 x i8] c"Usage: %s <file.bf> <output file>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [87 x i8] c"/* generated by bf.c */#include <stdio.h>\0Aint main(void) {char s[30000]={0};char*sp=s;\00"
@EOF = global i8 0
@.str.4 = [6 x i8] c"++sp;\00"
@.str.5 = [6 x i8] c"--sp;\00"
@.str.6 = [7 x i8] c"++*sp;\00"
@.str.7 = [7 x i8] c"--*sp;\00"
@.str.8 = [14 x i8] c"putchar(*sp);\00"
@.str.9 = [15 x i8] c"*sp=getchar();\00"
@.str.10 = [14 x i8] c"while (*sp) {\00"
@.str.12 = [24 x i8] c"Output written to: %s.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %4, label %42
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%11 = tail call i64 @fwrite(i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.3, i64 0, i64 0), i64 86, i64 1, i32* %10)
%12 = tail call signext i8 @fgetc(i32* %7)
%13 = load i8, i8* @EOF
%14 = icmp eq i8 %12, %13
br i1 %14, label %38, label %15
15: ; preds = %4, %34
%16 = phi i8 [ %35, %34 ], [ %12, %4 ]
%17 = sext i8 %16 to i32
switch i32 %17, label %34 [
i32 62, label %18
i32 60, label %20
i32 43, label %22
i32 45, label %24
i32 46, label %26
i32 44, label %28
i32 91, label %30
i32 93, label %32
]
18: ; preds = %15
%19 = tail call i64 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i64 5, i64 1, i32* %10)
br label %34
20: ; preds = %15
%21 = tail call i64 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i64 5, i64 1, i32* %10)
br label %34
22: ; preds = %15
%23 = tail call i64 @fwrite(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i64 6, i64 1, i32* %10)
br label %34
24: ; preds = %15
%25 = tail call i64 @fwrite(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i64 6, i64 1, i32* %10)
br label %34
26: ; preds = %15
%27 = tail call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i64 13, i64 1, i32* %10)
br label %34
28: ; preds = %15
%29 = tail call i64 @fwrite(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0), i64 14, i64 1, i32* %10)
br label %34
30: ; preds = %15
%31 = tail call i64 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.10, i64 0, i64 0), i64 13, i64 1, i32* %10)
br label %34
32: ; preds = %15
%33 = tail call i32 @fputc(i32 125, i32* %10)
br label %34
34: ; preds = %15, %32, %30, %28, %26, %24, %22, %20, %18
%35 = tail call signext i8 @fgetc(i32* %7)
%36 = load i8, i8* @EOF
%37 = icmp eq i8 %35, %36
br i1 %37, label %38, label %15
38: ; preds = %34, %4
%39 = tail call i32 @fputc(i32 125, i32* %10)
%40 = tail call i32 @fclose(i32* %7)
%41 = tail call i32 @fclose(i32* %10)
br label %42
42: ; preds = %2, %38
%43 = phi i8** [ %8, %38 ], [ %1, %2 ]
%44 = phi i8* [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.12, i64 0, i64 0), %38 ], [ getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), %2 ]
%45 = phi i32* [ @EXIT_SUCCESS, %38 ], [ @EXIT_FAILURE, %2 ]
%46 = load i8*, i8** %43
%47 = tail call i32 @printf(i8* %44, i8* %46)
%48 = load i32, i32* %45
ret i32 %48
}