#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*/ videoram_put(char *);
void videoram_put_hex(unsigned long v) {
  char s[2 + 2 * sizeof v + 1];
  char *p = &s[sizeof s];
  *--p = 0;
  do {
    char c = v % 16;
    v /= 16;
    *--p = c + (c < 10 ? '0' : 'A' - 10);
  } while (v > 0);
  *--p = 'x';
  *--p = '0';
  videoram_put(p);
}


x86 assembly (clang, -O0):
<videoram_put_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x20(%rbp),%rax
add    $0x13,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x0,-0x1(%rax)
mov    -0x8(%rbp),%rax
and    $0xf,%rax
mov    %al,-0x29(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x4,%rax
mov    %rax,-0x8(%rbp)
movsbl -0x29(%rbp),%eax
movsbl -0x29(%rbp),%esi
mov    $0x37,%ecx
mov    $0x30,%edx
cmp    $0xa,%esi
cmovl  %edx,%ecx
add    %ecx,%eax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,-0x1(%rax)
cmpq   $0x0,-0x8(%rbp)
ja     113b <videoram_put_hex+0x2b>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x78,-0x1(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x30,-0x1(%rax)
mov    -0x28(%rbp),%rdi
call   1030 <videoram_put@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<videoram_put_hex>:
sub    $0x18,%rsp
mov    %rdi,%rax
movb   $0x0,0x12(%rsp)
lea    0x10(%rsp),%rdi
mov    %rax,%rcx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %eax,%edx
and    $0xf,%edx
shr    $0x4,%rcx
lea    0x37(%rdx),%r8d
lea    0x30(%rdx),%esi
cmp    $0xa,%edx
cmovae %r8d,%esi
mov    %sil,0x1(%rdi)
add    $0xffffffffffffffff,%rdi
cmp    $0xf,%rax
mov    %rcx,%rax
ja     1130 <videoram_put_hex+0x20>
movw   $0x7830,(%rdi)
call   1030 <videoram_put@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
define void @videoram_put_hex(i64 %0) {
%2 = alloca i64
%3 = alloca [19 x i8]
%4 = alloca i8*
%5 = alloca i8
store i64 %0, i64* %2
%6 = getelementptr inbounds [19 x i8], [19 x i8]* %3, i64 0, i64 19
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = getelementptr inbounds i8, i8* %7, i32 -1
store i8* %8, i8** %4
store i8 0, i8* %8
br label %9
9: ; preds = %26, %1
%10 = load i64, i64* %2
%11 = urem i64 %10, 16
%12 = trunc i64 %11 to i8
store i8 %12, i8* %5
%13 = load i64, i64* %2
%14 = udiv i64 %13, 16
store i64 %14, i64* %2
%15 = load i8, i8* %5
%16 = sext i8 %15 to i32
%17 = load i8, i8* %5
%18 = sext i8 %17 to i32
%19 = icmp slt i32 %18, 10
%20 = zext i1 %19 to i64
%21 = select i1 %19, i32 48, i32 55
%22 = add nsw i32 %16, %21
%23 = trunc i32 %22 to i8
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i32 -1
store i8* %25, i8** %4
store i8 %23, i8* %25
br label %26
26: ; preds = %9
%27 = load i64, i64* %2
%28 = icmp ugt i64 %27, 0
br i1 %28, label %9, label %29
29: ; preds = %26
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i32 -1
store i8* %31, i8** %4
store i8 120, i8* %31
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i32 -1
store i8* %33, i8** %4
store i8 48, i8* %33
%34 = load i8*, i8** %4
%35 = call i32 @videoram_put(i8* %34)
ret void
}

LLVM IR (-O2):
define void @videoram_put_hex(i64 %0) {
%2 = alloca [19 x i8]
%3 = getelementptr inbounds [19 x i8], [19 x i8]* %2, i64 0, i64 0
%4 = getelementptr inbounds [19 x i8], [19 x i8]* %2, i64 0, i64 18
store i8 0, i8* %4
br label %5
5: ; preds = %5, %1
%6 = phi i8* [ %4, %1 ], [ %15, %5 ]
%7 = phi i64 [ %0, %1 ], [ %10, %5 ]
%8 = trunc i64 %7 to i32
%9 = and i32 %8, 15
%10 = lshr i64 %7, 4
%11 = icmp ult i32 %9, 10
%12 = select i1 %11, i32 48, i32 55
%13 = add nuw nsw i32 %12, %9
%14 = trunc i32 %13 to i8
%15 = getelementptr inbounds i8, i8* %6, i64 -1
store i8 %14, i8* %15
%16 = icmp ult i64 %7, 16
br i1 %16, label %17, label %5
17: ; preds = %5
%18 = getelementptr inbounds i8, i8* %6, i64 -2
store i8 120, i8* %18
%19 = getelementptr inbounds i8, i8* %6, i64 -3
store i8 48, i8* %19
%20 = call i32 @videoram_put(i8* %19)
ret void
}