#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, long double *,
                          long double *, long double *, long double *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ readAndParse(char *, char *, int);
int /*<<< orphan*/ sleep(int);
int combmonitor() {
  long double a[4], b[4], loadavg;
  FILE *fp;
  for (;;) {
    fp = fopen("/proc/stat", "r");
    fscanf(fp, "%*s %Lf %Lf %Lf %Lf", &a[0], &a[1], &a[2], &a[3]);
    fclose(fp);
    sleep(1);
    fp = fopen("/proc/stat", "r");
    fscanf(fp, "%*s %Lf %Lf %Lf %Lf", &b[0], &b[1], &b[2], &b[3]);
    fclose(fp);
    loadavg = ((b[0] + b[1] + b[2]) - (a[0] + a[1] + a[2])) /
              ((b[0] + b[1] + b[2] + b[3]) - (a[0] + a[1] + a[2] + a[3]));
    printf("The current CPU load is : %Lf\n", loadavg);
    printf(" Memory Total:\t\t");
    readAndParse("/proc/meminfo", "MemTotal:", 2);
    printf(" kB");
    printf("\n Memory Free:\t\t");
    readAndParse("/proc/meminfo", "MemFree:", 2);
    printf(" kB\n\n");
    sleep(1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<combmonitor>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
lea    0xe8e(%rip),%rdi
mov    %rdi,-0xb0(%rbp)
lea    0xe8b(%rip),%rsi
mov    %rsi,-0xa8(%rbp)
call   1060 <fopen@plt>
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rdi
lea    -0x30(%rbp),%rcx
lea    -0x20(%rbp),%r8
lea    -0x10(%rbp),%r9
lea    0xe60(%rip),%rsi
mov    %rsi,-0xa0(%rbp)
lea    -0x40(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x98(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
mov    -0xb0(%rbp),%rdi
mov    -0xa8(%rbp),%rsi
call   1060 <fopen@plt>
mov    -0xa0(%rbp),%rsi
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rdi
lea    -0x70(%rbp),%rcx
lea    -0x60(%rbp),%r8
lea    -0x50(%rbp),%r9
lea    -0x80(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x98(%rbp),%rdi
call   1030 <fclose@plt>
fldt   -0x80(%rbp)
fldt   -0x70(%rbp)
faddp  %st,%st(1)
fldt   -0x60(%rbp)
faddp  %st,%st(1)
fldt   -0x40(%rbp)
fldt   -0x30(%rbp)
faddp  %st,%st(1)
fldt   -0x20(%rbp)
faddp  %st,%st(1)
fld    %st(1)
fsub   %st(1),%st
fldt   -0x50(%rbp)
faddp  %st,%st(3)
fldt   -0x10(%rbp)
faddp  %st,%st(2)
fxch   %st(2)
fsubp  %st,%st(1)
fdivrp %st,%st(1)
fstpt  -0x90(%rbp)
fldt   -0x90(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
lea    0xdbf(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdd3(%rip),%rdi
lea    0xdda(%rip),%rsi
mov    $0x2,%edx
call   1070 <readAndParse@plt>
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd9f(%rip),%rdi
lea    0xdc5(%rip),%rsi
mov    $0x2,%edx
call   1070 <readAndParse@plt>
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
jmp    116b <combmonitor+0xb>

x86 assembly (clang, -O2):
<combmonitor>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
lea    0xe78(%rip),%r14
lea    0xe7c(%rip),%r15
lea    0xe77(%rip),%r12
lea    0xeb4(%rip),%rbx
nopl   (%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <fopen@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    %r12,%rsi
lea    0x50(%rsp),%rdx
lea    0x60(%rsp),%rcx
lea    0x70(%rsp),%r8
lea    0x80(%rsp),%r9
call   1060 <fscanf@plt>
mov    %r13,%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <fopen@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r12,%rsi
lea    0x10(%rsp),%rdx
lea    0x20(%rsp),%rcx
lea    0x30(%rsp),%r8
lea    0x40(%rsp),%r9
call   1060 <fscanf@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
fldt   0x10(%rsp)
fldt   0x20(%rsp)
faddp  %st,%st(1)
fldt   0x30(%rsp)
faddp  %st,%st(1)
fldt   0x50(%rsp)
fldt   0x60(%rsp)
faddp  %st,%st(1)
fldt   0x70(%rsp)
faddp  %st,%st(1)
fld    %st(1)
fsub   %st(1),%st
fldt   0x40(%rsp)
faddp  %st,%st(3)
fldt   0x80(%rsp)
faddp  %st,%st(2)
fxch   %st(2)
fsubp  %st,%st(1)
fdivrp %st,%st(1)
fstpt  (%rsp)
lea    0xdc7(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdd8(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
lea    0xde6(%rip),%rsi
mov    $0x2,%edx
call   1080 <readAndParse@plt>
lea    0xddf(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdd5(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
lea    0xdd5(%rip),%rsi
mov    $0x2,%edx
call   1080 <readAndParse@plt>
lea    0xdcd(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
jmp    11a0 <combmonitor+0x30>

LLVM IR (-O0):
@.str = [11 x i8] c"/proc/stat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [20 x i8] c"%*s %Lf %Lf %Lf %Lf\00"
@.str.3 = [31 x i8] c"The current CPU load is : %Lf\0A\00"
@.str.4 = [17 x i8] c" Memory Total:\09\09\00"
@.str.5 = [14 x i8] c"/proc/meminfo\00"
@.str.6 = [10 x i8] c"MemTotal:\00"
@.str.7 = [4 x i8] c" kB\00"
@.str.8 = [17 x i8] c"\0A Memory Free:\09\09\00"
@.str.9 = [9 x i8] c"MemFree:\00"
@.str.10 = [6 x i8] c" kB\0A\0A\00"
define i32 @combmonitor() {
%1 = alloca [4 x x86_fp80]
%2 = alloca [4 x x86_fp80]
%3 = alloca x86_fp80
%4 = alloca i32*
br label %5
5: ; preds = %5, %0
%6 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %4
%7 = load i32*, i32** %4
%8 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %1, i64 0, i64 0
%9 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %1, i64 0, i64 1
%10 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %1, i64 0, i64 2
%11 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %1, i64 0, i64 3
%12 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), x86_fp80* %8, x86_fp80* %9, x86_fp80* %10, x86_fp80* %11)
%13 = load i32*, i32** %4
%14 = call i32 @fclose(i32* %13)
%15 = call i32 @sleep(i32 1)
%16 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %4
%17 = load i32*, i32** %4
%18 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %2, i64 0, i64 0
%19 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %2, i64 0, i64 1
%20 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %2, i64 0, i64 2
%21 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %2, i64 0, i64 3
%22 = call i32 @fscanf(i32* %17, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), x86_fp80* %18, x86_fp80* %19, x86_fp80* %20, x86_fp80* %21)
%23 = load i32*, i32** %4
%24 = call i32 @fclose(i32* %23)
%25 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %2, i64 0, i64 0
%26 = load x86_fp80, x86_fp80* %25
%27 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %2, i64 0, i64 1
%28 = load x86_fp80, x86_fp80* %27
%29 = fadd x86_fp80 %26, %28
%30 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %2, i64 0, i64 2
%31 = load x86_fp80, x86_fp80* %30
%32 = fadd x86_fp80 %29, %31
%33 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %1, i64 0, i64 0
%34 = load x86_fp80, x86_fp80* %33
%35 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %1, i64 0, i64 1
%36 = load x86_fp80, x86_fp80* %35
%37 = fadd x86_fp80 %34, %36
%38 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %1, i64 0, i64 2
%39 = load x86_fp80, x86_fp80* %38
%40 = fadd x86_fp80 %37, %39
%41 = fsub x86_fp80 %32, %40
%42 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %2, i64 0, i64 0
%43 = load x86_fp80, x86_fp80* %42
%44 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %2, i64 0, i64 1
%45 = load x86_fp80, x86_fp80* %44
%46 = fadd x86_fp80 %43, %45
%47 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %2, i64 0, i64 2
%48 = load x86_fp80, x86_fp80* %47
%49 = fadd x86_fp80 %46, %48
%50 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %2, i64 0, i64 3
%51 = load x86_fp80, x86_fp80* %50
%52 = fadd x86_fp80 %49, %51
%53 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %1, i64 0, i64 0
%54 = load x86_fp80, x86_fp80* %53
%55 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %1, i64 0, i64 1
%56 = load x86_fp80, x86_fp80* %55
%57 = fadd x86_fp80 %54, %56
%58 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %1, i64 0, i64 2
%59 = load x86_fp80, x86_fp80* %58
%60 = fadd x86_fp80 %57, %59
%61 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %1, i64 0, i64 3
%62 = load x86_fp80, x86_fp80* %61
%63 = fadd x86_fp80 %60, %62
%64 = fsub x86_fp80 %52, %63
%65 = fdiv x86_fp80 %41, %64
store x86_fp80 %65, x86_fp80* %3
%66 = load x86_fp80, x86_fp80* %3
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), x86_fp80 %66)
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%69 = call i32 @readAndParse(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 2)
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
%72 = call i32 @readAndParse(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i32 2)
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
%74 = call i32 @sleep(i32 1)
br label %5
}

LLVM IR (-O2):
@.str = [11 x i8] c"/proc/stat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [20 x i8] c"%*s %Lf %Lf %Lf %Lf\00"
@.str.3 = [31 x i8] c"The current CPU load is : %Lf\0A\00"
@.str.4 = [17 x i8] c" Memory Total:\09\09\00"
@.str.5 = [14 x i8] c"/proc/meminfo\00"
@.str.6 = [10 x i8] c"MemTotal:\00"
@.str.7 = [4 x i8] c" kB\00"
@.str.8 = [17 x i8] c"\0A Memory Free:\09\09\00"
@.str.9 = [9 x i8] c"MemFree:\00"
@str = [5 x i8] c" kB\0A\00"
define i32 @combmonitor() {
%1 = alloca [4 x x86_fp80]
%2 = alloca [4 x x86_fp80]
%3 = bitcast [4 x x86_fp80]* %1 to i8*
%4 = bitcast [4 x x86_fp80]* %2 to i8*
%5 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %1, i64 0, i64 0
%6 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %1, i64 0, i64 1
%7 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %1, i64 0, i64 2
%8 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %1, i64 0, i64 3
%9 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %2, i64 0, i64 0
%10 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %2, i64 0, i64 1
%11 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %2, i64 0, i64 2
%12 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %2, i64 0, i64 3
br label %13
13: ; preds = %13, %0
%14 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @fscanf(i32* %14, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), x86_fp80* %5, x86_fp80* %6, x86_fp80* %7, x86_fp80* %8)
%16 = call i32 @fclose(i32* %14)
%17 = call i32 @sleep(i32 1)
%18 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @fscanf(i32* %18, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), x86_fp80* %9, x86_fp80* %10, x86_fp80* %11, x86_fp80* %12)
%20 = call i32 @fclose(i32* %18)
%21 = load x86_fp80, x86_fp80* %9
%22 = load x86_fp80, x86_fp80* %10
%23 = fadd x86_fp80 %21, %22
%24 = load x86_fp80, x86_fp80* %11
%25 = fadd x86_fp80 %23, %24
%26 = load x86_fp80, x86_fp80* %5
%27 = load x86_fp80, x86_fp80* %6
%28 = fadd x86_fp80 %26, %27
%29 = load x86_fp80, x86_fp80* %7
%30 = fadd x86_fp80 %28, %29
%31 = fsub x86_fp80 %25, %30
%32 = load x86_fp80, x86_fp80* %12
%33 = fadd x86_fp80 %25, %32
%34 = load x86_fp80, x86_fp80* %8
%35 = fadd x86_fp80 %30, %34
%36 = fsub x86_fp80 %33, %35
%37 = fdiv x86_fp80 %31, %36
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), x86_fp80 %37)
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%40 = call i32 @readAndParse(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 2)
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
%43 = call i32 @readAndParse(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i32 2)
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%45 = call i32 @sleep(i32 1)
br label %13
}