#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;
unsigned char *calloc(int, int);
int convert(int);
int /*<<< orphan*/ execute(unsigned char *, size_t);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(unsigned char *);
unsigned char *realloc(unsigned char *, size_t);
int /*<<< orphan*/ srand(unsigned int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int c;
  FILE *src;
  size_t cap = 1, len = 1;
  unsigned char *tape = calloc(1, 1);
  if (argc != 2)
    return fprintf(stderr, "Usage: %s FILE\n", *argv);
  if (!(src = fopen(argv[1], "r")))
    return fprintf(stderr, "Unable to open file '%s'\n", argv[1]);
  while ((c = fgetc(src)) != EOF) {
    if (c == 0xe2) {
      c = convert((fgetc(src) - 0xa0) * 0x40 + (fgetc(src) - 0x80));
      if (cap == len)
        tape = realloc(tape, cap <<= 1);
      tape[len++] = c;
    }
  }
  srand((unsigned int)&c);
  execute(tape, len);
  fclose(src);
  free(tape);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x1,-0x28(%rbp)
movq   $0x1,-0x30(%rbp)
mov    $0x1,%esi
mov    %esi,%edi
call   1090 <calloc@plt>
mov    %rax,-0x38(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1204 <main+0x64>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe09(%rip),%rsi
call   10a0 <fprintf@plt>
mov    %eax,-0x4(%rbp)
jmp    131f <main+0x17f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdfd(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    124b <main+0xab>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdd4(%rip),%rsi
call   10a0 <fprintf@plt>
mov    %eax,-0x4(%rbp)
jmp    131f <main+0x17f>
jmp    1250 <main+0xb0>
mov    -0x20(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2d85(%rip),%rcx
cmp    (%rcx),%eax
je     12ee <main+0x14e>
cmpl   $0xe2,-0x14(%rbp)
jne    12e9 <main+0x149>
mov    -0x20(%rbp),%rdi
call   1070 <fgetc@plt>
sub    $0xa0,%eax
shl    $0x6,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <fgetc@plt>
mov    -0x3c(%rbp),%edi
sub    $0x80,%eax
add    %eax,%edi
call   1040 <convert@plt>
mov    %eax,-0x14(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jne    12ce <main+0x12e>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rsi
shl    $0x1,%rsi
mov    %rsi,-0x28(%rbp)
call   10b0 <realloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,%dl
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x30(%rbp)
mov    %dl,(%rax,%rcx,1)
jmp    1250 <main+0xb0>
lea    -0x14(%rbp),%rax
mov    %eax,%edi
call   1080 <srand@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1060 <execute@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x1,%edi
mov    $0x1,%esi
call   1090 <calloc@plt>
cmp    $0x2,%ebp
jne    1233 <main+0x93>
mov    %rax,%r14
mov    0x8(%rbx),%rdi
lea    0xe3e(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1248 <main+0xa8>
mov    %rax,%r15
mov    %rax,%rdi
call   1070 <fgetc@plt>
mov    %eax,0x4(%rsp)
mov    0x2df6(%rip),%r13
mov    $0x1,%ebx
cmp    0x0(%r13),%eax
jne    126f <main+0xcf>
lea    0x4(%rsp),%rdi
call   1080 <srand@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <execute@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdba(%rip),%rsi
jmp    125c <main+0xbc>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xdb6(%rip),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10a0 <fprintf@plt>
mov    $0x1,%ebx
mov    $0x1,%r12d
jmp    129e <main+0xfe>
nopl   0x0(%rax)
mov    %bpl,(%r14,%rbx,1)
add    $0x1,%rbx
mov    %r15,%rdi
call   1070 <fgetc@plt>
mov    %eax,0x4(%rsp)
cmp    0x0(%r13),%eax
je     11fd <main+0x5d>
cmp    $0xe2,%eax
jne    1288 <main+0xe8>
mov    %r15,%rdi
call   1070 <fgetc@plt>
mov    %eax,%ebp
shl    $0x6,%ebp
mov    %r15,%rdi
call   1070 <fgetc@plt>
lea    (%rax,%rbp,1),%edi
add    $0xffffd780,%edi
call   1040 <convert@plt>
mov    %eax,%ebp
cmp    %rbx,%r12
jne    1280 <main+0xe0>
lea    (%rbx,%rbx,1),%r12
mov    %r14,%rdi
mov    %r12,%rsi
call   10b0 <realloc@plt>
mov    %rax,%r14
jmp    1280 <main+0xe0>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [16 x i8] c"Usage: %s FILE\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"Unable to open file '%s'\0A\00"
@EOF = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 1, i64* %8
store i64 1, i64* %9
%11 = call i8* @calloc(i32 1, i32 1)
store i8* %11, i8** %10
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = load i8*, i8** %16
%18 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 %18, i32* %3
br label %76
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %7
%24 = icmp ne i32* %23, null
br i1 %24, label %31, label %25
25: ; preds = %19
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %29)
store i32 %30, i32* %3
br label %76
31: ; preds = %19
br label %32
32: ; preds = %65, %31
%33 = load i32*, i32** %7
%34 = call i32 @fgetc(i32* %33)
store i32 %34, i32* %6
%35 = load i32, i32* @EOF
%36 = icmp ne i32 %34, %35
br i1 %36, label %37, label %66
37: ; preds = %32
%38 = load i32, i32* %6
%39 = icmp eq i32 %38, 226
br i1 %39, label %40, label %65
40: ; preds = %37
%41 = load i32*, i32** %7
%42 = call i32 @fgetc(i32* %41)
%43 = sub nsw i32 %42, 160
%44 = mul nsw i32 %43, 64
%45 = load i32*, i32** %7
%46 = call i32 @fgetc(i32* %45)
%47 = sub nsw i32 %46, 128
%48 = add nsw i32 %44, %47
%49 = call i32 @convert(i32 %48)
store i32 %49, i32* %6
%50 = load i64, i64* %8
%51 = load i64, i64* %9
%52 = icmp eq i64 %50, %51
br i1 %52, label %53, label %58
53: ; preds = %40
%54 = load i8*, i8** %10
%55 = load i64, i64* %8
%56 = shl i64 %55, 1
store i64 %56, i64* %8
%57 = call i8* @realloc(i8* %54, i64 %56)
store i8* %57, i8** %10
br label %58
58: ; preds = %53, %40
%59 = load i32, i32* %6
%60 = trunc i32 %59 to i8
%61 = load i8*, i8** %10
%62 = load i64, i64* %9
%63 = add i64 %62, 1
store i64 %63, i64* %9
%64 = getelementptr inbounds i8, i8* %61, i64 %62
store i8 %60, i8* %64
br label %65
65: ; preds = %58, %37
br label %32
66: ; preds = %32
%67 = ptrtoint i32* %6 to i32
%68 = call i32 @srand(i32 %67)
%69 = load i8*, i8** %10
%70 = load i64, i64* %9
%71 = call i32 @execute(i8* %69, i64 %70)
%72 = load i32*, i32** %7
%73 = call i32 @fclose(i32* %72)
%74 = load i8*, i8** %10
%75 = call i32 @free(i8* %74)
store i32 0, i32* %3
br label %76
76: ; preds = %66, %25, %14
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [16 x i8] c"Usage: %s FILE\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"Unable to open file '%s'\0A\00"
@EOF = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call dereferenceable_or_null(1) i8* @calloc(i32 1, i32 1)
%6 = icmp eq i32 %0, 2
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %1
%10 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %63
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %20, label %16
16: ; preds = %11
%17 = tail call i32 @fgetc(i32* %14)
store i32 %17, i32* %3
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %54, label %24
20: ; preds = %11
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %12
%23 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %22)
br label %63
24: ; preds = %16, %47
%25 = phi i32 [ %51, %47 ], [ %17, %16 ]
%26 = phi i8* [ %50, %47 ], [ %5, %16 ]
%27 = phi i64 [ %49, %47 ], [ 1, %16 ]
%28 = phi i64 [ %48, %47 ], [ 1, %16 ]
%29 = icmp eq i32 %25, 226
br i1 %29, label %30, label %47
30: ; preds = %24
%31 = tail call i32 @fgetc(i32* %14)
%32 = shl i32 %31, 6
%33 = tail call i32 @fgetc(i32* %14)
%34 = add i32 %33, -10368
%35 = add i32 %34, %32
%36 = tail call i32 @convert(i32 %35)
%37 = icmp eq i64 %28, %27
br i1 %37, label %38, label %41
38: ; preds = %30
%39 = shl i64 %27, 1
%40 = tail call i8* @realloc(i8* %26, i64 %39)
br label %41
41: ; preds = %38, %30
%42 = phi i64 [ %39, %38 ], [ %28, %30 ]
%43 = phi i8* [ %40, %38 ], [ %26, %30 ]
%44 = trunc i32 %36 to i8
%45 = add i64 %27, 1
%46 = getelementptr inbounds i8, i8* %43, i64 %27
store i8 %44, i8* %46
br label %47
47: ; preds = %41, %24
%48 = phi i64 [ %42, %41 ], [ %28, %24 ]
%49 = phi i64 [ %45, %41 ], [ %27, %24 ]
%50 = phi i8* [ %43, %41 ], [ %26, %24 ]
%51 = tail call i32 @fgetc(i32* %14)
store i32 %51, i32* %3
%52 = load i32, i32* @EOF
%53 = icmp eq i32 %51, %52
br i1 %53, label %54, label %24
54: ; preds = %47, %16
%55 = phi i64 [ 1, %16 ], [ %49, %47 ]
%56 = phi i8* [ %5, %16 ], [ %50, %47 ]
%57 = ptrtoint i32* %3 to i64
%58 = trunc i64 %57 to i32
%59 = call i32 @srand(i32 %58)
%60 = call i32 @execute(i8* %56, i64 %55)
%61 = call i32 @fclose(i32* %14)
%62 = call i32 @free(i8* %56)
br label %63
63: ; preds = %54, %20, %7
%64 = phi i32 [ %10, %7 ], [ 0, %54 ], [ %23, %20 ]
ret i32 %64
}