#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 /*<<< orphan*/);
int /*<<< orphan*/ freeMem();
int /*<<< orphan*/ puts(char *);
int shutdown(int err) {
  puts("Shutting down...");
  if (err == 0) {
    puts("No errors");
    freeMem();
    exit(0);
  } else if (err == 1) {
    puts("Error allocating main memory");
    exit(0);
  } else if (err == 2) {
    puts("Unknown instruction");
    exit(0);
  } else {
    puts("Unknown error");
    exit(0);
  }
  return -1;
}


x86 assembly (clang, -O0):
<shutdown>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    0xebe(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,-0x4(%rbp)
jne    116b <shutdown+0x3b>
lea    0xeb9(%rip),%rdi
call   1030 <puts@plt>
mov    $0x0,%al
call   1040 <freeMem@plt>
xor    %edi,%edi
call   1050 <exit@plt>
cmpl   $0x1,-0x4(%rbp)
jne    1188 <shutdown+0x58>
lea    0xe9f(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1050 <exit@plt>
cmpl   $0x2,-0x4(%rbp)
jne    11a5 <shutdown+0x75>
lea    0xe9f(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1050 <exit@plt>
lea    0xea0(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<shutdown>:
push   %rbx
mov    %edi,%ebx
lea    0xec6(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x2,%ebx
je     1167 <shutdown+0x37>
cmp    $0x1,%ebx
je     1170 <shutdown+0x40>
test   %ebx,%ebx
jne    1179 <shutdown+0x49>
lea    0xebd(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <freeMem@plt>
xor    %edi,%edi
call   1050 <exit@plt>
lea    0xeca(%rip),%rdi
jmp    1180 <shutdown+0x50>
lea    0xea4(%rip),%rdi
jmp    1180 <shutdown+0x50>
lea    0xecc(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"Shutting down...\00"
@.str.1 = [10 x i8] c"No errors\00"
@.str.2 = [29 x i8] c"Error allocating main memory\00"
@.str.3 = [20 x i8] c"Unknown instruction\00"
@.str.4 = [14 x i8] c"Unknown error\00"
define i32 @shutdown(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* %2
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = call i32 @puts(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 (...) @freeMem()
%9 = call i32 @exit(i32 0)
unreachable
10: ; preds = %1
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = call i32 @puts(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @exit(i32 0)
unreachable
16: ; preds = %10
%17 = load i32, i32* %2
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %16
%23 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%24 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [17 x i8] c"Shutting down...\00"
@.str.1 = [10 x i8] c"No errors\00"
@.str.2 = [29 x i8] c"Error allocating main memory\00"
@.str.3 = [20 x i8] c"Unknown instruction\00"
@.str.4 = [14 x i8] c"Unknown error\00"
define i32 @shutdown(i32 %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
switch i32 %0, label %13 [
i32 0, label %3
i32 1, label %7
i32 2, label %10
]
3: ; preds = %1
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 (...) @freeMem()
%6 = tail call i32 @exit(i32 0)
unreachable
7: ; preds = %1
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 @exit(i32 0)
unreachable
10: ; preds = %1
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%12 = tail call i32 @exit(i32 0)
unreachable
13: ; preds = %1
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%15 = tail call i32 @exit(i32 0)
unreachable
}