#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_wprint(int, int, int /*<<< orphan*/ *);
int vswprintf(int /*<<< orphan*/ *, int, int /*<<< orphan*/ const *,
              int /*<<< orphan*/);
int terminal_vwprintf(int x, int y, 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_wprint(x, y, buffer);
  return rc;
}


x86 assembly (clang, -O0):
<terminal_vwprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1153 <terminal_vwprintf+0x33>
movl   $0x0,-0x4(%rbp)
jmp    1193 <terminal_vwprintf+0x73>
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
lea    0x2edf(%rip),%rdi
mov    $0x3ff,%esi
call   1040 <vswprintf@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    118d <terminal_vwprintf+0x6d>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
lea    0x2ebb(%rip),%rdx
call   1030 <terminal_wprint@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<terminal_vwprintf>:
push   %rbp
push   %rbx
push   %rax
test   %rdx,%rdx
je     1157 <terminal_vwprintf+0x37>
mov    %esi,%ebx
mov    %edi,%ebp
lea    0x2f0d(%rip),%rdi
mov    $0x3ff,%esi
call   1040 <vswprintf@plt>
test   %eax,%eax
jle    1159 <terminal_vwprintf+0x39>
lea    0x2ef8(%rip),%rdx
mov    %ebp,%edi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <terminal_wprint@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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