#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*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void hexdump(FILE *f, const char *title, const unsigned char *s, size_t len) {
  fprintf(f, "%s", title);
  for (; len != 0; len--)
    fprintf(f, " 0x%02x", *(s++));
  fprintf(f, "\n");
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xec9(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
cmpq   $0x0,-0x20(%rbp)
je     117e <hexdump+0x6e>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movzbl (%rax),%edx
lea    0xe9d(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    113e <hexdump+0x2e>
mov    -0x8(%rbp),%rdi
lea    0xe82(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rdi,%r13
mov    %rsi,%rdi
mov    %r13,%rsi
call   1030 <fputs@plt>
test   %r14,%r14
je     117b <hexdump+0x4b>
lea    0xea7(%rip),%r12
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movzbl (%r15,%rbx,1),%edx
mov    %r13,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1160 <hexdump+0x30>
mov    $0xa,%edi
mov    %r13,%rsi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <fputc@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [8 x i8] c" 0x%02x\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @hexdump(i32* %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
store i32* %0, i32** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%9 = load i32*, i32** %5
%10 = load i8*, i8** %6
%11 = call i32 (i32*, i8*, ...) @fprintf(i32* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %12
12: ; preds = %22, %4
%13 = load i64, i64* %8
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %25
15: ; preds = %12
%16 = load i32*, i32** %5
%17 = load i8*, i8** %7
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %7
%19 = load i8, i8* %17
%20 = zext i8 %19 to i32
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %15
%23 = load i64, i64* %8
%24 = add i64 %23, -1
store i64 %24, i64* %8
br label %12
25: ; preds = %12
%26 = load i32*, i32** %5
%27 = call i32 (i32*, i8*, ...) @fprintf(i32* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}

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