#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 ssize_t;
typedef int /*<<< orphan*/ program;

/* Variables and functions */
char EOF;
int /*<<< orphan*/ O_RDONLY;
int STDIN_FILENO;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char getchar();
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ prepare_jumps(char *, int, char **);
int /*<<< orphan*/ putchar(char);
int read_prg(char *, int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  char program[50000], memory[30000];
  char *jump_map[50000];
  char *ip = program, *ptr = memory;
  int fd = 0;
  ssize_t prg_size = 0;
  if (argc < 2) {
    fd = STDIN_FILENO;
  } else {
    fd = open(argv[1], O_RDONLY);
    if (fd < 0) {
      fprintf(stderr, "Error opening %s!\n", argv[1]);
      perror("open");
      exit(1);
    }
  }
  prg_size = read_prg(program, sizeof(program), fd);
  prepare_jumps(program, prg_size, jump_map);
  while (ip < (program + prg_size)) {
    switch (*ip) {
    case '>':
      ++ptr;
      break;
    case '<':
      --ptr;
      break;
    case '+':
      ++(*ptr);
      break;
    case '-':
      --(*ptr);
      break;
    case '.':
      putchar(*ptr);
      fflush(stdout);
      break;
    case ',':
      *ptr = getchar();
      if (*ptr == EOF)
        exit(0);
      break;
    case '[':
      if (!*ptr) {
        ip = jump_map[ip - program];
      }
      break;
    case ']':
      if (*ptr) {
        ip = jump_map[ip - program];
      }
      break;
    }
    ++ip;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x75330,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0xc360(%rbp),%rax
mov    %rax,-0x75318(%rbp)
lea    -0x13890(%rbp),%rax
mov    %rax,-0x75320(%rbp)
movl   $0x0,-0x75324(%rbp)
movl   $0x0,-0x75328(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11f7 <main+0x67>
mov    0x2dd6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x75324(%rbp)
jmp    1258 <main+0xc8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x75324(%rbp)
cmpl   $0x0,-0x75324(%rbp)
jge    1253 <main+0xc3>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe94(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xe9b(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    1258 <main+0xc8>
lea    -0xc360(%rbp),%rdi
mov    -0x75324(%rbp),%edx
mov    $0xc350,%esi
call   1070 <read_prg@plt>
mov    %eax,-0x75328(%rbp)
lea    -0xc360(%rbp),%rdi
mov    -0x75328(%rbp),%esi
lea    -0x75310(%rbp),%rdx
call   1080 <prepare_jumps@plt>
mov    -0x75318(%rbp),%rax
lea    -0xc360(%rbp),%rcx
movslq -0x75328(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jae    1416 <main+0x286>
mov    -0x75318(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffd5,%eax
mov    %eax,%ecx
mov    %rcx,-0x75330(%rbp)
sub    $0x32,%eax
ja     13ff <main+0x26f>
mov    -0x75330(%rbp),%rax
lea    0xd24(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x75320(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x75320(%rbp)
jmp    13ff <main+0x26f>
mov    -0x75320(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x75320(%rbp)
jmp    13ff <main+0x26f>
mov    -0x75320(%rbp),%rax
mov    (%rax),%cl
add    $0x1,%cl
mov    %cl,(%rax)
jmp    13ff <main+0x26f>
mov    -0x75320(%rbp),%rax
mov    (%rax),%cl
add    $0xff,%cl
mov    %cl,(%rax)
jmp    13ff <main+0x26f>
mov    -0x75320(%rbp),%rax
movsbl (%rax),%edi
call   1030 <putchar@plt>
mov    0x2c79(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
jmp    13ff <main+0x26f>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,%cl
mov    -0x75320(%rbp),%rax
mov    %cl,(%rax)
mov    -0x75320(%rbp),%rax
movsbl (%rax),%eax
mov    0x2c62(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1390 <main+0x200>
xor    %edi,%edi
call   10b0 <exit@plt>
jmp    13ff <main+0x26f>
mov    -0x75320(%rbp),%rax
cmpb   $0x0,(%rax)
jne    13c5 <main+0x235>
mov    -0x75318(%rbp),%rax
lea    -0xc360(%rbp),%rcx
sub    %rcx,%rax
mov    -0x75310(%rbp,%rax,8),%rax
ff
mov    %rax,-0x75318(%rbp)
jmp    13ff <main+0x26f>
mov    -0x75320(%rbp),%rax
cmpb   $0x0,(%rax)
je     13fa <main+0x26a>
mov    -0x75318(%rbp),%rax
lea    -0xc360(%rbp),%rcx
sub    %rcx,%rax
mov    -0x75310(%rbp,%rax,8),%rax
ff
mov    %rax,-0x75318(%rbp)
jmp    13ff <main+0x26f>
mov    -0x75318(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x75318(%rbp)
jmp    128e <main+0xfe>
xor    %eax,%eax
add    $0x75330,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x75308,%rsp
cmp    $0x1,%edi
jg     11b1 <main+0x21>
mov    0x2e13(%rip),%rax
mov    (%rax),%edx
jmp    11d0 <main+0x40>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,%edx
test   %eax,%eax
js     12bb <main+0x12b>
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0xc350,%esi
call   1070 <read_prg@plt>
mov    %eax,%ebp
lea    0x13880(%rsp),%rdx
mov    %r12,%rdi
mov    %eax,%esi
call   1080 <prepare_jumps@plt>
test   %ebp,%ebp
jle    12a0 <main+0x110>
movslq %ebp,%rax
lea    (%rsp,%rax,1),%rbp
lea    0xc350(%rsp),%rbx
lea    0xdee(%rip),%r15
mov    0x2daf(%rip),%r13
mov    %r12,%r14
jmp    1239 <main+0xa9>
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%r14
cmp    %rbp,%r14
jae    12a0 <main+0x110>
movsbl (%r14),%eax
add    $0xffffffd5,%eax
cmp    $0x32,%eax
ja     1230 <main+0xa0>
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
addb   $0x1,(%rbx)
jmp    1230 <main+0xa0>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %al,(%rbx)
mov    0x2d7d(%rip),%rcx
cmp    (%rcx),%al
jne    1230 <main+0xa0>
jmp    12b4 <main+0x124>
addb   $0xff,(%rbx)
jmp    1230 <main+0xa0>
movsbl (%rbx),%edi
call   1030 <putchar@plt>
mov    0x0(%r13),%edi
call   1060 <fflush@plt>
jmp    1230 <main+0xa0>
add    $0xffffffffffffffff,%rbx
jmp    1230 <main+0xa0>
cmpb   $0x0,(%rbx)
jne    1230 <main+0xa0>
jmp    1293 <main+0x103>
cmpb   $0x0,(%rbx)
je     1230 <main+0xa0>
sub    %r12,%r14
mov    0x13880(%rsp,%r14,8),%r14
jmp    1230 <main+0xa0>
xor    %eax,%eax
add    $0x75308,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
call   10b0 <exit@plt>
mov    0x2d0e(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xdfd(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xe04(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"Error opening %s!\0A\00"
@.str.1 = [5 x i8] c"open\00"
@stdout = global i32 0
@EOF = global i8 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [50000 x i8]
%7 = alloca [30000 x i8]
%8 = alloca [50000 x i8*]
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = getelementptr inbounds [50000 x i8], [50000 x i8]* %6, i64 0, i64 0
store i8* %13, i8** %9
%14 = getelementptr inbounds [30000 x i8], [30000 x i8]* %7, i64 0, i64 0
store i8* %14, i8** %10
store i32 0, i32* %11
store i32 0, i32* %12
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 2
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = load i32, i32* @STDIN_FILENO
store i32 %18, i32* %11
br label %36
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* %22, i32 %23)
store i32 %24, i32* %11
%25 = load i32, i32* %11
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %35
27: ; preds = %19
%28 = load i32, i32* @stderr
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %31)
%33 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %19
br label %36
36: ; preds = %35, %17
%37 = getelementptr inbounds [50000 x i8], [50000 x i8]* %6, i64 0, i64 0
%38 = load i32, i32* %11
%39 = call i32 @read_prg(i8* %37, i32 50000, i32 %38)
store i32 %39, i32* %12
%40 = getelementptr inbounds [50000 x i8], [50000 x i8]* %6, i64 0, i64 0
%41 = load i32, i32* %12
%42 = getelementptr inbounds [50000 x i8*], [50000 x i8*]* %8, i64 0, i64 0
%43 = call i32 @prepare_jumps(i8* %40, i32 %41, i8** %42)
br label %44
44: ; preds = %113, %36
%45 = load i8*, i8** %9
%46 = getelementptr inbounds [50000 x i8], [50000 x i8]* %6, i64 0, i64 0
%47 = load i32, i32* %12
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = icmp ult i8* %45, %49
br i1 %50, label %51, label %116
51: ; preds = %44
%52 = load i8*, i8** %9
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
switch i32 %54, label %113 [
i32 62, label %55
i32 60, label %58
i32 43, label %61
i32 45, label %65
i32 46, label %69
i32 44, label %75
i32 91, label %87
i32 93, label %100
]
55: ; preds = %51
%56 = load i8*, i8** %10
%57 = getelementptr inbounds i8, i8* %56, i32 1
store i8* %57, i8** %10
br label %113
58: ; preds = %51
%59 = load i8*, i8** %10
%60 = getelementptr inbounds i8, i8* %59, i32 -1
store i8* %60, i8** %10
br label %113
61: ; preds = %51
%62 = load i8*, i8** %10
%63 = load i8, i8* %62
%64 = add i8 %63, 1
store i8 %64, i8* %62
br label %113
65: ; preds = %51
%66 = load i8*, i8** %10
%67 = load i8, i8* %66
%68 = add i8 %67, -1
store i8 %68, i8* %66
br label %113
69: ; preds = %51
%70 = load i8*, i8** %10
%71 = load i8, i8* %70
%72 = call i32 @putchar(i8 signext %71)
%73 = load i32, i32* @stdout
%74 = call i32 @fflush(i32 %73)
br label %113
75: ; preds = %51
%76 = call signext i8 (...) @getchar()
%77 = load i8*, i8** %10
store i8 %76, i8* %77
%78 = load i8*, i8** %10
%79 = load i8, i8* %78
%80 = sext i8 %79 to i32
%81 = load i8, i8* @EOF
%82 = sext i8 %81 to i32
%83 = icmp eq i32 %80, %82
br i1 %83, label %84, label %86
84: ; preds = %75
%85 = call i32 @exit(i32 0)
unreachable
86: ; preds = %75
br label %113
87: ; preds = %51
%88 = load i8*, i8** %10
%89 = load i8, i8* %88
%90 = icmp ne i8 %89, 0
br i1 %90, label %99, label %91
91: ; preds = %87
%92 = load i8*, i8** %9
%93 = getelementptr inbounds [50000 x i8], [50000 x i8]* %6, i64 0, i64 0
%94 = ptrtoint i8* %92 to i64
%95 = ptrtoint i8* %93 to i64
%96 = sub i64 %94, %95
%97 = getelementptr inbounds [50000 x i8*], [50000 x i8*]* %8, i64 0, i64 %96
%98 = load i8*, i8** %97
store i8* %98, i8** %9
br label %99
99: ; preds = %91, %87
br label %113
100: ; preds = %51
%101 = load i8*, i8** %10
%102 = load i8, i8* %101
%103 = icmp ne i8 %102, 0
br i1 %103, label %104, label %112
104: ; preds = %100
%105 = load i8*, i8** %9
%106 = getelementptr inbounds [50000 x i8], [50000 x i8]* %6, i64 0, i64 0
%107 = ptrtoint i8* %105 to i64
%108 = ptrtoint i8* %106 to i64
%109 = sub i64 %107, %108
%110 = getelementptr inbounds [50000 x i8*], [50000 x i8*]* %8, i64 0, i64 %109
%111 = load i8*, i8** %110
store i8* %111, i8** %9
br label %112
112: ; preds = %104, %100
br label %113
113: ; preds = %51, %112, %99, %86, %69, %65, %61, %58, %55
%114 = load i8*, i8** %9
%115 = getelementptr inbounds i8, i8* %114, i32 1
store i8* %115, i8** %9
br label %44
116: ; preds = %44
ret i32 0
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"Error opening %s!\0A\00"
@.str.1 = [5 x i8] c"open\00"
@stdout = global i32 0
@EOF = global i8 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [50000 x i8]
%4 = alloca [30000 x i8]
%5 = alloca [50000 x i8*]
%6 = getelementptr inbounds [50000 x i8], [50000 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [30000 x i8], [30000 x i8]* %4, i64 0, i64 0
%8 = bitcast [50000 x i8*]* %5 to i8*
%9 = icmp slt i32 %0, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = load i32, i32* @STDIN_FILENO
br label %24
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @O_RDONLY
%16 = tail call i32 @open(i8* %14, i32 %15)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %12
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %13
%21 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %12, %10
%25 = phi i32 [ %11, %10 ], [ %16, %12 ]
%26 = call i32 @read_prg(i8* %6, i32 50000, i32 %25)
%27 = getelementptr inbounds [50000 x i8*], [50000 x i8*]* %5, i64 0, i64 0
%28 = call i32 @prepare_jumps(i8* %6, i32 %26, i8** %27)
%29 = sext i32 %26 to i64
%30 = getelementptr inbounds [50000 x i8], [50000 x i8]* %3, i64 0, i64 %29
%31 = icmp sgt i32 %26, 0
br i1 %31, label %32, label %81
32: ; preds = %24
%33 = ptrtoint [50000 x i8]* %3 to i64
br label %34
34: ; preds = %32, %76
%35 = phi i8* [ %7, %32 ], [ %78, %76 ]
%36 = phi i8* [ %6, %32 ], [ %79, %76 ]
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
switch i32 %38, label %76 [
i32 62, label %39
i32 60, label %41
i32 43, label %43
i32 45, label %46
i32 46, label %49
i32 44, label %54
i32 91, label %60
i32 93, label %68
]
39: ; preds = %34
%40 = getelementptr inbounds i8, i8* %35, i64 1
br label %76
41: ; preds = %34
%42 = getelementptr inbounds i8, i8* %35, i64 -1
br label %76
43: ; preds = %34
%44 = load i8, i8* %35
%45 = add i8 %44, 1
store i8 %45, i8* %35
br label %76
46: ; preds = %34
%47 = load i8, i8* %35
%48 = add i8 %47, -1
store i8 %48, i8* %35
br label %76
49: ; preds = %34
%50 = load i8, i8* %35
%51 = call i32 @putchar(i8 signext %50)
%52 = load i32, i32* @stdout
%53 = call i32 @fflush(i32 %52)
br label %76
54: ; preds = %34
%55 = call signext i8 (...) @getchar()
store i8 %55, i8* %35
%56 = load i8, i8* @EOF
%57 = icmp eq i8 %55, %56
br i1 %57, label %58, label %76
58: ; preds = %54
%59 = call i32 @exit(i32 0)
unreachable
60: ; preds = %34
%61 = load i8, i8* %35
%62 = icmp eq i8 %61, 0
br i1 %62, label %63, label %76
63: ; preds = %60
%64 = ptrtoint i8* %36 to i64
%65 = sub i64 %64, %33
%66 = getelementptr inbounds [50000 x i8*], [50000 x i8*]* %5, i64 0, i64 %65
%67 = load i8*, i8** %66
br label %76
68: ; preds = %34
%69 = load i8, i8* %35
%70 = icmp eq i8 %69, 0
br i1 %70, label %76, label %71
71: ; preds = %68
%72 = ptrtoint i8* %36 to i64
%73 = sub i64 %72, %33
%74 = getelementptr inbounds [50000 x i8*], [50000 x i8*]* %5, i64 0, i64 %73
%75 = load i8*, i8** %74
br label %76
76: ; preds = %68, %71, %60, %63, %54, %34, %49, %46, %43, %41, %39
%77 = phi i8* [ %36, %34 ], [ %75, %71 ], [ %36, %68 ], [ %36, %60 ], [ %67, %63 ], [ %36, %54 ], [ %36, %49 ], [ %36, %46 ], [ %36, %43 ], [ %36, %41 ], [ %36, %39 ]
%78 = phi i8* [ %35, %34 ], [ %35, %71 ], [ %35, %68 ], [ %35, %60 ], [ %35, %63 ], [ %35, %54 ], [ %35, %49 ], [ %35, %46 ], [ %35, %43 ], [ %42, %41 ], [ %40, %39 ]
%79 = getelementptr inbounds i8, i8* %77, i64 1
%80 = icmp ult i8* %79, %30
br i1 %80, label %34, label %81
81: ; preds = %76, %24
ret i32 0
}