#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 */
unsigned char *append_sub32(unsigned char *, int);
unsigned char *append_uint32(unsigned char *, int);
unsigned char *append_uint64(unsigned char *cp, uint64_t i) {
  uint64_t j;
  if (i <= 0xffffffff)
    return append_uint32(cp, i);
  if ((j = i / 1000000000) > 1000000000) {
    cp = append_uint32(cp, j / 1000000000);
    j %= 1000000000;
    cp = append_sub32(cp, j);
  } else {
    cp = append_uint32(cp, i / 1000000000);
  }
  cp = append_sub32(cp, i % 1000000000);
  return cp;
}


x86 assembly (clang, -O0):
<append_uint64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
ja     114e <append_uint64+0x2e>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <append_uint32@plt>
mov    %rax,-0x8(%rbp)
jmp    11e0 <append_uint64+0xc0>
mov    -0x14(%rbp),%eax
mov    $0x3b9aca00,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
cmp    $0x3b9aca00,%eax
jle    11a4 <append_uint64+0x84>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%eax
mov    $0x3b9aca00,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
call   1040 <append_uint32@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x3b9aca00,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <append_sub32@plt>
mov    %rax,-0x10(%rbp)
jmp    11be <append_uint64+0x9e>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%eax
mov    $0x3b9aca00,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
call   1040 <append_uint32@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%eax
mov    $0x3b9aca00,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
call   1030 <append_sub32@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_uint64>:
jmp    1030 <append_uint32@plt>

LLVM IR (-O0):
define i8* @append_uint64(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = icmp ule i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = load i32, i32* %5
%12 = call i8* @append_uint32(i8* %10, i32 %11)
store i8* %12, i8** %3
br label %38
13: ; preds = %2
%14 = load i32, i32* %5
%15 = sdiv i32 %14, 1000000000
store i32 %15, i32* %6
%16 = icmp sgt i32 %15, 1000000000
br i1 %16, label %17, label %27
17: ; preds = %13
%18 = load i8*, i8** %4
%19 = load i32, i32* %6
%20 = sdiv i32 %19, 1000000000
%21 = call i8* @append_uint32(i8* %18, i32 %20)
store i8* %21, i8** %4
%22 = load i32, i32* %6
%23 = srem i32 %22, 1000000000
store i32 %23, i32* %6
%24 = load i8*, i8** %4
%25 = load i32, i32* %6
%26 = call i8* @append_sub32(i8* %24, i32 %25)
store i8* %26, i8** %4
br label %32
27: ; preds = %13
%28 = load i8*, i8** %4
%29 = load i32, i32* %5
%30 = sdiv i32 %29, 1000000000
%31 = call i8* @append_uint32(i8* %28, i32 %30)
store i8* %31, i8** %4
br label %32
32: ; preds = %27, %17
%33 = load i8*, i8** %4
%34 = load i32, i32* %5
%35 = srem i32 %34, 1000000000
%36 = call i8* @append_sub32(i8* %33, i32 %35)
store i8* %36, i8** %4
%37 = load i8*, i8** %4
store i8* %37, i8** %3
br label %38
38: ; preds = %32, %9
%39 = load i8*, i8** %3
ret i8* %39
}

LLVM IR (-O2):
define i8* @append_uint64(i8* %0, i32 %1) {
%3 = tail call i8* @append_uint32(i8* %0, i32 %1)
ret i8* %3
}