#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 *, char, char);
void print_hexbuf(const unsigned char *buffer, long len) {
  char hexdigits[] = "0123456789abcdef";
  for (int i = 0; i < len; i++) {
    int nib1 = buffer[i] >> 4;
    int nib2 = buffer[i] & 15;
    printf("%c%c", hexdigits[nib1], hexdigits[nib2]);
  }
}


x86 assembly (clang, -O0):
<print_hexbuf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xed9(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xed6(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xed4(%rip),%al
mov    %al,-0x20(%rbp)
movl   $0x0,-0x34(%rbp)
movslq -0x34(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    11a6 <print_hexbuf+0x96>
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
sar    $0x4,%eax
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
and    $0xf,%eax
mov    %eax,-0x3c(%rbp)
movslq -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,1),%cl
movslq -0x3c(%rbp),%rax
lea    0xe86(%rip),%rdi
movsbl %cl,%esi
movsbl -0x30(%rbp,%rax,1),%edx
call   1030 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1146 <print_hexbuf+0x36>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hexbuf>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rsi,%rsi
jle    116a <print_hexbuf+0x5a>
mov    %rsi,%r12
mov    %rdi,%r14
xor    %ebx,%ebx
lea    0xed3(%rip),%r13
lea    0xedd(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%r14,%rbx,1),%eax
mov    %rax,%rcx
shr    $0x4,%rcx
and    $0xf,%eax
movsbl (%rcx,%r13,1),%esi
movsbl (%rax,%r13,1),%edx
mov    %r15,%rdi
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1140 <print_hexbuf+0x30>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.print_hexbuf.hexdigits = [17 x i8] c"0123456789abcdef\00"
@.str = [5 x i8] c"%c%c\00"
define void @print_hexbuf(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca [17 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
%9 = bitcast [17 x i8]* %5 to i8*
store i32 0, i32* %6
br label %10
10: ; preds = %39, %2
%11 = load i32, i32* %6
%12 = sext i32 %11 to i64
%13 = load i64, i64* %4
%14 = icmp slt i64 %12, %13
br i1 %14, label %15, label %42
15: ; preds = %10
%16 = load i8*, i8** %3
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = ashr i32 %21, 4
store i32 %22, i32* %7
%23 = load i8*, i8** %3
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = and i32 %28, 15
store i32 %29, i32* %8
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %33, i8 signext %37)
br label %39
39: ; preds = %15
%40 = load i32, i32* %6
%41 = add nsw i32 %40, 1
store i32 %41, i32* %6
br label %10
42: ; preds = %10
ret void
}

LLVM IR (-O2):
@__const.print_hexbuf.hexdigits = [17 x i8] c"0123456789abcdef\00"
@.str = [5 x i8] c"%c%c\00"
define void @print_hexbuf(i8* nocapture %0, i64 %1) {
%3 = icmp sgt i64 %1, 0
br i1 %3, label %5, label %4
4: ; preds = %5, %2
ret void
5: ; preds = %2, %5
%6 = phi i64 [ %19, %5 ], [ 0, %2 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = zext i8 %8 to i32
%10 = lshr i32 %9, 4
%11 = and i32 %9, 15
%12 = zext i32 %10 to i64
%13 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.print_hexbuf.hexdigits, i64 0, i64 %12
%14 = load i8, i8* %13
%15 = zext i32 %11 to i64
%16 = getelementptr inbounds [17 x i8], [17 x i8]* @__const.print_hexbuf.hexdigits, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %14, i8 signext %17)
%19 = add nuw nsw i64 %6, 1
%20 = icmp eq i64 %19, %1
br i1 %20, label %4, label %5
}