#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*/ uart_putc(int /*<<< orphan*/);
int /*<<< orphan*/ uart_puts(char *);
void uart_putx(unsigned long long x) {
  char tmp[32];
  unsigned int i;
  unsigned int j;
  if (x == 0) {
    uart_putc('0');
  } else {
    tmp[31] = 0;
    i = 30;
    while (x > 0) {
      j = x % 16;
      if (j < 10)
        tmp[i] = '0' + j;
      else
        tmp[i] = 'a' + j - 10;
      x /= 16;
      i--;
    }
    uart_puts(&(tmp[i + 1]));
  }
}


x86 assembly (clang, -O0):
<uart_putx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1146 <uart_putx+0x26>
mov    $0x30,%edi
call   1030 <uart_putc@plt>
jmp    11c5 <uart_putx+0xa5>
movb   $0x0,-0x11(%rbp)
movl   $0x1e,-0x34(%rbp)
cmpq   $0x0,-0x8(%rbp)
jbe    11b1 <uart_putx+0x91>
mov    -0x8(%rbp),%rax
and    $0xf,%rax
mov    %eax,-0x38(%rbp)
cmpl   $0xa,-0x38(%rbp)
jae    1185 <uart_putx+0x65>
mov    -0x38(%rbp),%eax
add    $0x30,%eax
mov    %al,%cl
mov    -0x34(%rbp),%eax
mov    %cl,-0x30(%rbp,%rax,1)
jmp    1197 <uart_putx+0x77>
mov    -0x38(%rbp),%eax
add    $0x61,%eax
sub    $0xa,%eax
mov    %al,%cl
mov    -0x34(%rbp),%eax
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0x8(%rbp),%rax
shr    $0x4,%rax
mov    %rax,-0x8(%rbp)
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
jmp    1151 <uart_putx+0x31>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,%eax
lea    -0x30(%rbp),%rdi
add    %rax,%rdi
call   1040 <uart_puts@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uart_putx>:
test   %rdi,%rdi
je     117e <uart_putx+0x5e>
sub    $0x28,%rsp
movb   $0x0,0x1f(%rsp)
mov    $0x1f,%eax
mov    %rdi,%rcx
cs nopw 0x0(%rax,%rax,1)
add    $0xffffffff,%eax
mov    %edi,%edx
and    $0xf,%edx
lea    0x57(%rdx),%r8d
lea    0x30(%rdx),%esi
cmp    $0xa,%edx
movzbl %sil,%edx
movzbl %r8b,%esi
cmovb  %edx,%esi
mov    %sil,(%rsp,%rax,1)
shr    $0x4,%rcx
cmp    $0xf,%rdi
mov    %rcx,%rdi
ja     1140 <uart_putx+0x20>
mov    %eax,%eax
lea    (%rsp,%rax,1),%rdi
call   1040 <uart_puts@plt>
add    $0x28,%rsp
ret
mov    $0x30,%edi
jmp    1030 <uart_putc@plt>

LLVM IR (-O0):
define void @uart_putx(i64 %0) {
%2 = alloca i64
%3 = alloca [32 x i8]
%4 = alloca i32
%5 = alloca i32
store i64 %0, i64* %2
%6 = load i64, i64* %2
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @uart_putc(i32 48)
br label %47
10: ; preds = %1
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 31
store i8 0, i8* %11
store i32 30, i32* %4
br label %12
12: ; preds = %36, %10
%13 = load i64, i64* %2
%14 = icmp ugt i64 %13, 0
br i1 %14, label %15, label %41
15: ; preds = %12
%16 = load i64, i64* %2
%17 = urem i64 %16, 16
%18 = trunc i64 %17 to i32
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = icmp ult i32 %19, 10
br i1 %20, label %21, label %28
21: ; preds = %15
%22 = load i32, i32* %5
%23 = add i32 48, %22
%24 = trunc i32 %23 to i8
%25 = load i32, i32* %4
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 %26
store i8 %24, i8* %27
br label %36
28: ; preds = %15
%29 = load i32, i32* %5
%30 = add i32 97, %29
%31 = sub i32 %30, 10
%32 = trunc i32 %31 to i8
%33 = load i32, i32* %4
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 %34
store i8 %32, i8* %35
br label %36
36: ; preds = %28, %21
%37 = load i64, i64* %2
%38 = udiv i64 %37, 16
store i64 %38, i64* %2
%39 = load i32, i32* %4
%40 = add i32 %39, -1
store i32 %40, i32* %4
br label %12
41: ; preds = %12
%42 = load i32, i32* %4
%43 = add i32 %42, 1
%44 = zext i32 %43 to i64
%45 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 %44
%46 = call i32 @uart_puts(i8* %45)
br label %47
47: ; preds = %41, %8
ret void
}

LLVM IR (-O2):
define void @uart_putx(i64 %0) {
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%4 = icmp eq i64 %0, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @uart_putc(i32 48)
br label %28
7: ; preds = %1
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 31
store i8 0, i8* %8
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ %0, %7 ], [ %21, %9 ]
%11 = phi i32 [ 30, %7 ], [ %22, %9 ]
%12 = trunc i64 %10 to i32
%13 = and i32 %12, 15
%14 = icmp ult i32 %13, 10
%15 = trunc i32 %13 to i8
%16 = add nuw nsw i8 %15, 87
%17 = or i8 %15, 48
%18 = select i1 %14, i8 %17, i8 %16
%19 = zext i32 %11 to i64
%20 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 %19
store i8 %18, i8* %20
%21 = lshr i64 %10, 4
%22 = add nsw i32 %11, -1
%23 = icmp ult i64 %10, 16
br i1 %23, label %24, label %9
24: ; preds = %9
%25 = zext i32 %11 to i64
%26 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 %25
%27 = call i32 @uart_puts(i8* %26)
br label %28
28: ; preds = %24, %5
ret void
}