#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*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
size_t read(int, unsigned char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  unsigned char buffer[20];
  size_t offset = 0;
  size_t bytes_read;
  int i, fd;
  if (argc == 1) {
    fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if ((fd = open(argv[1], O_RDONLY)) == -1) {
    fprintf(stderr, "Err. open: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  do {
    bytes_read = read(fd, buffer, sizeof(buffer));
    printf("%#06x : ", offset);
    for (i = 0; i < bytes_read; ++i)
      printf("%02x ", buffer[i]);
    printf("\n");
    offset += bytes_read;
  } while (bytes_read == sizeof(buffer));
  close(fd);
  return (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)
movq   $0x0,-0x38(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11c2 <main+0x52>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe51(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x48(%rbp)
cmp    $0xffffffff,%eax
jne    121e <main+0xae>
mov    0x2ded(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    %rax,%rdx
lea    0xe0b(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    1223 <main+0xb3>
mov    -0x48(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x14,%edx
call   1050 <read@plt>
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rsi
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x44(%rbp)
movslq -0x44(%rbp),%rax
cmp    -0x40(%rbp),%rax
jae    1284 <main+0x114>
movslq -0x44(%rbp),%rax
movzbl -0x30(%rbp,%rax,1),%esi
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1251 <main+0xe1>
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x40(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x14,-0x40(%rbp)
je     1223 <main+0xb3>
mov    -0x48(%rbp),%edi
call   1040 <close@plt>
mov    0x2d08(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x1,%edi
je     1257 <main+0xd7>
mov    0x8(%rsi),%rdi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     126c <main+0xec>
mov    %eax,%r12d
lea    0xe69(%rip),%r15
lea    0xe6b(%rip),%rbx
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
mov    %r12d,%edi
mov    %rsp,%rsi
mov    $0x14,%edx
call   1060 <read@plt>
mov    %rax,%rbp
mov    %r15,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
test   %rbp,%rbp
je     122d <main+0xad>
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
movzbl (%rsp,%r14,1),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r14
cmp    %r14,%rbp
jne    1200 <main+0x80>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    %rbp,%r13
cmp    $0x14,%rbp
je     11d0 <main+0x50>
jmp    1237 <main+0xb7>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r12d,%edi
call   1050 <close@plt>
mov    0x2d7a(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xd96(%rip),%rsi
jmp    128f <main+0x10f>
mov    0x2d65(%rip),%rax
mov    (%rax),%ebx
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd8c(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

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

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