#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 */
struct adbuf {
  int dummy;
};

/* Variables and functions */
int adbuf_strcat(struct adbuf *, char *);
int adbuf_add_ulong(struct adbuf *b, unsigned long l) {
  char s[32];
  char *p = s + 32 - 1;
  *p-- = '\0';
  while (p >= s) {
    *p-- = '0' + (l % 10);
    l /= 10;
    if (l == 0)
      break;
  }
  p++;
  return adbuf_strcat(b, p);
}


x86 assembly (clang, -O0):
<adbuf_add_ulong>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x30(%rbp),%rax
add    $0x20,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x38(%rbp)
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rax
lea    -0x30(%rbp),%rcx
cmp    %rcx,%rax
jb     119f <adbuf_add_ulong+0x8f>
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
add    $0x30,%rdx
mov    %dl,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119a <adbuf_add_ulong+0x8a>
jmp    119f <adbuf_add_ulong+0x8f>
jmp    1142 <adbuf_add_ulong+0x32>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1030 <adbuf_strcat@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<adbuf_add_ulong>:
sub    $0x28,%rsp
mov    %rsi,%rdx
lea    0x1f(%rsp),%rcx
movb   $0x0,0x1f(%rsp)
movabs $0xcccccccccccccccd,%r9
cc cc cc
mov    %rsp,%r10
xchg   %ax,%ax
mov    %rdx,%r8
mov    %rdx,%rax
mul    %r9
lea    -0x1(%rcx),%rsi
shr    $0x3,%rdx
lea    (%rdx,%rdx,1),%eax
lea    (%rax,%rax,4),%r11d
mov    %r8d,%eax
sub    %r11d,%eax
or     $0x30,%al
mov    %al,-0x1(%rcx)
cmp    $0xa,%r8
jb     1165 <adbuf_add_ulong+0x55>
add    $0xfffffffffffffffe,%rcx
cmp    %r10,%rcx
mov    %rsi,%rcx
jae    1130 <adbuf_add_ulong+0x20>
call   1030 <adbuf_strcat@plt>
add    $0x28,%rsp
ret

LLVM IR (-O0):
%struct.adbuf = type { i32 }
define i32 @adbuf_add_ulong(%struct.adbuf* %0, i64 %1) {
%3 = alloca %struct.adbuf*
%4 = alloca i64
%5 = alloca [32 x i8]
%6 = alloca i8*
store %struct.adbuf* %0, %struct.adbuf** %3
store i64 %1, i64* %4
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds i8, i8* %7, i64 32
%9 = getelementptr inbounds i8, i8* %8, i64 -1
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = getelementptr inbounds i8, i8* %10, i32 -1
store i8* %11, i8** %6
store i8 0, i8* %10
br label %12
12: ; preds = %28, %2
%13 = load i8*, i8** %6
%14 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%15 = icmp uge i8* %13, %14
br i1 %15, label %16, label %29
16: ; preds = %12
%17 = load i64, i64* %4
%18 = urem i64 %17, 10
%19 = add i64 48, %18
%20 = trunc i64 %19 to i8
%21 = load i8*, i8** %6
%22 = getelementptr inbounds i8, i8* %21, i32 -1
store i8* %22, i8** %6
store i8 %20, i8* %21
%23 = load i64, i64* %4
%24 = udiv i64 %23, 10
store i64 %24, i64* %4
%25 = load i64, i64* %4
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %16
br label %29
28: ; preds = %16
br label %12
29: ; preds = %27, %12
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %6
%32 = load %struct.adbuf*, %struct.adbuf** %3
%33 = load i8*, i8** %6
%34 = call i32 @adbuf_strcat(%struct.adbuf* %32, i8* %33)
ret i32 %34
}

LLVM IR (-O2):
%struct.adbuf = type { i32 }
define i32 @adbuf_add_ulong(%struct.adbuf* %0, i64 %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
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 30
store i8 0, i8* %5
br label %7
7: ; preds = %2, %7
%8 = phi i64 [ %1, %2 ], [ %14, %7 ]
%9 = phi i8* [ %6, %2 ], [ %13, %7 ]
%10 = urem i64 %8, 10
%11 = trunc i64 %10 to i8
%12 = or i8 %11, 48
%13 = getelementptr inbounds i8, i8* %9, i64 -1
store i8 %12, i8* %9
%14 = udiv i64 %8, 10
%15 = icmp ugt i64 %8, 9
%16 = icmp uge i8* %13, %4
%17 = select i1 %15, i1 %16, i1 false
br i1 %17, label %7, label %18
18: ; preds = %7
%19 = call i32 @adbuf_strcat(%struct.adbuf* %0, i8* %9)
ret i32 %19
}