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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, float *);
int /*<<< orphan*/ time(int *);
int check_load() {
  FILE *fd;
  char loadline[128];
  float load;
  time_t currenttime;
  static time_t lastchecked;
  static float lastload;
  time(&currenttime);
  if ((currenttime - lastchecked) < 1)
    return (lastload * 100);
  fd = fopen("/proc/loadavg", "r");
  fscanf(fd, "%f ", &load);
  fclose(fd);
  lastload = load;
  time(&lastchecked);
  return (load * 100);
}


x86 assembly (clang, -O0):
<check_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
lea    -0x98(%rbp),%rdi
call   1050 <time@plt>
mov    -0x98(%rbp),%eax
sub    0x2ee1(%rip),%eax
cmp    $0x1,%eax
jge    1188 <check_load+0x48>
movss  0xe8c(%rip),%xmm0
mulss  0x2ecc(%rip),%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0x4(%rbp)
jmp    11f2 <check_load+0xb2>
lea    0xe75(%rip),%rdi
lea    0xe7c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe6a(%rip),%rsi
lea    -0x94(%rbp),%rdx
call   1040 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movss  -0x94(%rbp),%xmm0
ff
movss  %xmm0,0x2e79(%rip)
lea    0x2e6e(%rip),%rdi
call   1050 <time@plt>
movss  0xe1d(%rip),%xmm0
mulss  -0x94(%rbp),%xmm0
ff
cvttss2si %xmm0,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_load>:
push   %r14
push   %rbx
push   %rax
mov    %rsp,%rdi
call   1050 <time@plt>
mov    (%rsp),%eax
cmp    0x2eef(%rip),%eax
jle    11a8 <check_load+0x68>
lea    0xea6(%rip),%rdi
lea    0xead(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
lea    0xea0(%rip),%rsi
lea    0x4(%rsp),%rbx
mov    %rax,%rdi
mov    %rbx,%rdx
call   1040 <fscanf@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
movss  0x4(%rsp),%xmm0
movss  %xmm0,0x2eae(%rip)
lea    0x2ea3(%rip),%rdi
call   1050 <time@plt>
jmp    11af <check_load+0x6f>
lea    0x2e99(%rip),%rbx
movss  (%rbx),%xmm0
mulss  0xe45(%rip),%xmm0
cvttss2si %xmm0,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@check_load.lastchecked = internal global i32 0
@check_load.lastload = internal global float 0.000000e+00
@.str = [14 x i8] c"/proc/loadavg\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%f \00"
define i32 @check_load() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [128 x i8]
%4 = alloca float
%5 = alloca i32
%6 = call i32 @time(i32* %5)
%7 = load i32, i32* %5
%8 = load i32, i32* @check_load.lastchecked
%9 = sub nsw i32 %7, %8
%10 = icmp slt i32 %9, 1
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = load float, float* @check_load.lastload
%13 = fmul float %12, 1.000000e+02
%14 = fptosi float %13 to i32
store i32 %14, i32* %1
br label %26
15: ; preds = %0
%16 = 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* %16, i32** %2
%17 = load i32*, i32** %2
%18 = call i32 @fscanf(i32* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), float* %4)
%19 = load i32*, i32** %2
%20 = call i32 @fclose(i32* %19)
%21 = load float, float* %4
store float %21, float* @check_load.lastload
%22 = call i32 @time(i32* @check_load.lastchecked)
%23 = load float, float* %4
%24 = fmul float %23, 1.000000e+02
%25 = fptosi float %24 to i32
store i32 %25, i32* %1
br label %26
26: ; preds = %15, %11
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
@check_load.lastchecked = internal global i32 0
@check_load.lastload = internal unnamed_addr global float 0.000000e+00
@.str = [14 x i8] c"/proc/loadavg\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%f \00"
define i32 @check_load() {
%1 = alloca float
%2 = alloca i32
%3 = bitcast float* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 @time(i32* %2)
%6 = load i32, i32* %2
%7 = load i32, i32* @check_load.lastchecked
%8 = icmp sgt i32 %6, %7
br i1 %8, label %9, label %15
9: ; preds = %0
%10 = 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))
%11 = call i32 @fscanf(i32* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), float* %1)
%12 = call i32 @fclose(i32* %10)
%13 = load float, float* %1
store float %13, float* @check_load.lastload
%14 = call i32 @time(i32* @check_load.lastchecked)
br label %15
15: ; preds = %0, %9
%16 = phi float* [ %1, %9 ], [ @check_load.lastload, %0 ]
%17 = load float, float* %16
%18 = fmul float %17, 1.000000e+02
%19 = fptosi float %18 to i32
ret i32 %19
}