#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int unrez_strerror(int, char *, int);
int /*<<< orphan*/ vfprintf(int /*<<< orphan*/, char const *,
                            int /*<<< orphan*/);
void verror_errf(int errcode, const char *msg, va_list ap) {
  char buf[256];
  int r;
  fputs("error: ", stderr);
  vfprintf(stderr, msg, ap);
  r = unrez_strerror(errcode, buf, sizeof(buf));
  if (r == 0) {
    fprintf(stderr, ": %s\n", buf);
  } else {
    fprintf(stderr, ": error #%d occurred\n", errcode);
  }
}


x86 assembly (clang, -O0):
<verror_errf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
lea    0xe9b(%rip),%rdi
call   1030 <fputs@plt>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <vfprintf@plt>
mov    -0x4(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   1060 <unrez_strerror@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0x0,-0x124(%rbp)
jne    11c9 <verror_errf+0x89>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
lea    -0x120(%rbp),%rdx
lea    0xe4b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11e3 <verror_errf+0xa3>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe32(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verror_errf>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %edi,%r14d
mov    0x2e84(%rip),%r15
mov    (%r15),%esi
lea    0xe9a(%rip),%rdi
call   1030 <fputs@plt>
mov    (%r15),%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1050 <vfprintf@plt>
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0x100,%edx
call   1060 <unrez_strerror@plt>
mov    (%r15),%edi
test   %eax,%eax
je     11a2 <verror_errf+0x62>
lea    0xe78(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11b3 <verror_errf+0x73>
lea    0xe5f(%rip),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"error: \00"
@stderr = global i32 0
@.str.1 = [6 x i8] c": %s\0A\00"
@.str.2 = [22 x i8] c": error #%d occurred\0A\00"
define void @verror_errf(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [256 x i8]
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i32, i32* @stderr
%10 = call i32 @fputs(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %5
%13 = load i32, i32* %6
%14 = call i32 @vfprintf(i32 %11, i8* %12, i32 %13)
%15 = load i32, i32* %4
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%17 = call i32 @unrez_strerror(i32 %15, i8* %16, i32 256)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %3
%21 = load i32, i32* @stderr
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %22)
br label %28
24: ; preds = %3
%25 = load i32, i32* @stderr
%26 = load i32, i32* %4
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %24, %20
ret void
}

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