#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 */

/* Variables and functions */
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
void err_msg(int type, char *func, char *error) {
  char msg[512];
  if (type & 0x1) {
    fprintf(stderr, "Warning:  ");
    sprintf(msg, "Warning:  %s", error);
  } else if (type & 0x2) {
    fprintf(stderr, "FATAL:  ");
    sprintf(msg, "FATAL:  %s", error);
  }
  fprintf(stderr, "%s: %s\n", func, error);
  if (type & 0x4) {
    perror("perror() = ");
    fprintf(stderr, "errno = %d\n", errno);
  }
  fflush(stderr);
  if (type & 0x2) {
    exit(-1);
  }
}


x86 assembly (clang, -O0):
<err_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11a8 <err_msg+0x58>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
lea    0xe7b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe6d(%rip),%rsi
call   1060 <sprintf@plt>
jmp    11ea <err_msg+0x9a>
mov    -0x4(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     11e5 <err_msg+0x95>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe41(%rip),%rsi
call   1060 <sprintf@plt>
jmp    11ea <err_msg+0x9a>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe2a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x4(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     1244 <err_msg+0xf4>
lea    0xe15(%rip),%rdi
call   1050 <perror@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
mov    0x2da4(%rip),%rax
mov    (%rax),%edx
lea    0xe03(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
mov    -0x4(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     126b <err_msg+0x11b>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<err_msg>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebx
test   $0x1,%bl
jne    1180 <err_msg+0x30>
test   $0x2,%bl
je     11ac <err_msg+0x5c>
lea    0xeaa(%rip),%r12
lea    0xe9a(%rip),%rsi
jmp    118e <err_msg+0x3e>
lea    0xe84(%rip),%r12
lea    0xe72(%rip),%rsi
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %rsp,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1060 <sprintf@plt>
mov    0x2e2d(%rip),%r12
mov    (%r12),%edi
lea    0xe6e(%rip),%rsi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1030 <fprintf@plt>
test   $0x4,%bl
jne    11ed <err_msg+0x9d>
mov    (%r12),%edi
call   1040 <fflush@plt>
test   $0x2,%bl
jne    1216 <err_msg+0xc6>
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe40(%rip),%rdi
call   1050 <perror@plt>
mov    (%r12),%edi
mov    0x2dd4(%rip),%rax
mov    (%rax),%edx
lea    0xe33(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11d0 <err_msg+0x80>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [11 x i8] c"Warning: \00"
@.str.1 = [13 x i8] c"Warning: %s\00"
@.str.2 = [9 x i8] c"FATAL: \00"
@.str.3 = [11 x i8] c"FATAL: %s\00"
@.str.4 = [8 x i8] c"%s: %s\0A\00"
@.str.5 = [12 x i8] c"perror() = \00"
@.str.6 = [12 x i8] c"errno = %d\0A\00"
@errno = global i32 0
define void @err_msg(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [512 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = load i32, i32* %4
%9 = and i32 %8, 1
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %3
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%15 = load i8*, i8** %6
%16 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %28
17: ; preds = %3
%18 = load i32, i32* %4
%19 = and i32 %18, 2
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%25 = load i8*, i8** %6
%26 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %21, %17
br label %28
28: ; preds = %27, %11
%29 = load i32, i32* @stderr
%30 = load i8*, i8** %5
%31 = load i8*, i8** %6
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %30, i8* %31)
%33 = load i32, i32* %4
%34 = and i32 %33, 4
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %28
%37 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%38 = load i32, i32* @stderr
%39 = load i32, i32* @errno
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %36, %28
%42 = load i32, i32* @stderr
%43 = call i32 @fflush(i32 %42)
%44 = load i32, i32* %4
%45 = and i32 %44, 2
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %41
%48 = call i32 @exit(i32 -1)
unreachable
49: ; preds = %41
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [11 x i8] c"Warning: \00"
@.str.1 = [13 x i8] c"Warning: %s\00"
@.str.2 = [9 x i8] c"FATAL: \00"
@.str.3 = [11 x i8] c"FATAL: %s\00"
@.str.4 = [8 x i8] c"%s: %s\0A\00"
@.str.5 = [12 x i8] c"perror() = \00"
@.str.6 = [12 x i8] c"errno = %d\0A\00"
@errno = global i32 0
define void @err_msg(i32 %0, i8* %1, i8* %2) {
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%6 = and i32 %0, 1
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = and i32 %0, 2
%10 = icmp eq i32 %9, 0
br i1 %10, label %17, label %11
11: ; preds = %8, %3
%12 = phi i8* [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), %3 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), %8 ]
%13 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), %3 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), %8 ]
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* %12)
%16 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) %13, i8* %2)
br label %17
17: ; preds = %11, %8
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %1, i8* %2)
%20 = and i32 %0, 4
%21 = icmp eq i32 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %17
%23 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%24 = load i32, i32* @stderr
%25 = load i32, i32* @errno
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %22, %17
%28 = load i32, i32* @stderr
%29 = tail call i32 @fflush(i32 %28)
%30 = and i32 %0, 2
%31 = icmp eq i32 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %27
%33 = tail call i32 @exit(i32 -1)
unreachable
34: ; preds = %27
ret void
}