#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*/);
scalar_t__ vsprintf(char *, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ write_error(char *);
char *easy_printf_helper(const char *format, size_t size, va_list va) {
  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_helper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
shl    $0x0,%rdi
call   1030 <easy_malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <vsprintf@plt>
cmp    $0x0,%rax
jge    1198 <easy_printf_helper+0x58>
lea    0xe7b(%rip),%rdi
call   1040 <write_error@plt>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<easy_printf_helper>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rdi,%rbp
mov    %rsi,%rdi
call   1030 <easy_malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %r14d,%edx
call   1050 <vsprintf@plt>
test   %rax,%rax
js     1170 <easy_printf_helper+0x30>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe89(%rip),%rdi
call   1040 <write_error@plt>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
call   1060 <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_helper(i8* %0, i64 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i32 %2, i32* %6
%8 = load i64, i64* %5
%9 = mul i64 %8, 1
%10 = call i8* @easy_malloc(i64 %9)
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = load i8*, i8** %4
%13 = load i32, i32* %6
%14 = call i64 @vsprintf(i8* %11, i8* %12, i32 %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %3
%17 = call i32 @write_error(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %3
%21 = load i8*, i8** %7
ret i8* %21
}

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_helper(i8* nocapture %0, i64 %1, i32 %2) {
%4 = tail call i8* @easy_malloc(i64 %1)
%5 = tail call i64 @vsprintf(i8* %4, i8* %0, i32 %2)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %3
%8 = tail call i32 @write_error(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %3
ret i8* %4
}