#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(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int pread(int, unsigned char *, int, unsigned long);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
unsigned long str_to_ul(char *);
int main(int argc, char **argv) {
  int i, n, fd;
  unsigned long offset, len;
  char fn[64];
  unsigned char buf[16];
  if (argc < 4) {
    fprintf(stderr, "Usage: %s (dev #) (offset) (length)\n", argv[0]);
    return 1;
  }
  n = atoi(argv[1]);
  offset = str_to_ul(argv[2]);
  len = str_to_ul(argv[3]);
  sprintf(fn, "/dev/mcd%d", n);
  fd = open(fn, O_RDONLY);
  if (fd == -1) {
    perror("open");
    return 1;
  }
  printf("Dump Offset : %016lx, Dump Length: %016lx\n", offset, len);
  printf("(Address)-------  "
         "+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +a +b +c +d +e +f\n");
  while (len > 0) {
    printf("%016lx: ", offset);
    if ((n = pread(fd, buf, len > 16 ? 16 : len, offset)) <= 0) {
      perror("read");
      break;
    }
    for (i = 0; i < n; i++) {
      printf("%02x ", buf[i]);
    }
    printf("\n");
    len -= n;
    offset += n;
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    11db <main+0x4b>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe36(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1384 <main+0x1f4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <str_to_ul@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1030 <str_to_ul@plt>
mov    %rax,-0x30(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xe0a(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x70(%rbp),%rdi
mov    0x2dbd(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1257 <main+0xc7>
lea    0xdea(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1384 <main+0x1f4>
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x30(%rbp)
jbe    1375 <main+0x1e5>
mov    -0x28(%rbp),%rsi
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x8c(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0x88(%rbp)
cmpq   $0x10,-0x30(%rbp)
jbe    12c8 <main+0x138>
mov    $0x10,%eax
mov    %rax,-0x98(%rbp)
jmp    12d3 <main+0x143>
mov    -0x30(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0x88(%rbp),%rsi
mov    -0x8c(%rbp),%edi
mov    -0x98(%rbp),%rax
mov    %eax,%edx
mov    -0x28(%rbp),%rcx
call   10a0 <pread@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jg     130f <main+0x17f>
lea    0xda7(%rip),%rdi
call   1080 <perror@plt>
jmp    1375 <main+0x1e5>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1347 <main+0x1b7>
movslq -0x14(%rbp),%rax
movzbl -0x80(%rbp,%rax,1),%esi
lea    0xd7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1316 <main+0x186>
lea    0xcd5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movslq -0x18(%rbp),%rcx
mov    -0x30(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
movslq -0x18(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    127b <main+0xeb>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jg     11e8 <main+0x38>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe27(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%eax
jmp    12e8 <main+0x138>
mov    0x8(%rbx),%rdi
call   10b0 <atoi@plt>
mov    %eax,%ebp
mov    0x10(%rbx),%rdi
call   1040 <str_to_ul@plt>
mov    %rax,%r14
mov    0x18(%rbx),%rdi
call   1040 <str_to_ul@plt>
mov    %rax,%rbx
lea    0xe13(%rip),%rsi
lea    0x20(%rsp),%r15
mov    %r15,%rdi
mov    %ebp,%edx
call   10d0 <sprintf@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   1090 <open@plt>
mov    %eax,0xc(%rsp)
cmp    $0xffffffff,%eax
je     12f7 <main+0x147>
lea    0xdef(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe1a(%rip),%rdi
call   1050 <puts@plt>
test   %rbx,%rbx
je     12dd <main+0x12d>
lea    0xdff(%rip),%r15
nop
lea    0xde9(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    $0x10,%rbx
mov    $0x10,%edx
cmovb  %ebx,%edx
mov    0xc(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    %r14,%rcx
call   10c0 <pread@plt>
test   %eax,%eax
jle    130a <main+0x15a>
mov    %eax,%r12d
mov    %eax,%r13d
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movzbl 0x10(%rsp,%rbp,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
jne    12b0 <main+0x100>
mov    $0xa,%edi
call   1030 <putchar@plt>
movslq %r12d,%rax
add    %rax,%r14
sub    %rax,%rbx
jne    1270 <main+0xc0>
mov    0xc(%rsp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd32(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%eax
jmp    12e8 <main+0x138>
lea    0xd58(%rip),%rdi
call   10a0 <perror@plt>
jmp    12dd <main+0x12d>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [37 x i8] c"Usage: %s (dev #) (offset) (length)\0A\00"
@.str.1 = [11 x i8] c"/dev/mcd%d\00"
@O_RDONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [43 x i8] c"Dump Offset : %016lx, Dump Length: %016lx\0A\00"
@.str.4 = [67 x i8] c"(Address)------- +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +a +b +c +d +e +f\0A\00"
@.str.5 = [9 x i8] c"%016lx: \00"
@.str.6 = [5 x i8] c"read\00"
@.str.7 = [6 x i8] c"%02x \00"
@.str.8 = [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 i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i64
%11 = alloca [64 x i8]
%12 = alloca [16 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 4
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %19)
store i32 1, i32* %3
br label %98
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %7
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i64 @str_to_ul(i8* %28)
store i64 %29, i64* %9
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 3
%32 = load i8*, i8** %31
%33 = call i64 @str_to_ul(i8* %32)
store i64 %33, i64* %10
%34 = getelementptr inbounds [64 x i8], [64 x i8]* %11, i64 0, i64 0
%35 = load i32, i32* %7
%36 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %35)
%37 = getelementptr inbounds [64 x i8], [64 x i8]* %11, i64 0, i64 0
%38 = load i32, i32* @O_RDONLY
%39 = call i32 @open(i8* %37, i32 %38)
store i32 %39, i32* %8
%40 = load i32, i32* %8
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %44
42: ; preds = %21
%43 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %98
44: ; preds = %21
%45 = load i64, i64* %9
%46 = load i64, i64* %10
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i64 %45, i64 %46)
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.4, i64 0, i64 0))
br label %49
49: ; preds = %85, %44
%50 = load i64, i64* %10
%51 = icmp ugt i64 %50, 0
br i1 %51, label %52, label %95
52: ; preds = %49
%53 = load i64, i64* %9
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i64 %53)
%55 = load i32, i32* %8
%56 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%57 = load i64, i64* %10
%58 = icmp ugt i64 %57, 16
br i1 %58, label %59, label %60
59: ; preds = %52
br label %62
60: ; preds = %52
%61 = load i64, i64* %10
br label %62
62: ; preds = %60, %59
%63 = phi i64 [ 16, %59 ], [ %61, %60 ]
%64 = trunc i64 %63 to i32
%65 = load i64, i64* %9
%66 = call i32 @pread(i32 %55, i8* %56, i32 %64, i64 %65)
store i32 %66, i32* %7
%67 = icmp sle i32 %66, 0
br i1 %67, label %68, label %70
68: ; preds = %62
%69 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %95
70: ; preds = %62
store i32 0, i32* %6
br label %71
71: ; preds = %82, %70
%72 = load i32, i32* %6
%73 = load i32, i32* %7
%74 = icmp slt i32 %72, %73
br i1 %74, label %75, label %85
75: ; preds = %71
%76 = load i32, i32* %6
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 %77
%79 = load i8, i8* %78
%80 = zext i8 %79 to i32
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 %80)
br label %82
82: ; preds = %75
%83 = load i32, i32* %6
%84 = add nsw i32 %83, 1
store i32 %84, i32* %6
br label %71
85: ; preds = %71
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%87 = load i32, i32* %7
%88 = sext i32 %87 to i64
%89 = load i64, i64* %10
%90 = sub i64 %89, %88
store i64 %90, i64* %10
%91 = load i32, i32* %7
%92 = sext i32 %91 to i64
%93 = load i64, i64* %9
%94 = add i64 %93, %92
store i64 %94, i64* %9
br label %49
95: ; preds = %68, %49
%96 = load i32, i32* %8
%97 = call i32 @close(i32 %96)
store i32 0, i32* %3
br label %98
98: ; preds = %95, %42, %15
%99 = load i32, i32* %3
ret i32 %99
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [37 x i8] c"Usage: %s (dev #) (offset) (length)\0A\00"
@.str.1 = [11 x i8] c"/dev/mcd%d\00"
@O_RDONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [43 x i8] c"Dump Offset : %016lx, Dump Length: %016lx\0A\00"
@.str.5 = [9 x i8] c"%016lx: \00"
@.str.6 = [5 x i8] c"read\00"
@.str.7 = [6 x i8] c"%02x \00"
@str = [66 x i8] c"(Address)------- +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +a +b +c +d +e +f\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [64 x i8]
%4 = alloca [16 x i8]
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%7 = icmp slt i32 %0, 4
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %61
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i64 @str_to_ul(i8* %17)
%19 = getelementptr inbounds i8*, i8** %1, i64 3
%20 = load i8*, i8** %19
%21 = tail call i64 @str_to_ul(i8* %20)
%22 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* %5, i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %12
%27 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %61
28: ; preds = %12
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i64 %18, i64 %21)
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @str, i64 0, i64 0))
%31 = icmp eq i64 %21, 0
br i1 %31, label %59, label %32
32: ; preds = %28, %53
%33 = phi i64 [ %56, %53 ], [ %21, %28 ]
%34 = phi i64 [ %57, %53 ], [ %18, %28 ]
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i64 %34)
%36 = icmp ult i64 %33, 16
%37 = select i1 %36, i64 %33, i64 16
%38 = trunc i64 %37 to i32
%39 = call i32 @pread(i32 %24, i8* %6, i32 %38, i64 %34)
%40 = icmp slt i32 %39, 1
br i1 %40, label %43, label %41
41: ; preds = %32
%42 = zext i32 %39 to i64
br label %45
43: ; preds = %32
%44 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %59
45: ; preds = %41, %45
%46 = phi i64 [ 0, %41 ], [ %51, %45 ]
%47 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32 %49)
%51 = add nuw nsw i64 %46, 1
%52 = icmp eq i64 %51, %42
br i1 %52, label %53, label %45
53: ; preds = %45
%54 = tail call i32 @putchar(i32 10)
%55 = sext i32 %39 to i64
%56 = sub i64 %33, %55
%57 = add i64 %34, %55
%58 = icmp eq i64 %56, 0
br i1 %58, label %59, label %32
59: ; preds = %53, %28, %43
%60 = tail call i32 @close(i32 %24)
br label %61
61: ; preds = %59, %26, %8
%62 = phi i32 [ 1, %8 ], [ 1, %26 ], [ 0, %59 ]
ret i32 %62
}