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

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stdout;
scalar_t__ vsnprintf(char *, int, char const *, int /*<<< orphan*/);
void internal_log(const char *format, va_list ap) {
  char buf[1024];
  if (vsnprintf(buf, sizeof(buf), format, ap) < 0) {
    buf[sizeof(buf) - 1] = '\0';
  }
  fprintf(stdout, "%s\n", buf);
  fflush(stdout);
}


x86 assembly (clang, -O0):
<internal_log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    $0x400,%esi
call   1030 <vsnprintf@plt>
cmp    $0x0,%rax
jge    1168 <internal_log+0x38>
movb   $0x0,-0x11(%rbp)
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rdx
lea    0xe81(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<internal_log>:
push   %rbx
sub    $0x400,%rsp
mov    %esi,%ecx
mov    %rdi,%rdx
mov    %rsp,%rdi
mov    $0x400,%esi
call   1030 <vsnprintf@plt>
test   %rax,%rax
jns    1157 <internal_log+0x27>
movb   $0x0,0x3ff(%rsp)
mov    0x2e82(%rip),%rbx
mov    (%rbx),%edi
lea    0xe99(%rip),%rsi
mov    %rsp,%rdx
call   1040 <fprintf@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
add    $0x400,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define void @internal_log(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [1024 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%7 = load i8*, i8** %3
%8 = load i32, i32* %4
%9 = call i64 @vsnprintf(i8* %6, i32 1024, i8* %7, i32 %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 1023
store i8 0, i8* %12
br label %13
13: ; preds = %11, %2
%14 = load i32, i32* @stdout
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @stdout
%18 = call i32 @fflush(i32 %17)
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define void @internal_log(i8* nocapture %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i64 @vsnprintf(i8* %4, i32 1024, i8* %0, i32 %1)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 1023
store i8 0, i8* %8
br label %9
9: ; preds = %7, %2
%10 = load i32, i32* @stdout
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %4)
%12 = load i32, i32* @stdout
%13 = call i32 @fflush(i32 %12)
ret void
}