#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ puts(char *);
void fatalerror(int failure, char *wherewhat) {
  int exitcode;
  switch (failure) {
  case 2:
    exitcode = 3;
    (void)puts("Could not get required memory");
    break;
  case 1:
    exitcode = 2;
    (void)puts("Failed to open file");
    break;
  default:
    exitcode = -127;
    break;
  }
  perror(wherewhat);
  exit(exitcode);
}


x86 assembly (clang, -O0):
<fatalerror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0x1,%eax
je     117c <fatalerror+0x4c>
jmp    1153 <fatalerror+0x23>
mov    -0x18(%rbp),%eax
sub    $0x2,%eax
jne    1194 <fatalerror+0x64>
jmp    1164 <fatalerror+0x34>
movl   $0x3,-0x14(%rbp)
lea    0xe8e(%rip),%rdi
call   1030 <puts@plt>
jmp    119b <fatalerror+0x6b>
movl   $0x2,-0x14(%rbp)
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
jmp    119b <fatalerror+0x6b>
movl   $0xffffff81,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <perror@plt>
mov    -0x14(%rbp),%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<fatalerror>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
je     1153 <fatalerror+0x23>
mov    $0xffffff81,%ebp
cmp    $0x1,%edi
jne    1164 <fatalerror+0x34>
mov    $0x2,%ebp
lea    0xecd(%rip),%rdi
jmp    115f <fatalerror+0x2f>
mov    $0x3,%ebp
lea    0xea1(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <perror@plt>
mov    %ebp,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"Could not get required memory\00"
@.str.1 = [20 x i8] c"Failed to open file\00"
define void @fatalerror(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = load i32, i32* %3
switch i32 %6, label %11 [
i32 2, label %7
i32 1, label %9
]
7: ; preds = %2
store i32 3, i32* %5
%8 = call i32 @puts(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %12
9: ; preds = %2
store i32 2, i32* %5
%10 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %12
11: ; preds = %2
store i32 -127, i32* %5
br label %12
12: ; preds = %11, %9, %7
%13 = load i8*, i8** %4
%14 = call i32 @perror(i8* %13)
%15 = load i32, i32* %5
%16 = call i32 @exit(i32 %15)
unreachable
}

LLVM IR (-O2):
@.str = [30 x i8] c"Could not get required memory\00"
@.str.1 = [20 x i8] c"Failed to open file\00"
define void @fatalerror(i32 %0, i8* nocapture %1) {
switch i32 %0, label %8 [
i32 2, label %4
i32 1, label %3
]
3: ; preds = %2
br label %4
4: ; preds = %2, %3
%5 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), %3 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), %2 ]
%6 = phi i32 [ 2, %3 ], [ 3, %2 ]
%7 = tail call i32 @puts(i8* dereferenceable(1) %5)
br label %8
8: ; preds = %4, %2
%9 = phi i32 [ -127, %2 ], [ %6, %4 ]
%10 = tail call i32 @perror(i8* %1)
%11 = tail call i32 @exit(i32 %9)
unreachable
}