#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 */
typedef int uint64_t;

/* Variables and functions */
int /*<<< orphan*/ printStr(char *);
void printhex(uint64_t x) {
  char str[17];
  int i;
  for (i = 0; i < 16; i++) {
    str[15 - i] = (x & 0xF) + ((x & 0xF) < 10 ? '0' : 'a' - 10);
    x >>= 4;
  }
  str[16] = 0;
  printStr(str);
}


x86 assembly (clang, -O0):
<printhex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x10,-0x24(%rbp)
jge    1171 <printhex+0x61>
mov    -0x4(%rbp),%eax
and    $0xf,%eax
mov    -0x4(%rbp),%esi
and    $0xf,%esi
mov    $0x57,%ecx
mov    $0x30,%edx
cmp    $0xa,%esi
cmovl  %edx,%ecx
add    %ecx,%eax
mov    %al,%cl
mov    $0xf,%eax
sub    -0x24(%rbp),%eax
cltq
mov    %cl,-0x20(%rbp,%rax,1)
mov    -0x4(%rbp),%eax
sar    $0x4,%eax
mov    %eax,-0x4(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1122 <printhex+0x12>
movb   $0x0,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <printStr@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printhex>:
sub    $0x18,%rsp
mov    %edi,%eax
shr    $0x4,%eax
mov    %edi,%ecx
shr    $0x8,%ecx
mov    %edi,%edx
shr    $0xc,%edx
movd   %edi,%xmm1
movd   %eax,%xmm0
punpckldq %xmm1,%xmm0
movd   %ecx,%xmm2
movd   %edx,%xmm4
punpckldq %xmm2,%xmm4
punpcklqdq %xmm0,%xmm4
pand   0xeb9(%rip),%xmm4
movdqa 0xec1(%rip),%xmm0
movdqa %xmm0,%xmm5
pcmpgtd %xmm4,%xmm5
movdqa 0xec1(%rip),%xmm2
movdqa %xmm5,%xmm6
pandn  %xmm2,%xmm6
movdqa 0xec1(%rip),%xmm3
pand   %xmm3,%xmm5
por    %xmm6,%xmm5
paddd  %xmm4,%xmm5
packuswb %xmm5,%xmm5
packuswb %xmm5,%xmm5
movd   %xmm5,0xc(%rsp)
mov    %edi,%eax
shr    $0x10,%eax
and    $0xf,%eax
lea    0x57(%rax),%ecx
lea    0x30(%rax),%edx
cmp    $0xa,%eax
cmovae %ecx,%edx
mov    %dl,0xb(%rsp)
mov    %edi,%eax
shr    $0x14,%eax
and    $0xf,%eax
lea    0x57(%rax),%ecx
lea    0x30(%rax),%edx
cmp    $0xa,%eax
cmovae %ecx,%edx
mov    %dl,0xa(%rsp)
mov    %edi,%eax
shr    $0x18,%eax
and    $0xf,%eax
lea    0x57(%rax),%ecx
lea    0x30(%rax),%edx
cmp    $0xa,%eax
cmovae %ecx,%edx
mov    %dl,0x9(%rsp)
mov    %edi,%eax
shr    $0x1c,%eax
lea    0x57(%rax),%ecx
or     $0x30,%eax
cmp    $0xa0000000,%edi
cmovae %ecx,%eax
mov    %al,0x8(%rsp)
pshufd $0x0,%xmm1,%xmm1
psrad  $0x1f,%xmm1
psrld  $0x1c,%xmm1
pcmpgtd %xmm1,%xmm0
movdqa %xmm0,%xmm4
pandn  %xmm2,%xmm4
pand   %xmm3,%xmm0
por    %xmm4,%xmm0
paddd  %xmm1,%xmm0
packuswb %xmm0,%xmm0
packuswb %xmm0,%xmm0
movd   %xmm0,0x4(%rsp)
movd   %xmm0,(%rsp)
movb   $0x0,0x10(%rsp)
mov    %rsp,%rdi
call   1030 <printStr@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
define void @printhex(i32 %0) {
%2 = alloca i32
%3 = alloca [17 x i8]
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
br label %5
5: ; preds = %24, %1
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 16
br i1 %7, label %8, label %27
8: ; preds = %5
%9 = load i32, i32* %2
%10 = and i32 %9, 15
%11 = load i32, i32* %2
%12 = and i32 %11, 15
%13 = icmp slt i32 %12, 10
%14 = zext i1 %13 to i64
%15 = select i1 %13, i32 48, i32 87
%16 = add nsw i32 %10, %15
%17 = trunc i32 %16 to i8
%18 = load i32, i32* %4
%19 = sub nsw i32 15, %18
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 %20
store i8 %17, i8* %21
%22 = load i32, i32* %2
%23 = ashr i32 %22, 4
store i32 %23, i32* %2
br label %24
24: ; preds = %8
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %5
27: ; preds = %5
%28 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 16
store i8 0, i8* %28
%29 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 0
%30 = call i32 @printStr(i8* %29)
ret void
}

LLVM IR (-O2):
define void @printhex(i32 %0) {
%2 = alloca [17 x i8]
%3 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
%4 = lshr i32 %0, 4
%5 = lshr i32 %0, 8
%6 = lshr i32 %0, 12
%7 = insertelement <4 x i32> poison, i32 %0, i64 3
%8 = insertelement <4 x i32> %7, i32 %6, i64 0
%9 = insertelement <4 x i32> %8, i32 %5, i64 1
%10 = insertelement <4 x i32> %9, i32 %4, i64 2
%11 = and <4 x i32> %10, <i32 15, i32 15, i32 15, i32 15>
%12 = icmp ult <4 x i32> %11, <i32 10, i32 10, i32 10, i32 10>
%13 = select <4 x i1> %12, <4 x i32> <i32 48, i32 48, i32 48, i32 48>, <4 x i32> <i32 87, i32 87, i32 87, i32 87>
%14 = add nuw nsw <4 x i32> %13, %11
%15 = trunc <4 x i32> %14 to <4 x i8>
%16 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 12
%17 = bitcast i8* %16 to <4 x i8>*
store <4 x i8> %15, <4 x i8>* %17
%18 = lshr i32 %0, 16
%19 = and i32 %18, 15
%20 = icmp ult i32 %19, 10
%21 = select i1 %20, i32 48, i32 87
%22 = add nuw nsw i32 %21, %19
%23 = trunc i32 %22 to i8
%24 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 11
store i8 %23, i8* %24
%25 = lshr i32 %0, 20
%26 = and i32 %25, 15
%27 = icmp ult i32 %26, 10
%28 = select i1 %27, i32 48, i32 87
%29 = add nuw nsw i32 %28, %26
%30 = trunc i32 %29 to i8
%31 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 10
store i8 %30, i8* %31
%32 = lshr i32 %0, 24
%33 = and i32 %32, 15
%34 = icmp ult i32 %33, 10
%35 = select i1 %34, i32 48, i32 87
%36 = add nuw nsw i32 %35, %33
%37 = trunc i32 %36 to i8
%38 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 9
store i8 %37, i8* %38
%39 = lshr i32 %0, 28
%40 = icmp ult i32 %0, -1610612736
%41 = select i1 %40, i32 48, i32 87
%42 = add nuw nsw i32 %41, %39
%43 = trunc i32 %42 to i8
%44 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 8
store i8 %43, i8* %44
%45 = ashr i32 %0, 31
%46 = insertelement <4 x i32> poison, i32 %45, i64 0
%47 = shufflevector <4 x i32> %46, <4 x i32> poison, <4 x i32> zeroinitializer
%48 = and <4 x i32> %47, <i32 15, i32 15, i32 15, i32 15>
%49 = icmp ult <4 x i32> %48, <i32 10, i32 10, i32 10, i32 10>
%50 = select <4 x i1> %49, <4 x i32> <i32 48, i32 48, i32 48, i32 48>, <4 x i32> <i32 87, i32 87, i32 87, i32 87>
%51 = add nuw nsw <4 x i32> %50, %48
%52 = trunc <4 x i32> %51 to <4 x i8>
%53 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 4
%54 = bitcast i8* %53 to <4 x i8>*
store <4 x i8> %52, <4 x i8>* %54
%55 = and <4 x i32> %47, <i32 15, i32 15, i32 15, i32 15>
%56 = icmp ult <4 x i32> %55, <i32 10, i32 10, i32 10, i32 10>
%57 = select <4 x i1> %56, <4 x i32> <i32 48, i32 48, i32 48, i32 48>, <4 x i32> <i32 87, i32 87, i32 87, i32 87>
%58 = add nuw nsw <4 x i32> %57, %55
%59 = trunc <4 x i32> %58 to <4 x i8>
%60 = bitcast [17 x i8]* %2 to <4 x i8>*
store <4 x i8> %59, <4 x i8>* %60
%61 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 16
store i8 0, i8* %61
%62 = call i32 @printStr(i8* %3)
ret void
}