#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*/ errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
scalar_t__ strstr(char const *, char *);
int /*<<< orphan*/ vfprintf(int /*<<< orphan*/, char const *,
                            int /*<<< orphan*/);
void vsyslog(int fac, const char *fmt, va_list ap) {
  (void)vfprintf(stderr, fmt, ap);
  if (strstr(fmt, "%m"))
    (void)fprintf(stderr, " (%s)", strerror(errno));
  (void)fprintf(stderr, "\n");
  fflush(stderr);
}


x86 assembly (clang, -O0):
<vsyslog>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <vfprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     11bf <vsyslog+0x6f>
mov    0x2e48(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x18(%rbp),%edi
mov    %rax,%rdx
lea    0xe4b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
lea    0xe3a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vsyslog>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x2e82(%rip),%r14
mov    (%r14),%edi
call   1050 <vfprintf@plt>
lea    0xe93(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strstr@plt>
test   %rax,%rax
je     119e <vsyslog+0x4e>
mov    (%r14),%ebx
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe71(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r14),%edi
lea    0xe61(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r14),%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <fflush@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [3 x i8] c"%m\00"
@.str.1 = [6 x i8] c" (%s)\00"
@errno = global i32 0
@.str.2 = [2 x i8] c"\0A\00"
define void @vsyslog(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %5
%9 = load i32, i32* %6
%10 = call i32 @vfprintf(i32 %7, i8* %8, i32 %9)
%11 = load i8*, i8** %5
%12 = call i64 @strstr(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %3
%15 = load i32, i32* @stderr
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %14, %3
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32, i32* @stderr
%23 = call i32 @fflush(i32 %22)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [3 x i8] c"%m\00"
@.str.1 = [6 x i8] c" (%s)\00"
@errno = global i32 0
@.str.2 = [2 x i8] c"\0A\00"
define void @vsyslog(i32 %0, i8* %1, i32 %2) {
%4 = load i32, i32* @stderr
%5 = tail call i32 @vfprintf(i32 %4, i8* %1, i32 %2)
%6 = tail call i64 @strstr(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %13
13: ; preds = %8, %3
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%16 = load i32, i32* @stderr
%17 = tail call i32 @fflush(i32 %16)
ret void
}