#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int disassemble_instruction(long, unsigned char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned char *, long, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
unsigned char *malloc(long);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char *);
long strtol(char *, int /*<<< orphan*/ *, int);
int main(int argc, char **argv) {
  FILE *fptr;
  long size, offset;
  unsigned char *data;
  if (argc != 2 && argc != 3) {
    puts("usage: disassemble <file.bin> [$offset]");
    return EXIT_FAILURE;
  }
  fptr = fopen(argv[1], "rb");
  if (!fptr) {
    puts("file not file");
    return EXIT_FAILURE;
  }
  fseek(fptr, 0, SEEK_END);
  size = ftell(fptr);
  fseek(fptr, 0, SEEK_SET);
  data = malloc(size);
  fread(data, size, 1, fptr);
  fclose(fptr);
  if (argc == 3) {
    offset = strtol(argv[2], NULL, 16);
    size -= offset;
    data += offset;
  }
  {
    int result, bytes;
    bytes = 0;
    printf("0x%.4x: ", bytes + offset);
    while ((result = disassemble_instruction(size, data)) > 0) {
      size -= result;
      data += result;
      bytes += result;
      printf("0x%.4x: ", bytes + offset);
    }
    printf("disassembled %d bytes\n", bytes);
  }
  return EXIT_SUCCESS;
}


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)
cmpl   $0x2,-0x8(%rbp)
je     11e7 <main+0x47>
cmpl   $0x3,-0x8(%rbp)
je     11e7 <main+0x47>
lea    0xe2f(%rip),%rdi
call   1030 <puts@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    135c <main+0x1bc>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe32(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1227 <main+0x87>
lea    0xe1a(%rip),%rdi
call   1030 <puts@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    135c <main+0x1bc>
mov    -0x18(%rbp),%rdi
mov    0x2db6(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2d85(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
cmpl   $0x3,-0x8(%rbp)
jne    12c7 <main+0x127>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1080 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x38(%rbp)
movslq -0x38(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %eax,%esi
lea    0xd5a(%rip),%rdi
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   10b0 <disassemble_instruction@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jle    1341 <main+0x1a1>
movslq -0x34(%rbp),%rcx
mov    -0x20(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x34(%rbp),%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
movslq -0x38(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %eax,%esi
lea    0xd02(%rip),%rdi
call   1060 <printf@plt>
jmp    12e4 <main+0x144>
mov    -0x38(%rbp),%esi
lea    0xcf7(%rip),%rdi
call   1060 <printf@plt>
mov    0x2c71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-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    %edi,%eax
and    $0xfffffffe,%eax
cmp    $0x2,%eax
jne    1257 <main+0xb7>
mov    %rsi,%r12
mov    %edi,%r13d
mov    0x8(%rsi),%rdi
lea    0xe5e(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1260 <main+0xc0>
mov    %rax,%rbp
mov    0x2e06(%rip),%rax
mov    (%rax),%edx
xor    %r14d,%r14d
mov    %rbp,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %rbp,%rdi
call   1070 <ftell@plt>
mov    %rax,%r15
mov    0x2dd5(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %r15,%rdi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1040 <fread@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
cmp    $0x3,%r13d
jne    1275 <main+0xd5>
mov    0x10(%r12),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <strtol@plt>
mov    %rax,%r12
sub    %rax,%r15
add    %rax,%rbx
jmp    1275 <main+0xd5>
lea    0xda2(%rip),%rdi
jmp    1267 <main+0xc7>
lea    0xdc4(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d5d(%rip),%rax
jmp    12dc <main+0x13c>
lea    0xdbd(%rip),%rdi
mov    %r12d,%esi
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   10b0 <disassemble_instruction@plt>
test   %eax,%eax
jle    12c6 <main+0x126>
xor    %r14d,%r14d
lea    0xd9c(%rip),%rbp
nopl   (%rax)
mov    %eax,%ecx
sub    %rcx,%r15
add    %rcx,%rbx
add    %eax,%r14d
lea    (%r14,%r12,1),%esi
mov    %rbp,%rdi
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   10b0 <disassemble_instruction@plt>
test   %eax,%eax
jg     12a0 <main+0x100>
lea    0xd75(%rip),%rdi
mov    %r14d,%esi
call   1060 <printf@plt>
mov    0x2cec(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"usage: disassemble <file.bin> [$offset]\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [14 x i8] c"file not file\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [9 x i8] c"0x%.4x: \00"
@.str.4 = [23 x i8] c"disassembled %d bytes\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 3
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = call i32 @puts(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
store i32 %19, i32* %3
br label %94
20: ; preds = %14, %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %6
%25 = load i32*, i32** %6
%26 = icmp ne i32* %25, null
br i1 %26, label %30, label %27
27: ; preds = %20
%28 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
store i32 %29, i32* %3
br label %94
30: ; preds = %20
%31 = load i32*, i32** %6
%32 = load i32, i32* @SEEK_END
%33 = call i32 @fseek(i32* %31, i32 0, i32 %32)
%34 = load i32*, i32** %6
%35 = call i64 @ftell(i32* %34)
store i64 %35, i64* %7
%36 = load i32*, i32** %6
%37 = load i32, i32* @SEEK_SET
%38 = call i32 @fseek(i32* %36, i32 0, i32 %37)
%39 = load i64, i64* %7
%40 = call i8* @malloc(i64 %39)
store i8* %40, i8** %9
%41 = load i8*, i8** %9
%42 = load i64, i64* %7
%43 = load i32*, i32** %6
%44 = call i32 @fread(i8* %41, i64 %42, i32 1, i32* %43)
%45 = load i32*, i32** %6
%46 = call i32 @fclose(i32* %45)
%47 = load i32, i32* %4
%48 = icmp eq i32 %47, 3
br i1 %48, label %49, label %60
49: ; preds = %30
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 2
%52 = load i8*, i8** %51
%53 = call i64 @strtol(i8* %52, i32* null, i32 16)
store i64 %53, i64* %8
%54 = load i64, i64* %8
%55 = load i64, i64* %7
%56 = sub nsw i64 %55, %54
store i64 %56, i64* %7
%57 = load i64, i64* %8
%58 = load i8*, i8** %9
%59 = getelementptr inbounds i8, i8* %58, i64 %57
store i8* %59, i8** %9
br label %60
60: ; preds = %49, %30
store i32 0, i32* %11
%61 = load i32, i32* %11
%62 = sext i32 %61 to i64
%63 = load i64, i64* %8
%64 = add nsw i64 %62, %63
%65 = trunc i64 %64 to i32
%66 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %65)
br label %67
67: ; preds = %72, %60
%68 = load i64, i64* %7
%69 = load i8*, i8** %9
%70 = call i32 @disassemble_instruction(i64 %68, i8* %69)
store i32 %70, i32* %10
%71 = icmp sgt i32 %70, 0
br i1 %71, label %72, label %90
72: ; preds = %67
%73 = load i32, i32* %10
%74 = sext i32 %73 to i64
%75 = load i64, i64* %7
%76 = sub nsw i64 %75, %74
store i64 %76, i64* %7
%77 = load i32, i32* %10
%78 = load i8*, i8** %9
%79 = sext i32 %77 to i64
%80 = getelementptr inbounds i8, i8* %78, i64 %79
store i8* %80, i8** %9
%81 = load i32, i32* %10
%82 = load i32, i32* %11
%83 = add nsw i32 %82, %81
store i32 %83, i32* %11
%84 = load i32, i32* %11
%85 = sext i32 %84 to i64
%86 = load i64, i64* %8
%87 = add nsw i64 %85, %86
%88 = trunc i64 %87 to i32
%89 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %88)
br label %67
90: ; preds = %67
%91 = load i32, i32* %11
%92 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %91)
%93 = load i32, i32* @EXIT_SUCCESS
store i32 %93, i32* %3
br label %94
94: ; preds = %90, %27, %17
%95 = load i32, i32* %3
ret i32 %95
}

LLVM IR (-O2):
@.str = [40 x i8] c"usage: disassemble <file.bin> [$offset]\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [14 x i8] c"file not file\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.3 = [9 x i8] c"0x%.4x: \00"
@.str.4 = [23 x i8] c"disassembled %d bytes\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = and i32 %0, -2
%4 = icmp eq i32 %3, 2
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %54
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %54
14: ; preds = %7
%15 = load i32, i32* @SEEK_END
%16 = tail call i32 @fseek(i32* %10, i32 0, i32 %15)
%17 = tail call i64 @ftell(i32* %10)
%18 = load i32, i32* @SEEK_SET
%19 = tail call i32 @fseek(i32* %10, i32 0, i32 %18)
%20 = tail call i8* @malloc(i64 %17)
%21 = tail call i32 @fread(i8* %20, i64 %17, i32 1, i32* %10)
%22 = tail call i32 @fclose(i32* %10)
%23 = icmp eq i32 %0, 3
br i1 %23, label %24, label %31
24: ; preds = %14
%25 = getelementptr inbounds i8*, i8** %1, i64 2
%26 = load i8*, i8** %25
%27 = tail call i64 @strtol(i8* nocapture %26, i32* null, i32 16)
%28 = sub nsw i64 %17, %27
%29 = getelementptr inbounds i8, i8* %20, i64 %27
%30 = trunc i64 %27 to i32
br label %31
31: ; preds = %24, %14
%32 = phi i64 [ %28, %24 ], [ %17, %14 ]
%33 = phi i32 [ %30, %24 ], [ undef, %14 ]
%34 = phi i8* [ %29, %24 ], [ %20, %14 ]
%35 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %33)
%36 = tail call i32 @disassemble_instruction(i64 %32, i8* %34)
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %51
38: ; preds = %31, %38
%39 = phi i32 [ %49, %38 ], [ %36, %31 ]
%40 = phi i32 [ %46, %38 ], [ 0, %31 ]
%41 = phi i8* [ %45, %38 ], [ %34, %31 ]
%42 = phi i64 [ %44, %38 ], [ %32, %31 ]
%43 = zext i32 %39 to i64
%44 = sub nsw i64 %42, %43
%45 = getelementptr inbounds i8, i8* %41, i64 %43
%46 = add nsw i32 %39, %40
%47 = add i32 %46, %33
%48 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %47)
%49 = tail call i32 @disassemble_instruction(i64 %44, i8* %45)
%50 = icmp sgt i32 %49, 0
br i1 %50, label %38, label %51
51: ; preds = %38, %31
%52 = phi i32 [ 0, %31 ], [ %46, %38 ]
%53 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %52)
br label %54
54: ; preds = %51, %12, %5
%55 = phi i32* [ @EXIT_FAILURE, %5 ], [ @EXIT_SUCCESS, %51 ], [ @EXIT_FAILURE, %12 ]
%56 = load i32, i32* %55
ret i32 %56
}