#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*/ LINUX_REBOOT_CMD_POWER_OFF;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ reboot(int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ write(int, char *, int);
void terminate(void) {
  int fd;
  sleep(3);
  fd = open("/sys/kernel/debug/zcore/reipl", O_WRONLY, 0);
  if (fd == -1)
    goto no_reipl;
  write(fd, "1", 1);
  close(fd);
no_reipl:
  reboot(LINUX_REBOOT_CMD_POWER_OFF);
}


x86 assembly (clang, -O0):
<terminate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x3,%edi
call   1070 <sleep@plt>
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
lea    0xe8e(%rip),%rdi
xor    %edx,%edx
call   1050 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    118b <terminate+0x3b>
jmp    11a7 <terminate+0x57>
mov    -0x4(%rbp),%edi
lea    0xe89(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
call   1060 <reboot@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<terminate>:
push   %rbx
mov    $0x3,%edi
call   1070 <sleep@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
lea    0xe95(%rip),%rdi
xor    %edx,%edx
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     1193 <terminate+0x43>
mov    %eax,%ebx
lea    0xe9e(%rip),%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
pop    %rbx
jmp    1060 <reboot@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"/sys/kernel/debug/zcore/reipl\00"
@O_WRONLY = global i32 0
@.str.1 = [2 x i8] c"1\00"
@LINUX_REBOOT_CMD_POWER_OFF = global i32 0
define void @terminate() {
%1 = alloca i32
%2 = call i32 @sleep(i32 3)
%3 = load i32, i32* @O_WRONLY
%4 = call i32 @open(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %3, i32 0)
store i32 %4, i32* %1
%5 = load i32, i32* %1
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %8
7: ; preds = %0
br label %13
8: ; preds = %0
%9 = load i32, i32* %1
%10 = call i32 @write(i32 %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%11 = load i32, i32* %1
%12 = call i32 @close(i32 %11)
br label %13
13: ; preds = %8, %7
%14 = load i32, i32* @LINUX_REBOOT_CMD_POWER_OFF
%15 = call i32 @reboot(i32 %14)
ret void
}

LLVM IR (-O2):
@.str = [30 x i8] c"/sys/kernel/debug/zcore/reipl\00"
@O_WRONLY = global i32 0
@.str.1 = [2 x i8] c"1\00"
@LINUX_REBOOT_CMD_POWER_OFF = global i32 0
define void @terminate() {
%1 = tail call i32 @sleep(i32 3)
%2 = load i32, i32* @O_WRONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %2, i32 0)
%4 = icmp eq i32 %3, -1
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = tail call i32 @write(i32 %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%7 = tail call i32 @close(i32 %3)
br label %8
8: ; preds = %0, %5
%9 = load i32, i32* @LINUX_REBOOT_CMD_POWER_OFF
%10 = tail call i32 @reboot(i32 %9)
ret void
}