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

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ hexdump(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int,
                           int);
int /*<<< orphan*/ indent(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *malloc(int);
int read_binary(int /*<<< orphan*/ *, int);
void dump_binary(FILE *log, int level, int size) {
  uint8_t *buf = malloc(65536);
  uint8_t *ptr;
  int res, ofs = 0;
  assert(buf);
  res = read_binary(buf, size);
  for (ptr = buf; res > 0; ofs += 16, ptr += 16) {
    int csize = res > 16 ? 16 : res;
    indent(level + 1, log);
    fprintf(log, "%04x: ", ofs);
    hexdump(log, ptr, csize, 1);
    fprintf(log, "\n");
    res -= csize;
  }
  free(buf);
}


x86 assembly (clang, -O0):
<dump_binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    $0x10000,%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1030 <read_binary@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x24(%rbp)
jle    1254 <dump_binary+0xe4>
cmpl   $0x10,-0x24(%rbp)
jle    11d8 <dump_binary+0x68>
mov    $0x10,%eax
mov    %eax,-0x30(%rbp)
jmp    11de <dump_binary+0x6e>
mov    -0x24(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0xc(%rbp),%edi
add    $0x1,%edi
mov    -0x8(%rbp),%rsi
call   1060 <indent@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%edx
lea    0xdff(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    $0x1,%ecx
call   1080 <hexdump@plt>
mov    -0x8(%rbp),%rdi
lea    0xddf(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x2c(%rbp),%ecx
mov    -0x24(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0x40,%rax
mov    %rax,-0x20(%rbp)
jmp    11b7 <dump_binary+0x47>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_binary>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%r15d
mov    %rdi,%r13
mov    $0x10000,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1060 <assert@plt>
mov    %rbp,(%rsp)
mov    %rbp,%rdi
mov    %ebx,%esi
call   1030 <read_binary@plt>
test   %eax,%eax
jle    1229 <dump_binary+0xa9>
mov    %eax,%ebp
add    $0x1,%r15d
mov    (%rsp),%rbx
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
cmp    $0x10,%ebp
mov    $0x10,%r12d
cmovb  %ebp,%r12d
mov    %r15d,%edi
mov    %r13,%rsi
call   1070 <indent@plt>
mov    %r13,%rdi
lea    0xe0e(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
mov    $0x1,%ecx
call   1090 <hexdump@plt>
mov    $0xa,%edi
mov    %r13,%rsi
call   1050 <fputc@plt>
add    $0x10,%r14d
add    $0x40,%rbx
sub    %r12d,%ebp
jg     11d0 <dump_binary+0x50>
mov    (%rsp),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <free@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"%04x: \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @dump_binary(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%12 = call i32* @malloc(i32 65536)
store i32* %12, i32** %7
store i32 0, i32* %10
%13 = load i32*, i32** %7
%14 = call i32 @assert(i32* %13)
%15 = load i32*, i32** %7
%16 = load i32, i32* %6
%17 = call i32 @read_binary(i32* %15, i32 %16)
store i32 %17, i32* %9
%18 = load i32*, i32** %7
store i32* %18, i32** %8
br label %19
19: ; preds = %46, %3
%20 = load i32, i32* %9
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %51
22: ; preds = %19
%23 = load i32, i32* %9
%24 = icmp sgt i32 %23, 16
br i1 %24, label %25, label %26
25: ; preds = %22
br label %28
26: ; preds = %22
%27 = load i32, i32* %9
br label %28
28: ; preds = %26, %25
%29 = phi i32 [ 16, %25 ], [ %27, %26 ]
store i32 %29, i32* %11
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
%32 = load i32*, i32** %4
%33 = call i32 @indent(i32 %31, i32* %32)
%34 = load i32*, i32** %4
%35 = load i32, i32* %10
%36 = call i32 (i32*, i8*, ...) @fprintf(i32* %34, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %35)
%37 = load i32*, i32** %4
%38 = load i32*, i32** %8
%39 = load i32, i32* %11
%40 = call i32 @hexdump(i32* %37, i32* %38, i32 %39, i32 1)
%41 = load i32*, i32** %4
%42 = call i32 (i32*, i8*, ...) @fprintf(i32* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%43 = load i32, i32* %11
%44 = load i32, i32* %9
%45 = sub nsw i32 %44, %43
store i32 %45, i32* %9
br label %46
46: ; preds = %28
%47 = load i32, i32* %10
%48 = add nsw i32 %47, 16
store i32 %48, i32* %10
%49 = load i32*, i32** %8
%50 = getelementptr inbounds i32, i32* %49, i64 16
store i32* %50, i32** %8
br label %19
51: ; preds = %19
%52 = load i32*, i32** %7
%53 = call i32 @free(i32* %52)
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%04x: \00"
define void @dump_binary(i32* %0, i32 %1, i32 %2) {
%4 = tail call i32* @malloc(i32 65536)
%5 = tail call i32 @assert(i32* %4)
%6 = tail call i32 @read_binary(i32* %4, i32 %2)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %24
8: ; preds = %3
%9 = add nsw i32 %1, 1
br label %10
10: ; preds = %8, %10
%11 = phi i32* [ %4, %8 ], [ %22, %10 ]
%12 = phi i32 [ 0, %8 ], [ %21, %10 ]
%13 = phi i32 [ %6, %8 ], [ %20, %10 ]
%14 = icmp ult i32 %13, 16
%15 = select i1 %14, i32 %13, i32 16
%16 = tail call i32 @indent(i32 %9, i32* %0)
%17 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %12)
%18 = tail call i32 @hexdump(i32* %0, i32* %11, i32 %15, i32 1)
%19 = tail call i32 @fputc(i32 10, i32* %0)
%20 = sub nsw i32 %13, %15
%21 = add nuw nsw i32 %12, 16
%22 = getelementptr inbounds i32, i32* %11, i64 16
%23 = icmp sgt i32 %20, 0
br i1 %23, label %10, label %24
24: ; preds = %10, %3
%25 = tail call i32 @free(i32* %4)
ret void
}