#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 fprintf(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int hexDump(FILE *out, const uint8_t *buffer, size_t n) {
  while (n--) {
    int r = fprintf(out, "%02", *buffer++);
    if (r < 0)
      return r;
  }
  return 0;
}


x86 assembly (clang, -O0):
<hexDump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
cmp    $0x0,%rax
je     117b <hexDump+0x6b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%edx
lea    0xea7(%rip),%rsi
call   1030 <fprintf@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1176 <hexDump+0x66>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1182 <hexDump+0x72>
jmp    1124 <hexDump+0x14>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
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    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %r14d,%r14d
lea    0xed2(%rip),%r13
xor    %ebp,%ebp
cmp    %rbp,%r12
je     114f <hexDump+0x3f>
mov    (%r15,%rbp,4),%edx
mov    %rbx,%rdi
mov    %r13,%rsi
call   1030 <fprintf@plt>
add    $0x1,%rbp
test   %eax,%eax
jns    1130 <hexDump+0x20>
mov    %eax,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%02\00"
define i32 @hexDump(i32* %0, i32* %1, i64 %2) {
%4 = alloca i32
%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
br label %9
9: ; preds = %23, %3
%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 %24
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 ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %17)
store i32 %18, i32* %8
%19 = load i32, i32* %8
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %13
%22 = load i32, i32* %8
store i32 %22, i32* %4
br label %25
23: ; preds = %13
br label %9
24: ; preds = %9
store i32 0, i32* %4
br label %25
25: ; preds = %24, %21
%26 = load i32, i32* %4
ret i32 %26
}

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