#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*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sscanf(char *, char *, unsigned long long *,
                          unsigned long long *, unsigned long long *,
                          unsigned long long *, unsigned long long *,
                          unsigned long long *, unsigned long long *);
void get_stat_cpu() {
  FILE *f1, *f2;
  char line1[256], line2[256];
  unsigned long long user1, nice1, system1, idle1, iowait1, irq1, softirq1;
  unsigned long long user2, nice2, system2, idle2, iowait2, irq2, softirq2;
  unsigned long long total1, total2;
  double cpuload;
  f1 = fopen("/proc/stat", "r");
  if (f1) {
    fgets(line1, 256, f1);
    fclose(f1);
    sscanf(line1, "cpu  %llu %llu %llu %llu %llu %llu %llu", &user1, &nice1,
           &system1, &idle1, &iowait1, &irq1, &softirq1);
    sleep(1);
    f2 = fopen("/proc/stat", "r");
    if (f2) {
      fgets(line2, 256, f2);
      fclose(f2);
      sscanf(line2, "cpu  %llu %llu %llu %llu %llu %llu %llu", &user2, &nice2,
             &system2, &idle2, &iowait2, &irq2, &softirq2);
      total1 = user1 + nice1 + system1 + idle1 + iowait1 + irq1 + softirq1;
      total2 = user2 + nice2 + system2 + idle2 + iowait2 + irq2 + softirq2;
      cpuload = 1 - ((double)(idle2 - idle1) / (double)(total2 - total1));
      printf("%.0f\n", 100.0 * cpuload);
    }
  }
}


x86 assembly (clang, -O0):
<get_stat_cpu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2c0,%rsp
lea    0xebe(%rip),%rdi
lea    0xec2(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     13ce <get_stat_cpu+0x26e>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x110(%rbp),%rdi
lea    0xe84(%rip),%rsi
lea    -0x218(%rbp),%rdx
lea    -0x220(%rbp),%rcx
lea    -0x228(%rbp),%r8
lea    -0x230(%rbp),%r9
lea    -0x238(%rbp),%r11
lea    -0x240(%rbp),%r10
lea    -0x248(%rbp),%rax
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1060 <sscanf@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
lea    0xe22(%rip),%rdi
lea    0xe26(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     13c9 <get_stat_cpu+0x269>
mov    -0x10(%rbp),%rdx
lea    -0x210(%rbp),%rdi
mov    %rdi,-0x2a0(%rbp)
mov    $0x100,%esi
call   1050 <fgets@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x2a0(%rbp),%rdi
mov    %rsp,%rax
lea    -0x280(%rbp),%rcx
mov    %rcx,0x10(%rax)
lea    -0x278(%rbp),%rcx
mov    %rcx,0x8(%rax)
lea    -0x270(%rbp),%rcx
mov    %rcx,(%rax)
lea    0xdbe(%rip),%rsi
lea    -0x250(%rbp),%rdx
lea    -0x258(%rbp),%rcx
lea    -0x260(%rbp),%r8
lea    -0x268(%rbp),%r9
call   1060 <sscanf@plt>
mov    -0x218(%rbp),%rax
mov    -0x220(%rbp),%rcx
add    %rcx,%rax
mov    -0x228(%rbp),%rcx
add    %rcx,%rax
mov    -0x230(%rbp),%rcx
add    %rcx,%rax
mov    -0x238(%rbp),%rcx
add    %rcx,%rax
mov    -0x240(%rbp),%rcx
add    %rcx,%rax
mov    -0x248(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x288(%rbp)
mov    -0x250(%rbp),%rax
mov    -0x258(%rbp),%rcx
add    %rcx,%rax
mov    -0x260(%rbp),%rcx
add    %rcx,%rax
mov    -0x268(%rbp),%rcx
add    %rcx,%rax
mov    -0x270(%rbp),%rcx
add    %rcx,%rax
mov    -0x278(%rbp),%rcx
add    %rcx,%rax
mov    -0x280(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x290(%rbp)
mov    -0x268(%rbp),%rax
mov    -0x230(%rbp),%rcx
sub    %rcx,%rax
movq   %rax,%xmm1
movaps 0xcbf(%rip),%xmm3
punpckldq %xmm3,%xmm1
movapd 0xcc3(%rip),%xmm2
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm0
unpckhpd %xmm1,%xmm1
addsd  %xmm0,%xmm1
mov    -0x290(%rbp),%rax
mov    -0x288(%rbp),%rcx
sub    %rcx,%rax
movq   %rax,%xmm0
punpckldq %xmm3,%xmm0
subpd  %xmm2,%xmm0
movaps %xmm0,%xmm2
unpckhpd %xmm0,%xmm0
addsd  %xmm2,%xmm0
divsd  %xmm0,%xmm1
movsd  0xc67(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x298(%rbp)
ff
movsd  0xc4b(%rip),%xmm0
mulsd  -0x298(%rbp),%xmm0
ff
lea    0xca1(%rip),%rdi
call   1040 <printf@plt>
jmp    13ce <get_stat_cpu+0x26e>
add    $0x2c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_stat_cpu>:
push   %r14
push   %rbx
sub    $0x278,%rsp
lea    0xebf(%rip),%rdi
lea    0xec3(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1322 <get_stat_cpu+0x1c2>
mov    %rax,%rbx
lea    0x170(%rsp),%r14
mov    %r14,%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
sub    $0x8,%rsp
lea    0x40(%rsp),%rax
lea    0x48(%rsp),%rbx
lea    0x50(%rsp),%r10
lea    0xe7a(%rip),%rsi
lea    0x70(%rsp),%rdx
lea    0x68(%rsp),%rcx
lea    0x60(%rsp),%r8
lea    0x58(%rsp),%r9
mov    %r14,%rdi
push   %rax
push   %rbx
push   %r10
call   1060 <sscanf@plt>
add    $0x20,%rsp
mov    $0x1,%edi
call   1080 <sleep@plt>
lea    0xe38(%rip),%rdi
lea    0xe3c(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1322 <get_stat_cpu+0x1c2>
mov    %rax,%rbx
lea    0x70(%rsp),%r14
mov    %r14,%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
sub    $0x8,%rsp
lea    0x8(%rsp),%rax
lea    0x10(%rsp),%rbx
lea    0x18(%rsp),%r10
lea    0xdf6(%rip),%rsi
lea    0x38(%rsp),%rdx
lea    0x30(%rsp),%rcx
lea    0x28(%rsp),%r8
lea    0x20(%rsp),%r9
mov    %r14,%rdi
push   %rax
push   %rbx
push   %r10
call   1060 <sscanf@plt>
add    $0x20,%rsp
mov    0x60(%rsp),%rax
add    0x68(%rsp),%rax
add    0x58(%rsp),%rax
mov    0x50(%rsp),%rcx
add    %rcx,%rax
add    0x48(%rsp),%rax
add    0x40(%rsp),%rax
add    0x38(%rsp),%rax
mov    0x30(%rsp),%rdx
sub    %rax,%rdx
add    0x28(%rsp),%rdx
mov    0x18(%rsp),%rax
add    0x20(%rsp),%rdx
add    %rax,%rdx
sub    %rcx,%rax
movq   %rax,%xmm0
movdqa 0xd45(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xd49(%rip),%xmm2
subpd  %xmm2,%xmm0
movapd %xmm0,%xmm3
unpckhpd %xmm0,%xmm3
addsd  %xmm0,%xmm3
add    0x10(%rsp),%rdx
add    0x8(%rsp),%rdx
add    (%rsp),%rdx
movq   %rdx,%xmm0
punpckldq %xmm1,%xmm0
subpd  %xmm2,%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm0,%xmm1
divsd  %xmm1,%xmm3
movsd  0xd16(%rip),%xmm0
subsd  %xmm3,%xmm0
mulsd  0xd12(%rip),%xmm0
lea    0xd48(%rip),%rdi
call   1040 <printf@plt>
add    $0x278,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/proc/stat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [40 x i8] c"cpu %llu %llu %llu %llu %llu %llu %llu\00"
@.str.3 = [6 x i8] c"%.0f\0A\00"
define void @get_stat_cpu() {
%1 = alloca i32*
%2 = alloca i32*
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
%16 = alloca i64
%17 = alloca i64
%18 = alloca i64
%19 = alloca i64
%20 = alloca i64
%21 = alloca double
%22 = 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* %22, i32** %1
%23 = load i32*, i32** %1
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %85
25: ; preds = %0
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%27 = load i32*, i32** %1
%28 = call i32 @fgets(i8* %26, i32 256, i32* %27)
%29 = load i32*, i32** %1
%30 = call i32 @fclose(i32* %29)
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%32 = call i32 @sscanf(i8* %31, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i64* %5, i64* %6, i64* %7, i64* %8, i64* %9, i64* %10, i64* %11)
%33 = call i32 @sleep(i32 1)
%34 = 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* %34, i32** %2
%35 = load i32*, i32** %2
%36 = icmp ne i32* %35, null
br i1 %36, label %37, label %84
37: ; preds = %25
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%39 = load i32*, i32** %2
%40 = call i32 @fgets(i8* %38, i32 256, i32* %39)
%41 = load i32*, i32** %2
%42 = call i32 @fclose(i32* %41)
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%44 = call i32 @sscanf(i8* %43, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i64* %12, i64* %13, i64* %14, i64* %15, i64* %16, i64* %17, i64* %18)
%45 = load i64, i64* %5
%46 = load i64, i64* %6
%47 = add i64 %45, %46
%48 = load i64, i64* %7
%49 = add i64 %47, %48
%50 = load i64, i64* %8
%51 = add i64 %49, %50
%52 = load i64, i64* %9
%53 = add i64 %51, %52
%54 = load i64, i64* %10
%55 = add i64 %53, %54
%56 = load i64, i64* %11
%57 = add i64 %55, %56
store i64 %57, i64* %19
%58 = load i64, i64* %12
%59 = load i64, i64* %13
%60 = add i64 %58, %59
%61 = load i64, i64* %14
%62 = add i64 %60, %61
%63 = load i64, i64* %15
%64 = add i64 %62, %63
%65 = load i64, i64* %16
%66 = add i64 %64, %65
%67 = load i64, i64* %17
%68 = add i64 %66, %67
%69 = load i64, i64* %18
%70 = add i64 %68, %69
store i64 %70, i64* %20
%71 = load i64, i64* %15
%72 = load i64, i64* %8
%73 = sub i64 %71, %72
%74 = uitofp i64 %73 to double
%75 = load i64, i64* %20
%76 = load i64, i64* %19
%77 = sub i64 %75, %76
%78 = uitofp i64 %77 to double
%79 = fdiv double %74, %78
%80 = fsub double 1.000000e+00, %79
store double %80, double* %21
%81 = load double, double* %21
%82 = fmul double 1.000000e+02, %81
%83 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double %82)
br label %84
84: ; preds = %37, %25
br label %85
85: ; preds = %84, %0
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"/proc/stat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [40 x i8] c"cpu %llu %llu %llu %llu %llu %llu %llu\00"
@.str.3 = [6 x i8] c"%.0f\0A\00"
define void @get_stat_cpu() {
%1 = alloca [256 x i8]
%2 = alloca [256 x i8]
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
%16 = alloca i64
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%19 = bitcast i64* %3 to i8*
%20 = bitcast i64* %4 to i8*
%21 = bitcast i64* %5 to i8*
%22 = bitcast i64* %6 to i8*
%23 = bitcast i64* %7 to i8*
%24 = bitcast i64* %8 to i8*
%25 = bitcast i64* %9 to i8*
%26 = bitcast i64* %10 to i8*
%27 = bitcast i64* %11 to i8*
%28 = bitcast i64* %12 to i8*
%29 = bitcast i64* %13 to i8*
%30 = bitcast i64* %14 to i8*
%31 = bitcast i64* %15 to i8*
%32 = bitcast i64* %16 to i8*
%33 = 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))
%34 = icmp eq i32* %33, null
br i1 %34, label %80, label %35
35: ; preds = %0
%36 = call i32 @fgets(i8* %17, i32 256, i32* %33)
%37 = call i32 @fclose(i32* %33)
%38 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i64* %3, i64* %4, i64* %5, i64* %6, i64* %7, i64* %8, i64* %9)
%39 = call i32 @sleep(i32 1)
%40 = 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))
%41 = icmp eq i32* %40, null
br i1 %41, label %80, label %42
42: ; preds = %35
%43 = call i32 @fgets(i8* %18, i32 256, i32* %40)
%44 = call i32 @fclose(i32* %40)
%45 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i64* %10, i64* %11, i64* %12, i64* %13, i64* %14, i64* %15, i64* %16)
%46 = load i64, i64* %3
%47 = load i64, i64* %4
%48 = load i64, i64* %5
%49 = load i64, i64* %6
%50 = load i64, i64* %7
%51 = load i64, i64* %8
%52 = load i64, i64* %9
%53 = load i64, i64* %10
%54 = load i64, i64* %11
%55 = load i64, i64* %12
%56 = load i64, i64* %13
%57 = load i64, i64* %14
%58 = load i64, i64* %15
%59 = load i64, i64* %16
%60 = sub i64 %56, %49
%61 = uitofp i64 %60 to double
%62 = add i64 %47, %46
%63 = add i64 %62, %48
%64 = add i64 %63, %49
%65 = add i64 %64, %50
%66 = add i64 %65, %51
%67 = add i64 %66, %52
%68 = sub i64 %53, %67
%69 = add i64 %68, %54
%70 = add i64 %69, %55
%71 = add i64 %70, %56
%72 = add i64 %71, %57
%73 = add i64 %72, %58
%74 = add i64 %73, %59
%75 = uitofp i64 %74 to double
%76 = fdiv double %61, %75
%77 = fsub double 1.000000e+00, %76
%78 = fmul double %77, 1.000000e+02
%79 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), double %78)
br label %80
80: ; preds = %35, %42, %0
ret void
}