#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*/ sleep(int);
char *smprintf(char *, long double);
char *getcpuutil(void) {
  long double a[4], b[4], loadavg;
  FILE *fp;
  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])) * 100;
  return smprintf("%.0Lf", loadavg);
}


x86 assembly (clang, -O0):
<getcpuutil>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
lea    0xea2(%rip),%rdi
mov    %rdi,-0xb0(%rbp)
lea    0xe9f(%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    0xe74(%rip),%rsi
mov    %rsi,-0xa0(%rbp)
lea    -0x40(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x98(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   1070 <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   1040 <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)
flds   0xdc0(%rip)
fmulp  %st,%st(1)
fstpt  -0x90(%rbp)
fldt   -0x90(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
lea    0xdcb(%rip),%rdi
call   1030 <smprintf@plt>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getcpuutil>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x98,%rsp
lea    0xe9f(%rip),%r12
lea    0xea3(%rip),%r14
mov    %r12,%rdi
mov    %r14,%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0x60(%rsp),%rcx
lea    0x70(%rsp),%r8
lea    0x80(%rsp),%r9
lea    0xe7e(%rip),%r15
lea    0x50(%rsp),%rdx
mov    %rax,%rdi
mov    %r15,%rsi
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0x20(%rsp),%rcx
lea    0x30(%rsp),%r8
lea    0x40(%rsp),%r9
lea    0x10(%rsp),%rdx
mov    %rax,%rdi
mov    %r15,%rsi
call   1050 <fscanf@plt>
mov    %rbx,%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)
fmuls  0xdd7(%rip)
fstpt  (%rsp)
lea    0xdf2(%rip),%rdi
call   1030 <smprintf@plt>
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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 = [6 x i8] c"%.0Lf\00"
define i8* @getcpuutil() {
%1 = alloca [4 x x86_fp80]
%2 = alloca [4 x x86_fp80]
%3 = alloca x86_fp80
%4 = alloca i32*
%5 = 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* %5, i32** %4
%6 = load i32*, i32** %4
%7 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %1, i64 0, i64 0
%8 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %1, i64 0, i64 1
%9 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %1, i64 0, i64 2
%10 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %1, i64 0, i64 3
%11 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), x86_fp80* %7, x86_fp80* %8, x86_fp80* %9, x86_fp80* %10)
%12 = load i32*, i32** %4
%13 = call i32 @fclose(i32* %12)
%14 = call i32 @sleep(i32 1)
%15 = 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* %15, i32** %4
%16 = load i32*, i32** %4
%17 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %2, i64 0, i64 0
%18 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %2, i64 0, i64 1
%19 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %2, i64 0, i64 2
%20 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %2, i64 0, i64 3
%21 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), x86_fp80* %17, x86_fp80* %18, x86_fp80* %19, x86_fp80* %20)
%22 = load i32*, i32** %4
%23 = call i32 @fclose(i32* %22)
%24 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %2, i64 0, i64 0
%25 = load x86_fp80, x86_fp80* %24
%26 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %2, i64 0, i64 1
%27 = load x86_fp80, x86_fp80* %26
%28 = fadd x86_fp80 %25, %27
%29 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %2, i64 0, i64 2
%30 = load x86_fp80, x86_fp80* %29
%31 = fadd x86_fp80 %28, %30
%32 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %1, i64 0, i64 0
%33 = load x86_fp80, x86_fp80* %32
%34 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %1, i64 0, i64 1
%35 = load x86_fp80, x86_fp80* %34
%36 = fadd x86_fp80 %33, %35
%37 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %1, i64 0, i64 2
%38 = load x86_fp80, x86_fp80* %37
%39 = fadd x86_fp80 %36, %38
%40 = fsub x86_fp80 %31, %39
%41 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %2, i64 0, i64 0
%42 = load x86_fp80, x86_fp80* %41
%43 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %2, i64 0, i64 1
%44 = load x86_fp80, x86_fp80* %43
%45 = fadd x86_fp80 %42, %44
%46 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %2, i64 0, i64 2
%47 = load x86_fp80, x86_fp80* %46
%48 = fadd x86_fp80 %45, %47
%49 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %2, i64 0, i64 3
%50 = load x86_fp80, x86_fp80* %49
%51 = fadd x86_fp80 %48, %50
%52 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %1, i64 0, i64 0
%53 = load x86_fp80, x86_fp80* %52
%54 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %1, i64 0, i64 1
%55 = load x86_fp80, x86_fp80* %54
%56 = fadd x86_fp80 %53, %55
%57 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %1, i64 0, i64 2
%58 = load x86_fp80, x86_fp80* %57
%59 = fadd x86_fp80 %56, %58
%60 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %1, i64 0, i64 3
%61 = load x86_fp80, x86_fp80* %60
%62 = fadd x86_fp80 %59, %61
%63 = fsub x86_fp80 %51, %62
%64 = fdiv x86_fp80 %40, %63
%65 = fmul x86_fp80 %64, 0xK4005C800000000000000
store x86_fp80 %65, x86_fp80* %3
%66 = load x86_fp80, x86_fp80* %3
%67 = call i8* @smprintf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), x86_fp80 %66)
ret i8* %67
}

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 = [6 x i8] c"%.0Lf\00"
define i8* @getcpuutil() {
%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 = tail 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))
%6 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %1, i64 0, i64 0
%7 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %1, i64 0, i64 1
%8 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %1, i64 0, i64 2
%9 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %1, i64 0, i64 3
%10 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), x86_fp80* %6, x86_fp80* %7, x86_fp80* %8, x86_fp80* %9)
%11 = call i32 @fclose(i32* %5)
%12 = call i32 @sleep(i32 1)
%13 = 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))
%14 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %2, i64 0, i64 0
%15 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %2, i64 0, i64 1
%16 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %2, i64 0, i64 2
%17 = getelementptr inbounds [4 x x86_fp80], [4 x x86_fp80]* %2, i64 0, i64 3
%18 = call i32 @fscanf(i32* %13, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), x86_fp80* %14, x86_fp80* %15, x86_fp80* %16, x86_fp80* %17)
%19 = call i32 @fclose(i32* %13)
%20 = load x86_fp80, x86_fp80* %14
%21 = load x86_fp80, x86_fp80* %15
%22 = fadd x86_fp80 %20, %21
%23 = load x86_fp80, x86_fp80* %16
%24 = fadd x86_fp80 %22, %23
%25 = load x86_fp80, x86_fp80* %6
%26 = load x86_fp80, x86_fp80* %7
%27 = fadd x86_fp80 %25, %26
%28 = load x86_fp80, x86_fp80* %8
%29 = fadd x86_fp80 %27, %28
%30 = fsub x86_fp80 %24, %29
%31 = load x86_fp80, x86_fp80* %17
%32 = fadd x86_fp80 %24, %31
%33 = load x86_fp80, x86_fp80* %9
%34 = fadd x86_fp80 %29, %33
%35 = fsub x86_fp80 %32, %34
%36 = fdiv x86_fp80 %30, %35
%37 = fmul x86_fp80 %36, 0xK4005C800000000000000
%38 = call i8* @smprintf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), x86_fp80 %37)
ret i8* %38
}