#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 int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, float, float, float, float, float);
int /*<<< orphan*/ sscanf(char *, char *, float *);
int /*<<< orphan*/ sys_log(char *);
int check_load() {
  FILE *stream = NULL;
  char buf[8] = {0};
  float load[5];
  char loadinfo[150] = {0};
  int i;
  printf("\n---------check load average-----------\n");
  for (i = 0; i < 5; i++) {
    stream = NULL;
    if ((stream = popen("cat /proc/loadavg | awk '{print $1}'", "r")) == NULL)
      printf("popen failed\n");
    memset(buf, 0, sizeof(buf));
    fread(buf, sizeof(char), sizeof(buf), stream);
    buf[7] = '\0';
    sscanf(buf, "%f", &load[i]);
    pclose(stream);
    printf("load[%d] : %.2f\n", i, load[i]);
    if (i < 4)
      sleep(10);
  }
  if (load[0] > 0.8) {
    sprintf(loadinfo, "load : %.2f  %.2f  %.2f  %.2f  %.2f", load[0], load[1],
            load[2], load[3], load[4]);
    sys_log(loadinfo);
  }
  if ((load[0] < load[1]) && (load[1] < load[2]) && (load[2] < load[3]) &&
      (load[3] < load[4])) {
    printf("loadavg is increasing...\n");
    if (load[0] > 3) {
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<check_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movq   $0x0,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
lea    -0xd0(%rbp),%rdi
xor    %esi,%esi
mov    $0x96,%edx
call   1060 <memset@plt>
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0xd4(%rbp)
cmpl   $0x5,-0xd4(%rbp)
jge    12cd <check_load+0x13d>
movq   $0x0,-0x10(%rbp)
lea    0xe3b(%rip),%rdi
lea    0xe59(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1222 <check_load+0x92>
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
lea    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x8,%edx
call   1030 <fread@plt>
movb   $0x0,-0x11(%rbp)
lea    -0x18(%rbp),%rdi
movslq -0xd4(%rbp),%rax
lea    -0x30(%rbp),%rdx
shl    $0x2,%rax
add    %rax,%rdx
lea    0xe00(%rip),%rsi
call   1070 <sscanf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <pclose@plt>
mov    -0xd4(%rbp),%esi
movslq -0xd4(%rbp),%rax
movss  -0x30(%rbp,%rax,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdd7(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
cmpl   $0x4,-0xd4(%rbp)
jge    12b4 <check_load+0x124>
mov    $0xa,%edi
call   10b0 <sleep@plt>
jmp    12b9 <check_load+0x129>
mov    -0xd4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xd4(%rbp)
jmp    11de <check_load+0x4e>
movss  -0x30(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd22(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1320 <check_load+0x190>
lea    -0xd0(%rbp),%rdi
movss  -0x30(%rbp),%xmm0
movss  -0x2c(%rbp),%xmm1
movss  -0x28(%rbp),%xmm2
movss  -0x24(%rbp),%xmm3
movss  -0x20(%rbp),%xmm4
lea    0xd6f(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0xd0(%rbp),%rdi
call   1090 <sys_log@plt>
movss  -0x30(%rbp),%xmm1
movss  -0x2c(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    13a1 <check_load+0x211>
movss  -0x2c(%rbp),%xmm1
movss  -0x28(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    13a1 <check_load+0x211>
movss  -0x28(%rbp),%xmm1
movss  -0x24(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    13a1 <check_load+0x211>
movss  -0x24(%rbp),%xmm1
movss  -0x20(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    13a1 <check_load+0x211>
lea    0xd2f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movss  -0x30(%rbp),%xmm0
movss  0xc81(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    139c <check_load+0x20c>
movl   $0x1,-0x4(%rbp)
jmp    13a8 <check_load+0x218>
jmp    13a1 <check_load+0x211>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_load>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
movq   $0x0,0x18(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movq   $0x0,0xae(%rsp)
lea    0xe65(%rip),%rdi
call   1030 <puts@plt>
xor    %r12d,%r12d
lea    0x18(%rsp),%rbx
lea    0xe19(%rip),%r13
lea    0xe15(%rip),%rbp
xor    %r15d,%r15d
jmp    1242 <check_load+0xa2>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r15
add    $0x4,%r12
cmp    $0x5,%r15
je     12d9 <check_load+0x139>
lea    0xdc3(%rip),%rdi
lea    0xde1(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1269 <check_load+0xc9>
lea    0xe48(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1070 <memset@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x8,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
movb   $0x0,0x1f(%rsp)
lea    (%rsp,%r12,1),%rdx
mov    %rbx,%rdi
mov    %r13,%rsi
call   1080 <sscanf@plt>
mov    %r14,%rdi
call   1060 <pclose@plt>
movss  (%rsp,%r15,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %rbp,%rdi
mov    %r15d,%esi
mov    $0x1,%al
call   1050 <printf@plt>
cmp    $0x3,%r15
ja     1230 <check_load+0x90>
mov    $0xa,%edi
call   10c0 <sleep@plt>
jmp    1230 <check_load+0x90>
movss  (%rsp),%xmm0
cvtss2sd %xmm0,%xmm1
ucomisd 0xd16(%rip),%xmm1
jbe    1325 <check_load+0x185>
movss  0x4(%rsp),%xmm1
movss  0x8(%rsp),%xmm2
movss  0xc(%rsp),%xmm3
movss  0x10(%rsp),%xmm4
lea    0xd3c(%rip),%rsi
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   10b0 <sprintf@plt>
mov    %rbx,%rdi
call   10a0 <sys_log@plt>
movss  (%rsp),%xmm0
movss  0x4(%rsp),%xmm1
ucomiss %xmm0,%xmm1
jbe    1370 <check_load+0x1d0>
movss  0x8(%rsp),%xmm0
ucomiss %xmm1,%xmm0
jbe    1370 <check_load+0x1d0>
movss  0xc(%rsp),%xmm1
ucomiss %xmm0,%xmm1
jbe    1370 <check_load+0x1d0>
movss  0x10(%rsp),%xmm0
ucomiss %xmm1,%xmm0
jbe    1370 <check_load+0x1d0>
lea    0xd3b(%rip),%rdi
call   1030 <puts@plt>
movss  (%rsp),%xmm0
mov    $0x1,%eax
ucomiss 0xc9a(%rip),%xmm0
ja     1372 <check_load+0x1d2>
xor    %eax,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"\0A---------check load average-----------\0A\00"
@.str.1 = [37 x i8] c"cat /proc/loadavg | awk '{print $1}'\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [14 x i8] c"popen failed\0A\00"
@.str.4 = [3 x i8] c"%f\00"
@.str.5 = [17 x i8] c"load[%d] : %.2f\0A\00"
@.str.6 = [36 x i8] c"load : %.2f %.2f %.2f %.2f %.2f\00"
@.str.7 = [26 x i8] c"loadavg is increasing...\0A\00"
define i32 @check_load() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [8 x i8]
%4 = alloca [5 x float]
%5 = alloca [150 x i8]
%6 = alloca i32
store i32* null, i32** %2
%7 = bitcast [8 x i8]* %3 to i8*
%8 = bitcast [150 x i8]* %5 to i8*
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %6
br label %10
10: ; preds = %44, %0
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 5
br i1 %12, label %13, label %47
13: ; preds = %10
store i32* null, i32** %2
%14 = call i32* @popen(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %14, i32** %2
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %18
18: ; preds = %16, %13
%19 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%20 = call i32 @memset(i8* %19, i32 0, i32 8)
%21 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%22 = load i32*, i32** %2
%23 = call i32 @fread(i8* %21, i32 1, i32 8, i32* %22)
%24 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 7
store i8 0, i8* %24
%25 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [5 x float], [5 x float]* %4, i64 0, i64 %27
%29 = call i32 @sscanf(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), float* %28)
%30 = load i32*, i32** %2
%31 = call i32 @pclose(i32* %30)
%32 = load i32, i32* %6
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [5 x float], [5 x float]* %4, i64 0, i64 %34
%36 = load float, float* %35
%37 = fpext float %36 to double
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %32, double %37)
%39 = load i32, i32* %6
%40 = icmp slt i32 %39, 4
br i1 %40, label %41, label %43
41: ; preds = %18
%42 = call i32 @sleep(i32 10)
br label %43
43: ; preds = %41, %18
br label %44
44: ; preds = %43
%45 = load i32, i32* %6
%46 = add nsw i32 %45, 1
store i32 %46, i32* %6
br label %10
47: ; preds = %10
%48 = getelementptr inbounds [5 x float], [5 x float]* %4, i64 0, i64 0
%49 = load float, float* %48
%50 = fpext float %49 to double
%51 = fcmp ogt double %50, 8.000000e-01
br i1 %51, label %52, label %67
52: ; preds = %47
%53 = getelementptr inbounds [150 x i8], [150 x i8]* %5, i64 0, i64 0
%54 = getelementptr inbounds [5 x float], [5 x float]* %4, i64 0, i64 0
%55 = load float, float* %54
%56 = getelementptr inbounds [5 x float], [5 x float]* %4, i64 0, i64 1
%57 = load float, float* %56
%58 = getelementptr inbounds [5 x float], [5 x float]* %4, i64 0, i64 2
%59 = load float, float* %58
%60 = getelementptr inbounds [5 x float], [5 x float]* %4, i64 0, i64 3
%61 = load float, float* %60
%62 = getelementptr inbounds [5 x float], [5 x float]* %4, i64 0, i64 4
%63 = load float, float* %62
%64 = call i32 @sprintf(i8* %53, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), float %55, float %57, float %59, float %61, float %63)
%65 = getelementptr inbounds [150 x i8], [150 x i8]* %5, i64 0, i64 0
%66 = call i32 @sys_log(i8* %65)
br label %67
67: ; preds = %52, %47
%68 = getelementptr inbounds [5 x float], [5 x float]* %4, i64 0, i64 0
%69 = load float, float* %68
%70 = getelementptr inbounds [5 x float], [5 x float]* %4, i64 0, i64 1
%71 = load float, float* %70
%72 = fcmp olt float %69, %71
br i1 %72, label %73, label %98
73: ; preds = %67
%74 = getelementptr inbounds [5 x float], [5 x float]* %4, i64 0, i64 1
%75 = load float, float* %74
%76 = getelementptr inbounds [5 x float], [5 x float]* %4, i64 0, i64 2
%77 = load float, float* %76
%78 = fcmp olt float %75, %77
br i1 %78, label %79, label %98
79: ; preds = %73
%80 = getelementptr inbounds [5 x float], [5 x float]* %4, i64 0, i64 2
%81 = load float, float* %80
%82 = getelementptr inbounds [5 x float], [5 x float]* %4, i64 0, i64 3
%83 = load float, float* %82
%84 = fcmp olt float %81, %83
br i1 %84, label %85, label %98
85: ; preds = %79
%86 = getelementptr inbounds [5 x float], [5 x float]* %4, i64 0, i64 3
%87 = load float, float* %86
%88 = getelementptr inbounds [5 x float], [5 x float]* %4, i64 0, i64 4
%89 = load float, float* %88
%90 = fcmp olt float %87, %89
br i1 %90, label %91, label %98
91: ; preds = %85
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0))
%93 = getelementptr inbounds [5 x float], [5 x float]* %4, i64 0, i64 0
%94 = load float, float* %93
%95 = fcmp ogt float %94, 3.000000e+00
br i1 %95, label %96, label %97
96: ; preds = %91
store i32 1, i32* %1
br label %99
97: ; preds = %91
br label %98
98: ; preds = %97, %85, %79, %73, %67
store i32 0, i32* %1
br label %99
99: ; preds = %98, %96
%100 = load i32, i32* %1
ret i32 %100
}

LLVM IR (-O2):
@.str.1 = [37 x i8] c"cat /proc/loadavg | awk '{print $1}'\00"
@.str.2 = [2 x i8] c"r\00"
@.str.4 = [3 x i8] c"%f\00"
@.str.5 = [17 x i8] c"load[%d] : %.2f\0A\00"
@.str.6 = [36 x i8] c"load : %.2f %.2f %.2f %.2f %.2f\00"
@str = [40 x i8] c"\0A---------check load average-----------\00"
@str.8 = [25 x i8] c"loadavg is increasing...\00"
@str.9 = [13 x i8] c"popen failed\00"
define i32 @check_load() {
%1 = alloca i64
%2 = bitcast i64* %1 to [8 x i8]*
%3 = alloca [5 x float]
%4 = alloca [150 x i8]
%5 = bitcast i64* %1 to i8*
store i64 0, i64* %1
%6 = bitcast [5 x float]* %3 to i8*
%7 = getelementptr inbounds [150 x i8], [150 x i8]* %4, i64 0, i64 0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%9 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 7
br label %10
10: ; preds = %0, %29
%11 = phi i64 [ 0, %0 ], [ %30, %29 ]
%12 = call i32* @popen(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.9, i64 0, i64 0))
br label %16
16: ; preds = %14, %10
%17 = call i32 @memset(i8* %5, i32 0, i32 8)
%18 = call i32 @fread(i8* %5, i32 1, i32 8, i32* %12)
store i8 0, i8* %9
%19 = getelementptr inbounds [5 x float], [5 x float]* %3, i64 0, i64 %11
%20 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), float* %19)
%21 = call i32 @pclose(i32* %12)
%22 = load float, float* %19
%23 = fpext float %22 to double
%24 = trunc i64 %11 to i32
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %24, double %23)
%26 = icmp ult i64 %11, 4
br i1 %26, label %27, label %29
27: ; preds = %16
%28 = call i32 @sleep(i32 10)
br label %29
29: ; preds = %16, %27
%30 = add nuw nsw i64 %11, 1
%31 = icmp eq i64 %30, 5
br i1 %31, label %32, label %10
32: ; preds = %29
%33 = getelementptr inbounds [5 x float], [5 x float]* %3, i64 0, i64 0
%34 = load float, float* %33
%35 = fpext float %34 to double
%36 = fcmp ogt double %35, 8.000000e-01
br i1 %36, label %37, label %49
37: ; preds = %32
%38 = getelementptr inbounds [5 x float], [5 x float]* %3, i64 0, i64 1
%39 = load float, float* %38
%40 = getelementptr inbounds [5 x float], [5 x float]* %3, i64 0, i64 2
%41 = load float, float* %40
%42 = getelementptr inbounds [5 x float], [5 x float]* %3, i64 0, i64 3
%43 = load float, float* %42
%44 = getelementptr inbounds [5 x float], [5 x float]* %3, i64 0, i64 4
%45 = load float, float* %44
%46 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), float %34, float %39, float %41, float %43, float %45)
%47 = call i32 @sys_log(i8* %7)
%48 = load float, float* %33
br label %49
49: ; preds = %37, %32
%50 = phi float [ %48, %37 ], [ %34, %32 ]
%51 = getelementptr inbounds [5 x float], [5 x float]* %3, i64 0, i64 1
%52 = load float, float* %51
%53 = fcmp olt float %50, %52
br i1 %53, label %54, label %70
54: ; preds = %49
%55 = getelementptr inbounds [5 x float], [5 x float]* %3, i64 0, i64 2
%56 = load float, float* %55
%57 = fcmp olt float %52, %56
br i1 %57, label %58, label %70
58: ; preds = %54
%59 = getelementptr inbounds [5 x float], [5 x float]* %3, i64 0, i64 3
%60 = load float, float* %59
%61 = fcmp olt float %56, %60
%62 = getelementptr inbounds [5 x float], [5 x float]* %3, i64 0, i64 4
%63 = load float, float* %62
%64 = fcmp olt float %60, %63
%65 = select i1 %61, i1 %64, i1 false
br i1 %65, label %66, label %70
66: ; preds = %58
%67 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.8, i64 0, i64 0))
%68 = load float, float* %33
%69 = fcmp ogt float %68, 3.000000e+00
br i1 %69, label %71, label %70
70: ; preds = %66, %58, %54, %49
br label %71
71: ; preds = %66, %70
%72 = phi i32 [ 0, %70 ], [ 1, %66 ]
ret i32 %72
}