#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*/ putc(char);
void puth(unsigned long val) {
  int i;
  char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7',
                '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
  putc('0');
  putc('x');
  for (i = 0; i < 8; i++) {
    putc(hex[(val >> ((7 - i) * 4)) & 0x0f]);
  }
}


x86 assembly (clang, -O0):
<puth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0xedd(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeda(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    $0x30,%edi
call   1030 <putc@plt>
mov    $0x78,%edi
call   1030 <putc@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x8,-0xc(%rbp)
jge    1187 <puth+0x77>
mov    -0x8(%rbp),%rax
mov    $0x7,%ecx
sub    -0xc(%rbp),%ecx
shl    $0x2,%ecx
mov    %ecx,%ecx
shr    %cl,%rax
and    $0xf,%rax
movsbl -0x20(%rbp,%rax,1),%edi
call   1030 <putc@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114d <puth+0x3d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<puth>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x30,%edi
call   1030 <putc@plt>
mov    $0x78,%edi
call   1030 <putc@plt>
mov    %ebx,%eax
shr    $0x1c,%eax
lea    0xec9(%rip),%r14
movsbl (%rax,%r14,1),%edi
call   1030 <putc@plt>
mov    %ebx,%eax
shr    $0x18,%eax
and    $0xf,%eax
movsbl (%rax,%r14,1),%edi
call   1030 <putc@plt>
mov    %ebx,%eax
shr    $0x14,%eax
and    $0xf,%eax
movsbl (%rax,%r14,1),%edi
call   1030 <putc@plt>
mov    %ebx,%eax
shr    $0x10,%eax
and    $0xf,%eax
movsbl (%rax,%r14,1),%edi
call   1030 <putc@plt>
mov    %ebx,%eax
shr    $0xc,%eax
and    $0xf,%eax
movsbl (%rax,%r14,1),%edi
call   1030 <putc@plt>
mov    %ebx,%eax
shr    $0x8,%eax
and    $0xf,%eax
movsbl (%rax,%r14,1),%edi
call   1030 <putc@plt>
mov    %ebx,%eax
shr    $0x4,%eax
and    $0xf,%eax
movsbl (%rax,%r14,1),%edi
call   1030 <putc@plt>
and    $0xf,%ebx
movsbl (%rbx,%r14,1),%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <putc@plt>

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

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