#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*/ printhexdigit(int /*<<< orphan*/, unsigned int);
void printhex(char *buffer, unsigned char *data, int len) {
  char *ptr;
  unsigned int c;
  ptr = buffer;
  while (len--) {
    c = *data++;
    printhexdigit(ptr++, c >> 4);
    printhexdigit(ptr++, c & 0xf);
  }
  *ptr = '\0';
}


x86 assembly (clang, -O0):
<printhex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     1191 <printhex+0x81>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    %eax,%edi
mov    -0x24(%rbp),%esi
shr    $0x4,%esi
call   1030 <printhexdigit@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    %eax,%edi
mov    -0x24(%rbp),%esi
and    $0xf,%esi
call   1030 <printhexdigit@plt>
jmp    112b <printhex+0x1b>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printhex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
test   %edx,%edx
je     115e <printhex+0x4e>
mov    %rsi,%r14
mov    %edx,%r12d
xor    %r13d,%r13d
mov    %r15d,%ebx
xchg   %ax,%ax
movzbl (%r14,%r13,1),%ebp
mov    %ebp,%esi
shr    $0x4,%esi
mov    %ebx,%edi
call   1030 <printhexdigit@plt>
add    $0x2,%r15
lea    0x1(%rbx),%edi
and    $0xf,%ebp
mov    %ebp,%esi
call   1030 <printhexdigit@plt>
add    $0x1,%r13
add    $0x2,%ebx
cmp    %r13d,%r12d
jne    1130 <printhex+0x20>
movb   $0x0,(%r15)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @printhex(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
store i8* %9, i8** %7
br label %10
10: ; preds = %14, %3
%11 = load i32, i32* %6
%12 = add nsw i32 %11, -1
store i32 %12, i32* %6
%13 = icmp ne i32 %11, 0
br i1 %13, label %14, label %31
14: ; preds = %10
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %5
%17 = load i8, i8* %15
%18 = zext i8 %17 to i32
store i32 %18, i32* %8
%19 = load i8*, i8** %7
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %7
%21 = ptrtoint i8* %19 to i32
%22 = load i32, i32* %8
%23 = lshr i32 %22, 4
%24 = call i32 @printhexdigit(i32 %21, i32 %23)
%25 = load i8*, i8** %7
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %7
%27 = ptrtoint i8* %25 to i32
%28 = load i32, i32* %8
%29 = and i32 %28, 15
%30 = call i32 @printhexdigit(i32 %27, i32 %29)
br label %10
31: ; preds = %10
%32 = load i8*, i8** %7
store i8 0, i8* %32
ret void
}

LLVM IR (-O2):
define void @printhex(i8* %0, i8* nocapture %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %24, label %5
5: ; preds = %3, %5
%6 = phi i8* [ %10, %5 ], [ %1, %3 ]
%7 = phi i8* [ %18, %5 ], [ %0, %3 ]
%8 = phi i32 [ %9, %5 ], [ %2, %3 ]
%9 = add nsw i32 %8, -1
%10 = getelementptr inbounds i8, i8* %6, i64 1
%11 = load i8, i8* %6
%12 = zext i8 %11 to i32
%13 = getelementptr inbounds i8, i8* %7, i64 1
%14 = ptrtoint i8* %7 to i64
%15 = trunc i64 %14 to i32
%16 = lshr i32 %12, 4
%17 = tail call i32 @printhexdigit(i32 %15, i32 %16)
%18 = getelementptr inbounds i8, i8* %7, i64 2
%19 = ptrtoint i8* %13 to i64
%20 = trunc i64 %19 to i32
%21 = and i32 %12, 15
%22 = tail call i32 @printhexdigit(i32 %20, i32 %21)
%23 = icmp eq i32 %9, 0
br i1 %23, label %24, label %5
24: ; preds = %5, %3
%25 = phi i8* [ %0, %3 ], [ %18, %5 ]
store i8 0, i8* %25
ret void
}