#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 EOF;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
int main(int argc, char **argv) {
  FILE *in = stdin, *out = stdout;
  int c;
  int cellsize = 30000;
  fprintf(out,
          "#include <stdio.h>\n"
          "#include <stdlib.h>\n\n"
          "int main(int argc, char **argv)\n{\n"
          "\tunsigned char *cell = calloc(%d, 1);\n"
          "\tunsigned char *cells = cell;\n"
          "\tif (!cell) {\n"
          "\t\tfprintf(stderr, \"Error allocating memory.\\n\");\n"
          "\t\treturn 1;\n"
          "\t}\n\n",
          cellsize);
  while ((c = getc(in)) != EOF) {
    switch (c) {
    case '>':
      fprintf(out, "\t\t++cell;\n");
      break;
    case '<':
      fprintf(out, "\t\t--cell;\n");
      break;
    case '+':
      fprintf(out, "\t\t++*cell;\n");
      break;
    case '-':
      fprintf(out, "\t\t--*cell;\n");
      break;
    case '.':
      fprintf(out, "\t\tputchar(*cell);\n");
      break;
    case ',':
      fprintf(out, "\t\t*cell = getchar();\n");
      break;
    case '[':
      fprintf(out, "\twhile (*cell) {\n");
      break;
    case ']':
      fprintf(out, "\t}\n");
      break;
    default:
      break;
    }
  }
  fprintf(out, "\n\tfree(cells);\n\treturn 0;\n}\n\n");
}


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)
mov    0x2eab(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e85(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
movl   $0x7530,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%edx
lea    0xf65(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2e5f(%rip),%rcx
cmp    (%rcx),%eax
je     1274 <main+0x154>
mov    -0x24(%rbp),%eax
add    $0xffffffd5,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x32,%eax
ja     126a <main+0x14a>
mov    -0x30(%rbp),%rax
lea    0xe57(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x20(%rbp),%rdi
lea    0xfed(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    126f <main+0x14f>
mov    -0x20(%rbp),%rdi
lea    0xfe1(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    126f <main+0x14f>
mov    -0x20(%rbp),%rdi
lea    0xfd5(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    126f <main+0x14f>
mov    -0x20(%rbp),%rdi
lea    0xfca(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    126f <main+0x14f>
mov    -0x20(%rbp),%rdi
lea    0xfbf(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    126f <main+0x14f>
mov    -0x20(%rbp),%rdi
lea    0xfbb(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    126f <main+0x14f>
mov    -0x20(%rbp),%rdi
lea    0xfba(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    126f <main+0x14f>
mov    -0x20(%rbp),%rdi
lea    0xfb5(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    126f <main+0x14f>
jmp    126f <main+0x14f>
jmp    116e <main+0x4e>
mov    -0x20(%rbp),%rdi
lea    0xf98(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
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    0x2ea6(%rip),%rax
mov    (%rax),%rbx
mov    0x2e84(%rip),%rax
mov    (%rax),%r14
lea    0xf76(%rip),%rsi
mov    %r14,%rdi
mov    $0x7530,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <getc@plt>
mov    0x2e6c(%rip),%r15
cmp    (%r15),%eax
jne    11a3 <main+0x73>
lea    0x1097(%rip),%rdi
mov    $0x1d,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1040 <fwrite@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe56(%rip),%r12
lea    0x1050(%rip),%r13
lea    0x105b(%rip),%rbp
jmp    11e5 <main+0xb5>
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rbp,%rdi
nopw   0x0(%rax,%rax,1)
mov    %r14,%rcx
call   1040 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <getc@plt>
cmp    (%r15),%eax
je     1179 <main+0x49>
add    $0xffffffd5,%eax
cmp    $0x32,%eax
ja     11d8 <main+0xa8>
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
mov    $0xb,%esi
mov    $0x1,%edx
lea    0xfb9(%rip),%rdi
jmp    11d0 <main+0xa0>
mov    $0x15,%esi
mov    $0x1,%edx
lea    0xfd1(%rip),%rdi
jmp    11d0 <main+0xa0>
mov    $0xb,%esi
mov    $0x1,%edx
lea    0xf9f(%rip),%rdi
jmp    11d0 <main+0xa0>
mov    $0x12,%esi
mov    $0x1,%edx
lea    0xf98(%rip),%rdi
jmp    11d0 <main+0xa0>
mov    $0xa,%esi
mov    $0x1,%edx
lea    0xf62(%rip),%rdi
jmp    11d0 <main+0xa0>
mov    $0xa,%esi
mov    $0x1,%edx
lea    0xf41(%rip),%rdi
jmp    11d0 <main+0xa0>
mov    $0x11,%esi
mov    $0x1,%edx
mov    %r13,%rdi
jmp    11d0 <main+0xa0>

LLVM IR (-O0):
@stdin = global i32* null
@stdout = global i32* null
@.str = [222 x i8] c"#include <stdio.h>\0A#include <stdlib.h>\0A\0Aint main(int argc, char **argv)\0A{\0A\09unsigned char *cell = calloc(%d, 1);\0A\09unsigned char *cells = cell;\0A\09if (!cell) {\0A\09\09fprintf(stderr, \22Error allocating memory.\\n\22);\0A\09\09return 1;\0A\09}\0A\0A\00"
@EOF = global i32 0
@.str.1 = [11 x i8] c"\09\09++cell;\0A\00"
@.str.2 = [11 x i8] c"\09\09--cell;\0A\00"
@.str.3 = [12 x i8] c"\09\09++*cell;\0A\00"
@.str.4 = [12 x i8] c"\09\09--*cell;\0A\00"
@.str.5 = [19 x i8] c"\09\09putchar(*cell);\0A\00"
@.str.6 = [22 x i8] c"\09\09*cell = getchar();\0A\00"
@.str.7 = [18 x i8] c"\09while (*cell) {\0A\00"
@.str.8 = [4 x i8] c"\09}\0A\00"
@.str.9 = [30 x i8] c"\0A\09free(cells);\0A\09return 0;\0A}\0A\0A\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 i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32*, i32** @stdin
store i32* %10, i32** %6
%11 = load i32*, i32** @stdout
store i32* %11, i32** %7
store i32 30000, i32* %9
%12 = load i32*, i32** %7
%13 = load i32, i32* %9
%14 = call i32 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([222 x i8], [222 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %47, %2
%16 = load i32*, i32** %6
%17 = call i32 @getc(i32* %16)
store i32 %17, i32* %8
%18 = load i32, i32* @EOF
%19 = icmp ne i32 %17, %18
br i1 %19, label %20, label %48
20: ; preds = %15
%21 = load i32, i32* %8
switch i32 %21, label %46 [
i32 62, label %22
i32 60, label %25
i32 43, label %28
i32 45, label %31
i32 46, label %34
i32 44, label %37
i32 91, label %40
i32 93, label %43
]
22: ; preds = %20
%23 = load i32*, i32** %7
%24 = call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %47
25: ; preds = %20
%26 = load i32*, i32** %7
%27 = call i32 (i32*, i8*, ...) @fprintf(i32* %26, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %47
28: ; preds = %20
%29 = load i32*, i32** %7
%30 = call i32 (i32*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %47
31: ; preds = %20
%32 = load i32*, i32** %7
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %32, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %47
34: ; preds = %20
%35 = load i32*, i32** %7
%36 = call i32 (i32*, i8*, ...) @fprintf(i32* %35, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
br label %47
37: ; preds = %20
%38 = load i32*, i32** %7
%39 = call i32 (i32*, i8*, ...) @fprintf(i32* %38, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
br label %47
40: ; preds = %20
%41 = load i32*, i32** %7
%42 = call i32 (i32*, i8*, ...) @fprintf(i32* %41, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
br label %47
43: ; preds = %20
%44 = load i32*, i32** %7
%45 = call i32 (i32*, i8*, ...) @fprintf(i32* %44, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
br label %47
46: ; preds = %20
br label %47
47: ; preds = %46, %43, %40, %37, %34, %31, %28, %25, %22
br label %15
48: ; preds = %15
%49 = load i32*, i32** %7
%50 = call i32 (i32*, i8*, ...) @fprintf(i32* %49, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0))
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@stdin = global i32* null
@stdout = global i32* null
@.str = [222 x i8] c"#include <stdio.h>\0A#include <stdlib.h>\0A\0Aint main(int argc, char **argv)\0A{\0A\09unsigned char *cell = calloc(%d, 1);\0A\09unsigned char *cells = cell;\0A\09if (!cell) {\0A\09\09fprintf(stderr, \22Error allocating memory.\\n\22);\0A\09\09return 1;\0A\09}\0A\0A\00"
@EOF = global i32 0
@.str.1 = [11 x i8] c"\09\09++cell;\0A\00"
@.str.2 = [11 x i8] c"\09\09--cell;\0A\00"
@.str.3 = [12 x i8] c"\09\09++*cell;\0A\00"
@.str.4 = [12 x i8] c"\09\09--*cell;\0A\00"
@.str.5 = [19 x i8] c"\09\09putchar(*cell);\0A\00"
@.str.6 = [22 x i8] c"\09\09*cell = getchar();\0A\00"
@.str.7 = [18 x i8] c"\09while (*cell) {\0A\00"
@.str.8 = [4 x i8] c"\09}\0A\00"
@.str.9 = [30 x i8] c"\0A\09free(cells);\0A\09return 0;\0A}\0A\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32*, i32** @stdin
%4 = load i32*, i32** @stdout
%5 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([222 x i8], [222 x i8]* @.str, i64 0, i64 0), i32 30000)
%6 = tail call i32 @getc(i32* %3)
%7 = load i32, i32* @EOF
%8 = icmp eq i32 %6, %7
br i1 %8, label %31, label %9
9: ; preds = %2, %27
%10 = phi i32 [ %28, %27 ], [ %6, %2 ]
switch i32 %10, label %27 [
i32 62, label %11
i32 60, label %13
i32 43, label %15
i32 45, label %17
i32 46, label %19
i32 44, label %21
i32 91, label %23
i32 93, label %25
]
11: ; preds = %9
%12 = tail call i64 @fwrite(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i64 10, i64 1, i32* %4)
br label %27
13: ; preds = %9
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64 10, i64 1, i32* %4)
br label %27
15: ; preds = %9
%16 = tail call i64 @fwrite(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i64 11, i64 1, i32* %4)
br label %27
17: ; preds = %9
%18 = tail call i64 @fwrite(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i64 11, i64 1, i32* %4)
br label %27
19: ; preds = %9
%20 = tail call i64 @fwrite(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i64 18, i64 1, i32* %4)
br label %27
21: ; preds = %9
%22 = tail call i64 @fwrite(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i64 21, i64 1, i32* %4)
br label %27
23: ; preds = %9
%24 = tail call i64 @fwrite(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i64 17, i64 1, i32* %4)
br label %27
25: ; preds = %9
%26 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i64 3, i64 1, i32* %4)
br label %27
27: ; preds = %9, %25, %23, %21, %19, %17, %15, %13, %11
%28 = tail call i32 @getc(i32* %3)
%29 = load i32, i32* @EOF
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %9
31: ; preds = %27, %2
%32 = tail call i64 @fwrite(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0), i64 29, i64 1, i32* %4)
ret i32 0
}