#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  FILE *obj;
  int start_addr;
  unsigned char b;
  if (argc < 2) {
    fprintf(stderr, "Include start address on command line.\n");
    exit(1);
  }
  if (argc < 3) {
    fprintf(stderr, "Include file to convert on command line.\n");
    exit(1);
  }
  sscanf(argv[1], "%x", &start_addr);
  if ((obj = fopen(argv[2], "rb"))) {
    printf("%04X:", start_addr);
    while (fread(&b, 1, 1, obj) == 1) {
      printf(" %02X", b);
      if (!(++start_addr & 0x07))
        printf("\n:");
    }
    printf("\n");
    fclose(obj);
  }
  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    11af <main+0x3f>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
cmpl   $0x3,-0x8(%rbp)
jge    11d8 <main+0x68>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe5f(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe6b(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1070 <sscanf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe56(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1291 <main+0x121>
mov    -0x1c(%rbp),%esi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rcx
lea    -0x1d(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    127a <main+0x10a>
movzbl -0x1d(%rbp),%esi
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
and    $0x7,%eax
cmp    $0x0,%eax
jne    1275 <main+0x105>
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1223 <main+0xb3>
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
jle    1284 <main+0x104>
cmp    $0x2,%edi
je     1296 <main+0x116>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xeaa(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1080 <sscanf@plt>
mov    0x10(%rbx),%rdi
lea    0xe98(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1276 <main+0xf6>
mov    %rax,%rbx
mov    0x4(%rsp),%esi
lea    0xe7f(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x3(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    1264 <main+0xe4>
lea    0xe5b(%rip),%r14
lea    0xe5a(%rip),%r15
lea    0x3(%rsp),%r12
jmp    123a <main+0xba>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    1264 <main+0xe4>
movzbl 0x3(%rsp),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x4(%rsp),%eax
add    $0x1,%eax
mov    %eax,0x4(%rsp)
test   $0x7,%al
jne    1220 <main+0xa0>
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1220 <main+0xa0>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
lea    0xd6c(%rip),%rsi
jmp    12a6 <main+0x126>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
lea    0xd82(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [40 x i8] c"Include start address on command line.\0A\00"
@.str.1 = [42 x i8] c"Include file to convert on command line.\0A\00"
@.str.2 = [3 x i8] c"%x\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [6 x i8] c"%04X:\00"
@.str.5 = [6 x i8] c" %02X\00"
@.str.6 = [3 x i8] c"\0A:\00"
@.str.7 = [2 x i8] c"\0A\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 i8
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 %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 3
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %15
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @sscanf(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %7)
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %30, i32** %6
%31 = icmp ne i32* %30, null
br i1 %31, label %32, label %54
32: ; preds = %22
%33 = load i32, i32* %7
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %49, %32
%36 = load i32*, i32** %6
%37 = call i32 @fread(i8* %8, i32 1, i32 1, i32* %36)
%38 = icmp eq i32 %37, 1
br i1 %38, label %39, label %50
39: ; preds = %35
%40 = load i8, i8* %8
%41 = zext i8 %40 to i32
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %41)
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 1
store i32 %44, i32* %7
%45 = and i32 %44, 7
%46 = icmp ne i32 %45, 0
br i1 %46, label %49, label %47
47: ; preds = %39
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %49
49: ; preds = %47, %39
br label %35
50: ; preds = %35
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%52 = load i32*, i32** %6
%53 = call i32 @fclose(i32* %52)
br label %54
54: ; preds = %50, %22
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [40 x i8] c"Include start address on command line.\0A\00"
@.str.1 = [42 x i8] c"Include file to convert on command line.\0A\00"
@.str.2 = [3 x i8] c"%x\00"
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [6 x i8] c"%04X:\00"
@.str.5 = [6 x i8] c" %02X\00"
@.str.6 = [3 x i8] c"\0A:\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i8
%5 = bitcast i32* %3 to i8*
%6 = icmp slt i32 %0, 2
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = icmp eq i32 %0, 2
br i1 %12, label %13, label %17
13: ; preds = %11
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %11
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @sscanf(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %46, label %25
25: ; preds = %17
%26 = load i32, i32* %3
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %26)
%28 = call i32 @fread(i8* %4, i32 1, i32 1, i32* %23)
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %43
30: ; preds = %25, %40
%31 = load i8, i8* %4
%32 = zext i8 %31 to i32
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %32)
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 1
store i32 %35, i32* %3
%36 = and i32 %35, 7
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %30
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %40
40: ; preds = %38, %30
%41 = call i32 @fread(i8* %4, i32 1, i32 1, i32* %23)
%42 = icmp eq i32 %41, 1
br i1 %42, label %30, label %43
43: ; preds = %40, %25
%44 = call i32 @putchar(i32 10)
%45 = call i32 @fclose(i32* %23)
br label %46
46: ; preds = %43, %17
ret i32 0
}