#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ vfprintf(int /*<<< orphan*/, char const *,
                            int /*<<< orphan*/);
void _err(int exitcode, int flags, const char *fmt, va_list ap) {
  fprintf(stderr, "%s: ", (flags & 1) ? "error" : "warning");
  vfprintf(stderr, fmt, ap);
  if ((flags & 2) == 0)
    fprintf(stderr, ": %s", strerror(errno));
  fprintf(stderr, "\n");
  if (flags & 1)
    exit(exitcode);
}


x86 assembly (clang, -O0):
<_err>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%ecx
and    $0x1,%ecx
lea    0xea0(%rip),%rdx
lea    0xe93(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
lea    0xe80(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <vfprintf@plt>
mov    -0x8(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
jne    11d9 <_err+0x99>
mov    0x2e2e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x18(%rbp),%edi
mov    %rax,%rdx
lea    0xe41(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1207 <_err+0xc7>
mov    -0x4(%rbp),%edi
call   1050 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_err>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r15d
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %edi,%r14d
mov    0x2e86(%rip),%r12
mov    (%r12),%edi
test   $0x1,%bpl
lea    0xea2(%rip),%rax
lea    0xe95(%rip),%rdx
cmove  %rax,%rdx
lea    0xe85(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r12),%edi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1040 <vfprintf@plt>
test   $0x2,%bpl
jne    11bc <_err+0x7c>
mov    (%r12),%ebx
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe63(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r12),%edi
lea    0xe51(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
test   $0x1,%bpl
jne    11dd <_err+0x9d>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14d,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [5 x i8] c"%s: \00"
@.str.1 = [6 x i8] c"error\00"
@.str.2 = [8 x i8] c"warning\00"
@.str.3 = [5 x i8] c": %s\00"
@errno = global i32 0
@.str.4 = [2 x i8] c"\0A\00"
define void @_err(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%9 = load i32, i32* @stderr
%10 = load i32, i32* %6
%11 = and i32 %10, 1
%12 = icmp ne i32 %11, 0
%13 = zext i1 %12 to i64
%14 = select i1 %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0)
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %7
%18 = load i32, i32* %8
%19 = call i32 @vfprintf(i32 %16, i8* %17, i32 %18)
%20 = load i32, i32* %6
%21 = and i32 %20, 2
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %4
%24 = load i32, i32* @stderr
%25 = load i32, i32* @errno
%26 = call i8* @strerror(i32 %25)
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %23, %4
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%31 = load i32, i32* %6
%32 = and i32 %31, 1
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %28
%35 = load i32, i32* %5
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %28
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [5 x i8] c"%s: \00"
@.str.1 = [6 x i8] c"error\00"
@.str.2 = [8 x i8] c"warning\00"
@.str.3 = [5 x i8] c": %s\00"
@errno = global i32 0
@.str.4 = [2 x i8] c"\0A\00"
define void @_err(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = load i32, i32* @stderr
%6 = and i32 %1, 1
%7 = icmp eq i32 %6, 0
%8 = select i1 %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0)
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @stderr
%11 = tail call i32 @vfprintf(i32 %10, i8* %2, i32 %3)
%12 = and i32 %1, 2
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %4
%15 = load i32, i32* @stderr
%16 = load i32, i32* @errno
%17 = tail call i8* @strerror(i32 %16)
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %14, %4
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br i1 %7, label %24, label %22
22: ; preds = %19
%23 = tail call i32 @exit(i32 %0)
unreachable
24: ; preds = %19
ret void
}