#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 mdbm_log_vlog_at(char const *, int, int, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ mdbm_strlcpy(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strerror(int);
int vsnprintf(char *, int, char const *, int /*<<< orphan*/);
int mdbm_log_vlogerror_at(const char *file, int line, int level, int error,
                          const char *format, va_list args) {
  char buf[4096];
  int len;
  len = vsnprintf(buf, sizeof(buf) - 2, format, args);
  strcpy(buf + len, ": ");
  len += 2;
  if (!error) {
    error = errno;
  }
  if (len < sizeof(buf)) {
    mdbm_strlcpy(buf + len, strerror(error), sizeof(buf) - len);
  }
  return mdbm_log_vlog_at(file, line, level, buf, NULL);
}


x86 assembly (clang, -O0):
<mdbm_log_vlogerror_at>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
lea    -0x1030(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    $0xffe,%esi
call   1040 <vsnprintf@plt>
mov    %eax,-0x1034(%rbp)
lea    -0x1030(%rbp),%rdi
movslq -0x1034(%rbp),%rax
add    %rax,%rdi
lea    0xe5a(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x1034(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1034(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11d0 <mdbm_log_vlogerror_at+0x80>
mov    0x2e15(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
movslq -0x1034(%rbp),%rax
cmp    $0x1000,%rax
jae    1222 <mdbm_log_vlogerror_at+0xd2>
lea    -0x1030(%rbp),%rax
movslq -0x1034(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x1040(%rbp)
mov    -0x14(%rbp),%edi
call   1070 <strerror@plt>
mov    -0x1040(%rbp),%rdi
mov    %eax,%esi
movslq -0x1034(%rbp),%rcx
mov    $0x1000,%eax
sub    %rcx,%rax
mov    %eax,%edx
call   1060 <mdbm_strlcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    -0x1030(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1050 <mdbm_log_vlog_at@plt>
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mdbm_log_vlogerror_at>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    %ecx,%r14d
mov    %edx,%r13d
mov    %esi,%ebx
mov    %rdi,%r12
lea    0x10(%rsp),%rdi
mov    $0xffe,%esi
mov    %r8,%rdx
mov    %r9d,%ecx
call   1040 <vsnprintf@plt>
mov    %eax,%r15d
movslq %eax,%rbp
lea    (%rsp,%rbp,1),%rdi
add    $0x10,%rdi
lea    0xe6a(%rip),%rsi
call   1030 <strcpy@plt>
add    $0x2,%ebp
cmp    $0xfff,%ebp
ja     11e7 <mdbm_log_vlogerror_at+0x97>
mov    %ebx,0xc(%rsp)
mov    %r13d,%ebx
test   %r14d,%r14d
jne    11bc <mdbm_log_vlogerror_at+0x6c>
mov    0x2e27(%rip),%rax
mov    (%rax),%r14d
mov    %ebp,%eax
lea    (%rsp,%rax,1),%r13
add    $0x10,%r13
mov    %r14d,%edi
call   1070 <strerror@plt>
mov    $0xffe,%edx
sub    %r15d,%edx
mov    %r13,%rdi
mov    %eax,%esi
call   1060 <mdbm_strlcpy@plt>
mov    %ebx,%r13d
mov    0xc(%rsp),%ebx
lea    0x10(%rsp),%rcx
mov    %r12,%rdi
mov    %ebx,%esi
mov    %r13d,%edx
xor    %r8d,%r8d
call   1050 <mdbm_log_vlog_at@plt>
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c": \00"
@errno = global i32 0
define i32 @mdbm_log_vlogerror_at(i8* %0, i32 %1, i32 %2, i32 %3, i8* %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca [4096 x i8]
%14 = alloca i32
store i8* %0, i8** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i8* %4, i8** %11
store i32 %5, i32* %12
%15 = getelementptr inbounds [4096 x i8], [4096 x i8]* %13, i64 0, i64 0
%16 = load i8*, i8** %11
%17 = load i32, i32* %12
%18 = call i32 @vsnprintf(i8* %15, i32 4094, i8* %16, i32 %17)
store i32 %18, i32* %14
%19 = getelementptr inbounds [4096 x i8], [4096 x i8]* %13, i64 0, i64 0
%20 = load i32, i32* %14
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = call i32 @strcpy(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%24 = load i32, i32* %14
%25 = add nsw i32 %24, 2
store i32 %25, i32* %14
%26 = load i32, i32* %10
%27 = icmp ne i32 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %6
%29 = load i32, i32* @errno
store i32 %29, i32* %10
br label %30
30: ; preds = %28, %6
%31 = load i32, i32* %14
%32 = sext i32 %31 to i64
%33 = icmp ult i64 %32, 4096
br i1 %33, label %34, label %46
34: ; preds = %30
%35 = getelementptr inbounds [4096 x i8], [4096 x i8]* %13, i64 0, i64 0
%36 = load i32, i32* %14
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i32, i32* %10
%40 = call i32 @strerror(i32 %39)
%41 = load i32, i32* %14
%42 = sext i32 %41 to i64
%43 = sub i64 4096, %42
%44 = trunc i64 %43 to i32
%45 = call i32 @mdbm_strlcpy(i8* %38, i32 %40, i32 %44)
br label %46
46: ; preds = %34, %30
%47 = load i8*, i8** %7
%48 = load i32, i32* %8
%49 = load i32, i32* %9
%50 = getelementptr inbounds [4096 x i8], [4096 x i8]* %13, i64 0, i64 0
%51 = call i32 @mdbm_log_vlog_at(i8* %47, i32 %48, i32 %49, i8* %50, i32* null)
ret i32 %51
}

LLVM IR (-O2):
@.str = [3 x i8] c": \00"
@errno = global i32 0
define i32 @mdbm_log_vlogerror_at(i8* %0, i32 %1, i32 %2, i32 %3, i8* nocapture %4, i32 %5) {
%7 = alloca [4096 x i8]
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%9 = call i32 @vsnprintf(i8* %8, i32 4094, i8* %4, i32 %5)
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 %10
%12 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%13 = add nsw i32 %9, 2
%14 = icmp ult i32 %13, 4096
br i1 %14, label %15, label %24
15: ; preds = %6
%16 = icmp eq i32 %3, 0
%17 = load i32, i32* @errno
%18 = select i1 %16, i32 %17, i32 %3
%19 = zext i32 %13 to i64
%20 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 %19
%21 = call i32 @strerror(i32 %18)
%22 = sub nsw i32 4094, %9
%23 = call i32 @mdbm_strlcpy(i8* %20, i32 %21, i32 %22)
br label %24
24: ; preds = %15, %6
%25 = call i32 @mdbm_log_vlog_at(i8* %0, i32 %1, i32 %2, i8* %8, i32* null)
ret i32 %25
}