#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*/ fflush(int /*<<< orphan*/);
scalar_t__ printf(char *, char *);
int /*<<< orphan*/ stdout;
int vsprintf(char *, char const *, int /*<<< orphan*/);
int sarvprintf_std_ret(const char *format, va_list args) {
  char tmp[2048] = {
      0,
  };
  int res = vsprintf(tmp, format, args);
  res = res && printf("\r%s", tmp);
  fflush(stdout);
  return res;
}


x86 assembly (clang, -O0):
<sarvprintf_std_ret>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x810(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1040 <memset@plt>
lea    -0x810(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1060 <vsprintf@plt>
mov    %eax,-0x814(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x814(%rbp)
mov    %al,-0x815(%rbp)
je     11b3 <sarvprintf_std_ret+0x73>
lea    -0x810(%rbp),%rsi
lea    0xe5f(%rip),%rdi
call   1030 <printf@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x815(%rbp)
mov    -0x815(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x814(%rbp)
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    -0x814(%rbp),%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sarvprintf_std_ret>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x808,%rsp
mov    %esi,%r14d
mov    %rdi,%rbp
mov    %rsp,%r15
xor    %ebx,%ebx
mov    $0x800,%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %r14d,%edx
call   1060 <vsprintf@plt>
test   %eax,%eax
je     1190 <sarvprintf_std_ret+0x50>
lea    0xe80(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    %ebx,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"\0D%s\00"
@stdout = global i32 0
define i32 @sarvprintf_std_ret(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [2048 x i8]
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = bitcast [2048 x i8]* %5 to i8*
%8 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%9 = load i8*, i8** %3
%10 = load i32, i32* %4
%11 = call i32 @vsprintf(i8* %8, i8* %9, i32 %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%16 = call i64 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = icmp ne i64 %16, 0
br label %18
18: ; preds = %14, %2
%19 = phi i1 [ false, %2 ], [ %17, %14 ]
%20 = zext i1 %19 to i32
store i32 %20, i32* %6
%21 = load i32, i32* @stdout
%22 = call i32 @fflush(i32 %21)
%23 = load i32, i32* %6
ret i32 %23
}

LLVM IR (-O2):
@.str = [4 x i8] c"\0D%s\00"
@stdout = global i32 0
define i32 @sarvprintf_std_ret(i8* nocapture %0, i32 %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%5 = call i32 @vsprintf(i8* %4, i8* %0, i32 %1)
%6 = icmp eq i32 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = call i64 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %4)
%9 = icmp ne i64 %8, 0
%10 = zext i1 %9 to i32
br label %11
11: ; preds = %7, %2
%12 = phi i32 [ 0, %2 ], [ %10, %7 ]
%13 = load i32, i32* @stdout
%14 = call i32 @fflush(i32 %13)
ret i32 %12
}