#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 */
int snprintf(char *, int, char *, int);
void qword_addint(char **bpp, int *lp, int n) {
  int len;
  len = snprintf(*bpp, *lp, "%d ", n);
  if (len > *lp)
    len = *lp;
  *bpp += len;
  *lp -= len;
}


x86 assembly (clang, -O0):
<qword_addint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    -0x14(%rbp),%ecx
lea    0xec6(%rip),%rdx
call   1030 <snprintf@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jle    115a <qword_addint+0x4a>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
movslq %edx,%rdx
add    %rdx,%rcx
mov    %rcx,(%rax)
mov    -0x18(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
sub    %edx,%ecx
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qword_addint>:
push   %r14
push   %rbx
push   %rax
mov    %edx,%ecx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    (%rdi),%rdi
mov    (%rsi),%esi
lea    0xed8(%rip),%rdx
call   1030 <snprintf@plt>
mov    (%rbx),%ecx
cmp    %ecx,%eax
cmovg  %ecx,%eax
cltq
add    %rax,(%r14)
sub    %eax,%ecx
mov    %ecx,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d \00"
define void @qword_addint(i8** %0, i32* %1, i32 %2) {
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i8** %0, i8*** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%8 = load i8**, i8*** %4
%9 = load i8*, i8** %8
%10 = load i32*, i32** %5
%11 = load i32, i32* %10
%12 = load i32, i32* %6
%13 = call i32 @snprintf(i8* %9, i32 %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = load i32*, i32** %5
%16 = load i32, i32* %15
%17 = icmp sgt i32 %14, %16
br i1 %17, label %18, label %21
18: ; preds = %3
%19 = load i32*, i32** %5
%20 = load i32, i32* %19
store i32 %20, i32* %7
br label %21
21: ; preds = %18, %3
%22 = load i32, i32* %7
%23 = load i8**, i8*** %4
%24 = load i8*, i8** %23
%25 = sext i32 %22 to i64
%26 = getelementptr inbounds i8, i8* %24, i64 %25
store i8* %26, i8** %23
%27 = load i32, i32* %7
%28 = load i32*, i32** %5
%29 = load i32, i32* %28
%30 = sub nsw i32 %29, %27
store i32 %30, i32* %28
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d \00"
define void @qword_addint(i8** nocapture %0, i32* nocapture %1, i32 %2) {
%4 = load i8*, i8** %0
%5 = load i32, i32* %1
%6 = tail call i32 @snprintf(i8* %4, i32 %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %2)
%7 = load i32, i32* %1
%8 = icmp sgt i32 %6, %7
%9 = select i1 %8, i32 %7, i32 %6
%10 = load i8*, i8** %0
%11 = sext i32 %9 to i64
%12 = getelementptr inbounds i8, i8* %10, i64 %11
store i8* %12, i8** %0
%13 = sub nsw i32 %7, %9
store i32 %13, i32* %1
ret void
}