#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 scalar_t__ int64_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ dump(int /*<<< orphan*/ *, scalar_t__, size_t);
int /*<<< orphan*/ dump_file_header(int /*<<< orphan*/ *);
size_t dump_header(int /*<<< orphan*/ *, scalar_t__);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strtoll(char const *, char **, int /*<<< orphan*/);
int /*<<< orphan*/ usage();
int main(int argc, const char *argv[]) {
  if (argc < 2 || argc > 3) {
    usage();
  }
  FILE *fp = fopen(argv[1], "rb");
  if (!fp) {
    printf("File '%s' not found\n", argv[1]);
    exit(1);
  }
  printf("File: '%s'\n", argv[1]);
  int64_t ref = 0;
  if (argc == 3) {
    char *end;
    ref = strtoll(argv[2], &end, 0);
    if (*end != '\0') {
      printf("'%s' is not a number\n", argv[2]);
      exit(1);
    }
  }
  if (ref) {
    size_t sz = dump_header(fp, ref);
    dump(fp, ref + 8, sz);
  } else {
    dump_file_header(fp);
  }
  printf("\n");
  fclose(fp);
  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)
cmpl   $0x2,-0x8(%rbp)
jl     11ba <main+0x2a>
cmpl   $0x3,-0x8(%rbp)
jle    11c1 <main+0x31>
mov    $0x0,%al
call   1090 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe30(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1204 <main+0x74>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movq   $0x0,-0x20(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    1278 <main+0xe8>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1080 <strtoll@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1273 <main+0xe3>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    1278 <main+0xe8>
cmpq   $0x0,-0x20(%rbp)
je     12ae <main+0x11e>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <dump_header@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x8,%rsi
mov    -0x30(%rbp),%rdx
call   1070 <dump@plt>
jmp    12b7 <main+0x127>
mov    -0x18(%rbp),%rdi
call   1060 <dump_file_header@plt>
lea    0xd64(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
lea    -0x4(%rbx),%eax
cmp    $0xfffffffd,%eax
ja     11bd <main+0x1d>
xor    %eax,%eax
call   10a0 <usage@plt>
mov    0x8(%r14),%rdi
lea    0xe38(%rip),%rsi
call   10b0 <fopen@plt>
mov    0x8(%r14),%rsi
test   %rax,%rax
je     1253 <main+0xb3>
mov    %rax,%r15
lea    0xe38(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    $0x3,%ebx
jne    122d <main+0x8d>
mov    0x10(%r14),%rdi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1090 <strtoll@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
jne    125c <main+0xbc>
test   %rbx,%rbx
je     122d <main+0x8d>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <dump_header@plt>
add    $0x8,%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1080 <dump@plt>
jmp    1235 <main+0x95>
mov    %r15,%rdi
call   1070 <dump_file_header@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xda9(%rip),%rdi
jmp    1267 <main+0xc7>
mov    0x10(%r14),%rsi
lea    0xdbd(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [21 x i8] c"File '%s' not found\0A\00"
@.str.2 = [12 x i8] c"File: '%s'\0A\00"
@.str.3 = [22 x i8] c"'%s' is not a number\0A\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 i64
%8 = alloca i8*
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 3
br i1 %14, label %15, label %17
15: ; preds = %12, %2
%16 = call i32 (...) @usage()
br label %17
17: ; preds = %15, %12
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %21, i32** %6
%22 = load i32*, i32** %6
%23 = icmp ne i32* %22, null
br i1 %23, label %30, label %24
24: ; preds = %17
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %17
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %33)
store i64 0, i64* %7
%35 = load i32, i32* %4
%36 = icmp eq i32 %35, 3
br i1 %36, label %37, label %53
37: ; preds = %30
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i64 @strtoll(i8* %40, i8** %8, i32 0)
store i64 %41, i64* %7
%42 = load i8*, i8** %8
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %52
46: ; preds = %37
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 2
%49 = load i8*, i8** %48
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %49)
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %37
br label %53
53: ; preds = %52, %30
%54 = load i64, i64* %7
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %65
56: ; preds = %53
%57 = load i32*, i32** %6
%58 = load i64, i64* %7
%59 = call i64 @dump_header(i32* %57, i64 %58)
store i64 %59, i64* %9
%60 = load i32*, i32** %6
%61 = load i64, i64* %7
%62 = add nsw i64 %61, 8
%63 = load i64, i64* %9
%64 = call i32 @dump(i32* %60, i64 %62, i64 %63)
br label %68
65: ; preds = %53
%66 = load i32*, i32** %6
%67 = call i32 @dump_file_header(i32* %66)
br label %68
68: ; preds = %65, %56
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%70 = load i32*, i32** %6
%71 = call i32 @fclose(i32* %70)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [21 x i8] c"File '%s' not found\0A\00"
@.str.2 = [12 x i8] c"File: '%s'\0A\00"
@.str.3 = [22 x i8] c"'%s' is not a number\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = add i32 %0, -4
%5 = icmp ult i32 %4, -2
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 (...) @usage()
br label %8
8: ; preds = %2, %6
%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
%13 = load i8*, i8** %9
br i1 %12, label %14, label %17
14: ; preds = %8
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %8
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%19 = icmp eq i32 %0, 3
br i1 %19, label %20, label %38
20: ; preds = %17
%21 = bitcast i8** %3 to i8*
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = call i64 @strtoll(i8* %23, i8** %3, i32 0)
%25 = load i8*, i8** %3
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %20
%29 = load i8*, i8** %22
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %29)
%31 = tail call i32 @exit(i32 1)
unreachable
32: ; preds = %20
%33 = icmp eq i64 %24, 0
br i1 %33, label %38, label %34
34: ; preds = %32
%35 = tail call i64 @dump_header(i32* %11, i64 %24)
%36 = add nsw i64 %24, 8
%37 = tail call i32 @dump(i32* %11, i64 %36, i64 %35)
br label %40
38: ; preds = %17, %32
%39 = tail call i32 @dump_file_header(i32* %11)
br label %40
40: ; preds = %38, %34
%41 = tail call i32 @putchar(i32 10)
%42 = tail call i32 @fclose(i32* %11)
ret i32 0
}