#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 */
char *append_str(char *, char *);
char *append_int(long n, char *dest) {
  static char digits[] = "0123456789";
  char buf[32];
  buf[31] = 0;
  char *b = buf + 31;
  do {
    *(--b) = digits[n % 10];
  } while ((n /= 10) > 0);
  return append_str(b, dest);
}


x86 assembly (clang, -O0):
<append_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x0,-0x11(%rbp)
lea    -0x30(%rbp),%rax
add    $0x1f,%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
lea    0x2ee3(%rip),%rax
mov    (%rax,%rdx,1),%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,-0x1(%rax)
mov    -0x8(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jg     1130 <append_int+0x20>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <append_str@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_int>:
sub    $0x28,%rsp
mov    %rdi,%r10
lea    0x1f(%rsp),%rdi
movb   $0x0,0x1f(%rsp)
lea    0xed8(%rip),%r8
movabs $0x6666666666666667,%r9
66 66 66
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r10,%rax
imul   %r9
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x2,%rdx
add    %rax,%rdx
lea    (%rdx,%rdx,1),%rax
lea    (%rax,%rax,4),%rax
mov    %r10,%rcx
sub    %rax,%rcx
movzbl (%r8,%rcx,1),%eax
mov    %al,-0x1(%rdi)
add    $0xffffffffffffffff,%rdi
cmp    $0x9,%r10
mov    %rdx,%r10
jg     1140 <append_int+0x30>
call   1030 <append_str@plt>
add    $0x28,%rsp
ret

LLVM IR (-O0):
@append_int.digits = internal global [11 x i8] c"0123456789\00"
define i8* @append_int(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca [32 x i8]
%6 = alloca i8*
store i64 %0, i64* %3
store i8* %1, i8** %4
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 31
store i8 0, i8* %7
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds i8, i8* %8, i64 31
store i8* %9, i8** %6
br label %10
10: ; preds = %17, %2
%11 = load i64, i64* %3
%12 = srem i64 %11, 10
%13 = getelementptr inbounds [11 x i8], [11 x i8]* @append_int.digits, i64 0, i64 %12
%14 = load i8, i8* %13
%15 = load i8*, i8** %6
%16 = getelementptr inbounds i8, i8* %15, i32 -1
store i8* %16, i8** %6
store i8 %14, i8* %16
br label %17
17: ; preds = %10
%18 = load i64, i64* %3
%19 = sdiv i64 %18, 10
store i64 %19, i64* %3
%20 = icmp sgt i64 %19, 0
br i1 %20, label %10, label %21
21: ; preds = %17
%22 = load i8*, i8** %6
%23 = load i8*, i8** %4
%24 = call i8* @append_str(i8* %22, i8* %23)
ret i8* %24
}

LLVM IR (-O2):
@append_int.digits = internal unnamed_addr constant [11 x i8] c"0123456789\00"
define i8* @append_int(i64 %0, i8* %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 31
store i8 0, i8* %5
br label %6
6: ; preds = %6, %2
%7 = phi i64 [ %0, %2 ], [ %13, %6 ]
%8 = phi i8* [ %5, %2 ], [ %12, %6 ]
%9 = srem i64 %7, 10
%10 = getelementptr inbounds [11 x i8], [11 x i8]* @append_int.digits, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = getelementptr inbounds i8, i8* %8, i64 -1
store i8 %11, i8* %12
%13 = sdiv i64 %7, 10
%14 = icmp sgt i64 %7, 9
br i1 %14, label %6, label %15
15: ; preds = %6
%16 = call i8* @append_str(i8* %12, i8* %1)
ret i8* %16
}