#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*/ free(char *);
int gzputs(void *, char *);
int vasprintf(char **, char const *, int /*<<< orphan*/);
int gz_file_handler_vprintf(void *file, const char *fmt, va_list ap) {
  char *buf;
  int printed = vasprintf(&buf, fmt, ap);
  if (printed < 0) {
    return printed;
  }
  printed = gzputs(file, buf);
  free(buf);
  return printed;
}


x86 assembly (clang, -O0):
<gz_file_handler_vprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    -0x28(%rbp),%rdi
call   1040 <vasprintf@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    116b <gz_file_handler_vprintf+0x3b>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118a <gz_file_handler_vprintf+0x5a>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <gzputs@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gz_file_handler_vprintf>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %rsp,%rdi
call   1040 <vasprintf@plt>
test   %eax,%eax
js     115c <gz_file_handler_vprintf+0x2c>
mov    (%rsp),%rsi
mov    %r14,%rdi
call   1050 <gzputs@plt>
mov    %eax,%ebx
mov    (%rsp),%rdi
call   1030 <free@plt>
jmp    115e <gz_file_handler_vprintf+0x2e>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @gz_file_handler_vprintf(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i8*, i8** %6
%11 = load i32, i32* %7
%12 = call i32 @vasprintf(i8** %8, i8* %10, i32 %11)
store i32 %12, i32* %9
%13 = load i32, i32* %9
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = load i32, i32* %9
store i32 %16, i32* %4
br label %24
17: ; preds = %3
%18 = load i8*, i8** %5
%19 = load i8*, i8** %8
%20 = call i32 @gzputs(i8* %18, i8* %19)
store i32 %20, i32* %9
%21 = load i8*, i8** %8
%22 = call i32 @free(i8* %21)
%23 = load i32, i32* %9
store i32 %23, i32* %4
br label %24
24: ; preds = %17, %15
%25 = load i32, i32* %4
ret i32 %25
}

LLVM IR (-O2):
define i32 @gz_file_handler_vprintf(i8* %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 slt i32 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %3
%9 = load i8*, i8** %4
%10 = call i32 @gzputs(i8* %0, i8* %9)
%11 = load i8*, i8** %4
%12 = call i32 @free(i8* %11)
br label %13
13: ; preds = %3, %8
%14 = phi i32 [ %10, %8 ], [ %6, %3 ]
ret i32 %14
}