#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 errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *,
                           int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strerror(int);
int /*<<< orphan*/ verror_msg(char const *, int /*<<< orphan*/);
void vperror_msg(const char *s, va_list p) {
  int err = errno;
  if (s == 0)
    s = "";
  verror_msg(s, p);
  if (*s)
    s = ": ";
  fprintf(stderr, "%s%s\n", s, strerror(err));
}


x86 assembly (clang, -O0):
<vperror_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1161 <vperror_msg+0x31>
lea    0xeab(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <verror_msg@plt>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1185 <vperror_msg+0x55>
lea    0xe7f(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    0x2e54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%edi
call   1050 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rdx
mov    %eax,%ecx
lea    0xe52(%rip),%rsi
call   1040 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vperror_msg>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e9d(%rip),%rax
mov    (%rax),%r14d
test   %rdi,%rdi
lea    0xec0(%rip),%rbx
cmovne %rdi,%rbx
mov    %rbx,%rdi
call   1030 <verror_msg@plt>
cmpb   $0x0,(%rbx)
lea    0xea2(%rip),%rbp
cmove  %rbx,%rbp
mov    0x2e77(%rip),%rax
mov    (%rax),%ebx
mov    %r14d,%edi
call   1050 <strerror@plt>
lea    0xe89(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %eax,%ecx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <fprintf@plt>

LLVM IR (-O0):
@errno = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c": \00"
@stderr = global i32 0
@.str.2 = [6 x i8] c"%s%s\0A\00"
define void @vperror_msg(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 i32, i32* @errno
store i32 %6, i32* %5
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %2
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %3
br label %10
10: ; preds = %9, %2
%11 = load i8*, i8** %3
%12 = load i32, i32* %4
%13 = call i32 @verror_msg(i8* %11, i32 %12)
%14 = load i8*, i8** %3
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %10
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %18
18: ; preds = %17, %10
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %3
%21 = load i32, i32* %5
%22 = call i32 @strerror(i32 %21)
%23 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %20, i32 %22)
ret void
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c": \00"
@stderr = global i32 0
@.str.2 = [6 x i8] c"%s%s\0A\00"
define void @vperror_msg(i8* %0, i32 %1) {
%3 = load i32, i32* @errno
%4 = icmp eq i8* %0, null
%5 = select i1 %4, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %0
%6 = tail call i32 @verror_msg(i8* %5, i32 %1)
%7 = load i8, i8* %5
%8 = icmp eq i8 %7, 0
%9 = select i1 %8, i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0)
%10 = load i32, i32* @stderr
%11 = tail call i32 @strerror(i32 %3)
%12 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %9, i32 %11)
ret void
}