#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*/ wchar_t;
typedef int /*<<< orphan*/ va_list;

/* Variables and functions */
int terminal_wset(int /*<<< orphan*/ *);
int vswprintf(int /*<<< orphan*/ *, int, int /*<<< orphan*/ const *,
              int /*<<< orphan*/);
int terminal_vwsetf(const wchar_t *s, va_list args) {
  static wchar_t buffer[1024] = {0};
  int rc = 0;
  if (s == NULL)
    return 0;
  rc = vswprintf(buffer, 1024 - 1, s, args);
  if (rc > 0)
    rc = terminal_wset(buffer);
  return rc;
}


x86 assembly (clang, -O0):
<terminal_vwsetf>:
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_vwsetf+0x2d>
movl   $0x0,-0x4(%rbp)
jmp    1187 <terminal_vwsetf+0x67>
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0x2ee5(%rip),%rdi
mov    $0x3ff,%esi
call   1030 <vswprintf@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    1181 <terminal_vwsetf+0x61>
lea    0x2ec7(%rip),%rdi
call   1040 <terminal_wset@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_vwsetf>:
test   %rdi,%rdi
je     1151 <terminal_vwsetf+0x31>
push   %rax
mov    %esi,%ecx
mov    %rdi,%rdx
lea    0x2f0e(%rip),%rdi
mov    $0x3ff,%esi
call   1030 <vswprintf@plt>
test   %eax,%eax
lea    0x8(%rsp),%rsp
jle    1153 <terminal_vwsetf+0x33>
lea    0x2ef4(%rip),%rdi
jmp    1040 <terminal_wset@plt>
xor    %eax,%eax
ret

LLVM IR (-O0):
@terminal_vwsetf.buffer = internal global [1024 x i32] zeroinitializer
define i32 @terminal_vwsetf(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 0, i32* %6
%7 = load i32*, i32** %4
%8 = icmp eq i32* %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 i32*, i32** %4
%12 = load i32, i32* %5
%13 = call i32 @vswprintf(i32* getelementptr inbounds ([1024 x i32], [1024 x i32]* @terminal_vwsetf.buffer, i64 0, i64 0), i32 1023, i32* %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_wset(i32* getelementptr inbounds ([1024 x i32], [1024 x i32]* @terminal_vwsetf.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_vwsetf.buffer = internal global [1024 x i32] zeroinitializer
define i32 @terminal_vwsetf(i32* %0, i32 %1) {
%3 = icmp eq i32* %0, null
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = tail call i32 @vswprintf(i32* getelementptr inbounds ([1024 x i32], [1024 x i32]* @terminal_vwsetf.buffer, i64 0, i64 0), i32 1023, i32* %0, i32 %1)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @terminal_wset(i32* getelementptr inbounds ([1024 x i32], [1024 x i32]* @terminal_vwsetf.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
}