#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 */
scalar_t__ isprint(char);
int /*<<< orphan*/ printf(char *, char, char, char);
void print_hex(char *buffer) {
  static char conv[] = "0123456789ABCDEF";
  int i;
  for (i = 1; i <= buffer[0]; i++)
    printf("%c%c (%c) ", conv[((char)buffer[i] & 0xff) >> 4],
           conv[buffer[i] & 0x0f], isprint(buffer[i]) ? buffer[i] : '*');
}


x86 assembly (clang, -O0):
<print_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jg     11f0 <print_hex+0xd0>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
and    $0xff,%eax
sar    $0x4,%eax
movslq %eax,%rcx
lea    0x2edd(%rip),%rax
mov    (%rax,%rcx,1),%al
mov    %al,-0xe(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
and    $0xf,%eax
movslq %eax,%rcx
lea    0x2ebe(%rip),%rax
mov    (%rax,%rcx,1),%al
mov    %al,-0xd(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isprint@plt>
cmp    $0x0,%rax
je     11b7 <print_hex+0x97>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x14(%rbp)
jmp    11c4 <print_hex+0xa4>
mov    $0x2a,%eax
mov    %eax,-0x14(%rbp)
jmp    11c4 <print_hex+0xa4>
mov    -0xd(%rbp),%cl
mov    -0xe(%rbp),%dl
mov    -0x14(%rbp),%eax
lea    0xe2c(%rip),%rdi
movsbl %dl,%esi
movsbl %cl,%edx
movsbl %al,%ecx
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1133 <print_hex+0x13>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmpb   $0x0,(%rdi)
jle    119b <print_hex+0x7b>
mov    %rdi,%r15
xor    %ebx,%ebx
lea    0xec4(%rip),%r12
lea    0xece(%rip),%r14
jmp    117a <print_hex+0x5a>
cs nopw 0x0(%rax,%rax,1)
nop
movzbl 0x1(%r15,%rbx,1),%eax
movsbl 0x0(%r13,%r12,1),%esi
movsbl 0x0(%rbp,%r12,1),%edx
movsbl %al,%ecx
mov    %r14,%rdi
call   1030 <printf@plt>
movsbq (%r15),%rax
add    $0x1,%rbx
cmp    %rax,%rbx
jge    119b <print_hex+0x7b>
movsbl 0x1(%r15,%rbx,1),%edi
movzbl %dil,%r13d
shr    $0x4,%r13
mov    %edi,%ebp
and    $0xf,%ebp
call   1040 <isprint@plt>
test   %rax,%rax
jne    1150 <print_hex+0x30>
mov    $0x2a,%al
jmp    1156 <print_hex+0x36>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@print_hex.conv = internal unnamed_addr constant [17 x i8] c"0123456789ABCDEF\00"
@.str = [11 x i8] c"%c%c (%c) \00"
define void @print_hex(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp slt i8 %2, 1
br i1 %3, label %28, label %4
4: ; preds = %1, %21
%5 = phi i64 [ %24, %21 ], [ 1, %1 ]
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
%8 = zext i8 %7 to i32
%9 = lshr i32 %8, 4
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds [17 x i8], [17 x i8]* @print_hex.conv, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = and i32 %8, 15
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds [17 x i8], [17 x i8]* @print_hex.conv, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = tail call i64 @isprint(i8 signext %7)
%18 = icmp eq i64 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %4
%20 = load i8, i8* %6
br label %21
21: ; preds = %4, %19
%22 = phi i8 [ %20, %19 ], [ 42, %4 ]
%23 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8 signext %12, i8 signext %16, i8 signext %22)
%24 = add nuw nsw i64 %5, 1
%25 = load i8, i8* %0
%26 = sext i8 %25 to i64
%27 = icmp slt i64 %5, %26
br i1 %27, label %4, label %28
28: ; preds = %21, %1
ret void
}