#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*/ line_buff;
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*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sscanf(char *, char *, char *, long *, long *, long *,
                          long *, long *, long *, long *);
int get_cpu_rate(void) {
  FILE *fp;
  fp = fopen("/proc/stat", "r");
  char line_buff[256] = {0};
  char cpu[5];
  long int user, nice, sys, idle, iowait, irq, softirq;
  long int all1, all2, idle1, idle2;
  float usage;
  fgets(line_buff, sizeof(line_buff), fp);
  sscanf(line_buff, "%s%ld%ld%ld%ld%ld%ld%ld", cpu, &user, &nice, &sys, &idle,
         &iowait, &irq, &softirq);
  all1 = user + nice + sys + idle + iowait + irq + softirq;
  idle1 = idle;
  rewind(fp);
  sleep(1);
  memset(line_buff, 0, sizeof(line_buff));
  cpu[0] = '\0';
  user = nice = sys = idle = iowait = irq = softirq = 0;
  fgets(line_buff, sizeof(line_buff), fp);
  sscanf(line_buff, "%s%ld%ld%ld%ld%ld%ld%ld", cpu, &user, &nice, &sys, &idle,
         &iowait, &irq, &softirq);
  all2 = user + nice + sys + idle + iowait + irq + softirq;
  idle2 = idle;
  usage = (float)(all2 - all1 - (idle2 - idle1)) / (all2 - all1) * 100;
  printf("all=%ld\n", all2 - all1);
  printf("ilde=%ld\n", all2 - all1 - (idle2 - idle1));
  printf("cpu use = %.2f\n", usage);
  printf("=======================\n");
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<get_cpu_rate>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x198,%rsp
lea    0xe71(%rip),%rdi
lea    0xe75(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x100,%esi
call   1070 <fgets@plt>
lea    -0x110(%rbp),%rdi
lea    -0x115(%rbp),%rdx
lea    0xe31(%rip),%rsi
lea    -0x120(%rbp),%rcx
lea    -0x128(%rbp),%r8
lea    -0x130(%rbp),%r9
lea    -0x138(%rbp),%rbx
lea    -0x140(%rbp),%r11
lea    -0x148(%rbp),%r10
lea    -0x150(%rbp),%rax
mov    %rbx,(%rsp)
mov    %r11,0x8(%rsp)
mov    %r10,0x10(%rsp)
mov    %rax,0x18(%rsp)
call   1080 <sscanf@plt>
mov    -0x120(%rbp),%rax
add    -0x128(%rbp),%rax
add    -0x130(%rbp),%rax
add    -0x138(%rbp),%rax
add    -0x140(%rbp),%rax
add    -0x148(%rbp),%rax
add    -0x150(%rbp),%rax
mov    %rax,-0x158(%rbp)
mov    -0x138(%rbp),%rax
mov    %rax,-0x168(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <rewind@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
movb   $0x0,-0x115(%rbp)
movq   $0x0,-0x150(%rbp)
movq   $0x0,-0x148(%rbp)
movq   $0x0,-0x140(%rbp)
movq   $0x0,-0x138(%rbp)
movq   $0x0,-0x130(%rbp)
movq   $0x0,-0x128(%rbp)
movq   $0x0,-0x120(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x100,%esi
call   1070 <fgets@plt>
lea    -0x110(%rbp),%rdi
lea    -0x115(%rbp),%rdx
lea    0xcfe(%rip),%rsi
lea    -0x120(%rbp),%rcx
lea    -0x128(%rbp),%r8
lea    -0x130(%rbp),%r9
lea    -0x138(%rbp),%rbx
lea    -0x140(%rbp),%r11
lea    -0x148(%rbp),%r10
lea    -0x150(%rbp),%rax
mov    %rbx,(%rsp)
mov    %r11,0x8(%rsp)
mov    %r10,0x10(%rsp)
mov    %rax,0x18(%rsp)
call   1080 <sscanf@plt>
mov    -0x120(%rbp),%rax
add    -0x128(%rbp),%rax
add    -0x130(%rbp),%rax
add    -0x138(%rbp),%rax
add    -0x140(%rbp),%rax
add    -0x148(%rbp),%rax
add    -0x150(%rbp),%rax
mov    %rax,-0x160(%rbp)
mov    -0x138(%rbp),%rax
mov    %rax,-0x170(%rbp)
mov    -0x160(%rbp),%rax
sub    -0x158(%rbp),%rax
mov    -0x170(%rbp),%rcx
sub    -0x168(%rbp),%rcx
sub    %rcx,%rax
cvtsi2ss %rax,%xmm0
mov    -0x160(%rbp),%rax
sub    -0x158(%rbp),%rax
cvtsi2ss %rax,%xmm1
divss  %xmm1,%xmm0
movss  0xc1b(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0x174(%rbp)
ff
mov    -0x160(%rbp),%rsi
sub    -0x158(%rbp),%rsi
lea    0xc23(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x160(%rbp),%rsi
sub    -0x158(%rbp),%rsi
mov    -0x170(%rbp),%rax
sub    -0x168(%rbp),%rax
sub    %rax,%rsi
lea    0xbff(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movss  -0x174(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm0
lea    0xbef(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xbf1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x198,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cpu_rate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x158,%rsp
lea    0xe5c(%rip),%rdi
lea    0xe60(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,0x140(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
lea    0x50(%rsp),%r15
mov    %r15,%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1080 <fgets@plt>
lea    0x8(%rsp),%rax
lea    0x10(%rsp),%rbp
lea    0x18(%rsp),%rbx
lea    0x38(%rsp),%r10
lea    0xdb0(%rip),%rsi
lea    0x4b(%rsp),%r13
lea    0x30(%rsp),%rcx
lea    0x28(%rsp),%r8
lea    0x20(%rsp),%r9
mov    %r15,%rdi
mov    %r13,%rdx
push   %rax
push   %rbp
push   %rbx
push   %r10
mov    %r10,%rbp
call   1090 <sscanf@plt>
add    $0x20,%rsp
mov    0x28(%rsp),%r12
add    0x30(%rsp),%r12
add    0x20(%rsp),%r12
mov    0x38(%rsp),%rbx
add    %rbx,%r12
add    0x18(%rsp),%r12
add    0x10(%rsp),%r12
add    0x8(%rsp),%r12
mov    %r14,%rdi
call   1060 <rewind@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
movb   $0x0,0x4b(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
movq   $0x0,0x18(%rsp)
movq   $0x0,0x38(%rsp)
movq   $0x0,0x20(%rsp)
movq   $0x0,0x28(%rsp)
movq   $0x0,0x30(%rsp)
mov    %r15,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1080 <fgets@plt>
mov    %r15,%rdi
lea    0xce0(%rip),%rsi
mov    %r13,%rdx
lea    0x30(%rsp),%rcx
lea    0x28(%rsp),%r8
lea    0x20(%rsp),%r9
lea    0x8(%rsp),%rax
push   %rax
lea    0x18(%rsp),%rax
push   %rax
lea    0x28(%rsp),%rax
push   %rax
push   %rbp
call   1090 <sscanf@plt>
add    $0x20,%rsp
mov    0x30(%rsp),%rsi
sub    %r12,%rsi
add    0x28(%rsp),%rsi
mov    0x38(%rsp),%rax
add    0x20(%rsp),%rsi
add    %rax,%rsi
add    0x18(%rsp),%rsi
add    0x10(%rsp),%rsi
add    0x8(%rsp),%rsi
sub    %rax,%rbx
add    %rsi,%rbx
cvtsi2ss %rbx,%xmm1
cvtsi2ss %rsi,%xmm0
divss  %xmm0,%xmm1
mulss  0xc5c(%rip),%xmm1
movss  %xmm1,0x44(%rsp)
lea    0xc78(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xc73(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
movss  0x44(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xc62(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xc64(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x158,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [11 x i8] c"/proc/stat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [24 x i8] c"%s%ld%ld%ld%ld%ld%ld%ld\00"
@.str.3 = [9 x i8] c"all=%ld\0A\00"
@.str.4 = [10 x i8] c"ilde=%ld\0A\00"
@.str.5 = [16 x i8] c"cpu use = %.2f\0A\00"
@str = [24 x i8] c"=======================\00"
define i32 @get_cpu_rate() {
%1 = alloca [256 x i8]
%2 = alloca [5 x i8]
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = 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))
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%13 = bitcast i64* %3 to i8*
%14 = bitcast i64* %4 to i8*
%15 = bitcast i64* %5 to i8*
%16 = bitcast i64* %6 to i8*
%17 = bitcast i64* %7 to i8*
%18 = bitcast i64* %8 to i8*
%19 = bitcast i64* %9 to i8*
%20 = call i32 @fgets(i8* %11, i32 256, i32* %10)
%21 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %12, i64* %3, i64* %4, i64* %5, i64* %6, i64* %7, i64* %8, i64* %9)
%22 = load i64, i64* %3
%23 = load i64, i64* %4
%24 = load i64, i64* %5
%25 = load i64, i64* %6
%26 = load i64, i64* %7
%27 = load i64, i64* %8
%28 = load i64, i64* %9
%29 = call i32 @rewind(i32* %10)
%30 = call i32 @sleep(i32 1)
%31 = call i32 @memset(i8* %11, i32 0, i32 256)
store i8 0, i8* %12
store i64 0, i64* %9
store i64 0, i64* %8
store i64 0, i64* %7
store i64 0, i64* %6
store i64 0, i64* %5
store i64 0, i64* %4
store i64 0, i64* %3
%32 = call i32 @fgets(i8* %11, i32 256, i32* %10)
%33 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %12, i64* %3, i64* %4, i64* %5, i64* %6, i64* %7, i64* %8, i64* %9)
%34 = load i64, i64* %3
%35 = load i64, i64* %4
%36 = load i64, i64* %5
%37 = load i64, i64* %6
%38 = load i64, i64* %7
%39 = load i64, i64* %8
%40 = load i64, i64* %9
%41 = add i64 %23, %22
%42 = add i64 %41, %24
%43 = add i64 %42, %25
%44 = add i64 %43, %26
%45 = add i64 %44, %27
%46 = add i64 %45, %28
%47 = sub i64 %34, %46
%48 = add i64 %47, %35
%49 = add i64 %48, %36
%50 = add i64 %49, %37
%51 = add i64 %50, %38
%52 = add i64 %51, %39
%53 = add i64 %52, %40
%54 = sub i64 %25, %37
%55 = add i64 %53, %54
%56 = sitofp i64 %55 to float
%57 = sitofp i64 %53 to float
%58 = fdiv float %56, %57
%59 = fmul float %58, 1.000000e+02
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i64 %53)
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i64 %55)
%62 = fpext float %59 to double
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), double %62)
%64 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%65 = call i32 @fclose(i32* %10)
ret i32 0
}