#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 */
typedef scalar_t__ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ SIGHUP;
int /*<<< orphan*/ SIGKILL;
int /*<<< orphan*/ WNOHANG;
scalar_t__ cleanup_runlevel(scalar_t__, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ clear_zombies(int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
void exit_runlevel(uint8_t oldmask, uint8_t newmask) {
  uint8_t n = 0;
  if (cleanup_runlevel(oldmask, newmask, SIGHUP)) {
    while (n++ < 9) {
      sleep(5);
      clear_zombies(WNOHANG);
      if (cleanup_runlevel(oldmask, newmask, 0) == 0)
        return;
    }
    cleanup_runlevel(oldmask, newmask, SIGKILL);
  }
}


x86 assembly (clang, -O0):
<exit_runlevel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2e99(%rip),%rax
mov    (%rax),%edx
call   1040 <cleanup_runlevel@plt>
cmp    $0x0,%rax
je     11d7 <exit_runlevel+0xa7>
jmp    116d <exit_runlevel+0x3d>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
cmp    $0x9,%rax
jge    11c1 <exit_runlevel+0x91>
mov    $0x5,%edi
call   1050 <sleep@plt>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
call   1030 <clear_zombies@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1040 <cleanup_runlevel@plt>
cmp    $0x0,%rax
jne    11bc <exit_runlevel+0x8c>
jmp    11d7 <exit_runlevel+0xa7>
jmp    116d <exit_runlevel+0x3d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2e00(%rip),%rax
mov    (%rax),%edx
call   1040 <cleanup_runlevel@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exit_runlevel>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2eae(%rip),%rax
mov    (%rax),%edx
call   1040 <cleanup_runlevel@plt>
test   %rax,%rax
je     12ce <exit_runlevel+0x19e>
mov    $0x5,%edi
call   1050 <sleep@plt>
mov    0x2e7d(%rip),%r15
mov    (%r15),%edi
call   1030 <clear_zombies@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <cleanup_runlevel@plt>
test   %rax,%rax
je     12ce <exit_runlevel+0x19e>
mov    $0x5,%edi
call   1050 <sleep@plt>
mov    (%r15),%edi
call   1030 <clear_zombies@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <cleanup_runlevel@plt>
test   %rax,%rax
je     12ce <exit_runlevel+0x19e>
mov    $0x5,%edi
call   1050 <sleep@plt>
mov    (%r15),%edi
call   1030 <clear_zombies@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <cleanup_runlevel@plt>
test   %rax,%rax
je     12ce <exit_runlevel+0x19e>
mov    $0x5,%edi
call   1050 <sleep@plt>
mov    (%r15),%edi
call   1030 <clear_zombies@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <cleanup_runlevel@plt>
test   %rax,%rax
je     12ce <exit_runlevel+0x19e>
mov    $0x5,%edi
call   1050 <sleep@plt>
mov    (%r15),%edi
call   1030 <clear_zombies@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <cleanup_runlevel@plt>
test   %rax,%rax
je     12ce <exit_runlevel+0x19e>
mov    $0x5,%edi
call   1050 <sleep@plt>
mov    (%r15),%edi
call   1030 <clear_zombies@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <cleanup_runlevel@plt>
test   %rax,%rax
je     12ce <exit_runlevel+0x19e>
mov    $0x5,%edi
call   1050 <sleep@plt>
mov    (%r15),%edi
call   1030 <clear_zombies@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <cleanup_runlevel@plt>
test   %rax,%rax
je     12ce <exit_runlevel+0x19e>
mov    $0x5,%edi
call   1050 <sleep@plt>
mov    (%r15),%edi
call   1030 <clear_zombies@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <cleanup_runlevel@plt>
test   %rax,%rax
je     12ce <exit_runlevel+0x19e>
mov    $0x5,%edi
call   1050 <sleep@plt>
mov    (%r15),%edi
call   1030 <clear_zombies@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <cleanup_runlevel@plt>
test   %rax,%rax
je     12ce <exit_runlevel+0x19e>
mov    0x2d14(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <cleanup_runlevel@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SIGHUP = global i32 0
@WNOHANG = global i32 0
@SIGKILL = global i32 0
define void @exit_runlevel(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
store i64 %0, i64* %3
store i64 %1, i64* %4
store i64 0, i64* %5
%6 = load i64, i64* %3
%7 = load i64, i64* %4
%8 = load i32, i32* @SIGHUP
%9 = call i64 @cleanup_runlevel(i64 %6, i64 %7, i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %31
11: ; preds = %2
br label %12
12: ; preds = %25, %11
%13 = load i64, i64* %5
%14 = add nsw i64 %13, 1
store i64 %14, i64* %5
%15 = icmp slt i64 %13, 9
br i1 %15, label %16, label %26
16: ; preds = %12
%17 = call i32 @sleep(i32 5)
%18 = load i32, i32* @WNOHANG
%19 = call i32 @clear_zombies(i32 %18)
%20 = load i64, i64* %3
%21 = load i64, i64* %4
%22 = call i64 @cleanup_runlevel(i64 %20, i64 %21, i32 0)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %16
br label %31
25: ; preds = %16
br label %12
26: ; preds = %12
%27 = load i64, i64* %3
%28 = load i64, i64* %4
%29 = load i32, i32* @SIGKILL
%30 = call i64 @cleanup_runlevel(i64 %27, i64 %28, i32 %29)
br label %31
31: ; preds = %24, %26, %2
ret void
}

LLVM IR (-O2):
@SIGHUP = global i32 0
@WNOHANG = global i32 0
@SIGKILL = global i32 0
define void @exit_runlevel(i64 %0, i64 %1) {
%3 = load i32, i32* @SIGHUP
%4 = tail call i64 @cleanup_runlevel(i64 %0, i64 %1, i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %63, label %6
6: ; preds = %2
%7 = tail call i32 @sleep(i32 5)
%8 = load i32, i32* @WNOHANG
%9 = tail call i32 @clear_zombies(i32 %8)
%10 = tail call i64 @cleanup_runlevel(i64 %0, i64 %1, i32 0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %63, label %12
12: ; preds = %6
%13 = tail call i32 @sleep(i32 5)
%14 = load i32, i32* @WNOHANG
%15 = tail call i32 @clear_zombies(i32 %14)
%16 = tail call i64 @cleanup_runlevel(i64 %0, i64 %1, i32 0)
%17 = icmp eq i64 %16, 0
br i1 %17, label %63, label %18
18: ; preds = %12
%19 = tail call i32 @sleep(i32 5)
%20 = load i32, i32* @WNOHANG
%21 = tail call i32 @clear_zombies(i32 %20)
%22 = tail call i64 @cleanup_runlevel(i64 %0, i64 %1, i32 0)
%23 = icmp eq i64 %22, 0
br i1 %23, label %63, label %24
24: ; preds = %18
%25 = tail call i32 @sleep(i32 5)
%26 = load i32, i32* @WNOHANG
%27 = tail call i32 @clear_zombies(i32 %26)
%28 = tail call i64 @cleanup_runlevel(i64 %0, i64 %1, i32 0)
%29 = icmp eq i64 %28, 0
br i1 %29, label %63, label %30
30: ; preds = %24
%31 = tail call i32 @sleep(i32 5)
%32 = load i32, i32* @WNOHANG
%33 = tail call i32 @clear_zombies(i32 %32)
%34 = tail call i64 @cleanup_runlevel(i64 %0, i64 %1, i32 0)
%35 = icmp eq i64 %34, 0
br i1 %35, label %63, label %36
36: ; preds = %30
%37 = tail call i32 @sleep(i32 5)
%38 = load i32, i32* @WNOHANG
%39 = tail call i32 @clear_zombies(i32 %38)
%40 = tail call i64 @cleanup_runlevel(i64 %0, i64 %1, i32 0)
%41 = icmp eq i64 %40, 0
br i1 %41, label %63, label %42
42: ; preds = %36
%43 = tail call i32 @sleep(i32 5)
%44 = load i32, i32* @WNOHANG
%45 = tail call i32 @clear_zombies(i32 %44)
%46 = tail call i64 @cleanup_runlevel(i64 %0, i64 %1, i32 0)
%47 = icmp eq i64 %46, 0
br i1 %47, label %63, label %48
48: ; preds = %42
%49 = tail call i32 @sleep(i32 5)
%50 = load i32, i32* @WNOHANG
%51 = tail call i32 @clear_zombies(i32 %50)
%52 = tail call i64 @cleanup_runlevel(i64 %0, i64 %1, i32 0)
%53 = icmp eq i64 %52, 0
br i1 %53, label %63, label %54
54: ; preds = %48
%55 = tail call i32 @sleep(i32 5)
%56 = load i32, i32* @WNOHANG
%57 = tail call i32 @clear_zombies(i32 %56)
%58 = tail call i64 @cleanup_runlevel(i64 %0, i64 %1, i32 0)
%59 = icmp eq i64 %58, 0
br i1 %59, label %63, label %60
60: ; preds = %54
%61 = load i32, i32* @SIGKILL
%62 = tail call i64 @cleanup_runlevel(i64 %0, i64 %1, i32 %61)
br label %63
63: ; preds = %6, %12, %18, %24, %30, %36, %42, %48, %54, %2, %60
ret void
}