#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ hexdump(unsigned char *, unsigned long, unsigned long);
unsigned char *malloc(unsigned long);
int /*<<< orphan*/ printf(char *);
int hexdump_file(FILE *infile, unsigned long start, unsigned long stop,
                 unsigned long width) {
  char ch;
  unsigned long f_index = 0;
  unsigned long bb_index = 0;
  unsigned char *byte_buffer = malloc(width);
  if (byte_buffer == NULL) {
    printf("Could not allocate memory for byte_buffer\n");
    return -1;
  }
  while (!feof(infile)) {
    ch = getc(infile);
    if ((f_index >= start) && (f_index <= stop)) {
      byte_buffer[bb_index] = ch;
      bb_index++;
    }
    if (bb_index >= width) {
      hexdump(byte_buffer, bb_index, width);
      bb_index = 0;
    }
    f_index++;
  }
  if (bb_index)
    hexdump(byte_buffer, bb_index, width);
  fclose(infile);
  free(byte_buffer);
  return 0;
}


x86 assembly (clang, -O0):
<hexdump_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    11c8 <hexdump_file+0x58>
lea    0xe49(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129a <hexdump_file+0x12a>
jmp    11cd <hexdump_file+0x5d>
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11eb <hexdump_file+0x7b>
jmp    1265 <hexdump_file+0xf5>
mov    -0x10(%rbp),%rdi
call   1090 <getc@plt>
mov    %al,-0x29(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x18(%rbp),%rax
jb     122d <hexdump_file+0xbd>
mov    -0x38(%rbp),%rax
cmp    -0x20(%rbp),%rax
ja     122d <hexdump_file+0xbd>
mov    -0x29(%rbp),%dl
mov    -0x48(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x28(%rbp),%rax
jb     1254 <hexdump_file+0xe4>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1070 <hexdump@plt>
movq   $0x0,-0x40(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11cd <hexdump_file+0x5d>
cmpq   $0x0,-0x40(%rbp)
je     1281 <hexdump_file+0x111>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1070 <hexdump@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,(%rsp)
mov    %rsi,%r13
mov    %rdi,%rbx
mov    %rcx,%rdi
call   1080 <malloc@plt>
test   %rax,%rax
je     11f2 <hexdump_file+0x82>
mov    %rax,%r14
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    1218 <hexdump_file+0xa8>
xor    %ebp,%ebp
xor    %r12d,%r12d
jmp    11c0 <hexdump_file+0x50>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    1205 <hexdump_file+0x95>
mov    %rbx,%rdi
call   1090 <getc@plt>
cmp    %r13,%r12
jb     11db <hexdump_file+0x6b>
cmp    (%rsp),%r12
ja     11db <hexdump_file+0x6b>
mov    %al,(%r14,%rbp,1)
add    $0x1,%rbp
cmp    %r15,%rbp
jb     11b0 <hexdump_file+0x40>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1070 <hexdump@plt>
xor    %ebp,%ebp
jmp    11b0 <hexdump_file+0x40>
lea    0xe07(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
jmp    122a <hexdump_file+0xba>
test   %rbp,%rbp
je     1218 <hexdump_file+0xa8>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1070 <hexdump@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [43 x i8] c"Could not allocate memory for byte_buffer\0A\00"
define i32 @hexdump_file(i32* %0, i64 %1, i64 %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8
%11 = alloca i64
%12 = alloca i64
%13 = alloca i8*
store i32* %0, i32** %6
store i64 %1, i64* %7
store i64 %2, i64* %8
store i64 %3, i64* %9
store i64 0, i64* %11
store i64 0, i64* %12
%14 = load i64, i64* %9
%15 = call i8* @malloc(i64 %14)
store i8* %15, i8** %13
%16 = load i8*, i8** %13
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %4
%19 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %68
20: ; preds = %4
br label %21
21: ; preds = %52, %20
%22 = load i32*, i32** %6
%23 = call i32 @feof(i32* %22)
%24 = icmp ne i32 %23, 0
%25 = xor i1 %24, true
br i1 %25, label %26, label %55
26: ; preds = %21
%27 = load i32*, i32** %6
%28 = call signext i8 @getc(i32* %27)
store i8 %28, i8* %10
%29 = load i64, i64* %11
%30 = load i64, i64* %7
%31 = icmp uge i64 %29, %30
br i1 %31, label %32, label %43
32: ; preds = %26
%33 = load i64, i64* %11
%34 = load i64, i64* %8
%35 = icmp ule i64 %33, %34
br i1 %35, label %36, label %43
36: ; preds = %32
%37 = load i8, i8* %10
%38 = load i8*, i8** %13
%39 = load i64, i64* %12
%40 = getelementptr inbounds i8, i8* %38, i64 %39
store i8 %37, i8* %40
%41 = load i64, i64* %12
%42 = add i64 %41, 1
store i64 %42, i64* %12
br label %43
43: ; preds = %36, %32, %26
%44 = load i64, i64* %12
%45 = load i64, i64* %9
%46 = icmp uge i64 %44, %45
br i1 %46, label %47, label %52
47: ; preds = %43
%48 = load i8*, i8** %13
%49 = load i64, i64* %12
%50 = load i64, i64* %9
%51 = call i32 @hexdump(i8* %48, i64 %49, i64 %50)
store i64 0, i64* %12
br label %52
52: ; preds = %47, %43
%53 = load i64, i64* %11
%54 = add i64 %53, 1
store i64 %54, i64* %11
br label %21
55: ; preds = %21
%56 = load i64, i64* %12
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %63
58: ; preds = %55
%59 = load i8*, i8** %13
%60 = load i64, i64* %12
%61 = load i64, i64* %9
%62 = call i32 @hexdump(i8* %59, i64 %60, i64 %61)
br label %63
63: ; preds = %58, %55
%64 = load i32*, i32** %6
%65 = call i32 @fclose(i32* %64)
%66 = load i8*, i8** %13
%67 = call i32 @free(i8* %66)
store i32 0, i32* %5
br label %68
68: ; preds = %63, %18
%69 = load i32, i32* %5
ret i32 %69
}

LLVM IR (-O2):
@str = [42 x i8] c"Could not allocate memory for byte_buffer\00"
define i32 @hexdump_file(i32* nocapture %0, i64 %1, i64 %2, i64 %3) {
%5 = tail call i8* @malloc(i64 %3)
%6 = icmp eq i8* %5, null
br i1 %6, label %10, label %7
7: ; preds = %4
%8 = tail call i32 @feof(i32* %0)
%9 = icmp eq i32 %8, 0
br i1 %9, label %12, label %36
10: ; preds = %4
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
br label %39
12: ; preds = %7, %27
%13 = phi i64 [ %28, %27 ], [ 0, %7 ]
%14 = phi i64 [ %29, %27 ], [ 0, %7 ]
%15 = tail call signext i8 @getc(i32* %0)
%16 = icmp ult i64 %14, %1
%17 = icmp ugt i64 %14, %2
%18 = or i1 %16, %17
br i1 %18, label %22, label %19
19: ; preds = %12
%20 = getelementptr inbounds i8, i8* %5, i64 %13
store i8 %15, i8* %20
%21 = add i64 %13, 1
br label %22
22: ; preds = %19, %12
%23 = phi i64 [ %21, %19 ], [ %13, %12 ]
%24 = icmp ult i64 %23, %3
br i1 %24, label %27, label %25
25: ; preds = %22
%26 = tail call i32 @hexdump(i8* %5, i64 %23, i64 %3)
br label %27
27: ; preds = %25, %22
%28 = phi i64 [ 0, %25 ], [ %23, %22 ]
%29 = add i64 %14, 1
%30 = tail call i32 @feof(i32* %0)
%31 = icmp eq i32 %30, 0
br i1 %31, label %12, label %32
32: ; preds = %27
%33 = icmp eq i64 %28, 0
br i1 %33, label %36, label %34
34: ; preds = %32
%35 = tail call i32 @hexdump(i8* %5, i64 %28, i64 %3)
br label %36
36: ; preds = %7, %34, %32
%37 = tail call i32 @fclose(i32* %0)
%38 = tail call i32 @free(i8* %5)
br label %39
39: ; preds = %36, %10
%40 = phi i32 [ -1, %10 ], [ 0, %36 ]
ret i32 %40
}