#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
unsigned char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  FILE *f;
  unsigned char c;
  int i = 0;
  f = fopen("a.o65", "rb");
  if (f == NULL) {
    printf("*** Could not open opcode list ***\n");
  } else {
    printf("$0: ");
    while (!feof(f)) {
      c = getc(f);
      if (c == 255)
        break;
      if (c != '{') {
        printf("%c", c & 127);
      } else {
        c = getc(f);
        printf(" >>> %d", c & 127);
      }
      if (c & 128) {
        printf("\n$%x: ", ++i);
      }
    }
    printf(" *** END ***\n");
    fclose(f);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe93(%rip),%rdi
lea    0xe92(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119b <main+0x4b>
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1274 <main+0x124>
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11c7 <main+0x77>
jmp    125d <main+0x10d>
mov    -0x10(%rbp),%rdi
call   1070 <getc@plt>
mov    %al,-0x11(%rbp)
movzbl -0x11(%rbp),%eax
cmp    $0xff,%eax
jne    11e7 <main+0x97>
jmp    125d <main+0x10d>
movzbl -0x11(%rbp),%eax
cmp    $0x7b,%eax
je     120e <main+0xbe>
movzbl -0x11(%rbp),%esi
and    $0x7f,%esi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    122f <main+0xdf>
mov    -0x10(%rbp),%rdi
call   1070 <getc@plt>
mov    %al,-0x11(%rbp)
movzbl -0x11(%rbp),%esi
and    $0x7f,%esi
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movzbl -0x11(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     1258 <main+0x108>
mov    -0x18(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11a9 <main+0x59>
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xe81(%rip),%rdi
lea    0xe80(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11c3 <main+0x53>
mov    %rax,%rbp
lea    0xe6f(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbp,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     11da <main+0x6a>
lea    0xe69(%rip),%rdi
call   1040 <puts@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
jmp    11cf <main+0x5f>
lea    0xe60(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe2d(%rip),%r14
lea    0xe2e(%rip),%r15
xor    %r12d,%r12d
jmp    11fc <main+0x8c>
nopl   (%rax)
mov    %rbp,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11ad <main+0x3d>
mov    %rbp,%rdi
call   1090 <getc@plt>
cmp    $0x7b,%al
je     1220 <main+0xb0>
mov    %eax,%ebx
cmp    $0xff,%al
je     11ad <main+0x3d>
mov    %ebx,%eax
and    $0x7f,%al
movzbl %al,%edi
call   1030 <putchar@plt>
test   %bl,%bl
jns    11f0 <main+0x80>
jmp    123d <main+0xcd>
mov    %rbp,%rdi
call   1090 <getc@plt>
mov    %eax,%ebx
and    $0x7f,%al
movzbl %al,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
test   %bl,%bl
jns    11f0 <main+0x80>
add    $0x1,%r12d
mov    %r15,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11f0 <main+0x80>

LLVM IR (-O0):
@.str = [6 x i8] c"a.o65\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [36 x i8] c"*** Could not open opcode list ***\0A\00"
@.str.3 = [5 x i8] c"$0: \00"
@.str.4 = [3 x i8] c"%c\00"
@.str.5 = [8 x i8] c" >>> %d\00"
@.str.6 = [7 x i8] c"\0A$%x: \00"
@.str.7 = [14 x i8] c" *** END ***\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
%5 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
br label %54
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %12
12: ; preds = %49, %10
%13 = load i32*, i32** %2
%14 = call i32 @feof(i32* %13)
%15 = icmp ne i32 %14, 0
%16 = xor i1 %15, true
br i1 %16, label %17, label %50
17: ; preds = %12
%18 = load i32*, i32** %2
%19 = call zeroext i8 @getc(i32* %18)
store i8 %19, i8* %3
%20 = load i8, i8* %3
%21 = zext i8 %20 to i32
%22 = icmp eq i32 %21, 255
br i1 %22, label %23, label %24
23: ; preds = %17
br label %50
24: ; preds = %17
%25 = load i8, i8* %3
%26 = zext i8 %25 to i32
%27 = icmp ne i32 %26, 123
br i1 %27, label %28, label %33
28: ; preds = %24
%29 = load i8, i8* %3
%30 = zext i8 %29 to i32
%31 = and i32 %30, 127
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %31)
br label %40
33: ; preds = %24
%34 = load i32*, i32** %2
%35 = call zeroext i8 @getc(i32* %34)
store i8 %35, i8* %3
%36 = load i8, i8* %3
%37 = zext i8 %36 to i32
%38 = and i32 %37, 127
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %33, %28
%41 = load i8, i8* %3
%42 = zext i8 %41 to i32
%43 = and i32 %42, 128
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %40
%46 = load i32, i32* %4
%47 = add nsw i32 %46, 1
store i32 %47, i32* %4
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %45, %40
br label %12
50: ; preds = %23, %12
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
%52 = load i32*, i32** %2
%53 = call i32 @fclose(i32* %52)
br label %54
54: ; preds = %50, %8
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"a.o65\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.3 = [5 x i8] c"$0: \00"
@.str.5 = [8 x i8] c" >>> %d\00"
@.str.6 = [7 x i8] c"\0A$%x: \00"
@str = [13 x i8] c" *** END ***\00"
@str.8 = [35 x i8] c"*** Could not open opcode list ***\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.8, i64 0, i64 0))
br label %34
5: ; preds = %0
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%7 = tail call i32 @feof(i32* %1)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %31
9: ; preds = %5, %27
%10 = phi i32 [ %28, %27 ], [ 0, %5 ]
%11 = tail call zeroext i8 @getc(i32* %1)
switch i8 %11, label %12 [
i8 -1, label %31
i8 123, label %16
]
12: ; preds = %9
%13 = and i8 %11, 127
%14 = zext i8 %13 to i32
%15 = tail call i32 @putchar(i32 %14)
br label %21
16: ; preds = %9
%17 = tail call zeroext i8 @getc(i32* %1)
%18 = and i8 %17, 127
%19 = zext i8 %18 to i32
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %16, %12
%22 = phi i8 [ %11, %12 ], [ %17, %16 ]
%23 = icmp sgt i8 %22, -1
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = add nsw i32 %10, 1
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %24, %21
%28 = phi i32 [ %25, %24 ], [ %10, %21 ]
%29 = tail call i32 @feof(i32* %1)
%30 = icmp eq i32 %29, 0
br i1 %30, label %9, label %31
31: ; preds = %27, %9, %5
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%33 = tail call i32 @fclose(i32* %1)
br label %34
34: ; preds = %31, %3
ret i32 0
}