#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 */
float atof(char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  char loadavg[4];
  FILE *fp;
  fp = fopen("/proc/loadavg", "r");
  int i = 0;
  fread(loadavg, 4, 1, fp);
  for (i = 0; i < 4; i++) {
    printf("%c\n", loadavg[i]);
  }
  float loadfloat;
  loadfloat = atof(loadavg);
  printf("%f\n", loadfloat);
  if (loadfloat < 0.1) {
    printf("The system is not doing a lot currently.\n");
  } else if (loadfloat < 0.5) {
    printf("The system is working a little bit.\n");
  } else if (loadfloat < 2) {
    printf("The system is under heavy load.\n");
  } else {
    printf("ALERT: The system might be overloaded\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xebe(%rip),%rdi
lea    0xec5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    11ba <main+0x7a>
movslq -0x14(%rbp),%rax
movsbl -0x8(%rbp,%rax,1),%esi
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118b <main+0x4b>
lea    -0x8(%rbp),%rdi
call   1040 <atof@plt>
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe50(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe10(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    120d <main+0xcd>
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1278 <main+0x138>
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xdea(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    123b <main+0xfb>
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1273 <main+0x133>
movss  0xdcd(%rip),%xmm0
ucomiss -0x18(%rbp),%xmm0
jbe    1260 <main+0x120>
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    126e <main+0x12e>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1273 <main+0x133>
jmp    1278 <main+0x138>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xeb2(%rip),%rdi
lea    0xeb9(%rip),%rsi
call   1070 <fopen@plt>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
movsbl 0x8(%rsp),%esi
lea    0xe90(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movsbl 0x9(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movsbl 0xa(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movsbl 0xb(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   1050 <atof@plt>
movss  %xmm0,0xc(%rsp)
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
lea    0xe3e(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
movsd  0xe0b(%rip),%xmm0
ucomisd 0x10(%rsp),%xmm0
jbe    1206 <main+0xb6>
lea    0xe8e(%rip),%rdi
jmp    123f <main+0xef>
movss  0xdfa(%rip),%xmm0
movss  0xc(%rsp),%xmm1
ucomiss %xmm1,%xmm0
jbe    1222 <main+0xd2>
lea    0xe4e(%rip),%rdi
jmp    123f <main+0xef>
movss  0xde2(%rip),%xmm0
ucomiss %xmm1,%xmm0
lea    0xe1a(%rip),%rax
lea    0xded(%rip),%rdi
cmova  %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/loadavg\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%c\0A\00"
@.str.3 = [4 x i8] c"%f\0A\00"
@.str.4 = [42 x i8] c"The system is not doing a lot currently.\0A\00"
@.str.5 = [37 x i8] c"The system is working a little bit.\0A\00"
@.str.6 = [33 x i8] c"The system is under heavy load.\0A\00"
@.str.7 = [39 x i8] c"ALERT: The system might be overloaded\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4 x i8]
%3 = alloca i32*
%4 = alloca i32
%5 = alloca float
store i32 0, i32* %1
%6 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 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** %3
store i32 0, i32* %4
%7 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%8 = load i32*, i32** %3
%9 = call i32 @fread(i8* %7, i32 4, i32 1, i32* %8)
store i32 0, i32* %4
br label %10
10: ; preds = %20, %0
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 4
br i1 %12, label %13, label %23
13: ; preds = %10
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %13
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
br label %10
23: ; preds = %10
%24 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%25 = call float @atof(i8* %24)
store float %25, float* %5
%26 = load float, float* %5
%27 = fpext float %26 to double
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double %27)
%29 = load float, float* %5
%30 = fpext float %29 to double
%31 = fcmp olt double %30, 1.000000e-01
br i1 %31, label %32, label %34
32: ; preds = %23
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0))
br label %49
34: ; preds = %23
%35 = load float, float* %5
%36 = fpext float %35 to double
%37 = fcmp olt double %36, 5.000000e-01
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
br label %48
40: ; preds = %34
%41 = load float, float* %5
%42 = fcmp olt float %41, 2.000000e+00
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0))
br label %47
45: ; preds = %40
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0))
br label %47
47: ; preds = %45, %43
br label %48
48: ; preds = %47, %38
br label %49
49: ; preds = %48, %32
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/loadavg\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%c\0A\00"
@.str.3 = [4 x i8] c"%f\0A\00"
@str = [38 x i8] c"ALERT: The system might be overloaded\00"
@str.8 = [32 x i8] c"The system is under heavy load.\00"
@str.9 = [36 x i8] c"The system is working a little bit.\00"
@str.10 = [41 x i8] c"The system is not doing a lot currently.\00"
define i32 @main() {
%1 = alloca [4 x i8]
%2 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 @fread(i8* %2, i32 4, i32 1, i32* %3)
%5 = load i8, i8* %2
%6 = sext i8 %5 to i32
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %6)
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 1
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 2
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 3
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = call float @atof(i8* %2)
%21 = fpext float %20 to double
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double %21)
%23 = fcmp olt double %21, 1.000000e-01
br i1 %23, label %29, label %24
24: ; preds = %0
%25 = fcmp olt float %20, 5.000000e-01
br i1 %25, label %29, label %26
26: ; preds = %24
%27 = fcmp olt float %20, 2.000000e+00
%28 = select i1 %27, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @str.8, i64 0, i64 0), i8* getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0)
br label %29
29: ; preds = %26, %24, %0
%30 = phi i8* [ getelementptr inbounds ([41 x i8], [41 x i8]* @str.10, i64 0, i64 0), %0 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @str.9, i64 0, i64 0), %24 ], [ %28, %26 ]
%31 = tail call i32 @puts(i8* dereferenceable(1) %30)
ret i32 0
}