#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*/ sprintf(unsigned char *, char *, char const, char const);
const char *print_hex(const unsigned char *buf, unsigned int len) {
  const char d2h[] = "0123456789ABCDEF";
  int i = 0;
  static unsigned char priv_buf[1024];
  for (i = 0; i < len && i < 1024 / 3; i++) {
    sprintf(priv_buf + 3 * i, "%c%c ", d2h[(int)buf[i] / 16],
            d2h[(int)buf[i] % 16]);
  }
  if (len == 0)
    priv_buf[0] = '\0';
  return priv_buf;
}


x86 assembly (clang, -O0):
<print_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0xeda(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xed7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xed5(%rip),%al
mov    %al,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%ecx
xor    %eax,%eax
cmp    -0xc(%rbp),%ecx
mov    %al,-0x25(%rbp)
jae    116a <print_hex+0x5a>
cmpl   $0x155,-0x24(%rbp)
setl   %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    117a <print_hex+0x6a>
jmp    11dd <print_hex+0xcd>
imul   $0x3,-0x24(%rbp),%eax
cltq
lea    0x2eb9(%rip),%rdi
add    %rax,%rdi
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cltq
mov    -0x20(%rbp,%rax,1),%cl
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rdx
movzbl (%rax,%rdx,1),%eax
mov    $0x10,%esi
cltd
idiv   %esi
movslq %edx,%rax
lea    0xe4f(%rip),%rsi
movsbl %cl,%edx
movsbl -0x20(%rbp,%rax,1),%ecx
call   1030 <sprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114c <print_hex+0x3c>
cmpl   $0x0,-0xc(%rbp)
jne    11ee <print_hex+0xde>
movb   $0x0,0x2e52(%rip)
lea    0x2e4b(%rip),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
je     1197 <print_hex+0x87>
mov    %rdi,%r15
mov    %rsi,(%rsp)
lea    -0x1(%rsi),%eax
cmp    $0x154,%eax
mov    $0x154,%r13d
cmovb  %eax,%r13d
add    $0x1,%r13d
lea    0x2efd(%rip),%rbx
xor    %ebp,%ebp
lea    0xeb4(%rip),%r14
lea    0xebe(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%r15,%rbp,1),%eax
mov    %rax,%rcx
shr    $0x4,%rcx
movsbl (%rcx,%r14,1),%edx
and    $0xf,%eax
movsbl (%rax,%r14,1),%ecx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <sprintf@plt>
add    $0x1,%rbp
add    $0x3,%rbx
cmp    %rbp,%r13
jne    1160 <print_hex+0x50>
cmpl   $0x0,(%rsp)
jne    119e <print_hex+0x8e>
movb   $0x0,0x2ea2(%rip)
lea    0x2e9b(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.print_hex.d2h = [17 x i8] c"0123456789ABCDEF\00"
@print_hex.priv_buf = internal global [1024 x i8] zeroinitializer
@.str = [6 x i8] c"%c%c \00"
define i8* @print_hex(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [17 x i8]
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = bitcast [17 x i8]* %5 to i8*
store i32 0, i32* %6
store i32 0, i32* %6
br label %8
8: ; preds = %43, %2
%9 = load i32, i32* %6
%10 = load i32, i32* %4
%11 = icmp ult i32 %9, %10
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 341
br label %15
15: ; preds = %12, %8
%16 = phi i1 [ false, %8 ], [ %14, %12 ]
br i1 %16, label %17, label %46
17: ; preds = %15
%18 = load i32, i32* %6
%19 = mul nsw i32 3, %18
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @print_hex.priv_buf, i64 0, i64 0), i64 %20
%22 = load i8*, i8** %3
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = sdiv i32 %27, 16
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = load i8*, i8** %3
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = srem i32 %37, 16
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 signext %31, i8 signext %41)
br label %43
43: ; preds = %17
%44 = load i32, i32* %6
%45 = add nsw i32 %44, 1
store i32 %45, i32* %6
br label %8
46: ; preds = %15
%47 = load i32, i32* %4
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %46
store i8 0, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @print_hex.priv_buf, i64 0, i64 0)
br label %50
50: ; preds = %49, %46
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @print_hex.priv_buf, i64 0, i64 0)
}

LLVM IR (-O2):
@__const.print_hex.d2h = [17 x i8] c"0123456789ABCDEF\00"
@print_hex.priv_buf = internal global [1024 x i8] zeroinitializer
@.str = [6 x i8] c"%c%c \00"
define i8* @print_hex(i8* nocapture %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %28, label %4
4: ; preds = %2
%5 = add i32 %1, -1
%6 = call i32 @llvm.umin.i32(i32 %5, i32 340)
%7 = add nuw nsw i32 %6, 1
%8 = zext i32 %7 to i64
br label %9
9: ; preds = %4, %9
%10 = phi i64 [ 0, %4 ], [ %25, %9 ]
%11 = mul nuw nsw i64 %10, 3
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* @print_hex.priv_buf, i64 0, i64 %11
%13 = getelementptr inbounds i8, i8* %0, i64 %10
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = lshr i32 %15, 4
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.print_hex.d2h, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = and i32 %15, 15
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.print_hex.d2h, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = tail call i32 @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 signext %19, i8 signext %23)
%25 = add nuw nsw i64 %10, 1
%26 = icmp eq i64 %25, %8
br i1 %26, label %27, label %9
27: ; preds = %9
br i1 %3, label %28, label %29
28: ; preds = %2, %27
store i8 0, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @print_hex.priv_buf, i64 0, i64 0)
br label %29
29: ; preds = %28, %27
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @print_hex.priv_buf, i64 0, i64 0)
}