#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_putchar(char);
void uart_print_hex(unsigned long num) {
  long i;
  unsigned long j;
  for (i = 28; i >= 0; i -= 4) {
    j = (num >> i) & 0xf;
    if (j < 10)
      uart_putchar('0' + j);
    else
      uart_putchar('a' - 10 + j);
  }
}


x86 assembly (clang, -O0):
<uart_print_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x1c,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jl     1188 <uart_print_hex+0x78>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
shr    %cl,%rax
and    $0xf,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0xa,-0x18(%rbp)
jae    1162 <uart_print_hex+0x52>
mov    -0x18(%rbp),%rax
add    $0x30,%rax
movsbl %al,%edi
call   1030 <uart_putchar@plt>
jmp    1172 <uart_print_hex+0x62>
mov    -0x18(%rbp),%rax
add    $0x57,%rax
movsbl %al,%edi
call   1030 <uart_putchar@plt>
jmp    1177 <uart_print_hex+0x67>
mov    -0x10(%rbp),%rax
sub    $0x4,%rax
mov    %rax,-0x10(%rbp)
jmp    1124 <uart_print_hex+0x14>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uart_print_hex>:
push   %rbx
mov    %rdi,%rbx
mov    %ebx,%eax
shr    $0x1c,%eax
lea    0x30(%rax),%ecx
lea    0x57(%rax),%edx
cmp    $0xa,%eax
movzbl %cl,%eax
movzbl %dl,%ecx
cmovb  %eax,%ecx
movzbl %cl,%edi
call   1030 <uart_putchar@plt>
mov    %ebx,%eax
shr    $0x18,%eax
and    $0xf,%eax
lea    0x30(%rax),%ecx
lea    0x57(%rax),%edx
cmp    $0xa,%eax
movzbl %cl,%eax
movzbl %dl,%ecx
cmovb  %eax,%ecx
movzbl %cl,%edi
call   1030 <uart_putchar@plt>
mov    %ebx,%eax
shr    $0x14,%eax
and    $0xf,%eax
lea    0x30(%rax),%ecx
lea    0x57(%rax),%edx
cmp    $0xa,%eax
movzbl %cl,%eax
movzbl %dl,%ecx
cmovb  %eax,%ecx
movzbl %cl,%edi
call   1030 <uart_putchar@plt>
mov    %ebx,%eax
shr    $0x10,%eax
and    $0xf,%eax
lea    0x30(%rax),%ecx
lea    0x57(%rax),%edx
cmp    $0xa,%eax
movzbl %cl,%eax
movzbl %dl,%ecx
cmovb  %eax,%ecx
movzbl %cl,%edi
call   1030 <uart_putchar@plt>
mov    %ebx,%eax
shr    $0xc,%eax
and    $0xf,%eax
lea    0x30(%rax),%ecx
lea    0x57(%rax),%edx
cmp    $0xa,%eax
movzbl %cl,%eax
movzbl %dl,%ecx
cmovb  %eax,%ecx
movzbl %cl,%edi
call   1030 <uart_putchar@plt>
mov    %ebx,%eax
shr    $0x8,%eax
and    $0xf,%eax
lea    0x30(%rax),%ecx
lea    0x57(%rax),%edx
cmp    $0xa,%eax
movzbl %cl,%eax
movzbl %dl,%ecx
cmovb  %eax,%ecx
movzbl %cl,%edi
call   1030 <uart_putchar@plt>
mov    %ebx,%eax
shr    $0x4,%eax
and    $0xf,%eax
lea    0x30(%rax),%ecx
lea    0x57(%rax),%edx
cmp    $0xa,%eax
movzbl %cl,%eax
movzbl %dl,%ecx
cmovb  %eax,%ecx
movzbl %cl,%edi
call   1030 <uart_putchar@plt>
and    $0xf,%ebx
lea    0x30(%rbx),%eax
lea    0x57(%rbx),%ecx
cmp    $0xa,%rbx
movzbl %al,%eax
movzbl %cl,%ecx
cmovb  %eax,%ecx
movzbl %cl,%edi
pop    %rbx
jmp    1030 <uart_putchar@plt>

LLVM IR (-O0):
define void @uart_print_hex(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %2
store i64 28, i64* %3
br label %5
5: ; preds = %26, %1
%6 = load i64, i64* %3
%7 = icmp sge i64 %6, 0
br i1 %7, label %8, label %29
8: ; preds = %5
%9 = load i64, i64* %2
%10 = load i64, i64* %3
%11 = lshr i64 %9, %10
%12 = and i64 %11, 15
store i64 %12, i64* %4
%13 = load i64, i64* %4
%14 = icmp ult i64 %13, 10
br i1 %14, label %15, label %20
15: ; preds = %8
%16 = load i64, i64* %4
%17 = add i64 48, %16
%18 = trunc i64 %17 to i8
%19 = call i32 @uart_putchar(i8 signext %18)
br label %25
20: ; preds = %8
%21 = load i64, i64* %4
%22 = add i64 87, %21
%23 = trunc i64 %22 to i8
%24 = call i32 @uart_putchar(i8 signext %23)
br label %25
25: ; preds = %20, %15
br label %26
26: ; preds = %25
%27 = load i64, i64* %3
%28 = sub nsw i64 %27, 4
store i64 %28, i64* %3
br label %5
29: ; preds = %5
ret void
}

LLVM IR (-O2):
define void @uart_print_hex(i64 %0) {
%2 = lshr i64 %0, 28
%3 = and i64 %2, 15
%4 = icmp ult i64 %3, 10
%5 = trunc i64 %3 to i8
%6 = or i8 %5, 48
%7 = add nuw nsw i8 %5, 87
%8 = select i1 %4, i8 %6, i8 %7
%9 = tail call i32 @uart_putchar(i8 signext %8)
%10 = lshr i64 %0, 24
%11 = and i64 %10, 15
%12 = icmp ult i64 %11, 10
%13 = trunc i64 %11 to i8
%14 = or i8 %13, 48
%15 = trunc i64 %11 to i8
%16 = add nuw nsw i8 %15, 87
%17 = select i1 %12, i8 %14, i8 %16
%18 = tail call i32 @uart_putchar(i8 signext %17)
%19 = lshr i64 %0, 20
%20 = and i64 %19, 15
%21 = icmp ult i64 %20, 10
%22 = trunc i64 %20 to i8
%23 = or i8 %22, 48
%24 = trunc i64 %20 to i8
%25 = add nuw nsw i8 %24, 87
%26 = select i1 %21, i8 %23, i8 %25
%27 = tail call i32 @uart_putchar(i8 signext %26)
%28 = lshr i64 %0, 16
%29 = and i64 %28, 15
%30 = icmp ult i64 %29, 10
%31 = trunc i64 %29 to i8
%32 = or i8 %31, 48
%33 = trunc i64 %29 to i8
%34 = add nuw nsw i8 %33, 87
%35 = select i1 %30, i8 %32, i8 %34
%36 = tail call i32 @uart_putchar(i8 signext %35)
%37 = lshr i64 %0, 12
%38 = and i64 %37, 15
%39 = icmp ult i64 %38, 10
%40 = trunc i64 %38 to i8
%41 = or i8 %40, 48
%42 = trunc i64 %38 to i8
%43 = add nuw nsw i8 %42, 87
%44 = select i1 %39, i8 %41, i8 %43
%45 = tail call i32 @uart_putchar(i8 signext %44)
%46 = lshr i64 %0, 8
%47 = and i64 %46, 15
%48 = icmp ult i64 %47, 10
%49 = trunc i64 %47 to i8
%50 = or i8 %49, 48
%51 = trunc i64 %47 to i8
%52 = add nuw nsw i8 %51, 87
%53 = select i1 %48, i8 %50, i8 %52
%54 = tail call i32 @uart_putchar(i8 signext %53)
%55 = lshr i64 %0, 4
%56 = and i64 %55, 15
%57 = icmp ult i64 %56, 10
%58 = trunc i64 %56 to i8
%59 = or i8 %58, 48
%60 = trunc i64 %56 to i8
%61 = add nuw nsw i8 %60, 87
%62 = select i1 %57, i8 %59, i8 %61
%63 = tail call i32 @uart_putchar(i8 signext %62)
%64 = and i64 %0, 15
%65 = icmp ult i64 %64, 10
%66 = trunc i64 %64 to i8
%67 = or i8 %66, 48
%68 = trunc i64 %64 to i8
%69 = add nuw nsw i8 %68, 87
%70 = select i1 %65, i8 %67, i8 %69
%71 = tail call i32 @uart_putchar(i8 signext %70)
ret void
}