#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*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
void hexlify(FILE *where, const uint8_t *buf, size_t len, bool newl) {
  while (len--) {
    fprintf(where, "%2.2x", (int)*buf++);
  }
  if (newl)
    fputc('\n', where);
}


x86 assembly (clang, -O0):
<hexlify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
cmp    $0x0,%rax
je     1176 <hexlify+0x56>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%edx
lea    0xe94(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1137 <hexlify+0x17>
cmpl   $0x0,-0x1c(%rbp)
je     118e <hexlify+0x6e>
mov    -0x8(%rbp),%rsi
mov    $0xa,%edi
call   1030 <fputc@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexlify>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdi,%r15
test   %rdx,%rdx
je     1169 <hexlify+0x49>
mov    %rdx,%rbp
mov    %rsi,%r13
xor    %ebx,%ebx
lea    0xebb(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x0(%r13,%rbx,4),%edx
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <fprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1150 <hexlify+0x30>
test   %r14d,%r14d
je     1189 <hexlify+0x69>
mov    $0xa,%edi
mov    %r15,%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 = [6 x i8] c"%2.2x\00"
define void @hexlify(i32* %0, i32* %1, i64 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i64 %2, i64* %7
store i32 %3, i32* %8
br label %9
9: ; preds = %13, %4
%10 = load i64, i64* %7
%11 = add i64 %10, -1
store i64 %11, i64* %7
%12 = icmp ne i64 %10, 0
br i1 %12, label %13, label %19
13: ; preds = %9
%14 = load i32*, i32** %5
%15 = load i32*, i32** %6
%16 = getelementptr inbounds i32, i32* %15, i32 1
store i32* %16, i32** %6
%17 = load i32, i32* %15
%18 = call i32 @fprintf(i32* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %17)
br label %9
19: ; preds = %9
%20 = load i32, i32* %8
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i32*, i32** %5
%24 = call i32 @fputc(i8 signext 10, i32* %23)
br label %25
25: ; preds = %22, %19
ret void
}

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