#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 int uint64_t;

/* Variables and functions */
char digit_to_char(int);
char *serialize_number(uint64_t number, unsigned char base, char *buf) {
  int pos = 65, digit = 0;
  buf[pos] = 0;
  do {
    buf[--pos] = digit_to_char(number % base);
    number /= base;
  } while (number);
  return buf + pos;
}


x86 assembly (clang, -O0):
<serialize_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
mov    %rdx,-0x10(%rbp)
movl   $0x41,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
movzbl -0x5(%rbp),%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1030 <digit_to_char@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
movzbl -0x5(%rbp),%ecx
mov    -0x4(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    113f <serialize_number+0x2f>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serialize_number>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %edi,%ebp
movb   $0x0,0x41(%rdx)
add    $0x41,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%eax
cltd
idiv   %r14d
mov    %edx,%edi
mov    %eax,%ebp
call   1030 <digit_to_char@plt>
mov    %al,-0x1(%rbx)
add    $0xffffffffffffffff,%rbx
test   %ebp,%ebp
jne    1130 <serialize_number+0x20>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @serialize_number(i32 %0, i8 zeroext %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i8 %1, i8* %5
store i8* %2, i8** %6
store i32 65, i32* %7
store i32 0, i32* %8
%9 = load i8*, i8** %6
%10 = load i32, i32* %7
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
store i8 0, i8* %12
br label %13
13: ; preds = %28, %3
%14 = load i32, i32* %4
%15 = load i8, i8* %5
%16 = zext i8 %15 to i32
%17 = srem i32 %14, %16
%18 = call signext i8 @digit_to_char(i32 %17)
%19 = load i8*, i8** %6
%20 = load i32, i32* %7
%21 = add nsw i32 %20, -1
store i32 %21, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
store i8 %18, i8* %23
%24 = load i8, i8* %5
%25 = zext i8 %24 to i32
%26 = load i32, i32* %4
%27 = sdiv i32 %26, %25
store i32 %27, i32* %4
br label %28
28: ; preds = %13
%29 = load i32, i32* %4
%30 = icmp ne i32 %29, 0
br i1 %30, label %13, label %31
31: ; preds = %28
%32 = load i8*, i8** %6
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
ret i8* %35
}

LLVM IR (-O2):
define i8* @serialize_number(i32 %0, i8 zeroext %1, i8* writeonly %2) {
%4 = getelementptr inbounds i8, i8* %2, i64 65
store i8 0, i8* %4
%5 = zext i8 %1 to i32
br label %6
6: ; preds = %6, %3
%7 = phi i64 [ %11, %6 ], [ 65, %3 ]
%8 = phi i32 [ %13, %6 ], [ %0, %3 ]
%9 = srem i32 %8, %5
%10 = tail call signext i8 @digit_to_char(i32 %9)
%11 = add i64 %7, -1
%12 = getelementptr inbounds i8, i8* %2, i64 %11
store i8 %10, i8* %12
%13 = sdiv i32 %8, %5
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %6
15: ; preds = %6
%16 = getelementptr inbounds i8, i8* %2, i64 %11
ret i8* %16
}