#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 /*<<< orphan*/ EXIT_FAILURE;
char *easy_malloc(size_t);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int strlen(char const *);
scalar_t__ vsprintf(char *, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ write_error(char *);
char *easy_printf_unknown_helper(const char *format, va_list va) {
  size_t size = strlen(format) + 1000 + 1;
  char *string = easy_malloc(size * sizeof(char));
  if (vsprintf(string, format, va) < 0) {
    write_error(
        "Could not vsprintf. Probably allocated memory was too little.");
    exit(EXIT_FAILURE);
  }
  return string;
}


x86 assembly (clang, -O0):
<easy_printf_unknown_helper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x3e8,%eax
add    $0x1,%eax
cltq
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
shl    $0x0,%rdi
call   1030 <easy_malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1060 <vsprintf@plt>
cmp    $0x0,%rax
jge    11bb <easy_printf_unknown_helper+0x6b>
lea    0xe58(%rip),%rdi
call   1050 <write_error@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<easy_printf_unknown_helper>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbp
call   1040 <strlen@plt>
add    $0x3e9,%eax
movslq %eax,%rdi
call   1030 <easy_malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %r14d,%edx
call   1060 <vsprintf@plt>
test   %rax,%rax
js     118a <easy_printf_unknown_helper+0x3a>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe6f(%rip),%rdi
call   1050 <write_error@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [62 x i8] c"Could not vsprintf. Probably allocated memory was too little.\00"
@EXIT_FAILURE = global i32 0
define i8* @easy_printf_unknown_helper(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
%9 = add nsw i32 %8, 1000
%10 = add nsw i32 %9, 1
%11 = sext i32 %10 to i64
store i64 %11, i64* %5
%12 = load i64, i64* %5
%13 = mul i64 %12, 1
%14 = call i8* @easy_malloc(i64 %13)
store i8* %14, i8** %6
%15 = load i8*, i8** %6
%16 = load i8*, i8** %3
%17 = load i32, i32* %4
%18 = call i64 @vsprintf(i8* %15, i8* %16, i32 %17)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %2
%21 = call i32 @write_error(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %2
%25 = load i8*, i8** %6
ret i8* %25
}

LLVM IR (-O2):
@.str = [62 x i8] c"Could not vsprintf. Probably allocated memory was too little.\00"
@EXIT_FAILURE = global i32 0
define i8* @easy_printf_unknown_helper(i8* %0, i32 %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = add nsw i32 %3, 1001
%5 = sext i32 %4 to i64
%6 = tail call i8* @easy_malloc(i64 %5)
%7 = tail call i64 @vsprintf(i8* %6, i8* %0, i32 %1)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = tail call i32 @write_error(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
ret i8* %6
}