#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*/ printk(char *, ...);
void nsp32_byte_dump(void *ptr, int offset, int size) {
  unsigned char *tmp = ptr;
  int pos;
  if (size == 0) {
    return;
  }
  pos = 0;
  while (pos < size) {
    if (pos % 16 == 0) {
      printk("%08x:", pos + offset);
    }
    if (pos % 16 == 8) {
      printk(" -");
    }
    printk(" %02x", tmp[pos]);
    if ((pos % 16 == 15) && (pos + 1 != size)) {
      printk("\n");
    }
    pos++;
  }
  printk("\n");
}


x86 assembly (clang, -O0):
<nsp32_byte_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    1139 <nsp32_byte_dump+0x29>
jmp    11fd <nsp32_byte_dump+0xed>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11ef <nsp32_byte_dump+0xdf>
mov    -0x1c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1174 <nsp32_byte_dump+0x64>
mov    -0x1c(%rbp),%esi
add    -0xc(%rbp),%esi
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printk@plt>
mov    -0x1c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x8,%edx
jne    1196 <nsp32_byte_dump+0x86>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1030 <printk@plt>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printk@plt>
mov    -0x1c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0xf,%edx
jne    11e1 <nsp32_byte_dump+0xd1>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cmp    -0x10(%rbp),%eax
je     11e1 <nsp32_byte_dump+0xd1>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printk@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1140 <nsp32_byte_dump+0x30>
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1030 <printk@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nsp32_byte_dump>:
test   %edx,%edx
je     11e0 <nsp32_byte_dump+0xd0>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
jle    11c4 <nsp32_byte_dump+0xb4>
mov    %rdi,%rbx
mov    %edx,%ebp
mov    %esi,%eax
mov    %rax,(%rsp)
lea    -0x1(%rbp),%r13
xor    %r15d,%r15d
jmp    1145 <nsp32_byte_dump+0x35>
nopl   (%rax)
cmp    %r15,%rbp
je     11c4 <nsp32_byte_dump+0xb4>
mov    %r15,%r12
mov    %r12d,%r14d
and    $0xf,%r14d
cmp    $0x8,%r14d
je     1180 <nsp32_byte_dump+0x70>
test   %r14d,%r14d
jne    118e <nsp32_byte_dump+0x7e>
mov    (%rsp),%rax
lea    (%rax,%r12,1),%esi
lea    0xe97(%rip),%rdi
xor    %eax,%eax
call   1030 <printk@plt>
jmp    118e <nsp32_byte_dump+0x7e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xe7f(%rip),%rdi
xor    %eax,%eax
call   1030 <printk@plt>
movzbl (%rbx,%r12,1),%esi
lea    0xe6f(%rip),%rdi
xor    %eax,%eax
call   1030 <printk@plt>
lea    0x1(%r12),%r15
cmp    $0xf,%r14d
jne    1140 <nsp32_byte_dump+0x30>
cmp    %r12,%r13
je     1140 <nsp32_byte_dump+0x30>
lea    0xe57(%rip),%rdi
xor    %eax,%eax
call   1030 <printk@plt>
jmp    1140 <nsp32_byte_dump+0x30>
lea    0xe44(%rip),%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printk@plt>
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%08x:\00"
@.str.1 = [3 x i8] c" -\00"
@.str.2 = [6 x i8] c" %02x\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @nsp32_byte_dump(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
store i8* %9, i8** %7
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %3
br label %56
13: ; preds = %3
store i32 0, i32* %8
br label %14
14: ; preds = %51, %13
%15 = load i32, i32* %8
%16 = load i32, i32* %6
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %54
18: ; preds = %14
%19 = load i32, i32* %8
%20 = srem i32 %19, 16
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %18
%23 = load i32, i32* %8
%24 = load i32, i32* %5
%25 = add nsw i32 %23, %24
%26 = call i32 (i8*, ...) @printk(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %22, %18
%28 = load i32, i32* %8
%29 = srem i32 %28, 16
%30 = icmp eq i32 %29, 8
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 (i8*, ...) @printk(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %31, %27
%34 = load i8*, i8** %7
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = call i32 (i8*, ...) @printk(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %8
%42 = srem i32 %41, 16
%43 = icmp eq i32 %42, 15
br i1 %43, label %44, label %51
44: ; preds = %33
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 1
%47 = load i32, i32* %6
%48 = icmp ne i32 %46, %47
br i1 %48, label %49, label %51
49: ; preds = %44
%50 = call i32 (i8*, ...) @printk(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %51
51: ; preds = %49, %44, %33
%52 = load i32, i32* %8
%53 = add nsw i32 %52, 1
store i32 %53, i32* %8
br label %14
54: ; preds = %14
%55 = call i32 (i8*, ...) @printk(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %56
56: ; preds = %54, %12
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%08x:\00"
@.str.1 = [3 x i8] c" -\00"
@.str.2 = [6 x i8] c" %02x\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @nsp32_byte_dump(i8* nocapture %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %33, label %5
5: ; preds = %3
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %31
7: ; preds = %5
%8 = zext i32 %2 to i64
br label %9
9: ; preds = %7, %29
%10 = phi i64 [ 0, %7 ], [ %24, %29 ]
%11 = trunc i64 %10 to i32
%12 = and i32 %11, 15
switch i32 %12, label %18 [
i32 0, label %13
i32 8, label %16
]
13: ; preds = %9
%14 = add nsw i32 %11, %1
%15 = tail call i32 (i8*, ...) @printk(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %14)
br label %18
16: ; preds = %9
%17 = tail call i32 (i8*, ...) @printk(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %13, %9, %16
%19 = getelementptr inbounds i8, i8* %0, i64 %10
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = tail call i32 (i8*, ...) @printk(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = icmp ne i32 %12, 15
%24 = add nuw nsw i64 %10, 1
%25 = icmp eq i64 %24, %8
%26 = select i1 %23, i1 true, i1 %25
br i1 %26, label %29, label %27
27: ; preds = %18
%28 = tail call i32 (i8*, ...) @printk(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %29
29: ; preds = %27, %18
%30 = icmp eq i64 %24, %8
br i1 %30, label %31, label %9
31: ; preds = %29, %5
%32 = tail call i32 (i8*, ...) @printk(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %33
33: ; preds = %3, %31
ret void
}