#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*/ SEEK_END;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
scalar_t__ hex_dump(int /*<<< orphan*/ *, int /*<<< orphan*/, size_t, int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ show_usage(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  FILE *fp;
  size_t file_size;
  if (argc != 2) {
    show_usage(stdout, argv[0]);
    return 1;
  }
  fp = fopen(argv[1], "rb");
  if (fp == NULL) {
    fprintf(stderr, "%s: %s: No such file or directory\n", argv[0], argv[1]);
    return 2;
  }
  fseek(fp, 0, SEEK_END);
  file_size = ftell(fp);
  rewind(fp);
  if (hex_dump(fp, stdout, file_size, 8) != 0) {
    fprintf(stderr, "%s: No enough memory for execution\n", argv[0]);
    return 3;
  }
  fclose(fp);
  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)
je     11c1 <main+0x41>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1080 <show_usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    129f <main+0x11f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe30(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1216 <main+0x96>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xe00(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    129f <main+0x11f>
mov    -0x18(%rbp),%rdi
mov    0x2dc7(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <rewind@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d85(%rip),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%rdx
mov    $0x8,%ecx
call   10a0 <hex_dump@plt>
cmp    $0x0,%rax
je     128f <main+0x10f>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdaa(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x3,-0x4(%rbp)
jmp    129f <main+0x11f>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x2,%edi
jne    1216 <main+0x96>
mov    0x8(%r14),%rdi
lea    0xe62(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     122e <main+0xae>
mov    %rax,%rbx
mov    0x2e32(%rip),%rax
mov    (%rax),%edx
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1040 <rewind@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    $0x8,%ecx
call   10a0 <hex_dump@plt>
test   %rax,%rax
je     1253 <main+0xd3>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe1e(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x3,%ebp
jmp    125b <main+0xdb>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rsi
call   1080 <show_usage@plt>
mov    $0x1,%ebp
jmp    125b <main+0xdb>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
mov    0x8(%r14),%rcx
lea    0xdbe(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x2,%ebp
jmp    125b <main+0xdb>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"%s: %s: No such file or directory\0A\00"
@SEEK_END = global i32 0
@.str.2 = [36 x i8] c"%s: No enough memory for execution\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i32, i32* @stdout
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @show_usage(i32 %11, i8* %14)
store i32 1, i32* %3
br label %54
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %20, i32** %6
%21 = load i32*, i32** %6
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %32
23: ; preds = %16
%24 = load i32, i32* @stderr
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %27, i8* %30)
store i32 2, i32* %3
br label %54
32: ; preds = %16
%33 = load i32*, i32** %6
%34 = load i32, i32* @SEEK_END
%35 = call i32 @fseek(i32* %33, i32 0, i32 %34)
%36 = load i32*, i32** %6
%37 = call i64 @ftell(i32* %36)
store i64 %37, i64* %7
%38 = load i32*, i32** %6
%39 = call i32 @rewind(i32* %38)
%40 = load i32*, i32** %6
%41 = load i32, i32* @stdout
%42 = load i64, i64* %7
%43 = call i64 @hex_dump(i32* %40, i32 %41, i64 %42, i32 8)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %51
45: ; preds = %32
%46 = load i32, i32* @stderr
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 0
%49 = load i8*, i8** %48
%50 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %49)
store i32 3, i32* %3
br label %54
51: ; preds = %32
%52 = load i32*, i32** %6
%53 = call i32 @fclose(i32* %52)
store i32 0, i32* %3
br label %54
54: ; preds = %51, %45, %23, %10
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"%s: %s: No such file or directory\0A\00"
@SEEK_END = global i32 0
@.str.2 = [36 x i8] c"%s: No enough memory for execution\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stdout
%6 = load i8*, i8** %1
%7 = tail call i32 @show_usage(i32 %5, i8* %6)
br label %32
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %1
%16 = load i8*, i8** %9
%17 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %15, i8* %16)
br label %32
18: ; preds = %8
%19 = load i32, i32* @SEEK_END
%20 = tail call i32 @fseek(i32* %11, i32 0, i32 %19)
%21 = tail call i64 @ftell(i32* %11)
%22 = tail call i32 @rewind(i32* %11)
%23 = load i32, i32* @stdout
%24 = tail call i64 @hex_dump(i32* %11, i32 %23, i64 %21, i32 8)
%25 = icmp eq i64 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %18
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %1
%29 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %28)
br label %32
30: ; preds = %18
%31 = tail call i32 @fclose(i32* %11)
br label %32
32: ; preds = %30, %26, %13, %4
%33 = phi i32 [ 1, %4 ], [ 2, %13 ], [ 3, %26 ], [ 0, %30 ]
ret i32 %33
}