#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*/ tty_puts(char *);
void tty_puthex(unsigned long val) {
  char hex[] = "0123456789ABCDEF";
  char str[11];
  char *s = &str[10];
  int i;
  *--s = '\0';
  for (i = 0; i < 8; i++) {
    *--s = hex[(val & 0x0F)];
    val >>= 4;
  }
  *--s = 'x';
  *--s = '0';
  tty_puts(s);
}


x86 assembly (clang, -O0):
<tty_puthex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    0xedd(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeda(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xed8(%rip),%al
mov    %al,-0x10(%rbp)
lea    -0x2b(%rbp),%rax
add    $0xa,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x38(%rbp)
movb   $0x0,-0x1(%rax)
movl   $0x0,-0x3c(%rbp)
cmpl   $0x8,-0x3c(%rbp)
jge    11a3 <tty_puthex+0x93>
mov    -0x8(%rbp),%rax
and    $0xf,%rax
mov    -0x20(%rbp,%rax,1),%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,-0x1(%rax)
mov    -0x8(%rbp),%rax
shr    $0x4,%rax
mov    %rax,-0x8(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1161 <tty_puthex+0x51>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x38(%rbp)
movb   $0x78,-0x1(%rax)
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x38(%rbp)
movb   $0x30,-0x1(%rax)
mov    -0x38(%rbp),%rdi
call   1030 <tty_puts@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tty_puthex>:
sub    $0x18,%rsp
movb   $0x0,0x16(%rsp)
mov    %edi,%ecx
and    $0xf,%ecx
lea    0xedb(%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   $0x78,0xd(%rsp)
lea    0xc(%rsp),%rdi
movb   $0x30,0xc(%rsp)
call   1030 <tty_puts@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
@__const.tty_puthex.hex = [17 x i8] c"0123456789ABCDEF\00"
define void @tty_puthex(i64 %0) {
%2 = alloca i64
%3 = alloca [17 x i8]
%4 = alloca [11 x i8]
%5 = alloca i8*
%6 = alloca i32
store i64 %0, i64* %2
%7 = bitcast [17 x i8]* %3 to i8*
%8 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 10
store i8* %8, i8** %5
%9 = load i8*, i8** %5
%10 = getelementptr inbounds i8, i8* %9, i32 -1
store i8* %10, i8** %5
store i8 0, i8* %10
store i32 0, i32* %6
br label %11
11: ; preds = %23, %1
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 8
br i1 %13, label %14, label %26
14: ; preds = %11
%15 = load i64, i64* %2
%16 = and i64 %15, 15
%17 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i32 -1
store i8* %20, i8** %5
store i8 %18, i8* %20
%21 = load i64, i64* %2
%22 = lshr i64 %21, 4
store i64 %22, i64* %2
br label %23
23: ; preds = %14
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 1
store i32 %25, i32* %6
br label %11
26: ; preds = %11
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i32 -1
store i8* %28, i8** %5
store i8 120, i8* %28
%29 = load i8*, i8** %5
%30 = getelementptr inbounds i8, i8* %29, i32 -1
store i8* %30, i8** %5
store i8 48, i8* %30
%31 = load i8*, i8** %5
%32 = call i32 @tty_puts(i8* %31)
ret void
}

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