#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 errno;
int /*<<< orphan*/ logmessage(int, char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int);
int /*<<< orphan*/ vsnprintf(char *, int, char const *, int /*<<< orphan*/);
__attribute__((format(printf, 2, 0))) void
vlogerrmessage(int pri, const char *fmt, va_list args) {
  int _errno = errno;
  char buf[1024];
  vsnprintf(buf, sizeof(buf), fmt, args);
  logmessage(pri, "%s: %s", buf, strerror(_errno));
  errno = _errno;
}


x86 assembly (clang, -O0):
<vlogerrmessage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0x2e94(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    $0x400,%esi
call   1030 <vsnprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x42c(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x428(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <strerror@plt>
mov    -0x42c(%rbp),%edi
mov    -0x428(%rbp),%rdx
mov    %eax,%ecx
lea    0xe62(%rip),%rsi
call   1040 <logmessage@plt>
mov    -0x18(%rbp),%ecx
mov    0x2e33(%rip),%rax
mov    %ecx,(%rax)
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vlogerrmessage>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %edx,%ecx
mov    %rsi,%rdx
mov    %edi,%ebx
mov    0x2e95(%rip),%r15
mov    (%r15),%ebp
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x400,%esi
call   1030 <vsnprintf@plt>
mov    %ebp,%edi
call   1050 <strerror@plt>
lea    0xe94(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %eax,%ecx
call   1040 <logmessage@plt>
mov    %ebp,(%r15)
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
@.str = [7 x i8] c"%s: %s\00"
define void @vlogerrmessage(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1024 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i32, i32* @errno
store i32 %9, i32* %7
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%11 = load i8*, i8** %5
%12 = load i32, i32* %6
%13 = call i32 @vsnprintf(i8* %10, i32 1024, i8* %11, i32 %12)
%14 = load i32, i32* %4
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%16 = load i32, i32* %7
%17 = call i32 @strerror(i32 %16)
%18 = call i32 @logmessage(i32 %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %15, i32 %17)
%19 = load i32, i32* %7
store i32 %19, i32* @errno
ret void
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [7 x i8] c"%s: %s\00"
define void @vlogerrmessage(i32 %0, i8* nocapture %1, i32 %2) {
%4 = alloca [1024 x i8]
%5 = load i32, i32* @errno
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = call i32 @vsnprintf(i8* %6, i32 1024, i8* %1, i32 %2)
%8 = tail call i32 @strerror(i32 %5)
%9 = call i32 @logmessage(i32 %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %6, i32 %8)
store i32 %5, i32* @errno
ret void
}