#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*/ acpi_poweroff();
int /*<<< orphan*/ apm_poweroff();
int /*<<< orphan*/ hang();
int /*<<< orphan*/ outportb(int, char const);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ printf_warn(char *);
void shutdown(void) {
  printf("Attempting to poweroff with ACPI ...\n");
  acpi_poweroff();
  printf_warn("ACPI poweroff failed. Trying APM poweroff ...\n");
  apm_poweroff();
  printf_warn("APM poweroff failed. Trying emulator specific poweroff ...\n");
  const char *str;
  for (str = "Shutdown"; *str; ++str) {
    outportb(0x8900, *str);
  }
  outportb(0xF4, 0x00);
  printf_warn("Emulator specific poweroff failed. Hanging ...\n");
  hang();
}


x86 assembly (clang, -O0):
<shutdown>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe91(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <acpi_poweroff@plt>
lea    0xea4(%rip),%rdi
call   1030 <printf_warn@plt>
mov    $0x0,%al
call   1070 <apm_poweroff@plt>
lea    0xec0(%rip),%rdi
call   1030 <printf_warn@plt>
lea    0xef0(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11d4 <shutdown+0x74>
mov    -0x8(%rbp),%rax
mov    $0x8900,%edi
movsbl (%rax),%esi
call   1080 <outportb@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11a5 <shutdown+0x45>
mov    $0xf4,%edi
xor    %esi,%esi
call   1080 <outportb@plt>
lea    0xeb3(%rip),%rdi
call   1030 <printf_warn@plt>
mov    $0x0,%al
call   1060 <hang@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shutdown>:
push   %rax
lea    0xf33(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <acpi_poweroff@plt>
lea    0xe85(%rip),%rdi
call   1040 <printf_warn@plt>
xor    %eax,%eax
call   1070 <apm_poweroff@plt>
lea    0xea1(%rip),%rdi
call   1040 <printf_warn@plt>
mov    $0x8900,%edi
mov    $0x53,%esi
call   1080 <outportb@plt>
mov    $0x8900,%edi
mov    $0x68,%esi
call   1080 <outportb@plt>
mov    $0x8900,%edi
mov    $0x75,%esi
call   1080 <outportb@plt>
mov    $0x8900,%edi
mov    $0x74,%esi
call   1080 <outportb@plt>
mov    $0x8900,%edi
mov    $0x64,%esi
call   1080 <outportb@plt>
mov    $0x8900,%edi
mov    $0x6f,%esi
call   1080 <outportb@plt>
mov    $0x8900,%edi
mov    $0x77,%esi
call   1080 <outportb@plt>
mov    $0x8900,%edi
mov    $0x6e,%esi
call   1080 <outportb@plt>
mov    $0xf4,%edi
xor    %esi,%esi
call   1080 <outportb@plt>
lea    0xe4d(%rip),%rdi
call   1040 <printf_warn@plt>
xor    %eax,%eax
pop    %rcx
jmp    1060 <hang@plt>

LLVM IR (-O0):
@.str = [38 x i8] c"Attempting to poweroff with ACPI ...\0A\00"
@.str.1 = [47 x i8] c"ACPI poweroff failed. Trying APM poweroff ...\0A\00"
@.str.2 = [60 x i8] c"APM poweroff failed. Trying emulator specific poweroff ...\0A\00"
@.str.3 = [9 x i8] c"Shutdown\00"
@.str.4 = [48 x i8] c"Emulator specific poweroff failed. Hanging ...\0A\00"
define void @shutdown() {
%1 = alloca i8*
%2 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%3 = call i32 (...) @acpi_poweroff()
%4 = call i32 @printf_warn(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 (...) @apm_poweroff()
%6 = call i32 @printf_warn(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0))
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8** %1
br label %7
7: ; preds = %15, %0
%8 = load i8*, i8** %1
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %7
%12 = load i8*, i8** %1
%13 = load i8, i8* %12
%14 = call i32 @outportb(i32 35072, i8 signext %13)
br label %15
15: ; preds = %11
%16 = load i8*, i8** %1
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %1
br label %7
18: ; preds = %7
%19 = call i32 @outportb(i32 244, i8 signext 0)
%20 = call i32 @printf_warn(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0))
%21 = call i32 (...) @hang()
ret void
}

LLVM IR (-O2):
@.str.1 = [47 x i8] c"ACPI poweroff failed. Trying APM poweroff ...\0A\00"
@.str.2 = [60 x i8] c"APM poweroff failed. Trying emulator specific poweroff ...\0A\00"
@.str.4 = [48 x i8] c"Emulator specific poweroff failed. Hanging ...\0A\00"
@str = [37 x i8] c"Attempting to poweroff with ACPI ...\00"
define void @shutdown() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 (...) @acpi_poweroff()
%3 = tail call i32 @printf_warn(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32 (...) @apm_poweroff()
%5 = tail call i32 @printf_warn(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 @outportb(i32 35072, i8 signext 83)
%7 = tail call i32 @outportb(i32 35072, i8 signext 104)
%8 = tail call i32 @outportb(i32 35072, i8 signext 117)
%9 = tail call i32 @outportb(i32 35072, i8 signext 116)
%10 = tail call i32 @outportb(i32 35072, i8 signext 100)
%11 = tail call i32 @outportb(i32 35072, i8 signext 111)
%12 = tail call i32 @outportb(i32 35072, i8 signext 119)
%13 = tail call i32 @outportb(i32 35072, i8 signext 110)
%14 = tail call i32 @outportb(i32 244, i8 signext 0)
%15 = tail call i32 @printf_warn(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0))
%16 = tail call i32 (...) @hang()
ret void
}