#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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int atoi(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ free_stack();
char getchar();
int getopt(int, char **, char *);
int /*<<< orphan*/ init_stack(int);
long lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
long pop_stack();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ push_stack(long);
int /*<<< orphan*/ putchar(char);
int read(int, char *, long);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  static char usage[] = "usage: %s -f filename [-m memsize]\n";
  extern char *optarg;
  char *filename, insize;
  int c, fd, fflag = 0, err = 0, memsize = 1024, debug = 0;
  init_stack(50);
  while ((c = getopt(argc, argv, "m:f:d")) != -1)
    switch (c) {
    case 'f':
      filename = optarg;
      fflag = 1;
      break;
    case 'm':
      memsize = atoi(optarg);
      break;
    case 'd':
      debug = 1;
      break;
    default:
      err = 1;
      break;
    }
  if (fflag == 0) {
    fprintf(stderr, "%s: missing filename parameter\n", argv[0]);
    fprintf(stderr, usage, argv[0]);
    exit(1);
  } else if (err) {
    fprintf(stderr, usage, argv[0]);
    exit(1);
  }
  char memspace[memsize];
  char *mem = memspace;
  memset(memspace, 0, memsize);
  if ((fd = open(filename, O_RDONLY)) == -1) {
    fprintf(stderr, "Cannot open file: %s", strerror(errno));
    exit(1);
  }
  lseek(fd, 0, SEEK_END);
  long file_size = lseek(fd, 0, SEEK_CUR);
  lseek(fd, 0, SEEK_SET);
  if (debug)
    printf("file_size: %d\n", file_size);
  char *program = malloc(sizeof(char) * file_size);
  int read_in;
  if ((read_in = read(fd, program, file_size)) < 0) {
    fprintf(stderr, "Could not read in program: %s", strerror(errno));
    exit(1);
  }
  printf("Brainfuck Interpreter by Jacob Wiltse\n");
  printf("Memory Size: %d\n\n", memsize);
  long pos = 0;
  char input;
  while (pos < file_size) {
    input = program[pos];
    pos++;
    if (debug)
      printf("input: %c\n", input);
    switch (input) {
    case '>':
      ++mem;
      break;
    case '<':
      --mem;
      break;
    case '+':
      ++*mem;
      break;
    case '-':
      --*mem;
      break;
    case '.':
      putchar(*mem);
      break;
    case ',':
      *mem = getchar();
      break;
    case '[':
      if (*mem == 0) {
        int depth = 0;
        while (input != ']') {
          input = program[pos];
          pos++;
          if (input == '[')
            depth++;
          if (input == ']' && depth > 0) {
            input = ' ';
            depth--;
          }
        }
      } else {
        push_stack(pos);
      }
      break;
    case ']':
      if (*mem != 0) {
        long last_pos = pop_stack();
        push_stack(last_pos);
        pos = last_pos;
      } else
        pop_stack();
      break;
    default:
      break;
    }
  }
  if (insize == -1) {
    fprintf(stderr, "Connot read file: %s", strerror(errno));
    exit(1);
  }
  free_stack();
  free(program);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x400,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    $0x32,%edi
call   10e0 <init_stack@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe5f(%rip),%rdx
call   1100 <getopt@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
je     1306 <main+0xe6>
mov    -0x20(%rbp),%eax
mov    %eax,-0x84(%rbp)
sub    $0x64,%eax
je     12ee <main+0xce>
jmp    1295 <main+0x75>
mov    -0x84(%rbp),%eax
sub    $0x66,%eax
je     12bd <main+0x9d>
jmp    12a9 <main+0x89>
mov    -0x84(%rbp),%eax
sub    $0x6d,%eax
je     12d7 <main+0xb7>
jmp    12fa <main+0xda>
mov    0x2d04(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x28(%rbp)
jmp    1301 <main+0xe1>
mov    0x2cea(%rip),%rax
mov    (%rax),%rdi
call   1110 <atoi@plt>
mov    %eax,-0x30(%rbp)
jmp    1301 <main+0xe1>
movl   $0x1,-0x34(%rbp)
jmp    1301 <main+0xe1>
movl   $0x1,-0x2c(%rbp)
jmp    125f <main+0x3f>
cmpl   $0x0,-0x28(%rbp)
jne    1352 <main+0x132>
mov    0x2ca9(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdab(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2c8d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0x2d7d(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
cmpl   $0x0,-0x2c(%rbp)
je     1382 <main+0x162>
mov    0x2c5d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0x2d4d(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
jmp    1387 <main+0x167>
mov    -0x30(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,%rsp
mov    %rax,-0x48(%rbp)
mov    %rdi,-0x50(%rbp)
mov    -0x30(%rbp),%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    0x2c16(%rip),%rax
mov    (%rax),%esi
call   10f0 <open@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
jne    1411 <main+0x1f1>
mov    0x2be4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x88(%rbp)
mov    0x2bcd(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    -0x88(%rbp),%edi
mov    %rax,%rdx
lea    0xcf0(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x24(%rbp),%edi
mov    0x2bcd(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
mov    -0x24(%rbp),%edi
mov    0x2bb2(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
mov    %rax,-0x58(%rbp)
mov    -0x24(%rbp),%edi
mov    0x2b6b(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
cmpl   $0x0,-0x34(%rbp)
je     146a <main+0x24a>
mov    -0x58(%rbp),%rsi
lea    0xca4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x58(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x60(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x60(%rbp),%rsi
mov    -0x58(%rbp),%rdx
call   1080 <read@plt>
mov    %eax,-0x64(%rbp)
cmp    $0x0,%eax
jge    14d5 <main+0x2b5>
mov    0x2b20(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    0x2b09(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    -0x8c(%rbp),%edi
mov    %rax,%rdx
lea    0xc50(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
lea    0xc58(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%esi
lea    0xc6e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movq   $0x0,-0x70(%rbp)
mov    -0x70(%rbp),%rax
cmp    -0x58(%rbp),%rax
jge    16ae <main+0x48e>
mov    -0x60(%rbp),%rax
mov    -0x70(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x71(%rbp)
mov    -0x70(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x70(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     1540 <main+0x320>
movsbl -0x71(%rbp),%esi
lea    0xc34(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movsbl -0x71(%rbp),%eax
add    $0xffffffd5,%eax
mov    %eax,%ecx
mov    %rcx,-0x98(%rbp)
sub    $0x32,%eax
ja     16a4 <main+0x484>
mov    -0x98(%rbp),%rax
lea    0xa99(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    16a9 <main+0x489>
mov    -0x50(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x50(%rbp)
jmp    16a9 <main+0x489>
mov    -0x50(%rbp),%rax
mov    (%rax),%cl
add    $0x1,%cl
mov    %cl,(%rax)
jmp    16a9 <main+0x489>
mov    -0x50(%rbp),%rax
mov    (%rax),%cl
add    $0xff,%cl
mov    %cl,(%rax)
jmp    16a9 <main+0x489>
mov    -0x50(%rbp),%rax
movsbl (%rax),%edi
call   1040 <putchar@plt>
jmp    16a9 <main+0x489>
mov    $0x0,%al
call   1090 <getchar@plt>
mov    %al,%cl
mov    -0x50(%rbp),%rax
mov    %cl,(%rax)
jmp    16a9 <main+0x489>
mov    -0x50(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1659 <main+0x439>
movl   $0x0,-0x78(%rbp)
movsbl -0x71(%rbp),%eax
cmp    $0x5d,%eax
je     1654 <main+0x434>
mov    -0x60(%rbp),%rax
mov    -0x70(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x71(%rbp)
mov    -0x70(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x70(%rbp)
movsbl -0x71(%rbp),%eax
cmp    $0x5b,%eax
jne    162b <main+0x40b>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
movsbl -0x71(%rbp),%eax
cmp    $0x5d,%eax
jne    164f <main+0x42f>
cmpl   $0x0,-0x78(%rbp)
jle    164f <main+0x42f>
movb   $0x20,-0x71(%rbp)
mov    -0x78(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x78(%rbp)
jmp    15ee <main+0x3ce>
jmp    1662 <main+0x442>
mov    -0x70(%rbp),%rdi
call   10c0 <push_stack@plt>
jmp    16a9 <main+0x489>
mov    -0x50(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1698 <main+0x478>
mov    $0x0,%al
call   1140 <pop_stack@plt>
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rdi
call   10c0 <push_stack@plt>
mov    -0x80(%rbp),%rax
mov    %rax,-0x70(%rbp)
jmp    169f <main+0x47f>
mov    $0x0,%al
call   1140 <pop_stack@plt>
jmp    16a9 <main+0x489>
jmp    16a9 <main+0x489>
jmp    14fc <main+0x2dc>
movsbl -0x19(%rbp),%eax
cmp    $0xffffffff,%eax
jne    16f7 <main+0x4d7>
mov    0x28fe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x9c(%rbp)
mov    0x28e7(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    -0x9c(%rbp),%edi
mov    %rax,%rdx
lea    0xa90(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    $0x0,%al
call   10d0 <free_stack@plt>
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
mov    $0x32,%edi
call   10f0 <init_stack@plt>
movl   $0x0,-0x30(%rbp)
movl   $0x400,-0x38(%rbp)
mov    $0x1,%al
mov    %eax,-0x34(%rbp)
lea    0xe62(%rip),%r13
xor    %r12d,%r12d
jmp    1280 <main+0x50>
nop
mov    0x2d51(%rip),%rax
mov    (%rax),%r15
mov    $0x1,%r12d
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r13,%rdx
call   1110 <getopt@plt>
cmp    $0x66,%eax
je     1270 <main+0x40>
cmp    $0xffffffff,%eax
je     12c7 <main+0x97>
cmp    $0x64,%eax
je     12b5 <main+0x85>
cmp    $0x6d,%eax
jne    12be <main+0x8e>
mov    0x2d20(%rip),%rax
mov    (%rax),%rdi
call   1120 <atoi@plt>
mov    %eax,-0x38(%rbp)
jmp    1280 <main+0x50>
movl   $0x0,-0x34(%rbp)
jmp    1280 <main+0x50>
movl   $0x1,-0x30(%rbp)
jmp    1280 <main+0x50>
test   %r12d,%r12d
je     14e1 <main+0x2b1>
cmpl   $0x0,-0x30(%rbp)
mov    -0x38(%rbp),%r12d
jne    14fd <main+0x2cd>
mov    %r12d,%eax
mov    %rsp,%rdi
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rdi
mov    %rdi,%rsp
mov    %rdi,-0x30(%rbp)
xor    %esi,%esi
mov    %r12d,%edx
call   1080 <memset@plt>
mov    0x2cd1(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   1100 <open@plt>
cmp    $0xffffffff,%eax
je     1512 <main+0x2e2>
mov    %eax,%r14d
mov    0x2cc4(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
xor    %esi,%esi
call   1070 <lseek@plt>
mov    0x2ca9(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
xor    %esi,%esi
call   1070 <lseek@plt>
mov    %rax,%rbx
mov    0x2c63(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
xor    %esi,%esi
call   1070 <lseek@plt>
mov    -0x34(%rbp),%r15d
test   $0x1,%r15b
jne    1374 <main+0x144>
lea    0xd9d(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%edi
call   10c0 <malloc@plt>
mov    %rax,%r13
mov    %r14d,%edi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1090 <read@plt>
test   %eax,%eax
js     1532 <main+0x302>
lea    0xdb6(%rip),%rdi
call   1050 <puts@plt>
lea    0xd8d(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
test   %rbx,%rbx
jle    14c1 <main+0x291>
xor    %r12d,%r12d
jmp    13dc <main+0x1ac>
xor    %eax,%eax
call   10a0 <getchar@plt>
mov    -0x30(%rbp),%rcx
mov    %al,(%rcx)
nopl   0x0(%rax)
mov    %r14,%rbx
cmp    %r14,%r12
jge    14c1 <main+0x291>
mov    %rbx,%r14
movsbl 0x0(%r13,%r12,1),%ebx
test   $0x1,%r15b
jne    13fb <main+0x1cb>
lea    0xd54(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%r12
lea    -0x2b(%rbx),%eax
cmp    $0x32,%eax
ja     13d0 <main+0x1a0>
lea    0xbf2(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x30(%rbp),%rax
addb   $0x1,(%rax)
jmp    13d0 <main+0x1a0>
mov    -0x30(%rbp),%rax
addb   $0xff,(%rax)
jmp    13d0 <main+0x1a0>
mov    -0x30(%rbp),%rax
movsbl (%rax),%edi
call   1040 <putchar@plt>
jmp    13d0 <main+0x1a0>
addq   $0xffffffffffffffff,-0x30(%rbp)
jmp    13d0 <main+0x1a0>
addq   $0x1,-0x30(%rbp)
jmp    13d0 <main+0x1a0>
mov    -0x30(%rbp),%rax
cmpb   $0x0,(%rax)
je     1485 <main+0x255>
mov    %r12,%rdi
call   10d0 <push_stack@plt>
jmp    13d0 <main+0x1a0>
mov    -0x30(%rbp),%rax
mov    (%rax),%r15b
xor    %eax,%eax
call   1150 <pop_stack@plt>
test   %r15b,%r15b
je     147c <main+0x24c>
mov    %rax,%rbx
mov    %rax,%rdi
call   10d0 <push_stack@plt>
mov    %rbx,%r12
mov    -0x34(%rbp),%r15d
jmp    13d0 <main+0x1a0>
cmp    $0x5d,%bl
je     13d0 <main+0x1a0>
xor    %eax,%eax
movzbl 0x0(%r13,%r12,1),%ecx
add    $0x1,%r12
xor    %edx,%edx
cmp    $0x5b,%cl
sete   %dl
add    %eax,%edx
cmp    $0x5d,%cl
sete   %al
test   %edx,%edx
setg   %cl
and    %al,%cl
movzbl %cl,%ecx
sub    %ecx,%edx
xor    %al,%cl
mov    %edx,%eax
je     1490 <main+0x260>
jmp    13d0 <main+0x1a0>
xor    %eax,%eax
call   10e0 <free_stack@plt>
mov    %r13,%rdi
call   1030 <free@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ad8(%rip),%rbx
mov    (%rbx),%edi
mov    (%r14),%rdx
lea    0xbde(%rip),%rsi
call   10b0 <fprintf@plt>
mov    (%rbx),%edi
jmp    1506 <main+0x2d6>
mov    0x2abc(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0x2bb0(%rip),%rsi
jmp    1555 <main+0x325>
mov    0x2aa7(%rip),%rax
mov    (%rax),%ebx
mov    0x2a96(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
lea    0xbc2(%rip),%rsi
jmp    1550 <main+0x320>
mov    0x2a87(%rip),%rax
mov    (%rax),%ebx
mov    0x2a76(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
lea    0xbc6(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>

LLVM IR (-O0):
@main.usage = internal global [36 x i8] c"usage: %s -f filename [-m memsize]\0A\00"
@.str = [6 x i8] c"m:f:d\00"
@optarg = external global i8*
@stderr = global i32 0
@.str.1 = [32 x i8] c"%s: missing filename parameter\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [21 x i8] c"Cannot open file: %s\00"
@errno = global i32 0
@SEEK_END = global i32 0
@SEEK_CUR = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [15 x i8] c"file_size: %d\0A\00"
@.str.4 = [30 x i8] c"Could not read in program: %s\00"
@.str.5 = [39 x i8] c"Brainfuck Interpreter by Jacob Wiltse\0A\00"
@.str.6 = [18 x i8] c"Memory Size: %d\0A\0A\00"
@.str.7 = [11 x i8] c"input: %c\0A\00"
@.str.8 = [21 x i8] c"Connot read file: %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i64
%16 = alloca i8*
%17 = alloca i64
%18 = alloca i8*
%19 = alloca i32
%20 = alloca i64
%21 = alloca i8
%22 = alloca i32
%23 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
store i32 0, i32* %11
store i32 1024, i32* %12
store i32 0, i32* %13
%24 = call i32 @init_stack(i32 50)
br label %25
25: ; preds = %39, %2
%26 = load i32, i32* %4
%27 = load i8**, i8*** %5
%28 = call i32 @getopt(i32 %26, i8** %27, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 %28, i32* %8
%29 = icmp ne i32 %28, -1
br i1 %29, label %30, label %40
30: ; preds = %25
%31 = load i32, i32* %8
switch i32 %31, label %38 [
i32 102, label %32
i32 109, label %34
i32 100, label %37
]
32: ; preds = %30
%33 = load i8*, i8** @optarg
store i8* %33, i8** %6
store i32 1, i32* %10
br label %39
34: ; preds = %30
%35 = load i8*, i8** @optarg
%36 = call i32 @atoi(i8* %35)
store i32 %36, i32* %12
br label %39
37: ; preds = %30
store i32 1, i32* %13
br label %39
38: ; preds = %30
store i32 1, i32* %11
br label %39
39: ; preds = %38, %37, %34, %32
br label %25
40: ; preds = %25
%41 = load i32, i32* %10
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %55
43: ; preds = %40
%44 = load i32, i32* @stderr
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 0
%47 = load i8*, i8** %46
%48 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %47)
%49 = load i32, i32* @stderr
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 0
%52 = load i8*, i8** %51
%53 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @main.usage, i64 0, i64 0), i8* %52)
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %40
%56 = load i32, i32* %11
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %65
58: ; preds = %55
%59 = load i32, i32* @stderr
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 0
%62 = load i8*, i8** %61
%63 = call i32 @fprintf(i32 %59, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @main.usage, i64 0, i64 0), i8* %62)
%64 = call i32 @exit(i32 1)
unreachable
65: ; preds = %55
br label %66
66: ; preds = %65
%67 = load i32, i32* %12
%68 = zext i32 %67 to i64
%69 = call i8* @llvm.stacksave()
store i8* %69, i8** %14
%70 = alloca i8, i64 %68
store i64 %68, i64* %15
store i8* %70, i8** %16
%71 = load i32, i32* %12
%72 = call i32 @memset(i8* %70, i32 0, i32 %71)
%73 = load i8*, i8** %6
%74 = load i32, i32* @O_RDONLY
%75 = call i32 @open(i8* %73, i32 %74)
store i32 %75, i32* %9
%76 = icmp eq i32 %75, -1
br i1 %76, label %77, label %83
77: ; preds = %66
%78 = load i32, i32* @stderr
%79 = load i32, i32* @errno
%80 = call i8* @strerror(i32 %79)
%81 = call i32 @fprintf(i32 %78, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %80)
%82 = call i32 @exit(i32 1)
unreachable
83: ; preds = %66
%84 = load i32, i32* %9
%85 = load i32, i32* @SEEK_END
%86 = call i64 @lseek(i32 %84, i32 0, i32 %85)
%87 = load i32, i32* %9
%88 = load i32, i32* @SEEK_CUR
%89 = call i64 @lseek(i32 %87, i32 0, i32 %88)
store i64 %89, i64* %17
%90 = load i32, i32* %9
%91 = load i32, i32* @SEEK_SET
%92 = call i64 @lseek(i32 %90, i32 0, i32 %91)
%93 = load i32, i32* %13
%94 = icmp ne i32 %93, 0
br i1 %94, label %95, label %98
95: ; preds = %83
%96 = load i64, i64* %17
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i64 %96)
br label %98
98: ; preds = %95, %83
%99 = load i64, i64* %17
%100 = mul i64 1, %99
%101 = trunc i64 %100 to i32
%102 = call i8* @malloc(i32 %101)
store i8* %102, i8** %18
%103 = load i32, i32* %9
%104 = load i8*, i8** %18
%105 = load i64, i64* %17
%106 = call i32 @read(i32 %103, i8* %104, i64 %105)
store i32 %106, i32* %19
%107 = icmp slt i32 %106, 0
br i1 %107, label %108, label %114
108: ; preds = %98
%109 = load i32, i32* @stderr
%110 = load i32, i32* @errno
%111 = call i8* @strerror(i32 %110)
%112 = call i32 @fprintf(i32 %109, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %111)
%113 = call i32 @exit(i32 1)
unreachable
114: ; preds = %98
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
%116 = load i32, i32* %12
%117 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 %116)
store i64 0, i64* %20
br label %118
118: ; preds = %212, %114
%119 = load i64, i64* %20
%120 = load i64, i64* %17
%121 = icmp slt i64 %119, %120
br i1 %121, label %122, label %213
122: ; preds = %118
%123 = load i8*, i8** %18
%124 = load i64, i64* %20
%125 = getelementptr inbounds i8, i8* %123, i64 %124
%126 = load i8, i8* %125
store i8 %126, i8* %21
%127 = load i64, i64* %20
%128 = add nsw i64 %127, 1
store i64 %128, i64* %20
%129 = load i32, i32* %13
%130 = icmp ne i32 %129, 0
br i1 %130, label %131, label %135
131: ; preds = %122
%132 = load i8, i8* %21
%133 = sext i8 %132 to i32
%134 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i32 %133)
br label %135
135: ; preds = %131, %122
%136 = load i8, i8* %21
%137 = sext i8 %136 to i32
switch i32 %137, label %211 [
i32 62, label %138
i32 60, label %141
i32 43, label %144
i32 45, label %148
i32 46, label %152
i32 44, label %156
i32 91, label %159
i32 93, label %198
]
138: ; preds = %135
%139 = load i8*, i8** %16
%140 = getelementptr inbounds i8, i8* %139, i32 1
store i8* %140, i8** %16
br label %212
141: ; preds = %135
%142 = load i8*, i8** %16
%143 = getelementptr inbounds i8, i8* %142, i32 -1
store i8* %143, i8** %16
br label %212
144: ; preds = %135
%145 = load i8*, i8** %16
%146 = load i8, i8* %145
%147 = add i8 %146, 1
store i8 %147, i8* %145
br label %212
148: ; preds = %135
%149 = load i8*, i8** %16
%150 = load i8, i8* %149
%151 = add i8 %150, -1
store i8 %151, i8* %149
br label %212
152: ; preds = %135
%153 = load i8*, i8** %16
%154 = load i8, i8* %153
%155 = call i32 @putchar(i8 signext %154)
br label %212
156: ; preds = %135
%157 = call signext i8 (...) @getchar()
%158 = load i8*, i8** %16
store i8 %157, i8* %158
br label %212
159: ; preds = %135
%160 = load i8*, i8** %16
%161 = load i8, i8* %160
%162 = sext i8 %161 to i32
%163 = icmp eq i32 %162, 0
br i1 %163, label %164, label %194
164: ; preds = %159
store i32 0, i32* %22
br label %165
165: ; preds = %192, %164
%166 = load i8, i8* %21
%167 = sext i8 %166 to i32
%168 = icmp ne i32 %167, 93
br i1 %168, label %169, label %193
169: ; preds = %165
%170 = load i8*, i8** %18
%171 = load i64, i64* %20
%172 = getelementptr inbounds i8, i8* %170, i64 %171
%173 = load i8, i8* %172
store i8 %173, i8* %21
%174 = load i64, i64* %20
%175 = add nsw i64 %174, 1
store i64 %175, i64* %20
%176 = load i8, i8* %21
%177 = sext i8 %176 to i32
%178 = icmp eq i32 %177, 91
br i1 %178, label %179, label %182
179: ; preds = %169
%180 = load i32, i32* %22
%181 = add nsw i32 %180, 1
store i32 %181, i32* %22
br label %182
182: ; preds = %179, %169
%183 = load i8, i8* %21
%184 = sext i8 %183 to i32
%185 = icmp eq i32 %184, 93
br i1 %185, label %186, label %192
186: ; preds = %182
%187 = load i32, i32* %22
%188 = icmp sgt i32 %187, 0
br i1 %188, label %189, label %192
189: ; preds = %186
store i8 32, i8* %21
%190 = load i32, i32* %22
%191 = add nsw i32 %190, -1
store i32 %191, i32* %22
br label %192
192: ; preds = %189, %186, %182
br label %165
193: ; preds = %165
br label %197
194: ; preds = %159
%195 = load i64, i64* %20
%196 = call i32 @push_stack(i64 %195)
br label %197
197: ; preds = %194, %193
br label %212
198: ; preds = %135
%199 = load i8*, i8** %16
%200 = load i8, i8* %199
%201 = sext i8 %200 to i32
%202 = icmp ne i32 %201, 0
br i1 %202, label %203, label %208
203: ; preds = %198
%204 = call i64 (...) @pop_stack()
store i64 %204, i64* %23
%205 = load i64, i64* %23
%206 = call i32 @push_stack(i64 %205)
%207 = load i64, i64* %23
store i64 %207, i64* %20
br label %210
208: ; preds = %198
%209 = call i64 (...) @pop_stack()
br label %210
210: ; preds = %208, %203
br label %212
211: ; preds = %135
br label %212
212: ; preds = %211, %210, %197, %156, %152, %148, %144, %141, %138
br label %118
213: ; preds = %118
%214 = load i8, i8* %7
%215 = sext i8 %214 to i32
%216 = icmp eq i32 %215, -1
br i1 %216, label %217, label %223
217: ; preds = %213
%218 = load i32, i32* @stderr
%219 = load i32, i32* @errno
%220 = call i8* @strerror(i32 %219)
%221 = call i32 @fprintf(i32 %218, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i8* %220)
%222 = call i32 @exit(i32 1)
unreachable
223: ; preds = %213
%224 = call i32 (...) @free_stack()
%225 = load i8*, i8** %18
%226 = call i32 @free(i8* %225)
store i32 0, i32* %3
%227 = load i8*, i8** %14
%228 = load i32, i32* %3
ret i32 %228
}

LLVM IR (-O2):
@main.usage = internal global [36 x i8] c"usage: %s -f filename [-m memsize]\0A\00"
@.str = [6 x i8] c"m:f:d\00"
@optarg = external global i8*
@stderr = global i32 0
@.str.1 = [32 x i8] c"%s: missing filename parameter\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [21 x i8] c"Cannot open file: %s\00"
@errno = global i32 0
@SEEK_END = global i32 0
@SEEK_CUR = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [15 x i8] c"file_size: %d\0A\00"
@.str.4 = [30 x i8] c"Could not read in program: %s\00"
@.str.6 = [18 x i8] c"Memory Size: %d\0A\0A\00"
@.str.7 = [11 x i8] c"input: %c\0A\00"
@str = [38 x i8] c"Brainfuck Interpreter by Jacob Wiltse\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @init_stack(i32 50)
br label %4
4: ; preds = %19, %2
%5 = phi i1 [ true, %2 ], [ false, %19 ]
%6 = phi i32 [ 1024, %2 ], [ %11, %19 ]
%7 = phi i32 [ 0, %2 ], [ %16, %19 ]
%8 = phi i32 [ 0, %2 ], [ %20, %19 ]
%9 = phi i8* [ undef, %2 ], [ %21, %19 ]
br label %10
10: ; preds = %4, %25
%11 = phi i32 [ %6, %4 ], [ %27, %25 ]
%12 = phi i32 [ %7, %4 ], [ %16, %25 ]
%13 = phi i32 [ %8, %4 ], [ %20, %25 ]
%14 = phi i8* [ %9, %4 ], [ %21, %25 ]
br label %15
15: ; preds = %19, %10
%16 = phi i32 [ %12, %10 ], [ 1, %19 ]
%17 = phi i32 [ %13, %10 ], [ %20, %19 ]
%18 = phi i8* [ %14, %10 ], [ %21, %19 ]
br label %19
19: ; preds = %15, %23
%20 = phi i32 [ 1, %23 ], [ %17, %15 ]
%21 = phi i8* [ %24, %23 ], [ %18, %15 ]
%22 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
switch i32 %22, label %15 [
i32 -1, label %28
i32 102, label %23
i32 109, label %25
i32 100, label %4
]
23: ; preds = %19
%24 = load i8*, i8** @optarg
br label %19
25: ; preds = %19
%26 = load i8*, i8** @optarg
%27 = tail call i32 @atoi(i8* %26)
br label %10
28: ; preds = %19
%29 = icmp eq i32 %20, 0
br i1 %29, label %30, label %38
30: ; preds = %28
%31 = load i32, i32* @stderr
%32 = load i8*, i8** %1
%33 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %32)
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %1
%36 = tail call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @main.usage, i64 0, i64 0), i8* %35)
%37 = tail call i32 @exit(i32 1)
unreachable
38: ; preds = %28
%39 = icmp eq i32 %16, 0
br i1 %39, label %45, label %40
40: ; preds = %38
%41 = load i32, i32* @stderr
%42 = load i8*, i8** %1
%43 = tail call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @main.usage, i64 0, i64 0), i8* %42)
%44 = tail call i32 @exit(i32 1)
unreachable
45: ; preds = %38
%46 = zext i32 %11 to i64
%47 = alloca i8, i64 %46
%48 = call i32 @memset(i8* %47, i32 0, i32 %11)
%49 = load i32, i32* @O_RDONLY
%50 = call i32 @open(i8* %21, i32 %49)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %58
52: ; preds = %45
%53 = load i32, i32* @stderr
%54 = load i32, i32* @errno
%55 = call i8* @strerror(i32 %54)
%56 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %55)
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %45
%59 = load i32, i32* @SEEK_END
%60 = call i64 @lseek(i32 %50, i32 0, i32 %59)
%61 = load i32, i32* @SEEK_CUR
%62 = call i64 @lseek(i32 %50, i32 0, i32 %61)
%63 = load i32, i32* @SEEK_SET
%64 = call i64 @lseek(i32 %50, i32 0, i32 %63)
br i1 %5, label %67, label %65
65: ; preds = %58
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i64 %62)
br label %67
67: ; preds = %65, %58
%68 = trunc i64 %62 to i32
%69 = call i8* @malloc(i32 %68)
%70 = call i32 @read(i32 %50, i8* %69, i64 %62)
%71 = icmp slt i32 %70, 0
br i1 %71, label %72, label %78
72: ; preds = %67
%73 = load i32, i32* @stderr
%74 = load i32, i32* @errno
%75 = call i8* @strerror(i32 %74)
%76 = call i32 @fprintf(i32 %73, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %75)
%77 = call i32 @exit(i32 1)
unreachable
78: ; preds = %67
%79 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%80 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 %11)
%81 = icmp sgt i64 %62, 0
br i1 %81, label %82, label %139
82: ; preds = %78, %135
%83 = phi i64 [ %137, %135 ], [ 0, %78 ]
%84 = phi i8* [ %136, %135 ], [ %47, %78 ]
%85 = getelementptr inbounds i8, i8* %69, i64 %83
%86 = load i8, i8* %85
%87 = add nsw i64 %83, 1
%88 = sext i8 %86 to i32
br i1 %5, label %91, label %89
89: ; preds = %82
%90 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i32 %88)
br label %91
91: ; preds = %82, %89
switch i32 %88, label %135 [
i32 62, label %92
i32 60, label %94
i32 43, label %96
i32 45, label %99
i32 46, label %102
i32 44, label %105
i32 91, label %107
i32 93, label %129
]
92: ; preds = %91
%93 = getelementptr inbounds i8, i8* %84, i64 1
br label %135
94: ; preds = %91
%95 = getelementptr inbounds i8, i8* %84, i64 -1
br label %135
96: ; preds = %91
%97 = load i8, i8* %84
%98 = add i8 %97, 1
store i8 %98, i8* %84
br label %135
99: ; preds = %91
%100 = load i8, i8* %84
%101 = add i8 %100, -1
store i8 %101, i8* %84
br label %135
102: ; preds = %91
%103 = load i8, i8* %84
%104 = call i32 @putchar(i8 signext %103)
br label %135
105: ; preds = %91
%106 = call signext i8 (...) @getchar()
store i8 %106, i8* %84
br label %135
107: ; preds = %91
%108 = load i8, i8* %84
%109 = icmp eq i8 %108, 0
br i1 %109, label %110, label %127
110: ; preds = %107
%111 = icmp eq i8 %86, 93
br i1 %111, label %135, label %112
112: ; preds = %110, %112
%113 = phi i32 [ %125, %112 ], [ 0, %110 ]
%114 = phi i64 [ %117, %112 ], [ %87, %110 ]
%115 = getelementptr inbounds i8, i8* %69, i64 %114
%116 = load i8, i8* %115
%117 = add nsw i64 %114, 1
%118 = icmp eq i8 %116, 91
%119 = zext i1 %118 to i32
%120 = add nsw i32 %113, %119
%121 = icmp eq i8 %116, 93
%122 = icmp sgt i32 %120, 0
%123 = select i1 %121, i1 %122, i1 false
%124 = sext i1 %123 to i32
%125 = add nsw i32 %120, %124
%126 = xor i1 %123, %121
br i1 %126, label %135, label %112
127: ; preds = %107
%128 = call i32 @push_stack(i64 %87)
br label %135
129: ; preds = %91
%130 = load i8, i8* %84
%131 = icmp eq i8 %130, 0
%132 = call i64 (...) @pop_stack()
br i1 %131, label %135, label %133
133: ; preds = %129
%134 = call i32 @push_stack(i64 %132)
br label %135
135: ; preds = %112, %129, %110, %91, %133, %127, %105, %102, %99, %96, %94, %92
%136 = phi i8* [ %84, %91 ], [ %84, %133 ], [ %84, %127 ], [ %84, %105 ], [ %84, %102 ], [ %84, %99 ], [ %84, %96 ], [ %95, %94 ], [ %93, %92 ], [ %84, %110 ], [ %84, %129 ], [ %84, %112 ]
%137 = phi i64 [ %87, %91 ], [ %132, %133 ], [ %87, %127 ], [ %87, %105 ], [ %87, %102 ], [ %87, %99 ], [ %87, %96 ], [ %87, %94 ], [ %87, %92 ], [ %87, %110 ], [ %87, %129 ], [ %117, %112 ]
%138 = icmp slt i64 %137, %62
br i1 %138, label %82, label %139
139: ; preds = %135, %78
%140 = call i32 (...) @free_stack()
%141 = call i32 @free(i8* %69)
ret i32 0
}