#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_long(struct adbuf *b, long l) {
  int n = 0;
  char s[32];
  char *p = s + 32 - 1;
  *p-- = '\0';
  if (l < 0) {
    n = 1;
    l = -l;
  }
  while (p > s) {
    *p-- = '0' + (l % 10);
    l /= 10;
    if (l == 0)
      break;
  }
  if (n)
    *p-- = '-';
  p++;
  return adbuf_strcat(b, p);
}


x86 assembly (clang, -O0):
<adbuf_add_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x40(%rbp),%rax
add    $0x20,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x48(%rbp)
movb   $0x0,(%rax)
cmpq   $0x0,-0x10(%rbp)
jge    1165 <adbuf_add_long+0x55>
movl   $0x1,-0x14(%rbp)
xor    %eax,%eax
sub    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    116a <adbuf_add_long+0x5a>
mov    -0x48(%rbp),%rax
lea    -0x40(%rbp),%rcx
cmp    %rcx,%rax
jbe    11c7 <adbuf_add_long+0xb7>
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
add    $0x30,%rdx
mov    %dl,%cl
mov    -0x48(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x48(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c2 <adbuf_add_long+0xb2>
jmp    11c7 <adbuf_add_long+0xb7>
jmp    116a <adbuf_add_long+0x5a>
cmpl   $0x0,-0x14(%rbp)
je     11e3 <adbuf_add_long+0xd3>
mov    -0x48(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x48(%rbp)
movb   $0x2d,(%rax)
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1030 <adbuf_strcat@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<adbuf_add_long>:
sub    $0x28,%rsp
mov    %rsi,%rdx
neg    %rdx
cmovs  %rsi,%rdx
movb   $0x0,0x1f(%rsp)
lea    0x20(%rsp),%rcx
movabs $0x6666666666666667,%r8
66 66 66
mov    %rsp,%r10
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rdx,%r9
mov    %rdx,%rax
imul   %r8
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x2,%rdx
add    %rax,%rdx
lea    (%rdx,%rdx,1),%eax
lea    (%rax,%rax,4),%r11d
mov    %r9d,%eax
sub    %r11d,%eax
add    $0x30,%al
mov    %al,-0x2(%rcx)
add    $0xfffffffffffffff6,%r9
lea    -0x1(%rcx),%rax
cmp    $0xffffffffffffffec,%r9
ja     1183 <adbuf_add_long+0x73>
add    $0xfffffffffffffffd,%rcx
cmp    %r10,%rcx
mov    %rax,%rcx
ja     1140 <adbuf_add_long+0x30>
mov    $0xffffffffffffffff,%rcx
test   %rsi,%rsi
jns    119a <adbuf_add_long+0x8a>
movb   $0x2d,-0x2(%rax)
mov    $0xfffffffffffffffe,%rcx
add    %rcx,%rax
mov    %rax,%rsi
call   1030 <adbuf_strcat@plt>
add    $0x28,%rsp
ret

LLVM IR (-O0):
%struct.adbuf = type { i32 }
define i32 @adbuf_add_long(%struct.adbuf* %0, i64 %1) {
%3 = alloca %struct.adbuf*
%4 = alloca i64
%5 = alloca i32
%6 = alloca [32 x i8]
%7 = alloca i8*
store %struct.adbuf* %0, %struct.adbuf** %3
store i64 %1, i64* %4
store i32 0, i32* %5
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%9 = getelementptr inbounds i8, i8* %8, i64 32
%10 = getelementptr inbounds i8, i8* %9, i64 -1
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = getelementptr inbounds i8, i8* %11, i32 -1
store i8* %12, i8** %7
store i8 0, i8* %11
%13 = load i64, i64* %4
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %2
store i32 1, i32* %5
%16 = load i64, i64* %4
%17 = sub nsw i64 0, %16
store i64 %17, i64* %4
br label %18
18: ; preds = %15, %2
br label %19
19: ; preds = %35, %18
%20 = load i8*, i8** %7
%21 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%22 = icmp ugt i8* %20, %21
br i1 %22, label %23, label %36
23: ; preds = %19
%24 = load i64, i64* %4
%25 = srem i64 %24, 10
%26 = add nsw i64 48, %25
%27 = trunc i64 %26 to i8
%28 = load i8*, i8** %7
%29 = getelementptr inbounds i8, i8* %28, i32 -1
store i8* %29, i8** %7
store i8 %27, i8* %28
%30 = load i64, i64* %4
%31 = sdiv i64 %30, 10
store i64 %31, i64* %4
%32 = load i64, i64* %4
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %23
br label %36
35: ; preds = %23
br label %19
36: ; preds = %34, %19
%37 = load i32, i32* %5
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load i8*, i8** %7
%41 = getelementptr inbounds i8, i8* %40, i32 -1
store i8* %41, i8** %7
store i8 45, i8* %40
br label %42
42: ; preds = %39, %36
%43 = load i8*, i8** %7
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %7
%45 = load %struct.adbuf*, %struct.adbuf** %3
%46 = load i8*, i8** %7
%47 = call i32 @adbuf_strcat(%struct.adbuf* %45, i8* %46)
ret i32 %47
}

LLVM IR (-O2):
%struct.adbuf = type { i32 }
define i32 @adbuf_add_long(%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
%7 = icmp slt i64 %1, 0
%8 = sub nsw i64 0, %1
%9 = select i1 %7, i64 %8, i64 %1
br label %10
10: ; preds = %2, %10
%11 = phi i64 [ %9, %2 ], [ %17, %10 ]
%12 = phi i8* [ %6, %2 ], [ %16, %10 ]
%13 = srem i64 %11, 10
%14 = trunc i64 %13 to i8
%15 = add nsw i8 %14, 48
%16 = getelementptr inbounds i8, i8* %12, i64 -1
store i8 %15, i8* %12
%17 = sdiv i64 %11, 10
%18 = add nsw i64 %11, -10
%19 = icmp ult i64 %18, -19
%20 = icmp ugt i8* %16, %4
%21 = select i1 %19, i1 %20, i1 false
br i1 %21, label %10, label %22
22: ; preds = %10
br i1 %7, label %23, label %24
23: ; preds = %22
store i8 45, i8* %16
br label %24
24: ; preds = %23, %22
%25 = phi i64 [ -2, %23 ], [ -1, %22 ]
%26 = getelementptr inbounds i8, i8* %12, i64 %25
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = call i32 @adbuf_strcat(%struct.adbuf* %0, i8* %27)
ret i32 %28
}