#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*/ puts(unsigned char *);
void puthex(unsigned long val) {
  unsigned char buf[10];
  int i;
  for (i = 7; i >= 0; i--) {
    buf[i] = "0123456789ABCDEF"[val & 0x0F];
    val >>= 4;
  }
  buf[8] = '\0';
  puts(buf);
}


x86 assembly (clang, -O0):
<puthex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x7,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     1161 <puthex+0x51>
mov    -0x8(%rbp),%rcx
and    $0xf,%rcx
lea    0xec4(%rip),%rax
mov    (%rax,%rcx,1),%cl
movslq -0x18(%rbp),%rax
mov    %cl,-0x12(%rbp,%rax,1)
mov    -0x8(%rbp),%rax
shr    $0x4,%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1123 <puthex+0x13>
movb   $0x0,-0xa(%rbp)
lea    -0x12(%rbp),%rdi
call   1030 <puts@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<puthex>:
sub    $0x18,%rsp
mov    %edi,%ecx
and    $0xf,%ecx
lea    0xee0(%rip),%rax
mov    (%rcx,%rax,1),%cl
mov    %cl,0x15(%rsp)
mov    %edi,%ecx
shr    $0x4,%ecx
and    $0xf,%ecx
mov    (%rcx,%rax,1),%cl
mov    %cl,0x14(%rsp)
mov    %edi,%ecx
shr    $0x8,%ecx
and    $0xf,%ecx
mov    (%rcx,%rax,1),%cl
mov    %cl,0x13(%rsp)
mov    %edi,%ecx
shr    $0xc,%ecx
and    $0xf,%ecx
mov    (%rcx,%rax,1),%cl
mov    %cl,0x12(%rsp)
mov    %edi,%ecx
shr    $0x10,%ecx
and    $0xf,%ecx
mov    (%rcx,%rax,1),%cl
mov    %cl,0x11(%rsp)
mov    %edi,%ecx
shr    $0x14,%ecx
and    $0xf,%ecx
mov    (%rcx,%rax,1),%cl
mov    %cl,0x10(%rsp)
mov    %edi,%ecx
shr    $0x18,%ecx
and    $0xf,%ecx
mov    (%rcx,%rax,1),%cl
mov    %cl,0xf(%rsp)
shr    $0x1c,%edi
mov    (%rdi,%rax,1),%al
mov    %al,0xe(%rsp)
movb   $0x0,0x16(%rsp)
lea    0xe(%rsp),%rdi
call   1030 <puts@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"0123456789ABCDEF\00"
define void @puthex(i64 %0) {
%2 = alloca i64
%3 = alloca [10 x i8]
%4 = alloca i32
store i64 %0, i64* %2
store i32 7, i32* %4
br label %5
5: ; preds = %18, %1
%6 = load i32, i32* %4
%7 = icmp sge i32 %6, 0
br i1 %7, label %8, label %21
8: ; preds = %5
%9 = load i64, i64* %2
%10 = and i64 %9, 15
%11 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = load i32, i32* %4
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %14
store i8 %12, i8* %15
%16 = load i64, i64* %2
%17 = lshr i64 %16, 4
store i64 %17, i64* %2
br label %18
18: ; preds = %8
%19 = load i32, i32* %4
%20 = add nsw i32 %19, -1
store i32 %20, i32* %4
br label %5
21: ; preds = %5
%22 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 8
store i8 0, i8* %22
%23 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%24 = call i32 @puts(i8* %23)
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"0123456789ABCDEF\00"
define void @puthex(i64 %0) {
%2 = alloca [10 x i8]
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%4 = and i64 %0, 15
%5 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %4
%6 = load i8, i8* %5
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 7
store i8 %6, i8* %7
%8 = lshr i64 %0, 4
%9 = and i64 %8, 15
%10 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 6
store i8 %11, i8* %12
%13 = lshr i64 %0, 8
%14 = and i64 %13, 15
%15 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 5
store i8 %16, i8* %17
%18 = lshr i64 %0, 12
%19 = and i64 %18, 15
%20 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 4
store i8 %21, i8* %22
%23 = lshr i64 %0, 16
%24 = and i64 %23, 15
%25 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 3
store i8 %26, i8* %27
%28 = lshr i64 %0, 20
%29 = and i64 %28, 15
%30 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 2
store i8 %31, i8* %32
%33 = lshr i64 %0, 24
%34 = and i64 %33, 15
%35 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 1
store i8 %36, i8* %37
%38 = lshr i64 %0, 28
%39 = and i64 %38, 15
%40 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %39
%41 = load i8, i8* %40
store i8 %41, i8* %3
%42 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 8
store i8 0, i8* %42
%43 = call i32 @puts(i8* %3)
ret void
}