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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int getopt(int, char **, char *);
int /*<<< orphan*/ hexdump(int, int);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ optarg;
scalar_t__ opterr;
int optind;
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  int input_fd;
  int c;
  int bytes = -1;
  opterr = 0;
  while ((c = getopt(argc, argv, "hn:")) != -1) {
    switch (c) {
    case 'n':
      bytes = atoi(optarg);
      break;
    case 'h':
    default:
      usage();
      break;
    }
  }
  if (optind >= argc) {
    usage();
    return -1;
  }
  input_fd = open(argv[optind], O_RDONLY, 0);
  if (input_fd < 0) {
    printf("Error opening %s\n", argv[optind]);
    return -1;
  }
  hexdump(input_fd, bytes);
  close(input_fd);
  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)
movl   $0xffffffff,-0x1c(%rbp)
mov    0x2e34(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe57(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     1206 <main+0x96>
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x68,%eax
je     11f5 <main+0x85>
jmp    11ce <main+0x5e>
mov    -0x20(%rbp),%eax
sub    $0x6e,%eax
jne    11fa <main+0x8a>
jmp    11df <main+0x6f>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   1090 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    1201 <main+0x91>
jmp    11fa <main+0x8a>
mov    $0x0,%al
call   1060 <usage@plt>
jmp    119b <main+0x2b>
mov    0x2dcb(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jl     122b <main+0xbb>
mov    $0x0,%al
call   1060 <usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129e <main+0x12e>
mov    -0x10(%rbp),%rax
mov    0x2da2(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2d9c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1284 <main+0x114>
mov    -0x10(%rbp),%rax
mov    0x2d73(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xd91(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129e <main+0x12e>
mov    -0x14(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1050 <hexdump@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@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   %r12
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e44(%rip),%rax
movq   $0x0,(%rax)
mov    $0xffffffff,%r14d
lea    0xe68(%rip),%r15
mov    0x2e59(%rip),%r12
nop
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1080 <getopt@plt>
cmp    $0xffffffff,%eax
je     11ce <main+0x5e>
cmp    $0x6e,%eax
je     11c0 <main+0x50>
xor    %eax,%eax
call   1060 <usage@plt>
jmp    11a0 <main+0x30>
mov    (%r12),%edi
call   1090 <atoi@plt>
mov    %eax,%r14d
jmp    11a0 <main+0x30>
mov    0x2e03(%rip),%r12
movslq (%r12),%rax
cmp    %ebp,%eax
jge    120d <main+0x9d>
mov    (%rbx,%rax,8),%rdi
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
xor    %r15d,%r15d
xor    %edx,%edx
call   1070 <open@plt>
test   %eax,%eax
js     1216 <main+0xa6>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r14d,%esi
call   1050 <hexdump@plt>
mov    %ebp,%edi
call   1040 <close@plt>
jmp    1230 <main+0xc0>
xor    %eax,%eax
call   1060 <usage@plt>
jmp    122a <main+0xba>
movslq (%r12),%rax
mov    (%rbx,%rax,8),%rsi
lea    0xddf(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@opterr = global i64 0
@.str = [4 x i8] c"hn:\00"
@optarg = global i32 0
@optind = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [18 x i8] c"Error opening %s\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 i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %8
store i64 0, i64* @opterr
br label %9
9: ; preds = %22, %2
%10 = load i32, i32* %4
%11 = load i8**, i8*** %5
%12 = call i32 @getopt(i32 %10, i8** %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %12, i32* %7
%13 = icmp ne i32 %12, -1
br i1 %13, label %14, label %23
14: ; preds = %9
%15 = load i32, i32* %7
switch i32 %15, label %20 [
i32 110, label %16
i32 104, label %19
]
16: ; preds = %14
%17 = load i32, i32* @optarg
%18 = call i32 @atoi(i32 %17)
store i32 %18, i32* %8
br label %22
19: ; preds = %14
br label %20
20: ; preds = %14, %19
%21 = call i32 (...) @usage()
br label %22
22: ; preds = %20, %16
br label %9
23: ; preds = %9
%24 = load i32, i32* @optind
%25 = load i32, i32* %4
%26 = icmp sge i32 %24, %25
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 (...) @usage()
store i32 -1, i32* %3
br label %52
29: ; preds = %23
%30 = load i8**, i8*** %5
%31 = load i32, i32* @optind
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %30, i64 %32
%34 = load i8*, i8** %33
%35 = load i32, i32* @O_RDONLY
%36 = call i32 @open(i8* %34, i32 %35, i32 0)
store i32 %36, i32* %6
%37 = load i32, i32* %6
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %46
39: ; preds = %29
%40 = load i8**, i8*** %5
%41 = load i32, i32* @optind
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
%44 = load i8*, i8** %43
%45 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %44)
store i32 -1, i32* %3
br label %52
46: ; preds = %29
%47 = load i32, i32* %6
%48 = load i32, i32* %8
%49 = call i32 @hexdump(i32 %47, i32 %48)
%50 = load i32, i32* %6
%51 = call i32 @close(i32 %50)
store i32 0, i32* %3
br label %52
52: ; preds = %46, %39, %27
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@opterr = global i64 0
@.str = [4 x i8] c"hn:\00"
@optarg = global i32 0
@optind = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [18 x i8] c"Error opening %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
store i64 0, i64* @opterr
br label %3
3: ; preds = %7, %2
%4 = phi i32 [ %9, %7 ], [ -1, %2 ]
br label %5
5: ; preds = %3, %10
%6 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
switch i32 %6, label %10 [
i32 -1, label %12
i32 110, label %7
]
7: ; preds = %5
%8 = load i32, i32* @optarg
%9 = tail call i32 @atoi(i32 %8)
br label %3
10: ; preds = %5
%11 = tail call i32 (...) @usage()
br label %5
12: ; preds = %5
%13 = load i32, i32* @optind
%14 = icmp slt i32 %13, %0
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = tail call i32 (...) @usage()
br label %33
17: ; preds = %12
%18 = sext i32 %13 to i64
%19 = getelementptr inbounds i8*, i8** %1, i64 %18
%20 = load i8*, i8** %19
%21 = load i32, i32* @O_RDONLY
%22 = tail call i32 @open(i8* %20, i32 %21, i32 0)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %17
%25 = load i32, i32* @optind
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %1, i64 %26
%28 = load i8*, i8** %27
%29 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %28)
br label %33
30: ; preds = %17
%31 = tail call i32 @hexdump(i32 %22, i32 %4)
%32 = tail call i32 @close(i32 %22)
br label %33
33: ; preds = %30, %24, %15
%34 = phi i32 [ -1, %15 ], [ -1, %24 ], [ 0, %30 ]
ret i32 %34
}