#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 *, char);
int /*<<< orphan*/ putchar(char);
void kaDump(void *p, int len) {
  int i;
  for (i = 0; i < len; i++) {
    printf("%02x ", *(char *)(p + i));
    if (i % 16 == 15)
      putchar('\n');
  }
  if (i % 16 != 15)
    putchar('\n');
  putchar('\n');
}


x86 assembly (clang, -O0):
<kaDump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    118b <kaDump+0x6b>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
lea    0xeaf(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0xf,%edx
jne    1178 <kaDump+0x58>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    117d <kaDump+0x5d>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1136 <kaDump+0x16>
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0xf,%edx
je     11a9 <kaDump+0x89>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kaDump>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %esi,%esi
jle    1173 <kaDump+0x53>
mov    %esi,%r14d
mov    %rdi,%r12
mov    %esi,%ebp
xor    %ebx,%ebx
lea    0xec3(%rip),%r15
jmp    1149 <kaDump+0x29>
nop
add    $0x1,%rbx
cmp    %rbx,%rbp
je     116a <kaDump+0x4a>
movsbl (%r12,%rbx,1),%esi
mov    %r15,%rdi
call   1040 <printf@plt>
mov    %ebx,%eax
not    %eax
test   $0xf,%al
jne    1140 <kaDump+0x20>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1140 <kaDump+0x20>
not    %r14d
test   $0xf,%r14b
je     117d <kaDump+0x5d>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

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