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

/* Variables and functions */
int errno;
int /*<<< orphan*/ log_level_enabled(int);
int /*<<< orphan*/ log_msg(char const *, int, char const *, int, char *,
                           int /*<<< orphan*/ *);
int /*<<< orphan*/ *strerror(int);
int /*<<< orphan*/ vsnprintf(char *, int, char const *, int /*<<< orphan*/);
void _log_vwrite(const char *file, int line, const char *func, int do_errno,
                 int priority, const char *fmt, va_list ap) {
  int saved_errno = errno;
  char message[512 + 1];
  if (!log_level_enabled(priority))
    return;
  vsnprintf(&message[0], sizeof(message), fmt, ap);
  log_msg(file, line, func, priority, &message[0],
          do_errno ? strerror(saved_errno) : NULL);
}


x86 assembly (clang, -O0):
<_log_vwrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x260,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%edi
call   1030 <log_level_enabled@plt>
cmp    $0x0,%eax
jne    1186 <_log_vwrite+0x46>
jmp    122d <_log_vwrite+0xed>
lea    -0x230(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    0x10(%rbp),%ecx
mov    $0x201,%esi
call   1040 <vsnprintf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x258(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x24c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x248(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x23c(%rbp)
lea    -0x230(%rbp),%rax
mov    %rax,-0x238(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11f2 <_log_vwrite+0xb2>
mov    -0x2c(%rbp),%edi
call   1060 <strerror@plt>
mov    %rax,-0x260(%rbp)
jmp    1200 <_log_vwrite+0xc0>
xor    %eax,%eax
mov    %rax,-0x260(%rbp)
jmp    1200 <_log_vwrite+0xc0>
mov    -0x238(%rbp),%r8
mov    -0x23c(%rbp),%ecx
mov    -0x248(%rbp),%rdx
mov    -0x24c(%rbp),%esi
mov    -0x258(%rbp),%rdi
mov    -0x260(%rbp),%r9
call   1050 <log_msg@plt>
add    $0x260,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_log_vwrite>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %r9,%r14
mov    %r8d,%ebx
mov    %ecx,%ebp
mov    %rdx,0x8(%rsp)
mov    %esi,%r15d
mov    %rdi,%r12
mov    0x2e75(%rip),%rax
mov    (%rax),%r13d
mov    %r8d,%edi
call   1030 <log_level_enabled@plt>
test   %eax,%eax
je     11be <_log_vwrite+0x7e>
mov    0x250(%rsp),%ecx
lea    0x10(%rsp),%rdi
mov    $0x201,%esi
mov    %r14,%rdx
call   1040 <vsnprintf@plt>
test   %ebp,%ebp
je     11a4 <_log_vwrite+0x64>
mov    %r13d,%edi
call   1060 <strerror@plt>
mov    %rax,%r9
jmp    11a7 <_log_vwrite+0x67>
xor    %r9d,%r9d
lea    0x10(%rsp),%r8
mov    %r12,%rdi
mov    %r15d,%esi
mov    0x8(%rsp),%rdx
mov    %ebx,%ecx
call   1050 <log_msg@plt>
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
define void @_log_vwrite(i8* %0, i32 %1, i8* %2, i32 %3, i32 %4, i8* %5, i32 %6) {
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
%16 = alloca [513 x i8]
store i8* %0, i8** %8
store i32 %1, i32* %9
store i8* %2, i8** %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i8* %5, i8** %13
store i32 %6, i32* %14
%17 = load i32, i32* @errno
store i32 %17, i32* %15
%18 = load i32, i32* %12
%19 = call i32 @log_level_enabled(i32 %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %22, label %21
21: ; preds = %7
br label %41
22: ; preds = %7
%23 = getelementptr inbounds [513 x i8], [513 x i8]* %16, i64 0, i64 0
%24 = load i8*, i8** %13
%25 = load i32, i32* %14
%26 = call i32 @vsnprintf(i8* %23, i32 513, i8* %24, i32 %25)
%27 = load i8*, i8** %8
%28 = load i32, i32* %9
%29 = load i8*, i8** %10
%30 = load i32, i32* %12
%31 = getelementptr inbounds [513 x i8], [513 x i8]* %16, i64 0, i64 0
%32 = load i32, i32* %11
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %22
%35 = load i32, i32* %15
%36 = call i32* @strerror(i32 %35)
br label %38
37: ; preds = %22
br label %38
38: ; preds = %37, %34
%39 = phi i32* [ %36, %34 ], [ null, %37 ]
%40 = call i32 @log_msg(i8* %27, i32 %28, i8* %29, i32 %30, i8* %31, i32* %39)
br label %41
41: ; preds = %38, %21
ret void
}

LLVM IR (-O2):
@errno = global i32 0
define void @_log_vwrite(i8* %0, i32 %1, i8* %2, i32 %3, i32 %4, i8* nocapture %5, i32 %6) {
%8 = alloca [513 x i8]
%9 = load i32, i32* @errno
%10 = getelementptr inbounds [513 x i8], [513 x i8]* %8, i64 0, i64 0
%11 = tail call i32 @log_level_enabled(i32 %4)
%12 = icmp eq i32 %11, 0
br i1 %12, label %21, label %13
13: ; preds = %7
%14 = call i32 @vsnprintf(i8* %10, i32 513, i8* %5, i32 %6)
%15 = icmp eq i32 %3, 0
br i1 %15, label %18, label %16
16: ; preds = %13
%17 = tail call i32* @strerror(i32 %9)
br label %18
18: ; preds = %13, %16
%19 = phi i32* [ %17, %16 ], [ null, %13 ]
%20 = call i32 @log_msg(i8* %0, i32 %1, i8* %2, i32 %4, i8* %10, i32* %19)
br label %21
21: ; preds = %7, %18
ret void
}