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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ assert(char *);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ displayHexRecord(char *, int, int);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, long);
void hexDump(FILE *f, long cur_addr, long end, int bytes_per_line) {
  int record_length, read_count;
  char *data;
  assert(data = (char *)calloc(sizeof(data[0]), bytes_per_line));
  if (-1 == fseek(f, cur_addr, SEEK_SET))
    perror("fseek");
  while (1) {
    printf("%05x  ", cur_addr);
    read_count = end - cur_addr;
    if (read_count > bytes_per_line)
      read_count = bytes_per_line;
    record_length = fread(data, sizeof(char), read_count, f);
    displayHexRecord(data, record_length, bytes_per_line);
    if (record_length < bytes_per_line)
      break;
    if (end <= (cur_addr += record_length))
      break;
  }
  free(data);
}


x86 assembly (clang, -O0):
<hexDump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
mov    $0x1,%edi
call   1060 <calloc@plt>
mov    %rax,%rdi
mov    %rdi,-0x30(%rbp)
call   1070 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2e21(%rip),%rax
mov    (%rax),%edx
call   1080 <fseek@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11e1 <hexDump+0x61>
lea    0xe24(%rip),%rdi
call   10a0 <perror@plt>
jmp    11e6 <hexDump+0x66>
mov    -0x10(%rbp),%rsi
lea    0xe15(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rax
sub    -0x10(%rbp),%rax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    1213 <hexDump+0x93>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %eax,-0x20(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1090 <displayHexRecord@plt>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    124b <hexDump+0xcb>
jmp    126e <hexDump+0xee>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
add    -0x10(%rbp),%rcx
mov    %rcx,-0x10(%rbp)
cmp    %rcx,%rax
jg     1269 <hexDump+0xe9>
jmp    126e <hexDump+0xee>
jmp    11e6 <hexDump+0x66>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexDump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    $0x1,%edi
mov    %ecx,%esi
call   1060 <calloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1070 <assert@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <fseek@plt>
cmp    $0xffffffff,%eax
je     122e <hexDump+0xae>
cs nopw 0x0(%rax,%rax,1)
lea    0xe2f(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %r14d,%edx
sub    %ebx,%edx
cmp    %ebp,%edx
cmovg  %ebp,%edx
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r15,%rcx
call   1040 <fread@plt>
mov    %eax,%r13d
mov    %r12,%rdi
mov    %eax,%esi
mov    %ebp,%edx
call   1090 <displayHexRecord@plt>
cmp    %ebp,%r13d
jl     1218 <hexDump+0x98>
movslq %r13d,%rax
add    %rax,%rbx
cmp    %r14,%rbx
jl     11d0 <hexDump+0x50>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
lea    0xdcb(%rip),%rdi
call   10a0 <perror@plt>
jmp    11d0 <hexDump+0x50>

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [6 x i8] c"fseek\00"
@.str.1 = [7 x i8] c"%05x \00"
define void @hexDump(i32* %0, i64 %1, i64 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i32* %0, i32** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i32 %3, i32* %8
%12 = load i32, i32* %8
%13 = call i64 @calloc(i32 1, i32 %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %11
%15 = call i32 @assert(i8* %14)
%16 = load i32*, i32** %5
%17 = load i64, i64* %6
%18 = load i32, i32* @SEEK_SET
%19 = call i32 @fseek(i32* %16, i64 %17, i32 %18)
%20 = icmp eq i32 -1, %19
br i1 %20, label %21, label %23
21: ; preds = %4
%22 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %4
br label %24
24: ; preds = %23, %57
%25 = load i64, i64* %6
%26 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 %25)
%27 = load i64, i64* %7
%28 = load i64, i64* %6
%29 = sub nsw i64 %27, %28
%30 = trunc i64 %29 to i32
store i32 %30, i32* %10
%31 = load i32, i32* %10
%32 = load i32, i32* %8
%33 = icmp sgt i32 %31, %32
br i1 %33, label %34, label %36
34: ; preds = %24
%35 = load i32, i32* %8
store i32 %35, i32* %10
br label %36
36: ; preds = %34, %24
%37 = load i8*, i8** %11
%38 = load i32, i32* %10
%39 = load i32*, i32** %5
%40 = call i32 @fread(i8* %37, i32 1, i32 %38, i32* %39)
store i32 %40, i32* %9
%41 = load i8*, i8** %11
%42 = load i32, i32* %9
%43 = load i32, i32* %8
%44 = call i32 @displayHexRecord(i8* %41, i32 %42, i32 %43)
%45 = load i32, i32* %9
%46 = load i32, i32* %8
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %49
48: ; preds = %36
br label %58
49: ; preds = %36
%50 = load i64, i64* %7
%51 = load i32, i32* %9
%52 = sext i32 %51 to i64
%53 = load i64, i64* %6
%54 = add nsw i64 %53, %52
store i64 %54, i64* %6
%55 = icmp sle i64 %50, %54
br i1 %55, label %56, label %57
56: ; preds = %49
br label %58
57: ; preds = %49
br label %24
58: ; preds = %56, %48
%59 = load i8*, i8** %11
%60 = call i32 @free(i8* %59)
ret void
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [6 x i8] c"fseek\00"
@.str.1 = [7 x i8] c"%05x \00"
define void @hexDump(i32* nocapture %0, i64 %1, i64 %2, i32 %3) {
%5 = tail call i64 @calloc(i32 1, i32 %3)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i32 @assert(i8* %6)
%8 = load i32, i32* @SEEK_SET
%9 = tail call i32 @fseek(i32* %0, i64 %1, i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %4
%12 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %4
br label %14
14: ; preds = %13, %24
%15 = phi i64 [ %26, %24 ], [ %1, %13 ]
%16 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 %15)
%17 = sub nsw i64 %2, %15
%18 = trunc i64 %17 to i32
%19 = icmp sgt i32 %18, %3
%20 = select i1 %19, i32 %3, i32 %18
%21 = tail call i32 @fread(i8* %6, i32 1, i32 %20, i32* %0)
%22 = tail call i32 @displayHexRecord(i8* %6, i32 %21, i32 %3)
%23 = icmp slt i32 %21, %3
br i1 %23, label %28, label %24
24: ; preds = %14
%25 = sext i32 %21 to i64
%26 = add nsw i64 %15, %25
%27 = icmp slt i64 %26, %2
br i1 %27, label %14, label %28
28: ; preds = %24, %14
%29 = tail call i32 @free(i8* %6)
ret void
}