#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*/ msg;

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ vsnprintf(char *, int, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ write_log_file(int, char *);
void output_error_msg(const char *format, va_list ap) {
  char msg[1024];
  vsnprintf(msg, sizeof(msg), format, ap);
  fflush(stdout);
  fputs(msg, stderr);
  fflush(stderr);
  write_log_file(-1, msg);
}


x86 assembly (clang, -O0):
<output_error_msg>:
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>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
lea    -0x410(%rbp),%rdi
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
lea    -0x410(%rbp),%rsi
mov    $0xffffffff,%edi
call   1060 <write_log_file@plt>
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output_error_msg>:
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %esi,%ecx
mov    %rdi,%rdx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x400,%esi
call   1030 <vsnprintf@plt>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    0x2e6c(%rip),%rbx
mov    (%rbx),%esi
mov    %r14,%rdi
call   1040 <fputs@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
mov    $0xffffffff,%edi
mov    %r14,%rsi
call   1060 <write_log_file@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stdout = global i32 0
@stderr = global i32 0
define void @output_error_msg(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 i32 @vsnprintf(i8* %6, i32 1024, i8* %7, i32 %8)
%10 = load i32, i32* @stdout
%11 = call i32 @fflush(i32 %10)
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%13 = load i32, i32* @stderr
%14 = call i32 @fputs(i8* %12, i32 %13)
%15 = load i32, i32* @stderr
%16 = call i32 @fflush(i32 %15)
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%18 = call i32 @write_log_file(i32 -1, i8* %17)
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@stderr = global i32 0
define void @output_error_msg(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 i32 @vsnprintf(i8* %4, i32 1024, i8* %0, i32 %1)
%6 = load i32, i32* @stdout
%7 = tail call i32 @fflush(i32 %6)
%8 = load i32, i32* @stderr
%9 = call i32 @fputs(i8* %4, i32 %8)
%10 = load i32, i32* @stderr
%11 = call i32 @fflush(i32 %10)
%12 = call i32 @write_log_file(i32 -1, i8* %4)
ret void
}