#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 *);
int /*<<< orphan*/ printhex1(unsigned char);
void printhex(unsigned char *str) {
  int i;
  for (i = 0; i < str[0]; i++) {
    printhex1(str[i] / 16);
    printhex1(str[i] % 16);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<printhex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
jge    118d <printhex+0x6d>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
movzbl %al,%edi
call   1040 <printhex1@plt>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %dl,%al
movzbl %al,%edi
call   1040 <printhex1@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1133 <printhex+0x13>
lea    0xe6c(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printhex>:
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%al
test   %al,%al
je     117a <printhex+0x5a>
mov    %rdi,%r14
shr    $0x4,%al
movzbl %al,%edi
call   1040 <printhex1@plt>
movzbl (%r14),%edi
and    $0xf,%edi
call   1040 <printhex1@plt>
cmpb   $0x2,(%r14)
jb     117a <printhex+0x5a>
mov    $0x1,%ebx
nop
movzbl (%r14,%rbx,1),%eax
shr    $0x4,%al
movzbl %al,%edi
call   1040 <printhex1@plt>
movzbl (%r14,%rbx,1),%edi
and    $0xf,%edi
call   1040 <printhex1@plt>
add    $0x1,%rbx
movzbl (%r14),%eax
cmp    %rax,%rbx
jb     1150 <printhex+0x30>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
define void @printhex(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
br label %4
4: ; preds = %30, %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 = zext i8 %8 to i32
%10 = icmp slt i32 %5, %9
br i1 %10, label %11, label %33
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 = zext i8 %16 to i32
%18 = sdiv i32 %17, 16
%19 = trunc i32 %18 to i8
%20 = call i32 @printhex1(i8 zeroext %19)
%21 = load i8*, i8** %2
%22 = load i32, i32* %3
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = srem i32 %26, 16
%28 = trunc i32 %27 to i8
%29 = call i32 @printhex1(i8 zeroext %28)
br label %30
30: ; preds = %11
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
br label %4
33: ; preds = %4
%34 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
ret void
}

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