#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 terminal_measure(char *);
int vsnprintf(char *, int, char const *, int /*<<< orphan*/);
int terminal_vmeasuref(const char *s, va_list args) {
  static char buffer[1024] = {0};
  int rc = 0;
  if (s == NULL)
    return 0;
  rc = vsnprintf(buffer, 1024 - 1, s, args);
  if (rc > 0)
    rc = terminal_measure(buffer);
  return rc;
}


x86 assembly (clang, -O0):
<terminal_vmeasuref>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    114d <terminal_vmeasuref+0x2d>
movl   $0x0,-0x4(%rbp)
jmp    1187 <terminal_vmeasuref+0x67>
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0x2ee5(%rip),%rdi
mov    $0x3ff,%esi
call   1030 <vsnprintf@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    1181 <terminal_vmeasuref+0x61>
lea    0x2ec7(%rip),%rdi
call   1040 <terminal_measure@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<terminal_vmeasuref>:
test   %rdi,%rdi
je     1151 <terminal_vmeasuref+0x31>
push   %rax
mov    %esi,%ecx
mov    %rdi,%rdx
lea    0x2f0e(%rip),%rdi
mov    $0x3ff,%esi
call   1030 <vsnprintf@plt>
test   %eax,%eax
lea    0x8(%rsp),%rsp
jle    1153 <terminal_vmeasuref+0x33>
lea    0x2ef4(%rip),%rdi
jmp    1040 <terminal_measure@plt>
xor    %eax,%eax
ret

LLVM IR (-O0):
@terminal_vmeasuref.buffer = internal global [1024 x i8] zeroinitializer
define i32 @terminal_vmeasuref(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 0, i32* %6
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 0, i32* %3
br label %20
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = load i32, i32* %5
%13 = call i32 @vsnprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @terminal_vmeasuref.buffer, i64 0, i64 0), i32 1023, i8* %11, i32 %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = call i32 @terminal_measure(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @terminal_vmeasuref.buffer, i64 0, i64 0))
store i32 %17, i32* %6
br label %18
18: ; preds = %16, %10
%19 = load i32, i32* %6
store i32 %19, i32* %3
br label %20
20: ; preds = %18, %9
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
@terminal_vmeasuref.buffer = internal global [1024 x i8] zeroinitializer
define i32 @terminal_vmeasuref(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = tail call i32 @vsnprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @terminal_vmeasuref.buffer, i64 0, i64 0), i32 1023, i8* %0, i32 %1)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @terminal_measure(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @terminal_vmeasuref.buffer, i64 0, i64 0))
br label %9
9: ; preds = %4, %7, %2
%10 = phi i32 [ 0, %2 ], [ %8, %7 ], [ %5, %4 ]
ret i32 %10
}