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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ handle_fatal_error_and_exit(char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, unsigned char *, int);
int main(int argc, char *argv[]) {
  int fd;
  char *filename;
  unsigned char buffer[20];
  size_t offset;
  ssize_t bytes_read;
  int i;
  if (argc != 2) {
    printf("Usage: %s <filename>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  filename = argv[1];
  fd = open(filename, O_RDONLY);
  if (fd == -1) {
    handle_fatal_error_and_exit("Error opening a file.\n");
  }
  offset = 0;
  do {
    bytes_read = read(fd, buffer, sizeof(buffer));
    printf("0x%06x : ", (unsigned int)offset);
    for (i = 0; i < bytes_read; ++i) {
      printf("%02x ", buffer[i]);
    }
    printf("\n");
    offset += bytes_read;
  } while (bytes_read == sizeof(buffer));
  close(fd);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a3 <main+0x43>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11da <main+0x7a>
lea    0xe41(%rip),%rdi
call   1060 <handle_fatal_error_and_exit@plt>
movq   $0x0,-0x48(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x14,%edx
call   1050 <read@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x48(%rbp),%rax
mov    %eax,%esi
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%eax
cmp    -0x4c(%rbp),%eax
jge    1242 <main+0xe2>
movslq -0x50(%rbp),%rax
movzbl -0x40(%rbp,%rax,1),%esi
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    1211 <main+0xb1>
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x4c(%rbp),%rax
add    -0x48(%rbp),%rax
mov    %rax,-0x48(%rbp)
movslq -0x4c(%rbp),%rax
cmp    $0x14,%rax
je     11e2 <main+0x82>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    121c <main+0xac>
mov    0x8(%rsi),%rdi
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,%r12d
cmp    $0xffffffff,%eax
jne    11ad <main+0x3d>
lea    0xe6e(%rip),%rdi
call   1070 <handle_fatal_error_and_exit@plt>
lea    0xe83(%rip),%rbx
xor    %r13d,%r13d
nopw   0x0(%rax,%rax,1)
mov    %r12d,%edi
mov    %rsp,%rsi
mov    $0x14,%edx
call   1060 <read@plt>
mov    %eax,%ebp
lea    0xe54(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
jle    123b <main+0xcb>
mov    %ebp,%r14d
xor    %r15d,%r15d
nopl   (%rax)
movzbl (%rsp,%r15,1),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r15
cmp    %r15,%r14
jne    11f0 <main+0x80>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    %r14,%r13
cmp    $0x14,%ebp
je     11c0 <main+0x50>
jmp    1245 <main+0xd5>
mov    (%rsi),%rsi
lea    0xdda(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r12d,%edi
call   1050 <close@plt>
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"Usage: %s <filename>\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [23 x i8] c"Error opening a file.\0A\00"
@.str.2 = [10 x i8] c"0x%06x : \00"
@.str.3 = [6 x i8] c"%02x \00"
@.str.4 = [2 x i8] c"\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 i8*
%8 = alloca [20 x i8]
%9 = alloca i64
%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 %21
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %7
%25 = load i8*, i8** %7
%26 = load i32, i32* @O_RDONLY
%27 = call i32 @open(i8* %25, i32 %26)
store i32 %27, i32* %6
%28 = load i32, i32* %6
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %21
%31 = call i32 @handle_fatal_error_and_exit(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %30, %21
store i64 0, i64* %9
br label %33
33: ; preds = %60, %32
%34 = load i32, i32* %6
%35 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%36 = call i32 @read(i32 %34, i8* %35, i32 20)
store i32 %36, i32* %10
%37 = load i64, i64* %9
%38 = trunc i64 %37 to i32
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %38)
store i32 0, i32* %11
br label %40
40: ; preds = %51, %33
%41 = load i32, i32* %11
%42 = load i32, i32* %10
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %54
44: ; preds = %40
%45 = load i32, i32* %11
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %44
%52 = load i32, i32* %11
%53 = add nsw i32 %52, 1
store i32 %53, i32* %11
br label %40
54: ; preds = %40
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%56 = load i32, i32* %10
%57 = sext i32 %56 to i64
%58 = load i64, i64* %9
%59 = add i64 %58, %57
store i64 %59, i64* %9
br label %60
60: ; preds = %54
%61 = load i32, i32* %10
%62 = sext i32 %61 to i64
%63 = icmp eq i64 %62, 20
br i1 %63, label %33, label %64
64: ; preds = %60
%65 = load i32, i32* %6
%66 = call i32 @close(i32 %65)
%67 = load i32, i32* @EXIT_SUCCESS
%68 = call i32 @exit(i32 %67)
unreachable
}

LLVM IR (-O2):
@.str = [22 x i8] c"Usage: %s <filename>\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [23 x i8] c"Error opening a file.\0A\00"
@.str.2 = [10 x i8] c"0x%06x : \00"
@.str.3 = [6 x i8] c"%02x \00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [20 x i8]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = load i32, i32* @O_RDONLY
%15 = tail call i32 @open(i8* %13, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = tail call i32 @handle_fatal_error_and_exit(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %11
br label %20
20: ; preds = %19, %38
%21 = phi i64 [ %41, %38 ], [ 0, %19 ]
%22 = call i32 @read(i32 %15, i8* %4, i32 20)
%23 = trunc i64 %21 to i32
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = icmp sgt i32 %22, 0
br i1 %25, label %28, label %26
26: ; preds = %20
%27 = tail call i32 @putchar(i32 10)
br label %43
28: ; preds = %20
%29 = zext i32 %22 to i64
br label %30
30: ; preds = %28, %30
%31 = phi i64 [ 0, %28 ], [ %36, %30 ]
%32 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %34)
%36 = add nuw nsw i64 %31, 1
%37 = icmp eq i64 %36, %29
br i1 %37, label %38, label %30
38: ; preds = %30
%39 = tail call i32 @putchar(i32 10)
%40 = zext i32 %22 to i64
%41 = add i64 %21, %40
%42 = icmp eq i32 %22, 20
br i1 %42, label %20, label %43
43: ; preds = %38, %26
%44 = tail call i32 @close(i32 %15)
%45 = load i32, i32* @EXIT_SUCCESS
%46 = tail call i32 @exit(i32 %45)
unreachable
}