#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;

/* Variables and functions */
int /*<<< orphan*/ perror(char *);
int vsnprintf(char *, int, char const *, int /*<<< orphan*/);
void log_dolog_errno(const char *fmt, va_list args) {
  static char buf[256];
  int n = vsnprintf(buf, 256, fmt, args);
  if (buf[--n] == '\n')
    buf[n] = 0;
  perror(buf);
}


x86 assembly (clang, -O0):
<log_dolog_errno>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0x2f03(%rip),%rdi
mov    $0x100,%esi
call   1030 <vsnprintf@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
movslq %eax,%rcx
lea    0x2ee3(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1179 <log_dolog_errno+0x59>
movslq -0x10(%rbp),%rcx
lea    0x2ecb(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2ec0(%rip),%rdi
call   1040 <perror@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_dolog_errno>:
push   %rbx
mov    %esi,%ecx
mov    %rdi,%rdx
lea    0x2f13(%rip),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1030 <vsnprintf@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    1148 <log_dolog_errno+0x28>
movb   $0x0,-0x1(%rax,%rbx,1)
lea    0x2ef1(%rip),%rdi
pop    %rbx
jmp    1040 <perror@plt>

LLVM IR (-O0):
@log_dolog_errno.buf = internal global [256 x i8] zeroinitializer
define void @log_dolog_errno(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = load i32, i32* %4
%8 = call i32 @vsnprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @log_dolog_errno.buf, i64 0, i64 0), i32 256, i8* %6, i32 %7)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = add nsw i32 %9, -1
store i32 %10, i32* %5
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [256 x i8], [256 x i8]* @log_dolog_errno.buf, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 10
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [256 x i8], [256 x i8]* @log_dolog_errno.buf, i64 0, i64 %18
store i8 0, i8* %19
br label %20
20: ; preds = %16, %2
%21 = call i32 @perror(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @log_dolog_errno.buf, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@log_dolog_errno.buf = internal global [256 x i8] zeroinitializer
define void @log_dolog_errno(i8* nocapture %0, i32 %1) {
%3 = tail call i32 @vsnprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @log_dolog_errno.buf, i64 0, i64 0), i32 256, i8* %0, i32 %1)
%4 = add nsw i32 %3, -1
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds [256 x i8], [256 x i8]* @log_dolog_errno.buf, i64 0, i64 %5
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 10
br i1 %8, label %9, label %10
9: ; preds = %2
store i8 0, i8* %6
br label %10
10: ; preds = %9, %2
%11 = tail call i32 @perror(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @log_dolog_errno.buf, i64 0, i64 0))
ret void
}