#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_putd(unsigned long long d) {
  char tmp[32];
  unsigned int i;
  if (d == 0) {
    uart_putc('0');
  } else {
    tmp[31] = 0;
    i = 30;
    while (d > 0) {
      tmp[i] = '0' + (d % 10);
      d /= 10;
      i--;
    }
    uart_puts(&(tmp[i + 1]));
  }
}


x86 assembly (clang, -O0):
<uart_putd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1146 <uart_putd+0x26>
mov    $0x30,%edi
call   1030 <uart_putc@plt>
jmp    11ab <uart_putd+0x8b>
movb   $0x0,-0x11(%rbp)
movl   $0x1e,-0x34(%rbp)
cmpq   $0x0,-0x8(%rbp)
jbe    1197 <uart_putd+0x77>
mov    -0x8(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
add    $0x30,%rdx
mov    %dl,%cl
mov    -0x34(%rbp),%eax
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0x8(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x8(%rbp)
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
jmp    1151 <uart_putd+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_putd>:
test   %rdi,%rdi
je     1178 <uart_putd+0x58>
sub    $0x28,%rsp
movb   $0x0,0x1f(%rsp)
mov    $0x1f,%ecx
movabs $0xcccccccccccccccd,%r8
cc cc cc
nopl   (%rax)
mov    %rdi,%rax
mul    %r8
add    $0xffffffff,%ecx
shr    $0x3,%rdx
lea    (%rdx,%rdx,1),%eax
lea    (%rax,%rax,4),%eax
mov    %edi,%esi
sub    %eax,%esi
or     $0x30,%sil
mov    %sil,(%rsp,%rcx,1)
cmp    $0x9,%rdi
mov    %rdx,%rdi
ja     1140 <uart_putd+0x20>
mov    %ecx,%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_putd(i64 %0) {
%2 = alloca i64
%3 = alloca [32 x i8]
%4 = alloca i32
store i64 %0, i64* %2
%5 = load i64, i64* %2
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @uart_putc(i32 48)
br label %32
9: ; preds = %1
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 31
store i8 0, i8* %10
store i32 30, i32* %4
br label %11
11: ; preds = %14, %9
%12 = load i64, i64* %2
%13 = icmp ugt i64 %12, 0
br i1 %13, label %14, label %26
14: ; preds = %11
%15 = load i64, i64* %2
%16 = urem i64 %15, 10
%17 = add i64 48, %16
%18 = trunc i64 %17 to i8
%19 = load i32, i32* %4
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 %20
store i8 %18, i8* %21
%22 = load i64, i64* %2
%23 = udiv i64 %22, 10
store i64 %23, i64* %2
%24 = load i32, i32* %4
%25 = add i32 %24, -1
store i32 %25, i32* %4
br label %11
26: ; preds = %11
%27 = load i32, i32* %4
%28 = add i32 %27, 1
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 %29
%31 = call i32 @uart_puts(i8* %30)
br label %32
32: ; preds = %26, %7
ret void
}

LLVM IR (-O2):
define void @uart_putd(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 %24
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 i32 [ 30, %7 ], [ %18, %9 ]
%11 = phi i64 [ %0, %7 ], [ %17, %9 ]
%12 = urem i64 %11, 10
%13 = trunc i64 %12 to i8
%14 = or i8 %13, 48
%15 = zext i32 %10 to i64
%16 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 %15
store i8 %14, i8* %16
%17 = udiv i64 %11, 10
%18 = add i32 %10, -1
%19 = icmp ult i64 %11, 10
br i1 %19, label %20, label %9
20: ; preds = %9
%21 = zext i32 %10 to i64
%22 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 %21
%23 = call i32 @uart_puts(i8* %22)
br label %24
24: ; preds = %20, %5
ret void
}