#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*/ uint16_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ list_opcode(int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int main(int argc, const char *argv[]) {
  FILE *f;
  if (argc < 2)
    return 0;
  f = fopen(argv[1], "rb");
  if (!f) {
    printf("failed to open");
    return -1;
  }
  int addr = 0;
  while (1) {
    uint16_t opcode;
    if (fread(&opcode, 2, 1, f) != 1)
      break;
    list_opcode(addr, opcode);
    addr += 2;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    116c <main+0x2c>
movl   $0x0,-0x4(%rbp)
jmp    11f3 <main+0xb3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe85(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a7 <main+0x67>
lea    0xe6d(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f3 <main+0xb3>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rcx
lea    -0x20(%rbp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x1,%eax
je     11d3 <main+0x93>
jmp    11ec <main+0xac>
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1030 <list_opcode@plt>
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ae <main+0x6e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
cmp    $0x2,%edi
jl     11cc <main+0x8c>
mov    0x8(%rsi),%rdi
lea    0xea6(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11ba <main+0x7a>
mov    %rax,%rbx
lea    0x4(%rsp),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    11cc <main+0x8c>
xor    %ebp,%ebp
lea    0x4(%rsp),%r15
nopw   0x0(%rax,%rax,1)
mov    0x4(%rsp),%esi
mov    %ebp,%edi
call   1030 <list_opcode@plt>
add    $0x2,%ebp
mov    %r15,%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
je     1190 <main+0x50>
jmp    11cc <main+0x8c>
lea    0xe42(%rip),%rdi
call   1050 <printf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [15 x i8] c"failed to open\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 0, i32* %3
br label %34
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %6
%17 = load i32*, i32** %6
%18 = icmp ne i32* %17, null
br i1 %18, label %21, label %19
19: ; preds = %12
%20 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %34
21: ; preds = %12
store i32 0, i32* %7
br label %22
22: ; preds = %21, %27
%23 = load i32*, i32** %6
%24 = call i32 @fread(i32* %8, i32 2, i32 1, i32* %23)
%25 = icmp ne i32 %24, 1
br i1 %25, label %26, label %27
26: ; preds = %22
br label %33
27: ; preds = %22
%28 = load i32, i32* %7
%29 = load i32, i32* %8
%30 = call i32 @list_opcode(i32 %28, i32 %29)
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 2
store i32 %32, i32* %7
br label %22
33: ; preds = %26
store i32 0, i32* %3
br label %34
34: ; preds = %33, %19, %11
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [15 x i8] c"failed to open\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp slt i32 %0, 2
br i1 %4, label %24, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %14, label %10
10: ; preds = %5
%11 = bitcast i32* %3 to i8*
%12 = call i32 @fread(i32* %3, i32 2, i32 1, i32* %8)
%13 = icmp eq i32 %12, 1
br i1 %13, label %17, label %16
14: ; preds = %5
%15 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %24
16: ; preds = %17, %10
br label %24
17: ; preds = %10, %17
%18 = phi i32 [ %21, %17 ], [ 0, %10 ]
%19 = load i32, i32* %3
%20 = tail call i32 @list_opcode(i32 %18, i32 %19)
%21 = add nuw nsw i32 %18, 2
%22 = call i32 @fread(i32* %3, i32 2, i32 1, i32* %8)
%23 = icmp eq i32 %22, 1
br i1 %23, label %17, label %16
24: ; preds = %16, %2, %14
%25 = phi i32 [ -1, %14 ], [ 0, %2 ], [ 0, %16 ]
ret i32 %25
}