#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*/ bf_pp(int /*<<< orphan*/ *, int, char *);
void bf_compile(FILE *out, const char *text) {
  bf_pp(out, 0, "#include <stdio.h>");
  bf_pp(out, 0, "#include <stdint.h>");
  bf_pp(out, 0, "static uint8_t heap[65536];");
  bf_pp(out, 0, "static uint8_t *mem = heap;");
  bf_pp(out, 0, "\n");
  bf_pp(out, 0, "int");
  bf_pp(out, 0, "main(void)");
  bf_pp(out, 0, "{");
  int level = 1;
  for (;;) {
    switch (*text++) {
    case '\0':
      goto exit;
    case '>':
      bf_pp(out, level, "mem += 1;");
      break;
    case '<':
      bf_pp(out, level, "mem -= 1;");
      break;
    case '+':
      bf_pp(out, level, "*mem += 1;");
      break;
    case '-':
      bf_pp(out, level, "*mem -= 1;");
      break;
    case '.':
      bf_pp(out, level, "putchar(*mem);");
      break;
    case ',':
      bf_pp(out, level, "*mem = getchar();");
      break;
    case '[':
      bf_pp(out, level, "while(*mem) {");
      level += 1;
      break;
    case ']':
      level -= 1;
      bf_pp(out, level, "}");
      break;
    default:
      break;
    }
  }
exit:
  bf_pp(out, level, "return 0;");
  bf_pp(out, 0, "}");
}


x86 assembly (clang, -O0):
<bf_compile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
lea    0xed3(%rip),%rdx
call   1030 <bf_pp@plt>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
lea    0xed4(%rip),%rdx
call   1030 <bf_pp@plt>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
lea    0xed6(%rip),%rdx
call   1030 <bf_pp@plt>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
lea    0xee0(%rip),%rdx
call   1030 <bf_pp@plt>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
lea    0xeea(%rip),%rdx
call   1030 <bf_pp@plt>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
lea    0xeda(%rip),%rdx
call   1030 <bf_pp@plt>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
lea    0xecc(%rip),%rdx
call   1030 <bf_pp@plt>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
lea    0xf08(%rip),%rdx
call   1030 <bf_pp@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x18(%rbp)
test   %eax,%eax
je     1261 <bf_compile+0x151>
jmp    11d9 <bf_compile+0xc9>
mov    -0x18(%rbp),%eax
sub    $0x2b,%eax
je     1296 <bf_compile+0x186>
jmp    11ea <bf_compile+0xda>
mov    -0x18(%rbp),%eax
sub    $0x2c,%eax
je     12de <bf_compile+0x1ce>
jmp    11fb <bf_compile+0xeb>
mov    -0x18(%rbp),%eax
sub    $0x2d,%eax
je     12ae <bf_compile+0x19e>
jmp    120c <bf_compile+0xfc>
mov    -0x18(%rbp),%eax
sub    $0x2e,%eax
je     12c6 <bf_compile+0x1b6>
jmp    121d <bf_compile+0x10d>
mov    -0x18(%rbp),%eax
sub    $0x3c,%eax
je     127e <bf_compile+0x16e>
jmp    122e <bf_compile+0x11e>
mov    -0x18(%rbp),%eax
sub    $0x3e,%eax
je     1266 <bf_compile+0x156>
jmp    123f <bf_compile+0x12f>
mov    -0x18(%rbp),%eax
sub    $0x5b,%eax
je     12f6 <bf_compile+0x1e6>
jmp    1250 <bf_compile+0x140>
mov    -0x18(%rbp),%eax
sub    $0x5d,%eax
je     1317 <bf_compile+0x207>
jmp    1338 <bf_compile+0x228>
jmp    1342 <bf_compile+0x232>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xdfd(%rip),%rdx
call   1030 <bf_pp@plt>
jmp    133d <bf_compile+0x22d>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xdf0(%rip),%rdx
call   1030 <bf_pp@plt>
jmp    133d <bf_compile+0x22d>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xdcc(%rip),%rdx
call   1030 <bf_pp@plt>
jmp    133d <bf_compile+0x22d>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xdbf(%rip),%rdx
call   1030 <bf_pp@plt>
jmp    133d <bf_compile+0x22d>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xdb2(%rip),%rdx
call   1030 <bf_pp@plt>
jmp    133d <bf_compile+0x22d>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xda9(%rip),%rdx
call   1030 <bf_pp@plt>
jmp    133d <bf_compile+0x22d>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xda3(%rip),%rdx
call   1030 <bf_pp@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    133d <bf_compile+0x22d>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xd87(%rip),%rdx
call   1030 <bf_pp@plt>
jmp    133d <bf_compile+0x22d>
jmp    133d <bf_compile+0x22d>
jmp    11b7 <bf_compile+0xa7>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    0xd67(%rip),%rdx
call   1030 <bf_pp@plt>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
lea    0xd53(%rip),%rdx
call   1030 <bf_pp@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bf_compile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xfa4(%rip),%rdx
xor    %esi,%esi
call   1030 <bf_pp@plt>
lea    0xfa9(%rip),%rdx
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <bf_pp@plt>
lea    0xfac(%rip),%rdx
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <bf_pp@plt>
lea    0xfb7(%rip),%rdx
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <bf_pp@plt>
lea    0xfc2(%rip),%rdx
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <bf_pp@plt>
lea    0xfb3(%rip),%rdx
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <bf_pp@plt>
lea    0xfa6(%rip),%rdx
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <bf_pp@plt>
lea    0xfe3(%rip),%rdx
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <bf_pp@plt>
mov    $0x1,%ebp
lea    0xe4e(%rip),%r13
lea    0xfba(%rip),%r15
lea    0xfc1(%rip),%r12
jmp    11e0 <bf_compile+0xd0>
add    $0xffffffff,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r12,%rdx
call   1030 <bf_pp@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl (%rbx),%eax
add    $0x1,%rbx
lea    -0x2b(%rax),%ecx
cmp    $0x32,%ecx
ja     1287 <bf_compile+0x177>
movslq 0x0(%r13,%rcx,4),%rax
add    %r13,%rax
jmp    *%rax
mov    %r14,%rdi
mov    %ebp,%esi
lea    0xf33(%rip),%rdx
call   1030 <bf_pp@plt>
jmp    11e0 <bf_compile+0xd0>
mov    %r14,%rdi
mov    %ebp,%esi
lea    0xf45(%rip),%rdx
call   1030 <bf_pp@plt>
jmp    11e0 <bf_compile+0xd0>
mov    %r14,%rdi
mov    %ebp,%esi
lea    0xf18(%rip),%rdx
call   1030 <bf_pp@plt>
jmp    11e0 <bf_compile+0xd0>
mov    %r14,%rdi
mov    %ebp,%esi
lea    0xf10(%rip),%rdx
call   1030 <bf_pp@plt>
jmp    11e0 <bf_compile+0xd0>
mov    %r14,%rdi
mov    %ebp,%esi
lea    0xef3(%rip),%rdx
call   1030 <bf_pp@plt>
jmp    11e0 <bf_compile+0xd0>
mov    %r14,%rdi
mov    %ebp,%esi
lea    0xed5(%rip),%rdx
call   1030 <bf_pp@plt>
jmp    11e0 <bf_compile+0xd0>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %r15,%rdx
call   1030 <bf_pp@plt>
add    $0x1,%ebp
jmp    11e0 <bf_compile+0xd0>
test   %eax,%eax
jne    11e0 <bf_compile+0xd0>
lea    0xeed(%rip),%rdx
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <bf_pp@plt>
lea    0xeda(%rip),%rdx
mov    %r14,%rdi
xor    %esi,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <bf_pp@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"#include <stdio.h>\00"
@.str.1 = [20 x i8] c"#include <stdint.h>\00"
@.str.2 = [28 x i8] c"static uint8_t heap[65536];\00"
@.str.3 = [28 x i8] c"static uint8_t *mem = heap;\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [4 x i8] c"int\00"
@.str.6 = [11 x i8] c"main(void)\00"
@.str.7 = [2 x i8] c"{\00"
@.str.8 = [10 x i8] c"mem += 1;\00"
@.str.9 = [10 x i8] c"mem -= 1;\00"
@.str.10 = [11 x i8] c"*mem += 1;\00"
@.str.11 = [11 x i8] c"*mem -= 1;\00"
@.str.12 = [15 x i8] c"putchar(*mem);\00"
@.str.13 = [18 x i8] c"*mem = getchar();\00"
@.str.14 = [14 x i8] c"while(*mem) {\00"
@.str.15 = [2 x i8] c"}\00"
@.str.16 = [10 x i8] c"return 0;\00"
define void @bf_compile(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
store i32* %0, i32** %3
store i8* %1, i8** %4
%6 = load i32*, i32** %3
%7 = call i32 @bf_pp(i32* %6, i32 0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%8 = load i32*, i32** %3
%9 = call i32 @bf_pp(i32* %8, i32 0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32*, i32** %3
%11 = call i32 @bf_pp(i32* %10, i32 0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32*, i32** %3
%13 = call i32 @bf_pp(i32* %12, i32 0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%14 = load i32*, i32** %3
%15 = call i32 @bf_pp(i32* %14, i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%16 = load i32*, i32** %3
%17 = call i32 @bf_pp(i32* %16, i32 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%18 = load i32*, i32** %3
%19 = call i32 @bf_pp(i32* %18, i32 0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%20 = load i32*, i32** %3
%21 = call i32 @bf_pp(i32* %20, i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %5
br label %22
22: ; preds = %65, %2
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %4
%25 = load i8, i8* %23
%26 = sext i8 %25 to i32
switch i32 %26, label %64 [
i32 0, label %27
i32 62, label %28
i32 60, label %32
i32 43, label %36
i32 45, label %40
i32 46, label %44
i32 44, label %48
i32 91, label %52
i32 93, label %58
]
27: ; preds = %22
br label %66
28: ; preds = %22
%29 = load i32*, i32** %3
%30 = load i32, i32* %5
%31 = call i32 @bf_pp(i32* %29, i32 %30, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0))
br label %65
32: ; preds = %22
%33 = load i32*, i32** %3
%34 = load i32, i32* %5
%35 = call i32 @bf_pp(i32* %33, i32 %34, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0))
br label %65
36: ; preds = %22
%37 = load i32*, i32** %3
%38 = load i32, i32* %5
%39 = call i32 @bf_pp(i32* %37, i32 %38, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0))
br label %65
40: ; preds = %22
%41 = load i32*, i32** %3
%42 = load i32, i32* %5
%43 = call i32 @bf_pp(i32* %41, i32 %42, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i64 0, i64 0))
br label %65
44: ; preds = %22
%45 = load i32*, i32** %3
%46 = load i32, i32* %5
%47 = call i32 @bf_pp(i32* %45, i32 %46, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0))
br label %65
48: ; preds = %22
%49 = load i32*, i32** %3
%50 = load i32, i32* %5
%51 = call i32 @bf_pp(i32* %49, i32 %50, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.13, i64 0, i64 0))
br label %65
52: ; preds = %22
%53 = load i32*, i32** %3
%54 = load i32, i32* %5
%55 = call i32 @bf_pp(i32* %53, i32 %54, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.14, i64 0, i64 0))
%56 = load i32, i32* %5
%57 = add nsw i32 %56, 1
store i32 %57, i32* %5
br label %65
58: ; preds = %22
%59 = load i32, i32* %5
%60 = sub nsw i32 %59, 1
store i32 %60, i32* %5
%61 = load i32*, i32** %3
%62 = load i32, i32* %5
%63 = call i32 @bf_pp(i32* %61, i32 %62, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0))
br label %65
64: ; preds = %22
br label %65
65: ; preds = %64, %58, %52, %48, %44, %40, %36, %32, %28
br label %22
66: ; preds = %27
%67 = load i32*, i32** %3
%68 = load i32, i32* %5
%69 = call i32 @bf_pp(i32* %67, i32 %68, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.16, i64 0, i64 0))
%70 = load i32*, i32** %3
%71 = call i32 @bf_pp(i32* %70, i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"#include <stdio.h>\00"
@.str.1 = [20 x i8] c"#include <stdint.h>\00"
@.str.2 = [28 x i8] c"static uint8_t heap[65536];\00"
@.str.3 = [28 x i8] c"static uint8_t *mem = heap;\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [4 x i8] c"int\00"
@.str.6 = [11 x i8] c"main(void)\00"
@.str.7 = [2 x i8] c"{\00"
@.str.8 = [10 x i8] c"mem += 1;\00"
@.str.9 = [10 x i8] c"mem -= 1;\00"
@.str.10 = [11 x i8] c"*mem += 1;\00"
@.str.11 = [11 x i8] c"*mem -= 1;\00"
@.str.12 = [15 x i8] c"putchar(*mem);\00"
@.str.13 = [18 x i8] c"*mem = getchar();\00"
@.str.14 = [14 x i8] c"while(*mem) {\00"
@.str.15 = [2 x i8] c"}\00"
@.str.16 = [10 x i8] c"return 0;\00"
define void @bf_compile(i32* %0, i8* nocapture %1) {
%3 = tail call i32 @bf_pp(i32* %0, i32 0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @bf_pp(i32* %0, i32 0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @bf_pp(i32* %0, i32 0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 @bf_pp(i32* %0, i32 0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%7 = tail call i32 @bf_pp(i32* %0, i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%8 = tail call i32 @bf_pp(i32* %0, i32 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%9 = tail call i32 @bf_pp(i32* %0, i32 0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%10 = tail call i32 @bf_pp(i32* %0, i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %11
11: ; preds = %17, %2
%12 = phi i8* [ %1, %2 ], [ %14, %17 ]
%13 = phi i32 [ 1, %2 ], [ %18, %17 ]
%14 = getelementptr inbounds i8, i8* %12, i64 1
%15 = load i8, i8* %12
%16 = sext i8 %15 to i32
switch i32 %16, label %17 [
i32 0, label %37
i32 62, label %19
i32 60, label %21
i32 43, label %23
i32 45, label %25
i32 46, label %27
i32 44, label %29
i32 91, label %31
i32 93, label %34
]
17: ; preds = %11, %34, %31, %29, %27, %25, %23, %21, %19
%18 = phi i32 [ %13, %11 ], [ %35, %34 ], [ %33, %31 ], [ %13, %29 ], [ %13, %27 ], [ %13, %25 ], [ %13, %23 ], [ %13, %21 ], [ %13, %19 ]
br label %11
19: ; preds = %11
%20 = tail call i32 @bf_pp(i32* %0, i32 %13, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0))
br label %17
21: ; preds = %11
%22 = tail call i32 @bf_pp(i32* %0, i32 %13, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0))
br label %17
23: ; preds = %11
%24 = tail call i32 @bf_pp(i32* %0, i32 %13, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0))
br label %17
25: ; preds = %11
%26 = tail call i32 @bf_pp(i32* %0, i32 %13, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i64 0, i64 0))
br label %17
27: ; preds = %11
%28 = tail call i32 @bf_pp(i32* %0, i32 %13, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0))
br label %17
29: ; preds = %11
%30 = tail call i32 @bf_pp(i32* %0, i32 %13, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.13, i64 0, i64 0))
br label %17
31: ; preds = %11
%32 = tail call i32 @bf_pp(i32* %0, i32 %13, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.14, i64 0, i64 0))
%33 = add nsw i32 %13, 1
br label %17
34: ; preds = %11
%35 = add nsw i32 %13, -1
%36 = tail call i32 @bf_pp(i32* %0, i32 %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0))
br label %17
37: ; preds = %11
%38 = tail call i32 @bf_pp(i32* %0, i32 %13, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.16, i64 0, i64 0))
%39 = tail call i32 @bf_pp(i32* %0, i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0))
ret void
}