#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 check_load();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sys_log(char *);
int /*<<< orphan*/ system(char *);
main() {
  printf("**********************************\n");
  printf("load_daemon : start\n");
  printf("**********************************\n");
  int protect_flag = 0;
  while (1) {
    if (check_load() == 1) {
      printf("check_load : loadavg alert!!!!!!\n");
      if (protect_flag == 1) {
        sys_log("reboot due to overloaded!");
        system("reboot");
      }
      if (protect_flag == 0) {
        sys_log("protect mode due to overloaded!\n");
        system("killall udp_get");
        sleep(2);
        system("killall mydns");
        sleep(2);
        system("service apache2 stop");
        sleep(2);
        protect_flag = 1;
      }
    } else
      printf("check_load : loadavg ok!\n");
    sleep(60);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
lea    0xeb2(%rip),%rdi
call   1040 <printf@plt>
lea    0xe82(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1050 <check_load@plt>
cmp    $0x1,%eax
jne    122c <main+0xdc>
lea    0xe98(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
jne    11c8 <main+0x78>
lea    0xea4(%rip),%rdi
call   1060 <sys_log@plt>
lea    0xeb2(%rip),%rdi
call   1030 <system@plt>
cmpl   $0x0,-0x8(%rbp)
jne    1227 <main+0xd7>
lea    0xea3(%rip),%rdi
call   1060 <sys_log@plt>
lea    0xeb8(%rip),%rdi
call   1030 <system@plt>
mov    $0x2,%edi
call   1070 <sleep@plt>
lea    0xeb2(%rip),%rdi
call   1030 <system@plt>
mov    $0x2,%edi
call   1070 <sleep@plt>
lea    0xeaa(%rip),%rdi
call   1030 <system@plt>
mov    $0x2,%edi
call   1070 <sleep@plt>
movl   $0x1,-0x8(%rbp)
jmp    1238 <main+0xe8>
lea    0xe9d(%rip),%rdi
call   1040 <printf@plt>
mov    $0x3c,%edi
call   1070 <sleep@plt>
jmp    118a <main+0x3a>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xf27(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xf04(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xf40(%rip),%rbx
lea    0xe74(%rip),%rbp
lea    0xe87(%rip),%r14
lea    0xf12(%rip),%r15
xor    %r12d,%r12d
jmp    11b8 <main+0x68>
nop
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r12d,%r13d
mov    $0x3c,%edi
call   1070 <sleep@plt>
mov    %r13d,%r12d
xor    %eax,%eax
call   1050 <check_load@plt>
cmp    $0x1,%eax
jne    11a0 <main+0x50>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0x1,%r13d
test   %r12d,%r12d
je     11ef <main+0x9f>
cmp    $0x1,%r12d
jne    11ab <main+0x5b>
mov    %rbp,%rdi
call   1060 <sys_log@plt>
mov    %r14,%rdi
call   1040 <system@plt>
jmp    11ab <main+0x5b>
lea    0xe2b(%rip),%rdi
call   1060 <sys_log@plt>
lea    0xe40(%rip),%rdi
call   1040 <system@plt>
mov    $0x2,%edi
call   1070 <sleep@plt>
lea    0xe3a(%rip),%rdi
call   1040 <system@plt>
mov    $0x2,%edi
call   1070 <sleep@plt>
lea    0xe32(%rip),%rdi
call   1040 <system@plt>
mov    $0x2,%edi
call   1070 <sleep@plt>
jmp    11ab <main+0x5b>

LLVM IR (-O0):
@.str = [36 x i8] c"**********************************\0A\00"
@.str.1 = [21 x i8] c"load_daemon : start\0A\00"
@.str.2 = [34 x i8] c"check_load : loadavg alert!!!!!!\0A\00"
@.str.3 = [26 x i8] c"reboot due to overloaded!\00"
@.str.4 = [7 x i8] c"reboot\00"
@.str.5 = [33 x i8] c"protect mode due to overloaded!\0A\00"
@.str.6 = [16 x i8] c"killall udp_get\00"
@.str.7 = [14 x i8] c"killall mydns\00"
@.str.8 = [21 x i8] c"service apache2 stop\00"
@.str.9 = [26 x i8] c"check_load : loadavg ok!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %6
6: ; preds = %0, %30
%7 = call i32 (...) @check_load()
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %28
9: ; preds = %6
%10 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = call i32 @sys_log(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 @system(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %16
16: ; preds = %13, %9
%17 = load i32, i32* %2
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %16
%20 = call i32 @sys_log(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0))
%21 = call i32 @system(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%22 = call i32 @sleep(i32 2)
%23 = call i32 @system(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
%24 = call i32 @sleep(i32 2)
%25 = call i32 @system(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%26 = call i32 @sleep(i32 2)
store i32 1, i32* %2
br label %27
27: ; preds = %19, %16
br label %30
28: ; preds = %6
%29 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
br label %30
30: ; preds = %28, %27
%31 = call i32 @sleep(i32 60)
br label %6
}

LLVM IR (-O2):
@.str.3 = [26 x i8] c"reboot due to overloaded!\00"
@.str.4 = [7 x i8] c"reboot\00"
@.str.5 = [33 x i8] c"protect mode due to overloaded!\0A\00"
@.str.6 = [16 x i8] c"killall udp_get\00"
@.str.7 = [14 x i8] c"killall mydns\00"
@.str.8 = [21 x i8] c"service apache2 stop\00"
@str.10 = [20 x i8] c"load_daemon : start\00"
@str.11 = [35 x i8] c"**********************************\00"
@str.12 = [25 x i8] c"check_load : loadavg ok!\00"
@str.13 = [33 x i8] c"check_load : loadavg alert!!!!!!\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.11, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.10, i64 0, i64 0))
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.11, i64 0, i64 0))
br label %4
4: ; preds = %23, %0
%5 = phi i32 [ 0, %0 ], [ %24, %23 ]
%6 = tail call i32 (...) @check_load()
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %21
8: ; preds = %4
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.13, i64 0, i64 0))
switch i32 %5, label %23 [
i32 1, label %10
i32 0, label %13
]
10: ; preds = %8
%11 = tail call i32 @sys_log(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%12 = tail call i32 @system(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %23
13: ; preds = %8
%14 = tail call i32 @sys_log(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0))
%15 = tail call i32 @system(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%16 = tail call i32 @sleep(i32 2)
%17 = tail call i32 @system(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
%18 = tail call i32 @sleep(i32 2)
%19 = tail call i32 @system(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
%20 = tail call i32 @sleep(i32 2)
br label %23
21: ; preds = %4
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.12, i64 0, i64 0))
br label %23
23: ; preds = %10, %8, %13, %21
%24 = phi i32 [ 1, %13 ], [ 1, %10 ], [ %5, %21 ], [ 1, %8 ]
%25 = tail call i32 @sleep(i32 60)
br label %4
}