#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_print_str(char *);
int /*<<< orphan*/ uart_putc(char);
void uart_print_long(unsigned long ul) {
  int i;
  char c;
  uart_print_str("0x");
  for (i = 0; i < 8; i++) {
    c = (char)(ul >> ((7 - i) * 4)) & 0xf;
    if (c >= 0x0 && c <= 0x9)
      c += '0';
    else
      c += 'a' - 10;
    uart_putc(c);
  }
}


x86 assembly (clang, -O0):
<uart_print_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xecd(%rip),%rdi
call   1040 <uart_print_str@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x8,-0xc(%rbp)
jge    11b0 <uart_print_long+0x90>
mov    -0x8(%rbp),%rax
mov    $0x7,%ecx
sub    -0xc(%rbp),%ecx
shl    $0x2,%ecx
mov    %ecx,%ecx
shr    %cl,%rax
movsbl %al,%eax
and    $0xf,%eax
mov    %al,-0xd(%rbp)
movsbl -0xd(%rbp),%eax
cmp    $0x0,%eax
jl     118f <uart_print_long+0x6f>
movsbl -0xd(%rbp),%eax
cmp    $0x9,%eax
jg     118f <uart_print_long+0x6f>
movsbl -0xd(%rbp),%eax
add    $0x30,%eax
mov    %al,-0xd(%rbp)
jmp    1199 <uart_print_long+0x79>
movsbl -0xd(%rbp),%eax
add    $0x57,%eax
mov    %al,-0xd(%rbp)
movsbl -0xd(%rbp),%edi
call   1030 <uart_putc@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113f <uart_print_long+0x1f>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uart_print_long>:
push   %rbx
mov    %rdi,%rbx
lea    0xed5(%rip),%rdi
call   1040 <uart_print_str@plt>
mov    %ebx,%eax
shr    $0x1c,%eax
lea    0x30(%rax),%ecx
add    $0x57,%al
cmp    $0xa0000000,%ebx
movzbl %cl,%ecx
movzbl %al,%eax
cmovb  %ecx,%eax
movzbl %al,%edi
call   1030 <uart_putc@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_putc@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_putc@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_putc@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_putc@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_putc@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_putc@plt>
and    $0xf,%ebx
lea    0x30(%rbx),%eax
lea    0x57(%rbx),%ecx
cmp    $0xa,%ebx
movzbl %al,%eax
movzbl %cl,%ecx
cmovb  %eax,%ecx
movzbl %cl,%edi
pop    %rbx
jmp    1030 <uart_putc@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"0x\00"
define void @uart_print_long(i64 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i8
store i64 %0, i64* %2
%5 = call i32 @uart_print_str(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %6
6: ; preds = %40, %1
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 8
br i1 %8, label %9, label %43
9: ; preds = %6
%10 = load i64, i64* %2
%11 = load i32, i32* %3
%12 = sub nsw i32 7, %11
%13 = mul nsw i32 %12, 4
%14 = zext i32 %13 to i64
%15 = lshr i64 %10, %14
%16 = trunc i64 %15 to i8
%17 = sext i8 %16 to i32
%18 = and i32 %17, 15
%19 = trunc i32 %18 to i8
store i8 %19, i8* %4
%20 = load i8, i8* %4
%21 = sext i8 %20 to i32
%22 = icmp sge i32 %21, 0
br i1 %22, label %23, label %32
23: ; preds = %9
%24 = load i8, i8* %4
%25 = sext i8 %24 to i32
%26 = icmp sle i32 %25, 9
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = load i8, i8* %4
%29 = sext i8 %28 to i32
%30 = add nsw i32 %29, 48
%31 = trunc i32 %30 to i8
store i8 %31, i8* %4
br label %37
32: ; preds = %23, %9
%33 = load i8, i8* %4
%34 = sext i8 %33 to i32
%35 = add nsw i32 %34, 87
%36 = trunc i32 %35 to i8
store i8 %36, i8* %4
br label %37
37: ; preds = %32, %27
%38 = load i8, i8* %4
%39 = call i32 @uart_putc(i8 signext %38)
br label %40
40: ; preds = %37
%41 = load i32, i32* %3
%42 = add nsw i32 %41, 1
store i32 %42, i32* %3
br label %6
43: ; preds = %6
ret void
}

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