#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 */
size_t snprintf(char *, size_t const, char *, char const *);
scalar_t__ strlen(char *);
int sstrappend(char str[], size_t *len, size_t size, const char suffix[]) {
  const size_t free_space = size - *len;
  const size_t suffix_len = snprintf(str + *len, free_space, "%s", suffix);
  *len += strlen(str + *len);
  return suffix_len > free_space - 1;
}


x86 assembly (clang, -O0):
<sstrappend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    (%rcx),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
add    (%rax),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rcx
lea    0xe9f(%rip),%rdx
call   1040 <snprintf@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
add    (%rax),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
seta   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sstrappend>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rsi),%rdi
sub    %rdi,%rbx
add    %r15,%rdi
lea    0xebe(%rip),%rdx
mov    %rbx,%rsi
call   1040 <snprintf@plt>
mov    %rax,%r12
mov    (%r14),%r13
add    %r13,%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
add    %r13,%rax
mov    %rax,(%r14)
add    $0xffffffffffffffff,%rbx
xor    %eax,%eax
cmp    %rbx,%r12
seta   %al
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define i32 @sstrappend(i8* %0, i64* %1, i64 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i64*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
store i8* %0, i8** %5
store i64* %1, i64** %6
store i64 %2, i64* %7
store i8* %3, i8** %8
%11 = load i64, i64* %7
%12 = load i64*, i64** %6
%13 = load i64, i64* %12
%14 = sub i64 %11, %13
store i64 %14, i64* %9
%15 = load i8*, i8** %5
%16 = load i64*, i64** %6
%17 = load i64, i64* %16
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i64, i64* %9
%20 = load i8*, i8** %8
%21 = call i64 @snprintf(i8* %18, i64 %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %20)
store i64 %21, i64* %10
%22 = load i8*, i8** %5
%23 = load i64*, i64** %6
%24 = load i64, i64* %23
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = call i64 @strlen(i8* %25)
%27 = load i64*, i64** %6
%28 = load i64, i64* %27
%29 = add i64 %28, %26
store i64 %29, i64* %27
%30 = load i64, i64* %10
%31 = load i64, i64* %9
%32 = sub i64 %31, 1
%33 = icmp ugt i64 %30, %32
%34 = zext i1 %33 to i32
ret i32 %34
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define i32 @sstrappend(i8* %0, i64* nocapture %1, i64 %2, i8* %3) {
%5 = load i64, i64* %1
%6 = sub i64 %2, %5
%7 = getelementptr inbounds i8, i8* %0, i64 %5
%8 = tail call i64 @snprintf(i8* %7, i64 %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
%9 = load i64, i64* %1
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = tail call i64 @strlen(i8* dereferenceable(1) %10)
%12 = add i64 %11, %9
store i64 %12, i64* %1
%13 = add i64 %6, -1
%14 = icmp ugt i64 %8, %13
%15 = zext i1 %14 to i32
ret i32 %15
}