#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 uint8_t;
typedef scalar_t__ ssize_t;
typedef int /*<<< orphan*/ byte;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(int, int *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  uint8_t byte;
  int inputfd;
  ssize_t len;
  int n;
  int byte_nl = 4;
  if (2 != argc) {
    fprintf(stderr, "usage: %s <bin file> > <out file>\n", argv[0]);
    return 1;
  }
  inputfd = open(argv[1], O_RDONLY);
  if (inputfd < 0) {
    perror("open");
    return 1;
  }
  n = 1;
  while (1) {
    len = read(inputfd, &byte, sizeof(byte));
    if (len < 0) {
      perror("read");
      return 1;
    } else if (0 == len) {
      break;
    }
    printf("%02X", byte);
    if (0 == n % byte_nl) {
      printf("\n");
    }
    n++;
  }
  close(inputfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x4,-0x28(%rbp)
mov    $0x2,%eax
cmp    -0x8(%rbp),%eax
je     11b3 <main+0x53>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe5e(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1290 <main+0x130>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11ee <main+0x8e>
lea    0xe46(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1290 <main+0x130>
movl   $0x1,-0x24(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    122d <main+0xcd>
lea    0xe0c(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1290 <main+0x130>
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    123e <main+0xde>
jmp    1281 <main+0x121>
jmp    1243 <main+0xe3>
mov    -0x14(%rbp),%esi
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
cltd
idivl  -0x28(%rbp)
xor    %eax,%eax
cmp    %edx,%eax
jne    1273 <main+0x113>
lea    0xdb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11f5 <main+0x95>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    120c <main+0x9c>
mov    0x8(%rsi),%rdi
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
test   %eax,%eax
js     1248 <main+0xd8>
mov    %eax,%ebx
lea    0x4(%rsp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1060 <read@plt>
test   %rax,%rax
js     123f <main+0xcf>
mov    $0x1,%ebp
lea    0xe6b(%rip),%r14
lea    0x4(%rsp),%r15
jmp    11e7 <main+0x77>
nopl   0x0(%rax)
add    $0x1,%ebp
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x4,%edx
call   1060 <read@plt>
test   %rax,%rax
js     123f <main+0xcf>
test   %rax,%rax
je     122b <main+0xbb>
mov    0x4(%rsp),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   $0x3,%bpl
jne    11d0 <main+0x60>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11d0 <main+0x60>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xde1(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%eax
jmp    1234 <main+0xc4>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xde2(%rip),%rdi
jmp    124f <main+0xdf>
lea    0xdd4(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%eax
jmp    1234 <main+0xc4>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"usage: %s <bin file> > <out file>\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [5 x i8] c"read\00"
@.str.3 = [5 x i8] c"%02X\00"
@.str.4 = [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 i64
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 4, i32* %10
%11 = load i32, i32* %4
%12 = icmp ne i32 2, %11
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 1, i32* %3
br label %57
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* %22, i32 %23)
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %19
%28 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %57
29: ; preds = %19
store i32 1, i32* %9
br label %30
30: ; preds = %29, %51
%31 = load i32, i32* %7
%32 = call i64 @read(i32 %31, i32* %6, i32 4)
store i64 %32, i64* %8
%33 = load i64, i64* %8
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %57
37: ; preds = %30
%38 = load i64, i64* %8
%39 = icmp eq i64 0, %38
br i1 %39, label %40, label %41
40: ; preds = %37
br label %54
41: ; preds = %37
br label %42
42: ; preds = %41
%43 = load i32, i32* %6
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %43)
%45 = load i32, i32* %9
%46 = load i32, i32* %10
%47 = srem i32 %45, %46
%48 = icmp eq i32 0, %47
br i1 %48, label %49, label %51
49: ; preds = %42
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %51
51: ; preds = %49, %42
%52 = load i32, i32* %9
%53 = add nsw i32 %52, 1
store i32 %53, i32* %9
br label %30
54: ; preds = %40
%55 = load i32, i32* %7
%56 = call i32 @close(i32 %55)
store i32 0, i32* %3
br label %57
57: ; preds = %54, %35, %27, %13
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"usage: %s <bin file> > <out file>\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [5 x i8] c"read\00"
@.str.3 = [5 x i8] c"%02X\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %40
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 @open(i8* %12, i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %10
%17 = call i64 @read(i32 %14, i32* %3, i32 4)
%18 = icmp slt i64 %17, 0
br i1 %18, label %21, label %23
19: ; preds = %10
%20 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %40
21: ; preds = %34, %16
%22 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %40
23: ; preds = %16, %34
%24 = phi i64 [ %36, %34 ], [ %17, %16 ]
%25 = phi i32 [ %35, %34 ], [ 1, %16 ]
%26 = icmp eq i64 %24, 0
br i1 %26, label %38, label %27
27: ; preds = %23
%28 = load i32, i32* %3
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %28)
%30 = and i32 %25, 3
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = tail call i32 @putchar(i32 10)
br label %34
34: ; preds = %32, %27
%35 = add nuw nsw i32 %25, 1
%36 = call i64 @read(i32 %14, i32* %3, i32 4)
%37 = icmp slt i64 %36, 0
br i1 %37, label %21, label %23
38: ; preds = %23
%39 = tail call i32 @close(i32 %14)
br label %40
40: ; preds = %38, %21, %19, %6
%41 = phi i32 [ 1, %6 ], [ 1, %19 ], [ 1, %21 ], [ 0, %38 ]
ret i32 %41
}