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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *const, char *, ...);
void hexdump(FILE *const outfile, const void *const buf, const size_t len) {
  const uint8_t *const p = buf;
  for (size_t i = 0; i < len; i++) {
    if (i % 8 == 0)
      fprintf(outfile, "%s%04zu:", i == 0 ? "" : "\n", i);
    fprintf(outfile, " %02x", p[i]);
  }
  fprintf(outfile, "\n");
}


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    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11b2 <hexdump+0xa2>
mov    -0x28(%rbp),%rax
and    $0x7,%rax
cmp    $0x0,%rax
jne    1184 <hexdump+0x74>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rcx
lea    0xea6(%rip),%rdx
lea    0xea0(%rip),%rax
cmp    $0x0,%rcx
cmove  %rax,%rdx
mov    -0x28(%rbp),%rcx
lea    0xe83(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe71(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1134 <hexdump+0x24>
mov    -0x8(%rbp),%rdi
lea    0xe4c(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@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    %rdi,%rbx
test   %rdx,%rdx
je     1197 <hexdump+0x77>
mov    %rdx,%r14
mov    %rsi,%r15
lea    0xec0(%rip),%r12
lea    0xec4(%rip),%r13
xor    %ebp,%ebp
jmp    116a <hexdump+0x4a>
nopl   0x0(%rax,%rax,1)
mov    (%r15,%rbp,4),%edx
mov    %rbx,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%r14
je     1197 <hexdump+0x77>
test   $0x7,%bpl
jne    1150 <hexdump+0x30>
test   %rbp,%rbp
lea    0xe8f(%rip),%rdx
lea    0xe89(%rip),%rax
cmove  %rax,%rdx
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %rbp,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1150 <hexdump+0x30>
mov    $0xa,%edi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fputc@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"%s%04zu:\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [6 x i8] c" %02x\00"
define void @hexdump(i32* %0, i8* %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i64
store i32* %0, i32** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%9 = load i8*, i8** %5
%10 = bitcast i8* %9 to i32*
store i32* %10, i32** %7
store i64 0, i64* %8
br label %11
11: ; preds = %34, %3
%12 = load i64, i64* %8
%13 = load i64, i64* %6
%14 = icmp ult i64 %12, %13
br i1 %14, label %15, label %37
15: ; preds = %11
%16 = load i64, i64* %8
%17 = urem i64 %16, 8
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %15
%20 = load i32*, i32** %4
%21 = load i64, i64* %8
%22 = icmp eq i64 %21, 0
%23 = zext i1 %22 to i64
%24 = select i1 %22, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%25 = load i64, i64* %8
%26 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %24, i64 %25)
br label %27
27: ; preds = %19, %15
%28 = load i32*, i32** %4
%29 = load i32*, i32** %7
%30 = load i64, i64* %8
%31 = getelementptr inbounds i32, i32* %29, i64 %30
%32 = load i32, i32* %31
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %28, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %27
%35 = load i64, i64* %8
%36 = add i64 %35, 1
store i64 %36, i64* %8
br label %11
37: ; preds = %11
%38 = load i32*, i32** %4
%39 = call i32 (i32*, i8*, ...) @fprintf(i32* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"%s%04zu:\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [6 x i8] c" %02x\00"
define void @hexdump(i32* nocapture %0, i8* nocapture %1, i64 %2) {
%4 = bitcast i8* %1 to i32*
%5 = icmp eq i64 %2, 0
br i1 %5, label %6, label %8
6: ; preds = %16, %3
%7 = tail call i32 @fputc(i32 10, i32* %0)
ret void
8: ; preds = %3, %16
%9 = phi i64 [ %20, %16 ], [ 0, %3 ]
%10 = and i64 %9, 7
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = icmp eq i64 %9, 0
%14 = select i1 %13, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%15 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %14, i64 %9)
br label %16
16: ; preds = %12, %8
%17 = getelementptr inbounds i32, i32* %4, i64 %9
%18 = load i32, i32* %17
%19 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = add nuw i64 %9, 1
%21 = icmp eq i64 %20, %2
br i1 %21, label %6, label %8
}