#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 scalar_t__ time_t;

/* Variables and functions */
scalar_t__ time(int /*<<< orphan*/ *);
void calc_standard_average(const double total_capacity, double *const rate,
                           bool *const inaccurate) {
  static time_t time_start = 0;
  static double total_capacity_start = 0.0;
  static bool first = true;
  time_t time_now, dt;
  double dw;
  time_now = time(NULL);
  if (time_now == ((time_t)-1)) {
    *rate = 0.0;
    *inaccurate = true;
    return;
  }
  if (first) {
    time_start = time_now;
    total_capacity_start = total_capacity;
    first = false;
    *rate = 0.0;
    *inaccurate = true;
    return;
  }
  dt = time_now - time_start;
  dw = total_capacity_start - total_capacity;
  if (dt <= 0 || dw <= 0.0) {
    *rate = 0.0;
    *inaccurate = true;
    return;
  }
  *rate = 3600.0 * dw / dt;
  *inaccurate = dt < (120);
}


x86 assembly (clang, -O0):
<calc_standard_average>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1030 <time@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0xffffffffffffffff,-0x20(%rbp)
jne    1157 <calc_standard_average+0x47>
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
jmp    1226 <calc_standard_average+0x116>
cmpl   $0x0,0x2eca(%rip)
je     11a0 <calc_standard_average+0x90>
mov    -0x20(%rbp),%rax
mov    %rax,0x2ec9(%rip)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,0x2ec4(%rip)
movl   $0x0,0x2ea2(%rip)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
jmp    1226 <calc_standard_average+0x116>
mov    -0x20(%rbp),%rax
sub    0x2e8d(%rip),%rax
mov    %rax,-0x28(%rbp)
movsd  0x2e89(%rip),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
jle    11da <calc_standard_average+0xca>
xorps  %xmm0,%xmm0
ucomisd -0x30(%rbp),%xmm0
jb     11f4 <calc_standard_average+0xe4>
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
jmp    1226 <calc_standard_average+0x116>
movsd  0xe04(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
cvtsi2sdq -0x28(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
cmpq   $0x78,-0x28(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_standard_average>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
movsd  %xmm0,(%rsp)
xor    %edi,%edi
call   1030 <time@plt>
cmp    $0xffffffffffffffff,%rax
je     1193 <calc_standard_average+0x83>
cmpb   $0x0,0x2f0d(%rip)
je     1178 <calc_standard_average+0x68>
sub    0x2ef4(%rip),%rax
jle    1193 <calc_standard_average+0x83>
movsd  0x2ef2(%rip),%xmm0
subsd  (%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jae    1193 <calc_standard_average+0x83>
mulsd  0xea3(%rip),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rbx)
xor    %ecx,%ecx
cmp    $0x78,%rax
setb   %cl
jmp    119f <calc_standard_average+0x8f>
mov    %rax,0x2eb1(%rip)
movsd  (%rsp),%xmm0
movsd  %xmm0,0x2eac(%rip)
movb   $0x1,0x2ead(%rip)
movq   $0x0,(%rbx)
mov    $0x1,%ecx
mov    %ecx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@calc_standard_average.time_start = internal global i64 0
@calc_standard_average.total_capacity_start = internal global double 0.000000e+00
@calc_standard_average.first = internal global i32 1
define void @calc_standard_average(double %0, double* %1, i32* %2) {
%4 = alloca double
%5 = alloca double*
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i64
%9 = alloca double
store double %0, double* %4
store double* %1, double** %5
store i32* %2, i32** %6
%10 = call i64 @time(i32* null)
store i64 %10, i64* %7
%11 = load i64, i64* %7
%12 = icmp eq i64 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = load double*, double** %5
store double 0.000000e+00, double* %14
%15 = load i32*, i32** %6
store i32 1, i32* %15
br label %50
16: ; preds = %3
%17 = load i32, i32* @calc_standard_average.first
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = load i64, i64* %7
store i64 %20, i64* @calc_standard_average.time_start
%21 = load double, double* %4
store double %21, double* @calc_standard_average.total_capacity_start
store i32 0, i32* @calc_standard_average.first
%22 = load double*, double** %5
store double 0.000000e+00, double* %22
%23 = load i32*, i32** %6
store i32 1, i32* %23
br label %50
24: ; preds = %16
%25 = load i64, i64* %7
%26 = load i64, i64* @calc_standard_average.time_start
%27 = sub nsw i64 %25, %26
store i64 %27, i64* %8
%28 = load double, double* @calc_standard_average.total_capacity_start
%29 = load double, double* %4
%30 = fsub double %28, %29
store double %30, double* %9
%31 = load i64, i64* %8
%32 = icmp sle i64 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %24
%34 = load double, double* %9
%35 = fcmp ole double %34, 0.000000e+00
br i1 %35, label %36, label %39
36: ; preds = %33, %24
%37 = load double*, double** %5
store double 0.000000e+00, double* %37
%38 = load i32*, i32** %6
store i32 1, i32* %38
br label %50
39: ; preds = %33
%40 = load double, double* %9
%41 = fmul double 3.600000e+03, %40
%42 = load i64, i64* %8
%43 = sitofp i64 %42 to double
%44 = fdiv double %41, %43
%45 = load double*, double** %5
store double %44, double* %45
%46 = load i64, i64* %8
%47 = icmp slt i64 %46, 120
%48 = zext i1 %47 to i32
%49 = load i32*, i32** %6
store i32 %48, i32* %49
br label %50
50: ; preds = %39, %36, %19, %13
ret void
}

LLVM IR (-O2):
@calc_standard_average.time_start = internal unnamed_addr global i64 0
@calc_standard_average.total_capacity_start = internal unnamed_addr global double 0.000000e+00
@calc_standard_average.first = internal unnamed_addr global i1 false
define void @calc_standard_average(double %0, double* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = tail call i64 @time(i32* null)
%5 = icmp eq i64 %4, -1
br i1 %5, label %6, label %7
6: ; preds = %3
store double 0.000000e+00, double* %1
br label %25
7: ; preds = %3
%8 = load i1, i1* @calc_standard_average.first
br i1 %8, label %10, label %9
9: ; preds = %7
store i64 %4, i64* @calc_standard_average.time_start
store double %0, double* @calc_standard_average.total_capacity_start
store i1 true, i1* @calc_standard_average.first
store double 0.000000e+00, double* %1
br label %25
10: ; preds = %7
%11 = load i64, i64* @calc_standard_average.time_start
%12 = sub nsw i64 %4, %11
%13 = load double, double* @calc_standard_average.total_capacity_start
%14 = fsub double %13, %0
%15 = icmp slt i64 %12, 1
%16 = fcmp ole double %14, 0.000000e+00
%17 = select i1 %15, i1 true, i1 %16
br i1 %17, label %18, label %19
18: ; preds = %10
store double 0.000000e+00, double* %1
br label %25
19: ; preds = %10
%20 = fmul double %14, 3.600000e+03
%21 = sitofp i64 %12 to double
%22 = fdiv double %20, %21
store double %22, double* %1
%23 = icmp ult i64 %12, 120
%24 = zext i1 %23 to i32
br label %25
25: ; preds = %19, %18, %9, %6
%26 = phi i32 [ %24, %19 ], [ 1, %18 ], [ 1, %9 ], [ 1, %6 ]
store i32 %26, i32* %2
ret void
}