#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 */
struct sysinfo {
  scalar_t__ *loads;
};
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int SI_LOAD_SHIFT;
int atoi(char *);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ kill_cpu();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sysinfo(struct sysinfo *);
int main(int argc, char **argv) {
  struct sysinfo info;
  long d = (1 << SI_LOAD_SHIFT);
  float real_load;
  int fork_nums = 4;
  pid_t pid;
  if (argc >= 2) {
    fork_nums = atoi(argv[1]);
  }
  while (fork_nums--) {
    if ((pid = fork()) > 0) {
      continue;
    }
    for (;;) {
      sysinfo(&info);
      real_load = (float)info.loads[0] / (float)d;
      if (real_load <= 3.0) {
        kill_cpu();
      }
      if (real_load > 4.0)
        sleep(5);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e73(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%eax
shl    %cl,%eax
cltq
mov    %rax,-0x20(%rbp)
movl   $0x4,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     119d <main+0x4d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x28(%rbp)
jmp    11a2 <main+0x52>
mov    -0x28(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x28(%rbp)
cmp    $0x0,%eax
je     1240 <main+0xf0>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jle    11ce <main+0x7e>
jmp    11a2 <main+0x52>
jmp    11d3 <main+0x83>
lea    -0x18(%rbp),%rdi
call   1050 <sysinfo@plt>
mov    -0x18(%rbp),%rax
cvtsi2ssq (%rax),%xmm0
cvtsi2ssq -0x20(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xdfb(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     1216 <main+0xc6>
mov    $0x0,%al
call   1030 <kill_cpu@plt>
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xde1(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    123b <main+0xeb>
mov    $0x5,%edi
call   1060 <sleep@plt>
jmp    11d3 <main+0x83>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    0x2e83(%rip),%rax
mov    (%rax),%cl
mov    $0x1,%ebp
shl    %cl,%ebp
mov    $0x4,%ebx
cmp    $0x2,%edi
jl     117b <main+0x2b>
mov    0x8(%rsi),%rdi
call   1040 <atoi@plt>
mov    %eax,%ebx
add    $0x1,%ebx
xchg   %ax,%ax
add    $0xffffffff,%ebx
je     11f0 <main+0xa0>
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
jg     1180 <main+0x30>
cvtsi2ss %ebp,%xmm0
movss  %xmm0,0xc(%rsp)
lea    0x10(%rsp),%rbx
nop
mov    %rbx,%rdi
call   1050 <sysinfo@plt>
mov    0x10(%rsp),%rax
xorps  %xmm1,%xmm1
cvtsi2ssq (%rax),%xmm1
divss  0xc(%rsp),%xmm1
movss  0xe3d(%rip),%xmm0
ucomiss %xmm1,%xmm0
jb     11db <main+0x8b>
xor    %eax,%eax
movss  %xmm1,0x8(%rsp)
call   1030 <kill_cpu@plt>
movss  0x8(%rsp),%xmm1
ucomiss 0xe22(%rip),%xmm1
jbe    11a0 <main+0x50>
mov    $0x5,%edi
call   1060 <sleep@plt>
jmp    11a0 <main+0x50>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sysinfo = type { i64* }
@SI_LOAD_SHIFT = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sysinfo
%7 = alloca i64
%8 = alloca float
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @SI_LOAD_SHIFT
%12 = shl i32 1, %11
%13 = sext i32 %12 to i64
store i64 %13, i64* %7
store i32 4, i32* %9
%14 = load i32, i32* %4
%15 = icmp sge i32 %14, 2
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %9
br label %21
21: ; preds = %16, %2
br label %22
22: ; preds = %29, %21
%23 = load i32, i32* %9
%24 = add nsw i32 %23, -1
store i32 %24, i32* %9
%25 = icmp ne i32 %23, 0
br i1 %25, label %26, label %53
26: ; preds = %22
%27 = call i32 (...) @fork()
store i32 %27, i32* %10
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %26
br label %22
30: ; preds = %26
br label %31
31: ; preds = %52, %30
%32 = call i32 @sysinfo(%struct.sysinfo* %6)
%33 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %6, i32 0, i32 0
%34 = load i64*, i64** %33
%35 = getelementptr inbounds i64, i64* %34, i64 0
%36 = load i64, i64* %35
%37 = sitofp i64 %36 to float
%38 = load i64, i64* %7
%39 = sitofp i64 %38 to float
%40 = fdiv float %37, %39
store float %40, float* %8
%41 = load float, float* %8
%42 = fpext float %41 to double
%43 = fcmp ole double %42, 3.000000e+00
br i1 %43, label %44, label %46
44: ; preds = %31
%45 = call i32 (...) @kill_cpu()
br label %46
46: ; preds = %44, %31
%47 = load float, float* %8
%48 = fpext float %47 to double
%49 = fcmp ogt double %48, 4.000000e+00
br i1 %49, label %50, label %52
50: ; preds = %46
%51 = call i32 @sleep(i32 5)
br label %52
52: ; preds = %50, %46
br label %31
53: ; preds = %22
ret i32 0
}

LLVM IR (-O2):
%struct.sysinfo = type { i64* }
@SI_LOAD_SHIFT = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sysinfo
%4 = bitcast %struct.sysinfo* %3 to i8*
%5 = load i32, i32* @SI_LOAD_SHIFT
%6 = shl nuw i32 1, %5
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
br label %12
12: ; preds = %8, %2
%13 = phi i32 [ 4, %2 ], [ %11, %8 ]
br label %14
14: ; preds = %12, %17
%15 = phi i32 [ %18, %17 ], [ %13, %12 ]
%16 = icmp eq i32 %15, 0
br i1 %16, label %38, label %17
17: ; preds = %14
%18 = add nsw i32 %15, -1
%19 = tail call i32 (...) @fork()
%20 = icmp sgt i32 %19, 0
br i1 %20, label %14, label %21
21: ; preds = %17
%22 = getelementptr inbounds %struct.sysinfo, %struct.sysinfo* %3, i64 0, i32 0
%23 = sitofp i32 %6 to float
br label %24
24: ; preds = %37, %21
%25 = call i32 @sysinfo(%struct.sysinfo* %3)
%26 = load i64*, i64** %22
%27 = load i64, i64* %26
%28 = sitofp i64 %27 to float
%29 = fdiv float %28, %23
%30 = fcmp ugt float %29, 3.000000e+00
br i1 %30, label %33, label %31
31: ; preds = %24
%32 = call i32 (...) @kill_cpu()
br label %33
33: ; preds = %31, %24
%34 = fcmp ogt float %29, 4.000000e+00
br i1 %34, label %35, label %37
35: ; preds = %33
%36 = call i32 @sleep(i32 5)
br label %37
37: ; preds = %35, %33
br label %24
38: ; preds = %14
ret i32 0
}