#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*/ put_char(size_t);
extern void print_hex(size_t x) {
  size_t digit;
  size_t pos = 32;
  do {
    pos -= 4;
    digit = (x >> pos) & 0x0F;
    digit += (digit > 9) ? ('A' - 10) : '0';
    put_char(digit);
  } while (pos > 0);
}


x86 assembly (clang, -O0):
<print_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x20,-0x18(%rbp)
mov    -0x18(%rbp),%rax
sub    $0x4,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
shr    %cl,%rax
and    $0xf,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdx
mov    $0x30,%eax
mov    $0x37,%ecx
cmp    $0x9,%rdx
cmova  %ecx,%eax
cltq
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <put_char@plt>
cmpq   $0x0,-0x18(%rbp)
ja     1124 <print_hex+0x14>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hex>:
push   %rbx
mov    %rdi,%rbx
mov    %ebx,%eax
shr    $0x1c,%eax
lea    0x30(%rax),%rdi
lea    0x37(%rax),%rcx
cmp    $0xa,%eax
cmovae %rcx,%rdi
call   1030 <put_char@plt>
mov    %ebx,%eax
shr    $0x18,%eax
and    $0xf,%eax
lea    0x30(%rax),%rdi
lea    0x37(%rax),%rcx
cmp    $0xa,%eax
cmovae %rcx,%rdi
call   1030 <put_char@plt>
mov    %ebx,%eax
shr    $0x14,%eax
and    $0xf,%eax
lea    0x30(%rax),%rdi
lea    0x37(%rax),%rcx
cmp    $0xa,%eax
cmovae %rcx,%rdi
call   1030 <put_char@plt>
mov    %ebx,%eax
shr    $0x10,%eax
and    $0xf,%eax
lea    0x30(%rax),%rdi
lea    0x37(%rax),%rcx
cmp    $0xa,%eax
cmovae %rcx,%rdi
call   1030 <put_char@plt>
mov    %ebx,%eax
shr    $0xc,%eax
and    $0xf,%eax
lea    0x30(%rax),%rdi
lea    0x37(%rax),%rcx
cmp    $0xa,%eax
cmovae %rcx,%rdi
call   1030 <put_char@plt>
mov    %ebx,%eax
shr    $0x8,%eax
and    $0xf,%eax
lea    0x30(%rax),%rdi
lea    0x37(%rax),%rcx
cmp    $0xa,%eax
cmovae %rcx,%rdi
call   1030 <put_char@plt>
mov    %ebx,%eax
shr    $0x4,%eax
and    $0xf,%eax
lea    0x30(%rax),%rdi
lea    0x37(%rax),%rcx
cmp    $0xa,%eax
cmovae %rcx,%rdi
call   1030 <put_char@plt>
and    $0xf,%ebx
lea    0x30(%rbx),%rdi
lea    0x37(%rbx),%rax
cmp    $0xa,%rbx
cmovae %rax,%rdi
pop    %rbx
jmp    1030 <put_char@plt>

LLVM IR (-O0):
define void @print_hex(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %2
store i64 32, i64* %4
br label %5
5: ; preds = %21, %1
%6 = load i64, i64* %4
%7 = sub i64 %6, 4
store i64 %7, i64* %4
%8 = load i64, i64* %2
%9 = load i64, i64* %4
%10 = lshr i64 %8, %9
%11 = and i64 %10, 15
store i64 %11, i64* %3
%12 = load i64, i64* %3
%13 = icmp ugt i64 %12, 9
%14 = zext i1 %13 to i64
%15 = select i1 %13, i32 55, i32 48
%16 = sext i32 %15 to i64
%17 = load i64, i64* %3
%18 = add i64 %17, %16
store i64 %18, i64* %3
%19 = load i64, i64* %3
%20 = call i32 @put_char(i64 %19)
br label %21
21: ; preds = %5
%22 = load i64, i64* %4
%23 = icmp ugt i64 %22, 0
br i1 %23, label %5, label %24
24: ; preds = %21
ret void
}

LLVM IR (-O2):
define void @print_hex(i64 %0) {
%2 = lshr i64 %0, 28
%3 = and i64 %2, 15
%4 = icmp ugt i64 %3, 9
%5 = select i1 %4, i64 55, i64 48
%6 = add nuw nsw i64 %5, %3
%7 = tail call i32 @put_char(i64 %6)
%8 = lshr i64 %0, 24
%9 = and i64 %8, 15
%10 = icmp ugt i64 %9, 9
%11 = select i1 %10, i64 55, i64 48
%12 = add nuw nsw i64 %11, %9
%13 = tail call i32 @put_char(i64 %12)
%14 = lshr i64 %0, 20
%15 = and i64 %14, 15
%16 = icmp ugt i64 %15, 9
%17 = select i1 %16, i64 55, i64 48
%18 = add nuw nsw i64 %17, %15
%19 = tail call i32 @put_char(i64 %18)
%20 = lshr i64 %0, 16
%21 = and i64 %20, 15
%22 = icmp ugt i64 %21, 9
%23 = select i1 %22, i64 55, i64 48
%24 = add nuw nsw i64 %23, %21
%25 = tail call i32 @put_char(i64 %24)
%26 = lshr i64 %0, 12
%27 = and i64 %26, 15
%28 = icmp ugt i64 %27, 9
%29 = select i1 %28, i64 55, i64 48
%30 = add nuw nsw i64 %29, %27
%31 = tail call i32 @put_char(i64 %30)
%32 = lshr i64 %0, 8
%33 = and i64 %32, 15
%34 = icmp ugt i64 %33, 9
%35 = select i1 %34, i64 55, i64 48
%36 = add nuw nsw i64 %35, %33
%37 = tail call i32 @put_char(i64 %36)
%38 = lshr i64 %0, 4
%39 = and i64 %38, 15
%40 = icmp ugt i64 %39, 9
%41 = select i1 %40, i64 55, i64 48
%42 = add nuw nsw i64 %41, %39
%43 = tail call i32 @put_char(i64 %42)
%44 = and i64 %0, 15
%45 = icmp ugt i64 %44, 9
%46 = select i1 %45, i64 55, i64 48
%47 = add nuw nsw i64 %46, %44
%48 = tail call i32 @put_char(i64 %47)
ret void
}