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

/* Variables and functions */
int snprintf(char *, size_t, char *, char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
int /*<<< orphan*/ vsnprintf(char *, size_t, char const *, int /*<<< orphan*/);
int util_vssnprintf(char *str, size_t size, const char *format, va_list ap) {
  char buf1[size];
  char buf2[size];
  strncpy(buf1, str, size);
  vsnprintf(buf2, size, format, ap);
  return snprintf(str, size, "%s%s", buf1, buf2);
}


x86 assembly (clang, -O0):
<util_vssnprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x48(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1040 <vsnprintf@plt>
mov    -0x48(%rbp),%rcx
mov    -0x40(%rbp),%r8
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xe3a(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x28(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<util_vssnprintf>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,-0x2c(%rbp)
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%r14
mov    %rsp,%rbx
lea    0xf(%rsi),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r13,%rdx
call   1030 <strncpy@plt>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    -0x2c(%rbp),%ecx
call   1040 <vsnprintf@plt>
lea    0xe76(%rip),%rdx
mov    %r14,%rdi
mov    %r13,%rsi
mov    %rbx,%rcx
mov    %r15,%r8
call   1050 <snprintf@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s%s\00"
define i32 @util_vssnprintf(i8* %0, i64 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%12 = load i64, i64* %6
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %9
%14 = alloca i8, i64 %12
store i64 %12, i64* %10
%15 = load i64, i64* %6
%16 = alloca i8, i64 %15
store i64 %15, i64* %11
%17 = load i8*, i8** %5
%18 = load i64, i64* %6
%19 = call i32 @strncpy(i8* %14, i8* %17, i64 %18)
%20 = load i64, i64* %6
%21 = load i8*, i8** %7
%22 = load i32, i32* %8
%23 = call i32 @vsnprintf(i8* %16, i64 %20, i8* %21, i32 %22)
%24 = load i8*, i8** %5
%25 = load i64, i64* %6
%26 = call i32 @snprintf(i8* %24, i64 %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %14, i8* %16)
%27 = load i8*, i8** %9
ret i32 %26
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s%s\00"
define i32 @util_vssnprintf(i8* %0, i64 %1, i8* nocapture %2, i32 %3) {
%5 = alloca i8, i64 %1
%6 = alloca i8, i64 %1
%7 = call i32 @strncpy(i8* %5, i8* %0, i64 %1)
%8 = call i32 @vsnprintf(i8* %6, i64 %1, i8* %2, i32 %3)
%9 = call i32 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %5, i8* %6)
ret i32 %9
}