#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(char *);
extern void puthex(unsigned long data) {
  char hc[2];
  int i;
  hc[1] = '\0';
  for (i = 7; i >= 0; i--) {
    hc[0] = (char)((data & (0xF << (i * 4))) >> (i * 4));
    if (hc[0] < 0xA)
      hc[0] = hc[0] + 0x30;
    else if (hc[0] <= 0xF)
      hc[0] = hc[0] - 0xA + 0x41;
    else
      hc[0] = 'i';
    puts(hc);
  }
}


x86 assembly (clang, -O0):
<puthex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,-0x9(%rbp)
movl   $0x7,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     11b3 <puthex+0xa3>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
shl    $0x2,%ecx
mov    $0xf,%edx
shl    %cl,%edx
mov    %edx,%ecx
movslq %ecx,%rcx
and    %rcx,%rax
mov    -0x10(%rbp),%ecx
shl    $0x2,%ecx
mov    %ecx,%ecx
shr    %cl,%rax
mov    %al,-0xa(%rbp)
movsbl -0xa(%rbp),%eax
cmp    $0xa,%eax
jge    1174 <puthex+0x64>
movsbl -0xa(%rbp),%eax
add    $0x30,%eax
mov    %al,-0xa(%rbp)
jmp    119c <puthex+0x8c>
movsbl -0xa(%rbp),%eax
cmp    $0xf,%eax
jg     1193 <puthex+0x83>
movsbl -0xa(%rbp),%eax
sub    $0xa,%eax
add    $0x41,%eax
mov    %al,-0xa(%rbp)
jmp    1197 <puthex+0x87>
movb   $0x69,-0xa(%rbp)
jmp    119c <puthex+0x8c>
lea    -0xa(%rbp),%rdi
call   1030 <puts@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1127 <puthex+0x17>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<puthex>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
movb   $0x0,0xf(%rsp)
mov    $0x1c,%ebx
lea    0xe(%rsp),%r15
jmp    1148 <puthex+0x38>
nopl   (%rax)
add    $0x30,%al
mov    %al,0xe(%rsp)
mov    %r15,%rdi
call   1030 <puts@plt>
add    $0xfffffffffffffffc,%rbx
cmp    $0xfffffffffffffffc,%rbx
je     1177 <puthex+0x67>
mov    $0xf,%eax
mov    %ebx,%ecx
shl    %cl,%eax
cltq
and    %r14,%rax
shr    %cl,%rax
cmp    $0x9,%al
jle    1130 <puthex+0x20>
cmp    $0xf,%al
ja     1170 <puthex+0x60>
add    $0x37,%al
jmp    1132 <puthex+0x22>
cs nopw 0x0(%rax,%rax,1)
nop
movb   $0x69,0xe(%rsp)
jmp    1136 <puthex+0x26>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @puthex(i64 %0) {
%2 = alloca i64
%3 = alloca [2 x i8]
%4 = alloca i32
store i64 %0, i64* %2
%5 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
store i8 0, i8* %5
store i32 7, i32* %4
br label %6
6: ; preds = %52, %1
%7 = load i32, i32* %4
%8 = icmp sge i32 %7, 0
br i1 %8, label %9, label %55
9: ; preds = %6
%10 = load i64, i64* %2
%11 = load i32, i32* %4
%12 = mul nsw i32 %11, 4
%13 = shl i32 15, %12
%14 = sext i32 %13 to i64
%15 = and i64 %10, %14
%16 = load i32, i32* %4
%17 = mul nsw i32 %16, 4
%18 = zext i32 %17 to i64
%19 = lshr i64 %15, %18
%20 = trunc i64 %19 to i8
%21 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
store i8 %20, i8* %21
%22 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp slt i32 %24, 10
br i1 %25, label %26, label %33
26: ; preds = %9
%27 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = add nsw i32 %29, 48
%31 = trunc i32 %30 to i8
%32 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
store i8 %31, i8* %32
br label %49
33: ; preds = %9
%34 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp sle i32 %36, 15
br i1 %37, label %38, label %46
38: ; preds = %33
%39 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = sub nsw i32 %41, 10
%43 = add nsw i32 %42, 65
%44 = trunc i32 %43 to i8
%45 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
store i8 %44, i8* %45
br label %48
46: ; preds = %33
%47 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
store i8 105, i8* %47
br label %48
48: ; preds = %46, %38
br label %49
49: ; preds = %48, %26
%50 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%51 = call i32 @puts(i8* %50)
br label %52
52: ; preds = %49
%53 = load i32, i32* %4
%54 = add nsw i32 %53, -1
store i32 %54, i32* %4
br label %6
55: ; preds = %6
ret void
}

LLVM IR (-O2):
define void @puthex(i64 %0) {
%2 = alloca [2 x i8]
%3 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 1
store i8 0, i8* %4
br label %5
5: ; preds = %1, %22
%6 = phi i64 [ 7, %1 ], [ %24, %22 ]
%7 = shl nsw i64 %6, 2
%8 = trunc i64 %7 to i32
%9 = shl i32 15, %8
%10 = sext i32 %9 to i64
%11 = and i64 %10, %0
%12 = lshr i64 %11, %7
%13 = trunc i64 %12 to i8
%14 = icmp slt i8 %13, 10
br i1 %14, label %15, label %17
15: ; preds = %5
%16 = add nsw i8 %13, 48
store i8 %16, i8* %3
br label %22
17: ; preds = %5
%18 = icmp ult i8 %13, 16
br i1 %18, label %19, label %21
19: ; preds = %17
%20 = add nuw nsw i8 %13, 55
store i8 %20, i8* %3
br label %22
21: ; preds = %17
store i8 105, i8* %3
br label %22
22: ; preds = %19, %21, %15
%23 = call i32 @puts(i8* %3)
%24 = add nsw i64 %6, -1
%25 = icmp eq i64 %6, 0
br i1 %25, label %26, label %5
26: ; preds = %22
ret void
}