#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 */

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
void dumpHex(char *buffer, int len) {
  unsigned char i;
  for (i = 0; i < len; i++) {
    char text[4];
    if (i % 16 == 0) {
      printf(" ");
    }
    sprintf(text, "%02X \x00", (unsigned char)(*(buffer + i)));
    printf(text);
    if (i % 16 == 15) {
      printf("\n");
    }
  }
}


x86 assembly (clang, -O0):
<dumpHex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movb   $0x0,-0xd(%rbp)
movzbl -0xd(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11bc <dumpHex+0x9c>
movzbl -0xd(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1161 <dumpHex+0x41>
lea    0xea4(%rip),%rdi
call   1030 <printf@plt>
lea    -0x11(%rbp),%rdi
mov    -0x8(%rbp),%rax
movzbl -0xd(%rbp),%ecx
movslq %ecx,%rcx
lea    0xe8d(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1040 <sprintf@plt>
lea    -0x11(%rbp),%rdi
call   1030 <printf@plt>
movzbl -0xd(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0xf,%edx
jne    11aa <dumpHex+0x8a>
lea    0xe5d(%rip),%rdi
call   1030 <printf@plt>
jmp    11af <dumpHex+0x8f>
mov    -0xd(%rbp),%al
add    $0x1,%al
mov    %al,-0xd(%rbp)
jmp    1133 <dumpHex+0x13>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dumpHex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    11a8 <dumpHex+0x78>
mov    %esi,%r12d
mov    %rdi,%r14
xor    %ebp,%ebp
lea    0xeb2(%rip),%r15
lea    0x4(%rsp),%r13
jmp    116c <dumpHex+0x3c>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebp
movzbl %bpl,%ebp
cmp    %r12d,%ebp
jge    11a8 <dumpHex+0x78>
mov    %ebp,%ebx
and    $0xf,%ebx
jne    117d <dumpHex+0x4d>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    %ebp,%eax
movzbl (%r14,%rax,1),%edx
mov    %r13,%rdi
mov    %r15,%rsi
call   1050 <sprintf@plt>
mov    %r13,%rdi
call   1040 <printf@plt>
cmp    $0xf,%ebx
jne    1160 <dumpHex+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1160 <dumpHex+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str.1 = [7 x i8] c"%02X \00\00"
define void @dumpHex(i8* nocapture %0, i32 %1) {
%3 = alloca [4 x i8]
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %26
5: ; preds = %2
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
br label %7
7: ; preds = %5, %22
%8 = phi i32 [ 0, %5 ], [ %24, %22 ]
%9 = and i32 %8, 15
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 @putchar(i32 32)
br label %13
13: ; preds = %11, %7
%14 = zext i32 %8 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %16)
%18 = call i32 @printf(i8* %6)
%19 = icmp eq i32 %9, 15
br i1 %19, label %20, label %22
20: ; preds = %13
%21 = tail call i32 @putchar(i32 10)
br label %22
22: ; preds = %20, %13
%23 = add nuw nsw i32 %8, 1
%24 = and i32 %23, 255
%25 = icmp slt i32 %24, %1
br i1 %25, label %7, label %26
26: ; preds = %22, %2
ret void
}