#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 */

/* Variables and functions */
int EOF;
int getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
main() {
  int c;
  int tabs = 1;
  int size = 10000;
  printf("#include <stdio.h>\n");
  printf("main(){\n");
  printf("\tint p=%d;\n", size / 2);
  printf("\tint memory[%d];\n", size + 1);
  printf("\tint max = %d;\n", size);
  printf("\tint i;\n");
  printf("\tfor(i=0;i<max;i++){\n");
  printf("\t\tmemory[i]=0;\n");
  printf("\t}\n");
  while ((c = getchar()) != EOF) {
    if (c == ']')
      tabs--;
    int i;
    for (i = 0; i < tabs; i++) {
      putchar('\t');
    }
    switch (c) {
    case '>':
      printf("if(p<max)p++;\n");
      break;
    case '<':
      printf("if(p>0)p--;\n");
      break;
    case '+':
      printf("memory[p]++;\n");
      break;
    case '-':
      printf("memory[p]--;\n");
      break;
    case '.':
      printf("putchar(memory[p]);\n");
      break;
    case '\'':
      printf("memory[p]=getchar();\n");
      break;
    case '[':
      printf("while(memory[p]!=0){\n");
      tabs++;
      break;
    case ']':
      printf("}\n");
      break;
    default:
      printf("\r");
      break;
    }
  }
  printf("}\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x2710,-0x10(%rbp)
lea    0xf88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xf7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%esi
add    $0x1,%esi
lea    0xf74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xf75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf77(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf7a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2df6(%rip),%rcx
cmp    (%rcx),%eax
je     1315 <main+0x1e5>
cmpl   $0x5d,-0x8(%rbp)
jne    120d <main+0xdd>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1238 <main+0x108>
mov    $0x9,%edi
call   1030 <putchar@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1214 <main+0xe4>
mov    -0x8(%rbp),%eax
add    $0xffffffd9,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x36,%eax
ja     1302 <main+0x1d2>
mov    -0x20(%rbp),%rax
lea    0xda8(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xef2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1310 <main+0x1e0>
lea    0xeee(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1310 <main+0x1e0>
lea    0xee8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1310 <main+0x1e0>
lea    0xee3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1310 <main+0x1e0>
lea    0xede(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1310 <main+0x1e0>
lea    0xee0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1310 <main+0x1e0>
lea    0xee3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1310 <main+0x1e0>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1310 <main+0x1e0>
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11e1 <main+0xb1>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xfb8(%rip),%rdi
call   1040 <puts@plt>
lea    0xfbf(%rip),%rdi
call   1040 <puts@plt>
lea    0xf72(%rip),%rdi
mov    $0x1388,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf6b(%rip),%rdi
mov    $0x2711,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf6a(%rip),%rdi
mov    $0x2710,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf82(%rip),%rdi
call   1040 <puts@plt>
lea    0xf7e(%rip),%rdi
call   1040 <puts@plt>
lea    0xf87(%rip),%rdi
call   1040 <puts@plt>
lea    0xf8a(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    0x2e0e(%rip),%r13
cmp    0x0(%r13),%eax
jne    11fd <main+0xbd>
lea    0xf6b(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%r12d
mov    $0x1,%r14d
lea    0xdf3(%rip),%rbp
lea    0xf3e(%rip),%r15
jmp    1230 <main+0xf0>
mov    $0xd,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    %eax,%r12d
cmp    0x0(%r13),%eax
je     11e0 <main+0xa0>
xor    %eax,%eax
cmp    $0x5d,%r12d
sete   %al
sub    %eax,%r14d
test   %r14d,%r14d
jle    125f <main+0x11f>
mov    %r14d,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x9,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebx
jne    1250 <main+0x110>
add    $0xffffffd9,%r12d
cmp    $0x36,%r12d
ja     1216 <main+0xd6>
movslq 0x0(%rbp,%r12,4),%rax
add    %rbp,%rax
jmp    *%rax
lea    0xeef(%rip),%rdi
call   1040 <puts@plt>
jmp    1220 <main+0xe0>
lea    0xf17(%rip),%rdi
call   1040 <puts@plt>
jmp    1220 <main+0xe0>
lea    0xefc(%rip),%rdi
call   1040 <puts@plt>
jmp    1220 <main+0xe0>
lea    0xeda(%rip),%rdi
call   1040 <puts@plt>
jmp    1220 <main+0xe0>
lea    0xef7(%rip),%rdi
call   1040 <puts@plt>
jmp    1220 <main+0xe0>
lea    0xef2(%rip),%rdi
call   1040 <puts@plt>
jmp    1220 <main+0xe0>
lea    0xe7d(%rip),%rdi
call   1040 <puts@plt>
add    $0x1,%r14d
jmp    1220 <main+0xe0>
mov    %r15,%rdi
call   1040 <puts@plt>
jmp    1220 <main+0xe0>

LLVM IR (-O0):
@.str = [20 x i8] c"#include <stdio.h>\0A\00"
@.str.1 = [9 x i8] c"main(){\0A\00"
@.str.2 = [12 x i8] c"\09int p=%d;\0A\00"
@.str.3 = [18 x i8] c"\09int memory[%d];\0A\00"
@.str.4 = [16 x i8] c"\09int max = %d;\0A\00"
@.str.5 = [9 x i8] c"\09int i;\0A\00"
@.str.6 = [22 x i8] c"\09for(i=0;i<max;i++){\0A\00"
@.str.7 = [16 x i8] c"\09\09memory[i]=0;\0A\00"
@.str.8 = [4 x i8] c"\09}\0A\00"
@EOF = global i32 0
@.str.9 = [15 x i8] c"if(p<max)p++;\0A\00"
@.str.10 = [13 x i8] c"if(p>0)p--;\0A\00"
@.str.11 = [14 x i8] c"memory[p]++;\0A\00"
@.str.12 = [14 x i8] c"memory[p]--;\0A\00"
@.str.13 = [21 x i8] c"putchar(memory[p]);\0A\00"
@.str.14 = [22 x i8] c"memory[p]=getchar();\0A\00"
@.str.15 = [22 x i8] c"while(memory[p]!=0){\0A\00"
@.str.16 = [3 x i8] c"}\0A\00"
@.str.17 = [2 x i8] c"\0D\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %3
store i32 10000, i32* %4
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%8 = load i32, i32* %4
%9 = sdiv i32 %8, 2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %4
%12 = add nsw i32 %11, 1
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %14)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
br label %20
20: ; preds = %62, %0
%21 = call i32 (...) @getchar()
store i32 %21, i32* %2
%22 = load i32, i32* @EOF
%23 = icmp ne i32 %21, %22
br i1 %23, label %24, label %63
24: ; preds = %20
%25 = load i32, i32* %2
%26 = icmp eq i32 %25, 93
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i32, i32* %3
%29 = add nsw i32 %28, -1
store i32 %29, i32* %3
br label %30
30: ; preds = %27, %24
store i32 0, i32* %5
br label %31
31: ; preds = %37, %30
%32 = load i32, i32* %5
%33 = load i32, i32* %3
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %40
35: ; preds = %31
%36 = call i32 @putchar(i8 signext 9)
br label %37
37: ; preds = %35
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
store i32 %39, i32* %5
br label %31
40: ; preds = %31
%41 = load i32, i32* %2
switch i32 %41, label %60 [
i32 62, label %42
i32 60, label %44
i32 43, label %46
i32 45, label %48
i32 46, label %50
i32 39, label %52
i32 91, label %54
i32 93, label %58
]
42: ; preds = %40
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
br label %62
44: ; preds = %40
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
br label %62
46: ; preds = %40
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0))
br label %62
48: ; preds = %40
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.12, i64 0, i64 0))
br label %62
50: ; preds = %40
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.13, i64 0, i64 0))
br label %62
52: ; preds = %40
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.14, i64 0, i64 0))
br label %62
54: ; preds = %40
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.15, i64 0, i64 0))
%56 = load i32, i32* %3
%57 = add nsw i32 %56, 1
store i32 %57, i32* %3
br label %62
58: ; preds = %40
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.16, i64 0, i64 0))
br label %62
60: ; preds = %40
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0))
br label %62
62: ; preds = %60, %58, %54, %52, %50, %48, %46, %44, %42
br label %20
63: ; preds = %20
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.16, i64 0, i64 0))
%65 = load i32, i32* %1
ret i32 %65
}

LLVM IR (-O2):
@.str.2 = [12 x i8] c"\09int p=%d;\0A\00"
@.str.3 = [18 x i8] c"\09int memory[%d];\0A\00"
@.str.4 = [16 x i8] c"\09int max = %d;\0A\00"
@EOF = global i32 0
@str = [19 x i8] c"#include <stdio.h>\00"
@str.18 = [8 x i8] c"main(){\00"
@str.19 = [8 x i8] c"\09int i;\00"
@str.20 = [21 x i8] c"\09for(i=0;i<max;i++){\00"
@str.21 = [15 x i8] c"\09\09memory[i]=0;\00"
@str.22 = [3 x i8] c"\09}\00"
@str.24 = [2 x i8] c"}\00"
@str.25 = [21 x i8] c"while(memory[p]!=0){\00"
@str.26 = [21 x i8] c"memory[p]=getchar();\00"
@str.27 = [20 x i8] c"putchar(memory[p]);\00"
@str.28 = [13 x i8] c"memory[p]--;\00"
@str.29 = [13 x i8] c"memory[p]++;\00"
@str.30 = [12 x i8] c"if(p>0)p--;\00"
@str.31 = [14 x i8] c"if(p<max)p++;\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.18, i64 0, i64 0))
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 5000)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 10001)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 10000)
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.19, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.20, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.21, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.22, i64 0, i64 0))
%10 = tail call i32 (...) @getchar()
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
br i1 %12, label %50, label %13
13: ; preds = %0, %45
%14 = phi i32 [ %47, %45 ], [ %10, %0 ]
%15 = phi i32 [ %46, %45 ], [ 1, %0 ]
%16 = icmp eq i32 %14, 93
%17 = sext i1 %16 to i32
%18 = add i32 %15, %17
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %13, %20
%21 = phi i32 [ %23, %20 ], [ 0, %13 ]
%22 = tail call i32 @putchar(i8 signext 9)
%23 = add nuw nsw i32 %21, 1
%24 = icmp eq i32 %23, %18
br i1 %24, label %25, label %20
25: ; preds = %20, %13
switch i32 %14, label %43 [
i32 62, label %26
i32 60, label %28
i32 43, label %30
i32 45, label %32
i32 46, label %34
i32 39, label %36
i32 91, label %38
i32 93, label %41
]
26: ; preds = %25
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.31, i64 0, i64 0))
br label %45
28: ; preds = %25
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.30, i64 0, i64 0))
br label %45
30: ; preds = %25
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.29, i64 0, i64 0))
br label %45
32: ; preds = %25
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.28, i64 0, i64 0))
br label %45
34: ; preds = %25
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.27, i64 0, i64 0))
br label %45
36: ; preds = %25
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.26, i64 0, i64 0))
br label %45
38: ; preds = %25
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.25, i64 0, i64 0))
%40 = add nsw i32 %18, 1
br label %45
41: ; preds = %25
%42 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.24, i64 0, i64 0))
br label %45
43: ; preds = %25
%44 = tail call i32 bitcast (i32 (i8)* @putchar to i32 (i32)*)(i32 13)
br label %45
45: ; preds = %43, %41, %38, %36, %34, %32, %30, %28, %26
%46 = phi i32 [ %18, %43 ], [ %18, %41 ], [ %40, %38 ], [ %18, %36 ], [ %18, %34 ], [ %18, %32 ], [ %18, %30 ], [ %18, %28 ], [ %18, %26 ]
%47 = tail call i32 (...) @getchar()
%48 = load i32, i32* @EOF
%49 = icmp eq i32 %47, %48
br i1 %49, label %50, label %13
50: ; preds = %45, %0
%51 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.24, i64 0, i64 0))
ret i32 0
}