#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*/ chardump_line(char *, unsigned char *, int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *, char *);
int /*<<< orphan*/ hexdump_line(char *, unsigned char *, int, int);
int /*<<< orphan*/ stdout;
int hexdump_buf(FILE *f, int startaddr, unsigned char *buf, int len) {
  int addr;
  int n;
  unsigned char *p;
  char dst1[80];
  char dst2[80];
  addr = startaddr;
  p = (unsigned char *)buf;
  while (len) {
    n = 16;
    if (n > len)
      n = len;
    hexdump_line(dst1, p, n, 48);
    chardump_line(dst2, p, n, 16);
    fprintf(stdout, "%04x  %s  |%s|\n", addr, dst1, dst2);
    len -= n;
    addr += n;
    p += n;
  }
  return 0;
}


x86 assembly (clang, -O0):
<hexdump_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11f4 <hexdump_buf+0xc4>
movl   $0x10,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    117a <hexdump_buf+0x4a>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    $0x30,%ecx
call   1030 <hexdump_line@plt>
lea    -0xd0(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    $0x10,%ecx
call   1050 <chardump_line@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    -0x80(%rbp),%rcx
lea    -0xd0(%rbp),%r8
lea    0xe3b(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x24(%rbp),%ecx
mov    -0x1c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x24(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
jmp    1157 <hexdump_buf+0x27>
xor    %eax,%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump_buf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
test   %ecx,%ecx
je     11be <hexdump_buf+0x8e>
mov    %ecx,%ebp
mov    %rdx,%rbx
mov    %esi,%r14d
lea    0x50(%rsp),%r15
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
nop
cmp    $0x10,%ebp
mov    $0x10,%r13d
cmovl  %ebp,%r13d
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r13d,%edx
mov    $0x30,%ecx
call   1030 <hexdump_line@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r13d,%edx
mov    $0x10,%ecx
call   1050 <chardump_line@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
mov    %r14d,%edx
mov    %r15,%rcx
mov    %r12,%r8
call   1040 <fprintf@plt>
add    %r13d,%r14d
movslq %r13d,%rax
add    %rax,%rbx
sub    %eax,%ebp
jne    1160 <hexdump_buf+0x30>
xor    %eax,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [16 x i8] c"%04x %s |%s|\0A\00"
define i32 @hexdump_buf(i32* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca [80 x i8]
%13 = alloca [80 x i8]
store i32* %0, i32** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%14 = load i32, i32* %6
store i32 %14, i32* %9
%15 = load i8*, i8** %7
store i8* %15, i8** %11
br label %16
16: ; preds = %25, %4
%17 = load i32, i32* %8
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %49
19: ; preds = %16
store i32 16, i32* %10
%20 = load i32, i32* %10
%21 = load i32, i32* %8
%22 = icmp sgt i32 %20, %21
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = load i32, i32* %8
store i32 %24, i32* %10
br label %25
25: ; preds = %23, %19
%26 = getelementptr inbounds [80 x i8], [80 x i8]* %12, i64 0, i64 0
%27 = load i8*, i8** %11
%28 = load i32, i32* %10
%29 = call i32 @hexdump_line(i8* %26, i8* %27, i32 %28, i32 48)
%30 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%31 = load i8*, i8** %11
%32 = load i32, i32* %10
%33 = call i32 @chardump_line(i8* %30, i8* %31, i32 %32, i32 16)
%34 = load i32, i32* @stdout
%35 = load i32, i32* %9
%36 = getelementptr inbounds [80 x i8], [80 x i8]* %12, i64 0, i64 0
%37 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%38 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %35, i8* %36, i8* %37)
%39 = load i32, i32* %10
%40 = load i32, i32* %8
%41 = sub nsw i32 %40, %39
store i32 %41, i32* %8
%42 = load i32, i32* %10
%43 = load i32, i32* %9
%44 = add nsw i32 %43, %42
store i32 %44, i32* %9
%45 = load i32, i32* %10
%46 = load i8*, i8** %11
%47 = sext i32 %45 to i64
%48 = getelementptr inbounds i8, i8* %46, i64 %47
store i8* %48, i8** %11
br label %16
49: ; preds = %16
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [16 x i8] c"%04x %s |%s|\0A\00"
define i32 @hexdump_buf(i32* nocapture readnone %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca [80 x i8]
%6 = alloca [80 x i8]
%7 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%9 = icmp eq i32 %3, 0
br i1 %9, label %25, label %10
10: ; preds = %4, %10
%11 = phi i8* [ %23, %10 ], [ %2, %4 ]
%12 = phi i32 [ %21, %10 ], [ %1, %4 ]
%13 = phi i32 [ %20, %10 ], [ %3, %4 ]
%14 = icmp slt i32 %13, 16
%15 = select i1 %14, i32 %13, i32 16
%16 = call i32 @hexdump_line(i8* %7, i8* %11, i32 %15, i32 48)
%17 = call i32 @chardump_line(i8* %8, i8* %11, i32 %15, i32 16)
%18 = load i32, i32* @stdout
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %12, i8* %7, i8* %8)
%20 = sub nsw i32 %13, %15
%21 = add nsw i32 %15, %12
%22 = sext i32 %15 to i64
%23 = getelementptr inbounds i8, i8* %11, i64 %22
%24 = icmp eq i32 %20, 0
br i1 %24, label %25, label %10
25: ; preds = %10, %4
ret i32 0
}