#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;
struct szl_obj {
  int dummy;
};
struct szl_interp {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ free(char *);
struct szl_obj *szl_new_str_noalloc(struct szl_interp *, char *, size_t);
int vasprintf(char **, char const *, int /*<<< orphan*/);
struct szl_obj *szl_new_str_va(struct szl_interp *interp, const char *fmt,
                               va_list ap) {
  struct szl_obj *str = NULL;
  char *s;
  int len;
  len = vasprintf(&s, fmt, ap);
  if (len >= 0) {
    str = szl_new_str_noalloc(interp, s, (size_t)len);
    if (!str)
      free(s);
  }
  return str;
}


x86 assembly (clang, -O0):
<szl_new_str_va>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    -0x28(%rbp),%rdi
call   1040 <vasprintf@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jl     1196 <szl_new_str_va+0x66>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
movslq -0x2c(%rbp),%rdx
call   1050 <szl_new_str_noalloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1191 <szl_new_str_va+0x61>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    1196 <szl_new_str_va+0x66>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<szl_new_str_va>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
call   1040 <vasprintf@plt>
test   %eax,%eax
js     1164 <szl_new_str_va+0x34>
mov    0x8(%rsp),%rsi
mov    %eax,%edx
mov    %rbx,%rdi
call   1050 <szl_new_str_noalloc@plt>
test   %rax,%rax
jne    1166 <szl_new_str_va+0x36>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.szl_obj = type { i32 }
%struct.szl_interp = type { i32 }
define %struct.szl_obj* @szl_new_str_va(%struct.szl_interp* %0, i8* %1, i32 %2) {
%4 = alloca %struct.szl_interp*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.szl_obj*
%8 = alloca i8*
%9 = alloca i32
store %struct.szl_interp* %0, %struct.szl_interp** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store %struct.szl_obj* null, %struct.szl_obj** %7
%10 = load i8*, i8** %5
%11 = load i32, i32* %6
%12 = call i32 @vasprintf(i8** %8, i8* %10, i32 %11)
store i32 %12, i32* %9
%13 = load i32, i32* %9
%14 = icmp sge i32 %13, 0
br i1 %14, label %15, label %27
15: ; preds = %3
%16 = load %struct.szl_interp*, %struct.szl_interp** %4
%17 = load i8*, i8** %8
%18 = load i32, i32* %9
%19 = sext i32 %18 to i64
%20 = call %struct.szl_obj* @szl_new_str_noalloc(%struct.szl_interp* %16, i8* %17, i64 %19)
store %struct.szl_obj* %20, %struct.szl_obj** %7
%21 = load %struct.szl_obj*, %struct.szl_obj** %7
%22 = icmp ne %struct.szl_obj* %21, null
br i1 %22, label %26, label %23
23: ; preds = %15
%24 = load i8*, i8** %8
%25 = call i32 @free(i8* %24)
br label %26
26: ; preds = %23, %15
br label %27
27: ; preds = %26, %3
%28 = load %struct.szl_obj*, %struct.szl_obj** %7
ret %struct.szl_obj* %28
}

LLVM IR (-O2):
%struct.szl_obj = type { i32 }
%struct.szl_interp = type { i32 }
define %struct.szl_obj* @szl_new_str_va(%struct.szl_interp* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = call i32 @vasprintf(i8** %4, i8* %1, i32 %2)
%7 = icmp sgt i32 %6, -1
br i1 %7, label %8, label %16
8: ; preds = %3
%9 = load i8*, i8** %4
%10 = zext i32 %6 to i64
%11 = call %struct.szl_obj* @szl_new_str_noalloc(%struct.szl_interp* %0, i8* %9, i64 %10)
%12 = icmp eq %struct.szl_obj* %11, null
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i8*, i8** %4
%15 = call i32 @free(i8* %14)
br label %16
16: ; preds = %8, %13, %3
%17 = phi %struct.szl_obj* [ %11, %8 ], [ null, %13 ], [ null, %3 ]
ret %struct.szl_obj* %17
}