#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 getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ indent(int);
int /*<<< orphan*/ printf(char *);
int translate(FILE *src) {
  int c, indentlevel = 1;
  while ((c = getc(src)) != EOF) {
    switch (c) {
    case '>':
      indent(indentlevel);
      printf("++d;\n");
      break;
    case '<':
      indent(indentlevel);
      printf("--d;\n");
      break;
    case '+':
      indent(indentlevel);
      printf("++*d;\n");
      break;
    case '-':
      indent(indentlevel);
      printf("--*d;\n");
      break;
    case '.':
      indent(indentlevel);
      printf("(void) putchar(*d);\n");
      break;
    case ',':
      indent(indentlevel);
      printf("*d = getchar();\n");
      break;
    case '[':
      indent(indentlevel);
      indentlevel++;
      printf("while (*d) {\n");
      break;
    case ']':
      indentlevel--;
      indent(indentlevel);
      printf("}\n");
      break;
    default:
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<translate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e92(%rip),%rcx
cmp    (%rcx),%eax
je     126b <translate+0x13b>
mov    -0xc(%rbp),%eax
add    $0xffffffd5,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x32,%eax
ja     1261 <translate+0x131>
mov    -0x18(%rbp),%rax
lea    0xe82(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%edi
call   1040 <indent@plt>
lea    0xf36(%rip),%rdi
call   1030 <printf@plt>
jmp    1266 <translate+0x136>
mov    -0x10(%rbp),%edi
call   1040 <indent@plt>
lea    0xf23(%rip),%rdi
call   1030 <printf@plt>
jmp    1266 <translate+0x136>
mov    -0x10(%rbp),%edi
call   1040 <indent@plt>
lea    0xf10(%rip),%rdi
call   1030 <printf@plt>
jmp    1266 <translate+0x136>
mov    -0x10(%rbp),%edi
call   1040 <indent@plt>
lea    0xefe(%rip),%rdi
call   1030 <printf@plt>
jmp    1266 <translate+0x136>
mov    -0x10(%rbp),%edi
call   1040 <indent@plt>
lea    0xeec(%rip),%rdi
call   1030 <printf@plt>
jmp    1266 <translate+0x136>
mov    -0x10(%rbp),%edi
call   1040 <indent@plt>
lea    0xee8(%rip),%rdi
call   1030 <printf@plt>
jmp    1266 <translate+0x136>
mov    -0x10(%rbp),%edi
call   1040 <indent@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
lea    0xed7(%rip),%rdi
call   1030 <printf@plt>
jmp    1266 <translate+0x136>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <indent@plt>
lea    0xec3(%rip),%rdi
call   1030 <printf@plt>
jmp    1266 <translate+0x136>
jmp    1266 <translate+0x136>
jmp    1143 <translate+0x13>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<translate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <getc@plt>
mov    0x2e9e(%rip),%r14
cmp    (%r14),%eax
jne    1160 <translate+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%ebp
lea    0xe94(%rip),%r15
lea    0xf5b(%rip),%r12
lea    0xf52(%rip),%r13
jmp    11a2 <translate+0x72>
add    $0xffffffff,%ebp
mov    %ebp,%edi
call   1040 <indent@plt>
mov    %r13,%rdi
nopl   0x0(%rax)
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <getc@plt>
cmp    (%r14),%eax
je     114f <translate+0x1f>
add    $0xffffffd5,%eax
cmp    $0x32,%eax
ja     1195 <translate+0x65>
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
mov    %ebp,%edi
call   1040 <indent@plt>
lea    0xf44(%rip),%rdi
jmp    1190 <translate+0x60>
mov    %ebp,%edi
call   1040 <indent@plt>
lea    0xf0a(%rip),%rdi
jmp    1190 <translate+0x60>
mov    %ebp,%edi
call   1040 <indent@plt>
lea    0xf1e(%rip),%rdi
jmp    1190 <translate+0x60>
mov    %ebp,%edi
call   1040 <indent@plt>
lea    0xefa(%rip),%rdi
jmp    1190 <translate+0x60>
mov    %ebp,%edi
call   1040 <indent@plt>
lea    0xf0a(%rip),%rdi
jmp    1190 <translate+0x60>
mov    %ebp,%edi
call   1040 <indent@plt>
lea    0xeff(%rip),%rdi
jmp    1190 <translate+0x60>
mov    %ebp,%edi
call   1040 <indent@plt>
add    $0x1,%ebp
mov    %r12,%rdi
jmp    1190 <translate+0x60>

LLVM IR (-O0):
@EOF = global i32 0
@.str = [6 x i8] c"++d;\0A\00"
@.str.1 = [6 x i8] c"--d;\0A\00"
@.str.2 = [7 x i8] c"++*d;\0A\00"
@.str.3 = [7 x i8] c"--*d;\0A\00"
@.str.4 = [21 x i8] c"(void) putchar(*d);\0A\00"
@.str.5 = [17 x i8] c"*d = getchar();\0A\00"
@.str.6 = [14 x i8] c"while (*d) {\0A\00"
@.str.7 = [3 x i8] c"}\0A\00"
define i32 @translate(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32* %0, i32** %2
store i32 1, i32* %4
br label %5
5: ; preds = %49, %1
%6 = load i32*, i32** %2
%7 = call i32 @getc(i32* %6)
store i32 %7, i32* %3
%8 = load i32, i32* @EOF
%9 = icmp ne i32 %7, %8
br i1 %9, label %10, label %50
10: ; preds = %5
%11 = load i32, i32* %3
switch i32 %11, label %48 [
i32 62, label %12
i32 60, label %16
i32 43, label %20
i32 45, label %24
i32 46, label %28
i32 44, label %32
i32 91, label %36
i32 93, label %42
]
12: ; preds = %10
%13 = load i32, i32* %4
%14 = call i32 @indent(i32 %13)
%15 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %49
16: ; preds = %10
%17 = load i32, i32* %4
%18 = call i32 @indent(i32 %17)
%19 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %49
20: ; preds = %10
%21 = load i32, i32* %4
%22 = call i32 @indent(i32 %21)
%23 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %49
24: ; preds = %10
%25 = load i32, i32* %4
%26 = call i32 @indent(i32 %25)
%27 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %49
28: ; preds = %10
%29 = load i32, i32* %4
%30 = call i32 @indent(i32 %29)
%31 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %49
32: ; preds = %10
%33 = load i32, i32* %4
%34 = call i32 @indent(i32 %33)
%35 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %49
36: ; preds = %10
%37 = load i32, i32* %4
%38 = call i32 @indent(i32 %37)
%39 = load i32, i32* %4
%40 = add nsw i32 %39, 1
store i32 %40, i32* %4
%41 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
br label %49
42: ; preds = %10
%43 = load i32, i32* %4
%44 = add nsw i32 %43, -1
store i32 %44, i32* %4
%45 = load i32, i32* %4
%46 = call i32 @indent(i32 %45)
%47 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
br label %49
48: ; preds = %10
br label %49
49: ; preds = %48, %42, %36, %32, %28, %24, %20, %16, %12
br label %5
50: ; preds = %5
ret i32 0
}

LLVM IR (-O2):
@EOF = global i32 0
@str = [2 x i8] c"}\00"
@str.8 = [13 x i8] c"while (*d) {\00"
@str.9 = [16 x i8] c"*d = getchar();\00"
@str.10 = [20 x i8] c"(void) putchar(*d);\00"
@str.11 = [6 x i8] c"--*d;\00"
@str.12 = [6 x i8] c"++*d;\00"
@str.13 = [5 x i8] c"--d;\00"
@str.14 = [5 x i8] c"++d;\00"
define i32 @translate(i32* nocapture %0) {
%2 = tail call i32 @getc(i32* %0)
%3 = load i32, i32* @EOF
%4 = icmp eq i32 %2, %3
br i1 %4, label %35, label %5
5: ; preds = %1, %30
%6 = phi i32 [ %32, %30 ], [ %2, %1 ]
%7 = phi i32 [ %31, %30 ], [ 1, %1 ]
switch i32 %6, label %30 [
i32 62, label %8
i32 60, label %10
i32 43, label %12
i32 45, label %14
i32 46, label %16
i32 44, label %18
i32 91, label %20
i32 93, label %23
]
8: ; preds = %5
%9 = tail call i32 @indent(i32 %7)
br label %26
10: ; preds = %5
%11 = tail call i32 @indent(i32 %7)
br label %26
12: ; preds = %5
%13 = tail call i32 @indent(i32 %7)
br label %26
14: ; preds = %5
%15 = tail call i32 @indent(i32 %7)
br label %26
16: ; preds = %5
%17 = tail call i32 @indent(i32 %7)
br label %26
18: ; preds = %5
%19 = tail call i32 @indent(i32 %7)
br label %26
20: ; preds = %5
%21 = tail call i32 @indent(i32 %7)
%22 = add nsw i32 %7, 1
br label %26
23: ; preds = %5
%24 = add nsw i32 %7, -1
%25 = tail call i32 @indent(i32 %24)
br label %26
26: ; preds = %8, %10, %12, %14, %16, %18, %20, %23
%27 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0), %23 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @str.8, i64 0, i64 0), %20 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @str.9, i64 0, i64 0), %18 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @str.10, i64 0, i64 0), %16 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @str.11, i64 0, i64 0), %14 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @str.12, i64 0, i64 0), %12 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @str.13, i64 0, i64 0), %10 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @str.14, i64 0, i64 0), %8 ]
%28 = phi i32 [ %24, %23 ], [ %22, %20 ], [ %7, %18 ], [ %7, %16 ], [ %7, %14 ], [ %7, %12 ], [ %7, %10 ], [ %7, %8 ]
%29 = tail call i32 @puts(i8* dereferenceable(1) %27)
br label %30
30: ; preds = %26, %5
%31 = phi i32 [ %7, %5 ], [ %28, %26 ]
%32 = tail call i32 @getc(i32* %0)
%33 = load i32, i32* @EOF
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %5
35: ; preds = %30, %1
ret i32 0
}