#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*/ fputs(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char, int /*<<< orphan*/);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ stdout;
void hexprint(const char *label, const char *s) {
  unsigned char *p = (unsigned char *)s;
  fputs(label, stdout);
  for (size_t i = 0; *p; i++)
    printf("%c%02x", i % 16 ? ' ' : '\n', *p++);
  putchar('\n');
}


x86 assembly (clang, -O0):
<hexprint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
call   1050 <fputs@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11ba <hexprint+0x8a>
mov    -0x20(%rbp),%rdx
and    $0xf,%rdx
mov    $0xa,%eax
mov    $0x20,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
movzbl (%rcx),%edx
lea    0xe5f(%rip),%rdi
movsbl %al,%esi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1162 <hexprint+0x32>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexprint>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    0x2e9f(%rip),%rax
mov    (%rax),%esi
call   1050 <fputs@plt>
mov    (%r15),%al
test   %al,%al
je     1184 <hexprint+0x54>
xor    %ebx,%ebx
mov    $0xa,%ebp
lea    0xea3(%rip),%r14
nopl   (%rax)
test   $0xf,%bl
movzbl %al,%edx
mov    $0x20,%esi
cmove  %ebp,%esi
mov    %r14,%rdi
call   1040 <printf@plt>
movzbl 0x1(%r15,%rbx,1),%eax
add    $0x1,%rbx
test   %al,%al
jne    1160 <hexprint+0x30>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

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