#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 *, unsigned char, char);
int /*<<< orphan*/ putchar(char);
int hexbulk(unsigned char *buf, int n) {
  int i;
  for (i = 0; i < n; ++i)
    printf("%02x%c", buf[i], (i % 16 == 15 ? '\n' : ' '));
  if (i % 16 != 0)
    putchar('\n');
  return 0;
}


x86 assembly (clang, -O0):
<hexbulk>:
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    118a <hexbulk+0x6a>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x10(%rbp),%eax
mov    $0x10,%esi
cltd
idiv   %esi
mov    %edx,%esi
mov    $0x20,%eax
mov    $0xa,%edx
cmp    $0xf,%esi
cmove  %edx,%eax
lea    0xe8f(%rip),%rdi
movzbl %cl,%esi
movsbl %al,%edx
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1136 <hexbulk+0x16>
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     11a8 <hexbulk+0x88>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexbulk>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1185 <hexbulk+0x65>
mov    %esi,%r14d
mov    %rdi,%r12
mov    %esi,%ebp
xor    %ebx,%ebx
mov    $0xa,%r13d
lea    0xeba(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
movzbl (%r12,%rbx,1),%esi
mov    %ebx,%eax
not    %eax
test   $0xf,%al
mov    $0x20,%edx
cmove  %r13d,%edx
mov    %r15,%rdi
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1150 <hexbulk+0x30>
test   $0xf,%r14b
je     1185 <hexbulk+0x65>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%02x%c\00"
define i32 @hexbulk(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 inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
%16 = load i32, i32* %5
%17 = srem i32 %16, 16
%18 = icmp eq i32 %17, 15
%19 = zext i1 %18 to i64
%20 = select i1 %18, i32 10, i32 32
%21 = trunc i32 %20 to i8
%22 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %15, i8 signext %21)
br label %23
23: ; preds = %10
%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, 0
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 @putchar(i8 signext 10)
br label %32
32: ; preds = %30, %26
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"%02x%c\00"
define i32 @hexbulk(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, %6
%7 = phi i64 [ 0, %4 ], [ %14, %6 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = and i64 %7, 15
%11 = icmp eq i64 %10, 15
%12 = select i1 %11, i8 10, i8 32
%13 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %9, i8 signext %12)
%14 = add nuw nsw i64 %7, 1
%15 = icmp eq i64 %14, %5
br i1 %15, label %16, label %6
16: ; preds = %6
%17 = and i32 %1, 15
%18 = icmp eq i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %16
%20 = tail call i32 @putchar(i8 signext 10)
br label %21
21: ; preds = %2, %19, %16
ret i32 0
}