#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 */
int fabs(double);
int lingot_signal_frequencies_related(double, double, double, double *,
                                      double *);
double lingot_signal_frequency_locker(double freq, double minFrequency) {
  static int locked = 0;
  static double current_frequency = -1.0;
  static int hits_counter = 0;
  static int rehits_counter = 0;
  static int rehits_up_counter = 0;
  static const int nhits_to_lock = 4;
  static const int nhits_to_unlock = 5;
  static const int nhits_to_relock = 6;
  static const int nhits_to_relock_up = 8;
  double multiplier = 0.0;
  double multiplier2 = 0.0;
  static double old_multiplier = 0.0;
  static double old_multiplier2 = 0.0;
  int fail = 0;
  double result = 0.0;
  int consistent_with_current_frequency = 0;
  consistent_with_current_frequency = lingot_signal_frequencies_related(
      freq, current_frequency, minFrequency, &multiplier, &multiplier2);
  if (!locked) {
    if ((freq > 0.0) && (current_frequency == 0.0)) {
      consistent_with_current_frequency = 1;
      multiplier = 1.0;
      multiplier2 = 1.0;
    }
    if (consistent_with_current_frequency && (multiplier == 1.0) &&
        (multiplier2 == 1.0)) {
      current_frequency = freq * multiplier;
      if (++hits_counter >= nhits_to_lock) {
        locked = 1;
        hits_counter = 0;
      }
    } else {
      hits_counter = 0;
      current_frequency = 0.0;
    }
  } else {
    if (consistent_with_current_frequency) {
      if (fabs(multiplier2 - 1.0) < 1e-5) {
        result = freq * multiplier;
        current_frequency = result;
        rehits_counter = 0;
        if (fabs(multiplier - 1.0) > 1e-5) {
          if (fabs(multiplier - old_multiplier) < 1e-5) {
            if (++rehits_up_counter >= nhits_to_relock_up) {
              result = freq;
              current_frequency = result;
              rehits_up_counter = 0;
              fail = 0;
            }
          } else {
            rehits_up_counter = 0;
          }
        } else {
          rehits_up_counter = 0;
        }
      } else {
        rehits_up_counter = 0;
        if (fabs(multiplier2 - 0.5) < 1e-5) {
          hits_counter--;
        }
        fail = 1;
        if (freq * multiplier < minFrequency) {
        } else {
          if (fabs(multiplier2 - old_multiplier2) < 1e-5) {
            if (++rehits_counter >= nhits_to_relock) {
              result = freq * multiplier;
              current_frequency = result;
              rehits_counter = 0;
              fail = 0;
            }
          }
        }
      }
    } else {
      fail = 1;
    }
    if (fail) {
      result = current_frequency;
      hits_counter++;
      if (hits_counter >= nhits_to_unlock) {
        current_frequency = 0.0;
        locked = 0;
        hits_counter = 0;
        result = 0.0;
      }
    } else {
      hits_counter = 0;
    }
  }
  old_multiplier = multiplier;
  old_multiplier2 = multiplier2;
  return result;
}


x86 assembly (clang, -O0):
<lingot_signal_frequency_locker>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0x2ecb(%rip),%xmm1
movsd  -0x10(%rbp),%xmm2
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <lingot_signal_frequencies_related@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,0x2ebf(%rip)
jne    1276 <lingot_signal_frequency_locker+0x156>
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11d5 <lingot_signal_frequency_locker+0xb5>
movsd  0x2e8f(%rip),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11d5 <lingot_signal_frequency_locker+0xb5>
jp     11d5 <lingot_signal_frequency_locker+0xb5>
movl   $0x1,-0x34(%rbp)
movsd  0xe3d(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe30(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     125c <lingot_signal_frequency_locker+0x13c>
movsd  -0x18(%rbp),%xmm0
movsd  0xe14(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    125c <lingot_signal_frequency_locker+0x13c>
jp     125c <lingot_signal_frequency_locker+0x13c>
movsd  -0x20(%rbp),%xmm0
movsd  0xdf7(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    125c <lingot_signal_frequency_locker+0x13c>
jp     125c <lingot_signal_frequency_locker+0x13c>
movsd  -0x8(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,0x2e05(%rip)
mov    0x2e13(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e0a(%rip)
cmp    $0x4,%eax
jl     1257 <lingot_signal_frequency_locker+0x137>
movl   $0x1,0x2df3(%rip)
movl   $0x0,0x2ded(%rip)
jmp    1271 <lingot_signal_frequency_locker+0x151>
movl   $0x0,0x2dde(%rip)
xorps  %xmm0,%xmm0
movsd  %xmm0,0x2dbf(%rip)
jmp    14e9 <lingot_signal_frequency_locker+0x3c9>
cmpl   $0x0,-0x34(%rbp)
je     1474 <lingot_signal_frequency_locker+0x354>
movsd  -0x20(%rbp),%xmm0
movsd  0xd73(%rip),%xmm1
subsd  %xmm1,%xmm0
call   1030 <fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  0xd66(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1389 <lingot_signal_frequency_locker+0x269>
movsd  -0x8(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,0x2d68(%rip)
movl   $0x0,0x2d76(%rip)
movsd  -0x18(%rbp),%xmm0
movsd  0xd21(%rip),%xmm1
subsd  %xmm1,%xmm0
call   1030 <fabs@plt>
cvtsi2sd %eax,%xmm0
movsd  0xd14(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    137a <lingot_signal_frequency_locker+0x25a>
movsd  -0x18(%rbp),%xmm0
subsd  0x2d45(%rip),%xmm0
call   1030 <fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  0xcec(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    136b <lingot_signal_frequency_locker+0x24b>
mov    0x2d20(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2d17(%rip)
cmp    $0x8,%eax
jl     1366 <lingot_signal_frequency_locker+0x246>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,0x2cdb(%rip)
movl   $0x0,0x2ced(%rip)
movl   $0x0,-0x24(%rbp)
jmp    1375 <lingot_signal_frequency_locker+0x255>
movl   $0x0,0x2cd7(%rip)
jmp    1384 <lingot_signal_frequency_locker+0x264>
movl   $0x0,0x2cc8(%rip)
jmp    146f <lingot_signal_frequency_locker+0x34f>
movl   $0x0,0x2cb9(%rip)
movsd  -0x20(%rbp),%xmm0
movsd  0xc70(%rip),%xmm1
subsd  %xmm1,%xmm0
call   1030 <fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  0xc53(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    13ce <lingot_signal_frequency_locker+0x2ae>
mov    0x2c7f(%rip),%eax
add    $0xffffffff,%eax
mov    %eax,0x2c76(%rip)
movl   $0x1,-0x24(%rbp)
movsd  -0x8(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    13f3 <lingot_signal_frequency_locker+0x2d3>
jmp    146a <lingot_signal_frequency_locker+0x34a>
movsd  -0x20(%rbp),%xmm0
subsd  0x2c58(%rip),%xmm0
call   1030 <fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  0xbf7(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1465 <lingot_signal_frequency_locker+0x345>
mov    0x2c27(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2c1e(%rip)
cmp    $0x6,%eax
jl     1460 <lingot_signal_frequency_locker+0x340>
movsd  -0x8(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,0x2be1(%rip)
movl   $0x0,0x2bef(%rip)
movl   $0x0,-0x24(%rbp)
jmp    1465 <lingot_signal_frequency_locker+0x345>
jmp    146a <lingot_signal_frequency_locker+0x34a>
jmp    146f <lingot_signal_frequency_locker+0x34f>
jmp    147b <lingot_signal_frequency_locker+0x35b>
movl   $0x1,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     14da <lingot_signal_frequency_locker+0x3ba>
movsd  0x2ba3(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    0x2bac(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2ba3(%rip)
cmpl   $0x5,0x2b9c(%rip)
jl     14d5 <lingot_signal_frequency_locker+0x3b5>
xorps  %xmm0,%xmm0
movsd  %xmm0,0x2b77(%rip)
movl   $0x0,0x2b7d(%rip)
movl   $0x0,0x2b77(%rip)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    14e4 <lingot_signal_frequency_locker+0x3c4>
movl   $0x0,0x2b60(%rip)
jmp    14e9 <lingot_signal_frequency_locker+0x3c9>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,0x2b5a(%rip)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,0x2b55(%rip)
movsd  -0x30(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lingot_signal_frequency_locker>:
push   %rbx
sub    $0x20,%rsp
movapd %xmm1,%xmm2
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
movsd  0x2eee(%rip),%xmm1
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
movsd  %xmm0,0x18(%rsp)
movsd  %xmm2,0x10(%rsp)
call   1040 <lingot_signal_frequencies_related@plt>
cmpb   $0x0,0x2ede(%rip)
je     120c <lingot_signal_frequency_locker+0xec>
test   %eax,%eax
je     1241 <lingot_signal_frequency_locker+0x121>
movsd  0x8(%rsp),%xmm0
addsd  0xe8a(%rip),%xmm0
call   1030 <fabs@plt>
test   %eax,%eax
jle    12f4 <lingot_signal_frequency_locker+0x1d4>
movl   $0x0,0x2eb7(%rip)
movsd  0x8(%rsp),%xmm0
addsd  0xe6d(%rip),%xmm0
call   1030 <fabs@plt>
test   %eax,%eax
jg     11b3 <lingot_signal_frequency_locker+0x93>
addl   $0xffffffff,0x2e91(%rip)
movsd  (%rsp),%xmm0
mulsd  0x18(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
ja     1241 <lingot_signal_frequency_locker+0x121>
movsd  0x8(%rsp),%xmm0
subsd  0x2e80(%rip),%xmm0
call   1030 <fabs@plt>
test   %eax,%eax
jg     1241 <lingot_signal_frequency_locker+0x121>
mov    0x2e61(%rip),%eax
lea    0x1(%rax),%ecx
mov    %ecx,0x2e58(%rip)
cmp    $0x5,%eax
jl     1241 <lingot_signal_frequency_locker+0x121>
movsd  0x18(%rsp),%xmm0
mulsd  (%rsp),%xmm0
lea    0x2e41(%rip),%rbx
jmp    1378 <lingot_signal_frequency_locker+0x258>
xorpd  %xmm0,%xmm0
movsd  0x18(%rsp),%xmm2
ucomisd %xmm0,%xmm2
jbe    127f <lingot_signal_frequency_locker+0x15f>
movsd  0x2e0c(%rip),%xmm1
ucomisd %xmm0,%xmm1
jne    127f <lingot_signal_frequency_locker+0x15f>
jp     127f <lingot_signal_frequency_locker+0x15f>
movabs $0x3ff0000000000000,%rax
mov    %rax,(%rsp)
mov    %rax,0x8(%rsp)
jmp    12a6 <lingot_signal_frequency_locker+0x186>
movsd  0x2de7(%rip),%xmm0
mov    0x2df5(%rip),%eax
lea    0x1(%rax),%ecx
mov    %ecx,0x2dec(%rip)
cmp    $0x4,%eax
jl     1390 <lingot_signal_frequency_locker+0x270>
movq   $0x0,0x2dc4(%rip)
movb   $0x0,0x2dcd(%rip)
movl   $0x0,0x2dc7(%rip)
jmp    12eb <lingot_signal_frequency_locker+0x1cb>
test   %eax,%eax
je     12d6 <lingot_signal_frequency_locker+0x1b6>
movsd  (%rsp),%xmm0
ucomisd 0xd70(%rip),%xmm0
jne    12d6 <lingot_signal_frequency_locker+0x1b6>
jp     12d6 <lingot_signal_frequency_locker+0x1b6>
movsd  0x8(%rsp),%xmm0
ucomisd 0xd5e(%rip),%xmm0
jne    12d6 <lingot_signal_frequency_locker+0x1b6>
jp     12d6 <lingot_signal_frequency_locker+0x1b6>
movsd  %xmm2,0x2d82(%rip)
mov    0x2d90(%rip),%eax
lea    0x1(%rax),%ecx
mov    %ecx,0x2d87(%rip)
xorpd  %xmm0,%xmm0
cmp    $0x3,%eax
jl     1390 <lingot_signal_frequency_locker+0x270>
movb   $0x1,0x2d6f(%rip)
jmp    1386 <lingot_signal_frequency_locker+0x266>
movl   $0x0,0x2d64(%rip)
movq   $0x0,0x2d45(%rip)
xorpd  %xmm0,%xmm0
jmp    1390 <lingot_signal_frequency_locker+0x270>
movsd  (%rsp),%xmm0
movapd %xmm0,%xmm1
mulsd  0x18(%rsp),%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  %xmm1,0x2d1f(%rip)
movl   $0x0,0x2d2d(%rip)
addsd  0xce5(%rip),%xmm0
call   1030 <fabs@plt>
lea    0x2d1d(%rip),%rbx
test   %eax,%eax
jle    1349 <lingot_signal_frequency_locker+0x229>
movsd  (%rsp),%xmm0
subsd  0x2d10(%rip),%xmm0
call   1030 <fabs@plt>
test   %eax,%eax
jle    1351 <lingot_signal_frequency_locker+0x231>
movsd  0x10(%rsp),%xmm0
jmp    1380 <lingot_signal_frequency_locker+0x260>
mov    0x2cf5(%rip),%eax
lea    0x1(%rax),%ecx
mov    %ecx,0x2cec(%rip)
cmp    $0x6,%eax
movsd  0x10(%rsp),%xmm0
jle    1386 <lingot_signal_frequency_locker+0x266>
lea    0x2cda(%rip),%rbx
movsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x2cb0(%rip)
movl   $0x0,(%rbx)
movl   $0x0,0x2cb4(%rip)
movsd  (%rsp),%xmm1
movsd  %xmm1,0x2cb3(%rip)
movsd  0x8(%rsp),%xmm1
movsd  %xmm1,0x2cad(%rip)
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@lingot_signal_frequency_locker.locked = internal global i32 0
@lingot_signal_frequency_locker.current_frequency = internal global double -1.000000e+00
@lingot_signal_frequency_locker.hits_counter = internal global i32 0
@lingot_signal_frequency_locker.rehits_counter = internal global i32 0
@lingot_signal_frequency_locker.rehits_up_counter = internal global i32 0
@lingot_signal_frequency_locker.nhits_to_lock = internal constant i32 4
@lingot_signal_frequency_locker.nhits_to_unlock = internal constant i32 5
@lingot_signal_frequency_locker.nhits_to_relock = internal constant i32 6
@lingot_signal_frequency_locker.nhits_to_relock_up = internal constant i32 8
@lingot_signal_frequency_locker.old_multiplier = internal global double 0.000000e+00
@lingot_signal_frequency_locker.old_multiplier2 = internal global double 0.000000e+00
define double @lingot_signal_frequency_locker(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca double
%9 = alloca i32
store double %0, double* %3
store double %1, double* %4
store double 0.000000e+00, double* %5
store double 0.000000e+00, double* %6
store i32 0, i32* %7
store double 0.000000e+00, double* %8
store i32 0, i32* %9
%10 = load double, double* %3
%11 = load double, double* @lingot_signal_frequency_locker.current_frequency
%12 = load double, double* %4
%13 = call i32 @lingot_signal_frequencies_related(double %10, double %11, double %12, double* %5, double* %6)
store i32 %13, i32* %9
%14 = load i32, i32* @lingot_signal_frequency_locker.locked
%15 = icmp ne i32 %14, 0
br i1 %15, label %43, label %16
16: ; preds = %2
%17 = load double, double* %3
%18 = fcmp ogt double %17, 0.000000e+00
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load double, double* @lingot_signal_frequency_locker.current_frequency
%21 = fcmp oeq double %20, 0.000000e+00
br i1 %21, label %22, label %23
22: ; preds = %19
store i32 1, i32* %9
store double 1.000000e+00, double* %5
store double 1.000000e+00, double* %6
br label %23
23: ; preds = %22, %19, %16
%24 = load i32, i32* %9
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %41
26: ; preds = %23
%27 = load double, double* %5
%28 = fcmp oeq double %27, 1.000000e+00
br i1 %28, label %29, label %41
29: ; preds = %26
%30 = load double, double* %6
%31 = fcmp oeq double %30, 1.000000e+00
br i1 %31, label %32, label %41
32: ; preds = %29
%33 = load double, double* %3
%34 = load double, double* %5
%35 = fmul double %33, %34
store double %35, double* @lingot_signal_frequency_locker.current_frequency
%36 = load i32, i32* @lingot_signal_frequency_locker.hits_counter
%37 = add nsw i32 %36, 1
store i32 %37, i32* @lingot_signal_frequency_locker.hits_counter
%38 = icmp sge i32 %37, 4
br i1 %38, label %39, label %40
39: ; preds = %32
store i32 1, i32* @lingot_signal_frequency_locker.locked
store i32 0, i32* @lingot_signal_frequency_locker.hits_counter
br label %40
40: ; preds = %39, %32
br label %42
41: ; preds = %29, %26, %23
store i32 0, i32* @lingot_signal_frequency_locker.hits_counter
store double 0.000000e+00, double* @lingot_signal_frequency_locker.current_frequency
br label %42
42: ; preds = %41, %40
br label %131
43: ; preds = %2
%44 = load i32, i32* %9
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %117
46: ; preds = %43
%47 = load double, double* %6
%48 = fsub double %47, 1.000000e+00
%49 = call i32 @fabs(double %48)
%50 = sitofp i32 %49 to double
%51 = fcmp olt double %50, 1.000000e-05
br i1 %51, label %52, label %81
52: ; preds = %46
%53 = load double, double* %3
%54 = load double, double* %5
%55 = fmul double %53, %54
store double %55, double* %8
%56 = load double, double* %8
store double %56, double* @lingot_signal_frequency_locker.current_frequency
store i32 0, i32* @lingot_signal_frequency_locker.rehits_counter
%57 = load double, double* %5
%58 = fsub double %57, 1.000000e+00
%59 = call i32 @fabs(double %58)
%60 = sitofp i32 %59 to double
%61 = fcmp ogt double %60, 1.000000e-05
br i1 %61, label %62, label %79
62: ; preds = %52
%63 = load double, double* %5
%64 = load double, double* @lingot_signal_frequency_locker.old_multiplier
%65 = fsub double %63, %64
%66 = call i32 @fabs(double %65)
%67 = sitofp i32 %66 to double
%68 = fcmp olt double %67, 1.000000e-05
br i1 %68, label %69, label %77
69: ; preds = %62
%70 = load i32, i32* @lingot_signal_frequency_locker.rehits_up_counter
%71 = add nsw i32 %70, 1
store i32 %71, i32* @lingot_signal_frequency_locker.rehits_up_counter
%72 = icmp sge i32 %71, 8
br i1 %72, label %73, label %76
73: ; preds = %69
%74 = load double, double* %3
store double %74, double* %8
%75 = load double, double* %8
store double %75, double* @lingot_signal_frequency_locker.current_frequency
store i32 0, i32* @lingot_signal_frequency_locker.rehits_up_counter
store i32 0, i32* %7
br label %76
76: ; preds = %73, %69
br label %78
77: ; preds = %62
store i32 0, i32* @lingot_signal_frequency_locker.rehits_up_counter
br label %78
78: ; preds = %77, %76
br label %80
79: ; preds = %52
store i32 0, i32* @lingot_signal_frequency_locker.rehits_up_counter
br label %80
80: ; preds = %79, %78
br label %116
81: ; preds = %46
store i32 0, i32* @lingot_signal_frequency_locker.rehits_up_counter
%82 = load double, double* %6
%83 = fsub double %82, 5.000000e-01
%84 = call i32 @fabs(double %83)
%85 = sitofp i32 %84 to double
%86 = fcmp olt double %85, 1.000000e-05
br i1 %86, label %87, label %90
87: ; preds = %81
%88 = load i32, i32* @lingot_signal_frequency_locker.hits_counter
%89 = add nsw i32 %88, -1
store i32 %89, i32* @lingot_signal_frequency_locker.hits_counter
br label %90
90: ; preds = %87, %81
store i32 1, i32* %7
%91 = load double, double* %3
%92 = load double, double* %5
%93 = fmul double %91, %92
%94 = load double, double* %4
%95 = fcmp olt double %93, %94
br i1 %95, label %96, label %97
96: ; preds = %90
br label %115
97: ; preds = %90
%98 = load double, double* %6
%99 = load double, double* @lingot_signal_frequency_locker.old_multiplier2
%100 = fsub double %98, %99
%101 = call i32 @fabs(double %100)
%102 = sitofp i32 %101 to double
%103 = fcmp olt double %102, 1.000000e-05
br i1 %103, label %104, label %114
104: ; preds = %97
%105 = load i32, i32* @lingot_signal_frequency_locker.rehits_counter
%106 = add nsw i32 %105, 1
store i32 %106, i32* @lingot_signal_frequency_locker.rehits_counter
%107 = icmp sge i32 %106, 6
br i1 %107, label %108, label %113
108: ; preds = %104
%109 = load double, double* %3
%110 = load double, double* %5
%111 = fmul double %109, %110
store double %111, double* %8
%112 = load double, double* %8
store double %112, double* @lingot_signal_frequency_locker.current_frequency
store i32 0, i32* @lingot_signal_frequency_locker.rehits_counter
store i32 0, i32* %7
br label %113
113: ; preds = %108, %104
br label %114
114: ; preds = %113, %97
br label %115
115: ; preds = %114, %96
br label %116
116: ; preds = %115, %80
br label %118
117: ; preds = %43
store i32 1, i32* %7
br label %118
118: ; preds = %117, %116
%119 = load i32, i32* %7
%120 = icmp ne i32 %119, 0
br i1 %120, label %121, label %129
121: ; preds = %118
%122 = load double, double* @lingot_signal_frequency_locker.current_frequency
store double %122, double* %8
%123 = load i32, i32* @lingot_signal_frequency_locker.hits_counter
%124 = add nsw i32 %123, 1
store i32 %124, i32* @lingot_signal_frequency_locker.hits_counter
%125 = load i32, i32* @lingot_signal_frequency_locker.hits_counter
%126 = icmp sge i32 %125, 5
br i1 %126, label %127, label %128
127: ; preds = %121
store double 0.000000e+00, double* @lingot_signal_frequency_locker.current_frequency
store i32 0, i32* @lingot_signal_frequency_locker.locked
store i32 0, i32* @lingot_signal_frequency_locker.hits_counter
store double 0.000000e+00, double* %8
br label %128
128: ; preds = %127, %121
br label %130
129: ; preds = %118
store i32 0, i32* @lingot_signal_frequency_locker.hits_counter
br label %130
130: ; preds = %129, %128
br label %131
131: ; preds = %130, %42
%132 = load double, double* %5
store double %132, double* @lingot_signal_frequency_locker.old_multiplier
%133 = load double, double* %6
store double %133, double* @lingot_signal_frequency_locker.old_multiplier2
%134 = load double, double* %8
ret double %134
}

LLVM IR (-O2):
@lingot_signal_frequency_locker.locked = internal unnamed_addr global i1 false
@lingot_signal_frequency_locker.current_frequency = internal unnamed_addr global double -1.000000e+00
@lingot_signal_frequency_locker.hits_counter = internal unnamed_addr global i32 0
@lingot_signal_frequency_locker.rehits_counter = internal unnamed_addr global i32 0
@lingot_signal_frequency_locker.rehits_up_counter = internal unnamed_addr global i32 0
@lingot_signal_frequency_locker.old_multiplier = internal unnamed_addr global double 0.000000e+00
@lingot_signal_frequency_locker.old_multiplier2 = internal unnamed_addr global double 0.000000e+00
define double @lingot_signal_frequency_locker(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = bitcast double* %3 to i8*
store double 0.000000e+00, double* %3
%6 = bitcast double* %4 to i8*
store double 0.000000e+00, double* %4
%7 = load double, double* @lingot_signal_frequency_locker.current_frequency
%8 = call i32 @lingot_signal_frequencies_related(double %0, double %7, double %1, double* %3, double* %4)
%9 = load i1, i1* @lingot_signal_frequency_locker.locked
br i1 %9, label %30, label %10
10: ; preds = %2
%11 = fcmp ogt double %0, 0.000000e+00
%12 = load double, double* @lingot_signal_frequency_locker.current_frequency
%13 = fcmp oeq double %12, 0.000000e+00
%14 = select i1 %11, i1 %13, i1 false
br i1 %14, label %15, label %16
15: ; preds = %10
store double 1.000000e+00, double* %3
store double 1.000000e+00, double* %4
br label %24
16: ; preds = %10
%17 = load double, double* %3
%18 = load double, double* %4
%19 = icmp ne i32 %8, 0
%20 = fcmp oeq double %17, 1.000000e+00
%21 = select i1 %19, i1 %20, i1 false
%22 = fcmp oeq double %18, 1.000000e+00
%23 = select i1 %21, i1 %22, i1 false
br i1 %23, label %24, label %29
24: ; preds = %15, %16
store double %0, double* @lingot_signal_frequency_locker.current_frequency
%25 = load i32, i32* @lingot_signal_frequency_locker.hits_counter
%26 = add nsw i32 %25, 1
store i32 %26, i32* @lingot_signal_frequency_locker.hits_counter
%27 = icmp sgt i32 %25, 2
br i1 %27, label %28, label %92
28: ; preds = %24
store i1 true, i1* @lingot_signal_frequency_locker.locked
store i32 0, i32* @lingot_signal_frequency_locker.hits_counter
br label %92
29: ; preds = %16
store i32 0, i32* @lingot_signal_frequency_locker.hits_counter
store double 0.000000e+00, double* @lingot_signal_frequency_locker.current_frequency
br label %92
30: ; preds = %2
%31 = icmp eq i32 %8, 0
br i1 %31, label %78, label %32
32: ; preds = %30
%33 = load double, double* %4
%34 = fadd double %33, -1.000000e+00
%35 = call i32 @fabs(double %34)
%36 = icmp slt i32 %35, 1
br i1 %36, label %37, label %53
37: ; preds = %32
%38 = load double, double* %3
%39 = fmul double %38, %0
store double %39, double* @lingot_signal_frequency_locker.current_frequency
store i32 0, i32* @lingot_signal_frequency_locker.rehits_counter
%40 = fadd double %38, -1.000000e+00
%41 = call i32 @fabs(double %40)
%42 = icmp sgt i32 %41, 0
br i1 %42, label %43, label %87
43: ; preds = %37
%44 = load double, double* %3
%45 = load double, double* @lingot_signal_frequency_locker.old_multiplier
%46 = fsub double %44, %45
%47 = call i32 @fabs(double %46)
%48 = icmp slt i32 %47, 1
br i1 %48, label %49, label %87
49: ; preds = %43
%50 = load i32, i32* @lingot_signal_frequency_locker.rehits_up_counter
%51 = add nsw i32 %50, 1
store i32 %51, i32* @lingot_signal_frequency_locker.rehits_up_counter
%52 = icmp sgt i32 %50, 6
br i1 %52, label %84, label %90
53: ; preds = %32
store i32 0, i32* @lingot_signal_frequency_locker.rehits_up_counter
%54 = load double, double* %4
%55 = fadd double %54, -5.000000e-01
%56 = call i32 @fabs(double %55)
%57 = icmp slt i32 %56, 1
br i1 %57, label %58, label %61
58: ; preds = %53
%59 = load i32, i32* @lingot_signal_frequency_locker.hits_counter
%60 = add nsw i32 %59, -1
store i32 %60, i32* @lingot_signal_frequency_locker.hits_counter
br label %61
61: ; preds = %58, %53
%62 = load double, double* %3
%63 = fmul double %62, %0
%64 = fcmp olt double %63, %1
br i1 %64, label %78, label %65
65: ; preds = %61
%66 = load double, double* %4
%67 = load double, double* @lingot_signal_frequency_locker.old_multiplier2
%68 = fsub double %66, %67
%69 = call i32 @fabs(double %68)
%70 = icmp slt i32 %69, 1
br i1 %70, label %71, label %78
71: ; preds = %65
%72 = load i32, i32* @lingot_signal_frequency_locker.rehits_counter
%73 = add nsw i32 %72, 1
store i32 %73, i32* @lingot_signal_frequency_locker.rehits_counter
%74 = icmp sgt i32 %72, 4
br i1 %74, label %75, label %78
75: ; preds = %71
%76 = load double, double* %3
%77 = fmul double %76, %0
br label %84
78: ; preds = %61, %71, %65, %30
%79 = load double, double* @lingot_signal_frequency_locker.current_frequency
%80 = load i32, i32* @lingot_signal_frequency_locker.hits_counter
%81 = add nsw i32 %80, 1
store i32 %81, i32* @lingot_signal_frequency_locker.hits_counter
%82 = icmp sgt i32 %80, 3
br i1 %82, label %83, label %92
83: ; preds = %78
store double 0.000000e+00, double* @lingot_signal_frequency_locker.current_frequency
store i1 false, i1* @lingot_signal_frequency_locker.locked
store i32 0, i32* @lingot_signal_frequency_locker.hits_counter
br label %92
84: ; preds = %49, %75
%85 = phi double [ %77, %75 ], [ %0, %49 ]
%86 = phi i32* [ @lingot_signal_frequency_locker.rehits_counter, %75 ], [ @lingot_signal_frequency_locker.rehits_up_counter, %49 ]
store double %85, double* @lingot_signal_frequency_locker.current_frequency
br label %87
87: ; preds = %84, %37, %43
%88 = phi i32* [ @lingot_signal_frequency_locker.rehits_up_counter, %43 ], [ @lingot_signal_frequency_locker.rehits_up_counter, %37 ], [ %86, %84 ]
%89 = phi double [ %39, %43 ], [ %39, %37 ], [ %85, %84 ]
store i32 0, i32* %88
br label %90
90: ; preds = %87, %49
%91 = phi double [ %39, %49 ], [ %89, %87 ]
store i32 0, i32* @lingot_signal_frequency_locker.hits_counter
br label %92
92: ; preds = %90, %83, %78, %29, %28, %24
%93 = phi double [ 0.000000e+00, %83 ], [ %79, %78 ], [ %91, %90 ], [ 0.000000e+00, %28 ], [ 0.000000e+00, %24 ], [ 0.000000e+00, %29 ]
%94 = load double, double* %3
store double %94, double* @lingot_signal_frequency_locker.old_multiplier
%95 = load double, double* %4
store double %95, double* @lingot_signal_frequency_locker.old_multiplier2
ret double %93
}