#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 /*<<< orphan*/ bb;

/* Variables and functions */
int /*<<< orphan*/ strcat(char *, char *);
void cat_n(char *buf, unsigned long n) {
  char bb[60 + 1];
  char *p = bb + sizeof(bb) - 1;
  *p = 0;
  do {
    *--p = "0123456789"[n % 10];
    n = n / 10;
  } while (n);
  strcat(buf, p);
}


x86 assembly (clang, -O0):
<cat_n>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x50(%rbp),%rax
add    $0x3d,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
lea    0xeb4(%rip),%rax
mov    (%rax,%rdx,1),%cl
mov    -0x58(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x58(%rbp)
mov    %cl,-0x1(%rax)
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1137 <cat_n+0x27>
mov    -0x8(%rbp),%rdi
mov    -0x58(%rbp),%rsi
call   1030 <strcat@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cat_n>:
sub    $0x48,%rsp
mov    %rsi,%r10
lea    0x3c(%rsp),%rsi
movb   $0x0,0x3c(%rsp)
lea    0xed8(%rip),%r8
movabs $0xcccccccccccccccd,%r9
cc cc cc
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r10,%rax
mul    %r9
shr    $0x3,%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(%rsi)
add    $0xffffffffffffffff,%rsi
cmp    $0x9,%r10
mov    %rdx,%r10
ja     1140 <cat_n+0x30>
call   1030 <strcat@plt>
add    $0x48,%rsp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"0123456789\00"
define void @cat_n(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca [61 x i8]
%6 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
%7 = getelementptr inbounds [61 x i8], [61 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds i8, i8* %7, i64 61
%9 = getelementptr inbounds i8, i8* %8, i64 -1
store i8* %9, i8** %6
%10 = load i8*, i8** %6
store i8 0, i8* %10
br label %11
11: ; preds = %20, %2
%12 = load i64, i64* %4
%13 = urem i64 %12, 10
%14 = getelementptr inbounds [11 x i8], [11 x i8]* @.str, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = load i8*, i8** %6
%17 = getelementptr inbounds i8, i8* %16, i32 -1
store i8* %17, i8** %6
store i8 %15, i8* %17
%18 = load i64, i64* %4
%19 = udiv i64 %18, 10
store i64 %19, i64* %4
br label %20
20: ; preds = %11
%21 = load i64, i64* %4
%22 = icmp ne i64 %21, 0
br i1 %22, label %11, label %23
23: ; preds = %20
%24 = load i8*, i8** %3
%25 = load i8*, i8** %6
%26 = call i32 @strcat(i8* %24, i8* %25)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"0123456789\00"
define void @cat_n(i8* %0, i64 %1) {
%3 = alloca [61 x i8]
%4 = getelementptr inbounds [61 x i8], [61 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds [61 x i8], [61 x i8]* %3, i64 0, i64 60
store i8 0, i8* %5
br label %6
6: ; preds = %6, %2
%7 = phi i64 [ %1, %2 ], [ %13, %6 ]
%8 = phi i8* [ %5, %2 ], [ %12, %6 ]
%9 = urem i64 %7, 10
%10 = getelementptr inbounds [11 x i8], [11 x i8]* @.str, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = getelementptr inbounds i8, i8* %8, i64 -1
store i8 %11, i8* %12
%13 = udiv i64 %7, 10
%14 = icmp ult i64 %7, 10
br i1 %14, label %15, label %6
15: ; preds = %6
%16 = call i32 @strcat(i8* %0, i8* %12)
ret void
}