#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*/ b;

/* Variables and functions */
char const *bprintf(char *, int);
int /*<<< orphan*/ memcpy(long double *, long double *, int);
int pscanf(char *, char *, long double *, long double *, long double *,
           long double *, long double *, long double *, long double *);
const char *cpu_perc(void) {
  int perc;
  static long double a[7];
  static int valid;
  long double b[7];
  memcpy(b, a, sizeof(b));
  if (pscanf("/proc/stat", "%*s %Lf %Lf %Lf %Lf %Lf %Lf %Lf", &a[0], &a[1],
             &a[2], &a[3], &a[4], &a[5], &a[6]) != 7) {
    return NULL;
  }
  if (!valid) {
    valid = 1;
    return NULL;
  }
  perc = 100 *
         ((b[0] + b[1] + b[2] + b[5] + b[6]) -
          (a[0] + a[1] + a[2] + a[5] + a[6])) /
         ((b[0] + b[1] + b[2] + b[3] + b[4] + b[5] + b[6]) -
          (a[0] + a[1] + a[2] + a[3] + a[4] + a[5] + a[6]));
  return bprintf("%d", perc);
}


x86 assembly (clang, -O0):
<cpu_perc>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
lea    -0x80(%rbp),%rdi
lea    0x2f0a(%rip),%rsi
mov    $0x70,%edx
call   1040 <memcpy@plt>
lea    0xead(%rip),%rdi
lea    0xeb1(%rip),%rsi
lea    0x2eeb(%rip),%rdx
mov    %rdx,%rcx
add    $0x10,%rcx
mov    %rdx,%r8
add    $0x20,%r8
mov    %rdx,%r9
add    $0x30,%r9
mov    %rdx,%r11
add    $0x40,%r11
mov    %rdx,%r10
add    $0x50,%r10
mov    %rdx,%rax
add    $0x60,%rax
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1050 <pscanf@plt>
cmp    $0x7,%eax
je     11b8 <cpu_perc+0x88>
movq   $0x0,-0x8(%rbp)
jmp    12b4 <cpu_perc+0x184>
cmpl   $0x0,0x2f01(%rip)
jne    11dc <cpu_perc+0xac>
movl   $0x1,0x2ef1(%rip)
movq   $0x0,-0x8(%rbp)
jmp    12b4 <cpu_perc+0x184>
fldt   -0x80(%rbp)
fldt   -0x70(%rbp)
faddp  %st,%st(1)
fldt   -0x60(%rbp)
faddp  %st,%st(1)
fld    %st(0)
fstpt  -0xa0(%rbp)
fldt   -0x30(%rbp)
fadd   %st,%st(1)
fldt   -0x20(%rbp)
fadd   %st,%st(2)
fldt   0x2e4f(%rip)
fldt   0x2e59(%rip)
faddp  %st,%st(1)
fldt   0x2e61(%rip)
faddp  %st,%st(1)
fldt   0x2e89(%rip)
fld    %st(1)
fadd   %st(1),%st
fldt   0x2e8f(%rip)
fadd   %st,%st(1)
fxch   %st(6)
fsubp  %st,%st(1)
flds   0xdd3(%rip)
fmulp  %st,%st(1)
fldt   -0xa0(%rbp)
fxch   %st(1)
fstpt  -0x94(%rbp)
fldt   -0x50(%rbp)
faddp  %st,%st(1)
fldt   -0x40(%rbp)
faddp  %st,%st(1)
fldt   -0x94(%rbp)
fxch   %st(1)
faddp  %st,%st(5)
fxch   %st(4)
faddp  %st,%st(3)
fldt   0x2e25(%rip)
faddp  %st,%st(2)
fldt   0x2e2d(%rip)
faddp  %st,%st(2)
faddp  %st,%st(1)
faddp  %st,%st(3)
fsubp  %st,%st(2)
fdivp  %st,%st(1)
fnstcw -0x86(%rbp)
movzwl -0x86(%rbp),%eax
or     $0xc00,%eax
mov    %ax,-0x88(%rbp)
fldcw  -0x88(%rbp)
fistpl -0x84(%rbp)
fldcw  -0x86(%rbp)
mov    -0x84(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xd84(%rip),%rdi
call   1030 <bprintf@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpu_perc>:
push   %rbx
sub    $0x90,%rsp
lea    0x2f11(%rip),%rbx
lea    0x20(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x70,%edx
call   1040 <memcpy@plt>
sub    $0x8,%rsp
lea    0x2f54(%rip),%rax
lea    0x2f3d(%rip),%r10
lea    0x2f26(%rip),%r11
lea    0xe93(%rip),%rdi
lea    0xe97(%rip),%rsi
lea    0x2ee1(%rip),%rcx
lea    0x2eea(%rip),%r8
lea    0x2ef3(%rip),%r9
mov    %rbx,%rdx
push   %rax
push   %r10
push   %r11
call   1050 <pscanf@plt>
add    $0x20,%rsp
cmp    $0x7,%eax
jne    1280 <cpu_perc+0x150>
cmpb   $0x0,0x2f12(%rip)
je     1279 <cpu_perc+0x149>
fldt   0x20(%rsp)
fldt   0x30(%rsp)
faddp  %st,%st(1)
fldt   0x40(%rsp)
faddp  %st,%st(1)
fldt   0x70(%rsp)
fld    %st(0)
fstpt  0x14(%rsp)
fadd   %st(1),%st
fldt   0x80(%rsp)
fadd   %st,%st(1)
fxch   %st(1)
fstpt  0x8(%rsp)
fldt   0x2e6b(%rip)
fldt   0x2e75(%rip)
faddp  %st,%st(1)
fldt   0x2e7d(%rip)
faddp  %st,%st(1)
fldt   0x2ea5(%rip)
fld    %st(1)
fadd   %st(1),%st
fldt   0x2eab(%rip)
fadd   %st,%st(1)
fldt   0x8(%rsp)
fsubp  %st,%st(2)
fxch   %st(1)
fstpt  0x8(%rsp)
fldt   0x50(%rsp)
faddp  %st,%st(5)
fldt   0x60(%rsp)
faddp  %st,%st(5)
fldt   0x14(%rsp)
faddp  %st,%st(5)
fxch   %st(3)
faddp  %st,%st(4)
fldt   0x2e51(%rip)
faddp  %st,%st(2)
fldt   0x2e59(%rip)
faddp  %st,%st(2)
faddp  %st,%st(1)
faddp  %st,%st(1)
fsubrp %st,%st(1)
fldt   0x8(%rsp)
fmuls  0xdb7(%rip)
fdivp  %st,%st(1)
fnstcw (%rsp)
movzwl (%rsp),%eax
or     $0xc00,%eax
mov    %ax,0x2(%rsp)
fldcw  0x2(%rsp)
fistpl 0x4(%rsp)
fldcw  (%rsp)
mov    0x4(%rsp),%esi
lea    0xdbd(%rip),%rdi
call   1030 <bprintf@plt>
jmp    1282 <cpu_perc+0x152>
movb   $0x1,0x2e40(%rip)
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@cpu_perc.a = internal global [7 x x86_fp80] zeroinitializer
@cpu_perc.valid = internal global i32 0
@.str = [11 x i8] c"/proc/stat\00"
@.str.1 = [32 x i8] c"%*s %Lf %Lf %Lf %Lf %Lf %Lf %Lf\00"
@.str.2 = [3 x i8] c"%d\00"
define i8* @cpu_perc() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca [7 x x86_fp80]
%4 = getelementptr inbounds [7 x x86_fp80], [7 x x86_fp80]* %3, i64 0, i64 0
%5 = call i32 @memcpy(x86_fp80* %4, x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 0), i32 112)
%6 = call i32 @pscanf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 0), x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 1), x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 2), x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 3), x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 4), x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 5), x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 6))
%7 = icmp ne i32 %6, 7
br i1 %7, label %8, label %9
8: ; preds = %0
store i8* null, i8** %1
br label %77
9: ; preds = %0
%10 = load i32, i32* @cpu_perc.valid
%11 = icmp ne i32 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %9
store i32 1, i32* @cpu_perc.valid
store i8* null, i8** %1
br label %77
13: ; preds = %9
%14 = getelementptr inbounds [7 x x86_fp80], [7 x x86_fp80]* %3, i64 0, i64 0
%15 = load x86_fp80, x86_fp80* %14
%16 = getelementptr inbounds [7 x x86_fp80], [7 x x86_fp80]* %3, i64 0, i64 1
%17 = load x86_fp80, x86_fp80* %16
%18 = fadd x86_fp80 %15, %17
%19 = getelementptr inbounds [7 x x86_fp80], [7 x x86_fp80]* %3, i64 0, i64 2
%20 = load x86_fp80, x86_fp80* %19
%21 = fadd x86_fp80 %18, %20
%22 = getelementptr inbounds [7 x x86_fp80], [7 x x86_fp80]* %3, i64 0, i64 5
%23 = load x86_fp80, x86_fp80* %22
%24 = fadd x86_fp80 %21, %23
%25 = getelementptr inbounds [7 x x86_fp80], [7 x x86_fp80]* %3, i64 0, i64 6
%26 = load x86_fp80, x86_fp80* %25
%27 = fadd x86_fp80 %24, %26
%28 = load x86_fp80, x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 0)
%29 = load x86_fp80, x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 1)
%30 = fadd x86_fp80 %28, %29
%31 = load x86_fp80, x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 2)
%32 = fadd x86_fp80 %30, %31
%33 = load x86_fp80, x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 5)
%34 = fadd x86_fp80 %32, %33
%35 = load x86_fp80, x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 6)
%36 = fadd x86_fp80 %34, %35
%37 = fsub x86_fp80 %27, %36
%38 = fmul x86_fp80 0xK4005C800000000000000, %37
%39 = getelementptr inbounds [7 x x86_fp80], [7 x x86_fp80]* %3, i64 0, i64 0
%40 = load x86_fp80, x86_fp80* %39
%41 = getelementptr inbounds [7 x x86_fp80], [7 x x86_fp80]* %3, i64 0, i64 1
%42 = load x86_fp80, x86_fp80* %41
%43 = fadd x86_fp80 %40, %42
%44 = getelementptr inbounds [7 x x86_fp80], [7 x x86_fp80]* %3, i64 0, i64 2
%45 = load x86_fp80, x86_fp80* %44
%46 = fadd x86_fp80 %43, %45
%47 = getelementptr inbounds [7 x x86_fp80], [7 x x86_fp80]* %3, i64 0, i64 3
%48 = load x86_fp80, x86_fp80* %47
%49 = fadd x86_fp80 %46, %48
%50 = getelementptr inbounds [7 x x86_fp80], [7 x x86_fp80]* %3, i64 0, i64 4
%51 = load x86_fp80, x86_fp80* %50
%52 = fadd x86_fp80 %49, %51
%53 = getelementptr inbounds [7 x x86_fp80], [7 x x86_fp80]* %3, i64 0, i64 5
%54 = load x86_fp80, x86_fp80* %53
%55 = fadd x86_fp80 %52, %54
%56 = getelementptr inbounds [7 x x86_fp80], [7 x x86_fp80]* %3, i64 0, i64 6
%57 = load x86_fp80, x86_fp80* %56
%58 = fadd x86_fp80 %55, %57
%59 = load x86_fp80, x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 0)
%60 = load x86_fp80, x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 1)
%61 = fadd x86_fp80 %59, %60
%62 = load x86_fp80, x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 2)
%63 = fadd x86_fp80 %61, %62
%64 = load x86_fp80, x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 3)
%65 = fadd x86_fp80 %63, %64
%66 = load x86_fp80, x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 4)
%67 = fadd x86_fp80 %65, %66
%68 = load x86_fp80, x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 5)
%69 = fadd x86_fp80 %67, %68
%70 = load x86_fp80, x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 6)
%71 = fadd x86_fp80 %69, %70
%72 = fsub x86_fp80 %58, %71
%73 = fdiv x86_fp80 %38, %72
%74 = fptosi x86_fp80 %73 to i32
store i32 %74, i32* %2
%75 = load i32, i32* %2
%76 = call i8* @bprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %75)
store i8* %76, i8** %1
br label %77
77: ; preds = %13, %12, %8
%78 = load i8*, i8** %1
ret i8* %78
}

LLVM IR (-O2):
@cpu_perc.a = internal global [7 x x86_fp80] zeroinitializer
@cpu_perc.valid = internal unnamed_addr global i1 false
@.str = [11 x i8] c"/proc/stat\00"
@.str.1 = [32 x i8] c"%*s %Lf %Lf %Lf %Lf %Lf %Lf %Lf\00"
@.str.2 = [3 x i8] c"%d\00"
define i8* @cpu_perc() {
%1 = alloca [7 x x86_fp80]
%2 = bitcast [7 x x86_fp80]* %1 to i8*
%3 = getelementptr inbounds [7 x x86_fp80], [7 x x86_fp80]* %1, i64 0, i64 0
%4 = call i32 @memcpy(x86_fp80* %3, x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 0), i32 112)
%5 = call i32 @pscanf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 0), x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 1), x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 2), x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 3), x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 4), x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 5), x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 6))
%6 = icmp eq i32 %5, 7
br i1 %6, label %7, label %53
7: ; preds = %0
%8 = load i1, i1* @cpu_perc.valid
br i1 %8, label %10, label %9
9: ; preds = %7
store i1 true, i1* @cpu_perc.valid
br label %53
10: ; preds = %7
%11 = load x86_fp80, x86_fp80* %3
%12 = getelementptr inbounds [7 x x86_fp80], [7 x x86_fp80]* %1, i64 0, i64 1
%13 = load x86_fp80, x86_fp80* %12
%14 = fadd x86_fp80 %11, %13
%15 = getelementptr inbounds [7 x x86_fp80], [7 x x86_fp80]* %1, i64 0, i64 2
%16 = load x86_fp80, x86_fp80* %15
%17 = fadd x86_fp80 %14, %16
%18 = getelementptr inbounds [7 x x86_fp80], [7 x x86_fp80]* %1, i64 0, i64 5
%19 = load x86_fp80, x86_fp80* %18
%20 = fadd x86_fp80 %17, %19
%21 = getelementptr inbounds [7 x x86_fp80], [7 x x86_fp80]* %1, i64 0, i64 6
%22 = load x86_fp80, x86_fp80* %21
%23 = fadd x86_fp80 %20, %22
%24 = load x86_fp80, x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 0)
%25 = load x86_fp80, x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 1)
%26 = fadd x86_fp80 %24, %25
%27 = load x86_fp80, x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 2)
%28 = fadd x86_fp80 %26, %27
%29 = load x86_fp80, x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 5)
%30 = fadd x86_fp80 %28, %29
%31 = load x86_fp80, x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 6)
%32 = fadd x86_fp80 %30, %31
%33 = fsub x86_fp80 %23, %32
%34 = fmul x86_fp80 %33, 0xK4005C800000000000000
%35 = getelementptr inbounds [7 x x86_fp80], [7 x x86_fp80]* %1, i64 0, i64 3
%36 = load x86_fp80, x86_fp80* %35
%37 = fadd x86_fp80 %17, %36
%38 = getelementptr inbounds [7 x x86_fp80], [7 x x86_fp80]* %1, i64 0, i64 4
%39 = load x86_fp80, x86_fp80* %38
%40 = fadd x86_fp80 %37, %39
%41 = fadd x86_fp80 %19, %40
%42 = fadd x86_fp80 %22, %41
%43 = load x86_fp80, x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 3)
%44 = fadd x86_fp80 %28, %43
%45 = load x86_fp80, x86_fp80* getelementptr inbounds ([7 x x86_fp80], [7 x x86_fp80]* @cpu_perc.a, i64 0, i64 4)
%46 = fadd x86_fp80 %44, %45
%47 = fadd x86_fp80 %29, %46
%48 = fadd x86_fp80 %31, %47
%49 = fsub x86_fp80 %42, %48
%50 = fdiv x86_fp80 %34, %49
%51 = fptosi x86_fp80 %50 to i32
%52 = call i8* @bprintf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %51)
br label %53
53: ; preds = %0, %10, %9
%54 = phi i8* [ %52, %10 ], [ null, %9 ], [ null, %0 ]
ret i8* %54
}