#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*/ *, char *, ...);
void dump_hex(FILE *f, const uint8_t *buf, size_t len) {
  size_t i, col;
  col = 0;
  for (i = 0; i < len; i++) {
    fprintf(f, " 0x%02x,", buf[i]);
    if (++col == 8) {
      fprintf(f, "\n");
      col = 0;
    }
  }
  if (col != 0)
    fprintf(f, "\n");
}


x86 assembly (clang, -O0):
<dump_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11a5 <dump_hex+0x95>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xea8(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
cmp    $0x8,%rax
jne    118f <dump_hex+0x7f>
mov    -0x8(%rbp),%rdi
lea    0xe89(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movq   $0x0,-0x28(%rbp)
jmp    1194 <dump_hex+0x84>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1134 <dump_hex+0x24>
cmpq   $0x0,-0x28(%rbp)
je     11c2 <dump_hex+0xb2>
mov    -0x8(%rbp),%rdi
lea    0xe4e(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_hex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdx,%rdx
je     11a5 <dump_hex+0x85>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r13
lea    0xec0(%rip),%r12
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    1159 <dump_hex+0x39>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%r14
je     1185 <dump_hex+0x65>
mov    (%r15,%rbx,4),%edx
mov    %r13,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%rbp
cmp    $0x8,%rbp
jne    1150 <dump_hex+0x30>
mov    $0xa,%edi
mov    %r13,%rsi
call   1030 <fputc@plt>
xor    %ebp,%ebp
jmp    1150 <dump_hex+0x30>
test   %rbp,%rbp
je     11a5 <dump_hex+0x85>
mov    $0xa,%edi
mov    %r13,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fputc@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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