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

/* Variables and functions */
double fabs(double);
double fps_estimate_simple(double, double, int);
double rangelimit(double, int, int);
double fps_estimate_2speeds(double frame_s, int reset) {
  static double ifpsA = 0., ifpsB = 0., t, td;
  double d;
  static int transition = 0;
  if (reset)
    ifpsA = ifpsB = frame_s;
  ifpsA = fps_estimate_simple(ifpsA, frame_s, 0.4);
  ifpsB = fps_estimate_simple(ifpsB, frame_s, 4.);
  d = fabs(ifpsA / ifpsB);
  if (d < 1.)
    d = 1. / d;
  if (d > 1.2) {
    transition = 1;
    t = 0.;
  }
  if (transition) {
    td = rangelimit(frame_s / 0.2, 0., 1.);
    ifpsA = ifpsA + td * (ifpsB - ifpsA) / (1. - t);
    t += td;
    if (t >= 0.999)
      transition = 0;
  }
  return ifpsA;
}


x86 assembly (clang, -O0):
<fps_estimate_2speeds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     114f <fps_estimate_2speeds+0x2f>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,0x2ef9(%rip)
movsd  %xmm0,0x2ee9(%rip)
movsd  0x2ee1(%rip),%xmm0
movsd  -0x8(%rbp),%xmm1
xor    %edi,%edi
call   1030 <fps_estimate_simple@plt>
movsd  %xmm0,0x2ecd(%rip)
movsd  0x2ecd(%rip),%xmm0
movsd  -0x8(%rbp),%xmm1
mov    $0x4,%edi
call   1030 <fps_estimate_simple@plt>
movsd  %xmm0,0x2eb6(%rip)
movsd  0x2ea6(%rip),%xmm0
divsd  0x2ea6(%rip),%xmm0
movaps 0xe7f(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe4e(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11cf <fps_estimate_2speeds+0xaf>
movsd  0xe3b(%rip),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe2c(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11fb <fps_estimate_2speeds+0xdb>
movl   $0x1,0x2e68(%rip)
xorps  %xmm0,%xmm0
movsd  %xmm0,0x2e4d(%rip)
cmpl   $0x0,0x2e56(%rip)
je     12b2 <fps_estimate_2speeds+0x192>
movsd  -0x8(%rbp),%xmm0
movsd  0xe03(%rip),%xmm1
divsd  %xmm1,%xmm0
xor    %edi,%edi
mov    $0x1,%esi
call   1040 <rangelimit@plt>
movsd  %xmm0,0x2e23(%rip)
movsd  0x2e03(%rip),%xmm0
movsd  0x2e13(%rip),%xmm1
movsd  0x2dfb(%rip),%xmm2
subsd  0x2deb(%rip),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xda7(%rip),%xmm2
subsd  0x2de7(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,0x2dc7(%rip)
movsd  0x2dd7(%rip),%xmm0
addsd  0x2dc7(%rip),%xmm0
movsd  %xmm0,0x2dbf(%rip)
movsd  0x2db7(%rip),%xmm0
movsd  0xd77(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     12ad <fps_estimate_2speeds+0x18d>
movl   $0x0,0x2dab(%rip)
jmp    12b2 <fps_estimate_2speeds+0x192>
movsd  0x2d7e(%rip),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fps_estimate_2speeds>:
push   %rax
movaps %xmm0,%xmm1
test   %edi,%edi
je     113d <fps_estimate_2speeds+0x1d>
movsd  %xmm1,0x2f10(%rip)
movsd  %xmm1,0x2f00(%rip)
movaps %xmm1,%xmm0
jmp    1145 <fps_estimate_2speeds+0x25>
movsd  0x2ef3(%rip),%xmm0
movsd  %xmm1,(%rsp)
xor    %edi,%edi
call   1030 <fps_estimate_simple@plt>
movsd  %xmm0,0x2edf(%rip)
movsd  0x2edf(%rip),%xmm0
movsd  (%rsp),%xmm1
mov    $0x4,%edi
call   1030 <fps_estimate_simple@plt>
movapd %xmm0,%xmm1
movsd  0x2ebc(%rip),%xmm0
movapd %xmm0,%xmm2
divsd  %xmm1,%xmm2
andpd  0xe74(%rip),%xmm2
movsd  %xmm1,0x2eac(%rip)
movsd  0xe74(%rip),%xmm1
ucomisd %xmm2,%xmm1
jbe    11aa <fps_estimate_2speeds+0x8a>
divsd  %xmm2,%xmm1
movapd %xmm1,%xmm2
ucomisd 0xe66(%rip),%xmm2
jbe    11c8 <fps_estimate_2speeds+0xa8>
movb   $0x1,0x2e95(%rip)
movq   $0x0,0x2e82(%rip)
jmp    11d1 <fps_estimate_2speeds+0xb1>
cmpb   $0x1,0x2e81(%rip)
jne    1247 <fps_estimate_2speeds+0x127>
movsd  (%rsp),%xmm0
divsd  0xe42(%rip),%xmm0
xor    %edi,%edi
mov    $0x1,%esi
call   1040 <rangelimit@plt>
movapd %xmm0,%xmm1
movsd  0x2e42(%rip),%xmm2
movsd  0x2e42(%rip),%xmm0
subsd  %xmm2,%xmm0
mulsd  %xmm1,%xmm0
movsd  0x2e3a(%rip),%xmm3
movsd  0xdfa(%rip),%xmm4
subsd  %xmm3,%xmm4
divsd  %xmm4,%xmm0
addsd  %xmm2,%xmm0
movsd  %xmm0,0x2e0e(%rip)
addsd  %xmm3,%xmm1
movsd  %xmm1,0x2e12(%rip)
ucomisd 0xdea(%rip),%xmm1
jb     1247 <fps_estimate_2speeds+0x127>
movb   $0x0,0x2e09(%rip)
pop    %rax
ret

LLVM IR (-O0):
@fps_estimate_2speeds.ifpsA = internal global double 0.000000e+00
@fps_estimate_2speeds.ifpsB = internal global double 0.000000e+00
@fps_estimate_2speeds.t = internal global double 0.000000e+00
@fps_estimate_2speeds.td = internal global double 0.000000e+00
@fps_estimate_2speeds.transition = internal global i32 0
define double @fps_estimate_2speeds(double %0, i32 %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca double
store double %0, double* %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = load double, double* %3
store double %9, double* @fps_estimate_2speeds.ifpsB
store double %9, double* @fps_estimate_2speeds.ifpsA
br label %10
10: ; preds = %8, %2
%11 = load double, double* @fps_estimate_2speeds.ifpsA
%12 = load double, double* %3
%13 = call double @fps_estimate_simple(double %11, double %12, i32 0)
store double %13, double* @fps_estimate_2speeds.ifpsA
%14 = load double, double* @fps_estimate_2speeds.ifpsB
%15 = load double, double* %3
%16 = call double @fps_estimate_simple(double %14, double %15, i32 4)
store double %16, double* @fps_estimate_2speeds.ifpsB
%17 = load double, double* @fps_estimate_2speeds.ifpsA
%18 = load double, double* @fps_estimate_2speeds.ifpsB
%19 = fdiv double %17, %18
%20 = call double @llvm.fabs.f64(double %19)
store double %20, double* %5
%21 = load double, double* %5
%22 = fcmp olt double %21, 1.000000e+00
br i1 %22, label %23, label %26
23: ; preds = %10
%24 = load double, double* %5
%25 = fdiv double 1.000000e+00, %24
store double %25, double* %5
br label %26
26: ; preds = %23, %10
%27 = load double, double* %5
%28 = fcmp ogt double %27, 1.200000e+00
br i1 %28, label %29, label %30
29: ; preds = %26
store i32 1, i32* @fps_estimate_2speeds.transition
store double 0.000000e+00, double* @fps_estimate_2speeds.t
br label %30
30: ; preds = %29, %26
%31 = load i32, i32* @fps_estimate_2speeds.transition
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %54
33: ; preds = %30
%34 = load double, double* %3
%35 = fdiv double %34, 2.000000e-01
%36 = call double @rangelimit(double %35, i32 0, i32 1)
store double %36, double* @fps_estimate_2speeds.td
%37 = load double, double* @fps_estimate_2speeds.ifpsA
%38 = load double, double* @fps_estimate_2speeds.td
%39 = load double, double* @fps_estimate_2speeds.ifpsB
%40 = load double, double* @fps_estimate_2speeds.ifpsA
%41 = fsub double %39, %40
%42 = fmul double %38, %41
%43 = load double, double* @fps_estimate_2speeds.t
%44 = fsub double 1.000000e+00, %43
%45 = fdiv double %42, %44
%46 = fadd double %37, %45
store double %46, double* @fps_estimate_2speeds.ifpsA
%47 = load double, double* @fps_estimate_2speeds.td
%48 = load double, double* @fps_estimate_2speeds.t
%49 = fadd double %48, %47
store double %49, double* @fps_estimate_2speeds.t
%50 = load double, double* @fps_estimate_2speeds.t
%51 = fcmp oge double %50, 0x3FEFF7CED916872B
br i1 %51, label %52, label %53
52: ; preds = %33
store i32 0, i32* @fps_estimate_2speeds.transition
br label %53
53: ; preds = %52, %33
br label %54
54: ; preds = %53, %30
%55 = load double, double* @fps_estimate_2speeds.ifpsA
ret double %55
}

LLVM IR (-O2):
@fps_estimate_2speeds.ifpsA = internal unnamed_addr global double 0.000000e+00
@fps_estimate_2speeds.ifpsB = internal unnamed_addr global double 0.000000e+00
@fps_estimate_2speeds.t = internal unnamed_addr global double 0.000000e+00
@fps_estimate_2speeds.transition = internal unnamed_addr global i1 false
define double @fps_estimate_2speeds(double %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = load double, double* @fps_estimate_2speeds.ifpsA
br label %7
6: ; preds = %2
store double %0, double* @fps_estimate_2speeds.ifpsB
store double %0, double* @fps_estimate_2speeds.ifpsA
br label %7
7: ; preds = %4, %6
%8 = phi double [ %5, %4 ], [ %0, %6 ]
%9 = tail call double @fps_estimate_simple(double %8, double %0, i32 0)
store double %9, double* @fps_estimate_2speeds.ifpsA
%10 = load double, double* @fps_estimate_2speeds.ifpsB
%11 = tail call double @fps_estimate_simple(double %10, double %0, i32 4)
store double %11, double* @fps_estimate_2speeds.ifpsB
%12 = load double, double* @fps_estimate_2speeds.ifpsA
%13 = fdiv double %12, %11
%14 = tail call double @llvm.fabs.f64(double %13)
%15 = fcmp olt double %14, 1.000000e+00
%16 = fdiv double 1.000000e+00, %14
%17 = select i1 %15, double %16, double %14
%18 = fcmp ogt double %17, 1.200000e+00
br i1 %18, label %19, label %20
19: ; preds = %7
store i1 true, i1* @fps_estimate_2speeds.transition
store double 0.000000e+00, double* @fps_estimate_2speeds.t
br label %22
20: ; preds = %7
%21 = load i1, i1* @fps_estimate_2speeds.transition
br i1 %21, label %22, label %36
22: ; preds = %19, %20
%23 = fdiv double %0, 2.000000e-01
%24 = tail call double @rangelimit(double %23, i32 0, i32 1)
%25 = load double, double* @fps_estimate_2speeds.ifpsA
%26 = load double, double* @fps_estimate_2speeds.ifpsB
%27 = fsub double %26, %25
%28 = fmul double %24, %27
%29 = load double, double* @fps_estimate_2speeds.t
%30 = fsub double 1.000000e+00, %29
%31 = fdiv double %28, %30
%32 = fadd double %25, %31
store double %32, double* @fps_estimate_2speeds.ifpsA
%33 = fadd double %24, %29
store double %33, double* @fps_estimate_2speeds.t
%34 = fcmp ult double %33, 0x3FEFF7CED916872B
br i1 %34, label %36, label %35
35: ; preds = %22
store i1 false, i1* @fps_estimate_2speeds.transition
br label %36
36: ; preds = %22, %35, %20
%37 = phi double [ %32, %22 ], [ %32, %35 ], [ %12, %20 ]
ret double %37
}