#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 */
typedef size_t uint8_t;
typedef int uint64_t;

/* Variables and functions */
int /*<<< orphan*/ UART_write(char *);
void UART_writeDecU64(uint64_t v, uint8_t n) {
  char buf[22];
  uint8_t i;
  for (i = 0; i < n; ++i)
    buf[i] = ' ';
  buf[n] = '\0';
  i = n;
  do {
    uint8_t d = v % 10;
    v /= 10;
    buf[--i] = '0' + d;
  } while (v != 0);
  UART_write(buf);
}


x86 assembly (clang, -O0):
<UART_writeDecU64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    114f <UART_writeDecU64+0x3f>
mov    -0x38(%rbp),%rax
movb   $0x20,-0x30(%rbp,%rax,1)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1127 <UART_writeDecU64+0x17>
mov    -0x10(%rbp),%rax
movb   $0x0,-0x30(%rbp,%rax,1)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x40(%rbp),%rax
add    $0x30,%rax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,-0x31(%rbp,%rax,1)
cmpl   $0x0,-0x4(%rbp)
jne    1160 <UART_writeDecU64+0x50>
lea    -0x30(%rbp),%rdi
call   1030 <UART_write@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UART_writeDecU64>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
test   %rsi,%rsi
je     1141 <UART_writeDecU64+0x21>
mov    %rsp,%rdi
mov    $0x20,%esi
mov    %r14,%rdx
call   1030 <memset@plt>
movb   $0x0,(%rsp,%r14,1)
lea    (%rsp,%r14,1),%rax
add    $0xffffffffffffffff,%rax
xchg   %ax,%ax
movslq %ebx,%rcx
imul   $0x66666667,%rcx,%rbx
mov    %rbx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rbx
add    %edx,%ebx
lea    (%rbx,%rbx,1),%edx
lea    (%rdx,%rdx,4),%edx
mov    %ecx,%esi
sub    %edx,%esi
add    $0x30,%sil
mov    %sil,(%rax)
add    $0x9,%ecx
add    $0xffffffffffffffff,%rax
cmp    $0x12,%ecx
ja     1150 <UART_writeDecU64+0x30>
mov    %rsp,%rdi
call   1040 <UART_write@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @UART_writeDecU64(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca [22 x i8]
%6 = alloca i64
%7 = alloca i64
store i32 %0, i32* %3
store i64 %1, i64* %4
store i64 0, i64* %6
br label %8
8: ; preds = %15, %2
%9 = load i64, i64* %6
%10 = load i64, i64* %4
%11 = icmp ult i64 %9, %10
br i1 %11, label %12, label %18
12: ; preds = %8
%13 = load i64, i64* %6
%14 = getelementptr inbounds [22 x i8], [22 x i8]* %5, i64 0, i64 %13
store i8 32, i8* %14
br label %15
15: ; preds = %12
%16 = load i64, i64* %6
%17 = add i64 %16, 1
store i64 %17, i64* %6
br label %8
18: ; preds = %8
%19 = load i64, i64* %4
%20 = getelementptr inbounds [22 x i8], [22 x i8]* %5, i64 0, i64 %19
store i8 0, i8* %20
%21 = load i64, i64* %4
store i64 %21, i64* %6
br label %22
22: ; preds = %34, %18
%23 = load i32, i32* %3
%24 = srem i32 %23, 10
%25 = sext i32 %24 to i64
store i64 %25, i64* %7
%26 = load i32, i32* %3
%27 = sdiv i32 %26, 10
store i32 %27, i32* %3
%28 = load i64, i64* %7
%29 = add i64 48, %28
%30 = trunc i64 %29 to i8
%31 = load i64, i64* %6
%32 = add i64 %31, -1
store i64 %32, i64* %6
%33 = getelementptr inbounds [22 x i8], [22 x i8]* %5, i64 0, i64 %32
store i8 %30, i8* %33
br label %34
34: ; preds = %22
%35 = load i32, i32* %3
%36 = icmp ne i32 %35, 0
br i1 %36, label %22, label %37
37: ; preds = %34
%38 = getelementptr inbounds [22 x i8], [22 x i8]* %5, i64 0, i64 0
%39 = call i32 @UART_write(i8* %38)
ret void
}

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