#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 round(double);
int lingot_signal_frequencies_related(double freq1, double freq2,
                                      double minFrequency,
                                      double *mulFreq1ToFreq,
                                      double *mulFreq2ToFreq) {
  int result = 0;
  static const double tol = 5e-2;
  static const int maxDivisor = 4;
  if ((freq1 != 0.0) && (freq2 != 0.0)) {
    double smallFreq = freq1;
    double bigFreq = freq2;
    if (bigFreq < smallFreq) {
      smallFreq = freq2;
      bigFreq = freq1;
    }
    int divisor;
    double frac;
    double error = -1.0;
    for (divisor = 1; divisor <= maxDivisor; divisor++) {
      if (minFrequency * divisor > smallFreq) {
        break;
      }
      frac = bigFreq * divisor / smallFreq;
      error = fabs(frac - round(frac));
      if (error < tol) {
        if (smallFreq == freq1) {
          *mulFreq1ToFreq = 1.0 / divisor;
          *mulFreq2ToFreq = 1.0 / round(frac);
        } else {
          *mulFreq1ToFreq = 1.0 / round(frac);
          *mulFreq2ToFreq = 1.0 / divisor;
        }
        result = 1;
        break;
      }
    }
  } else {
    *mulFreq1ToFreq = 0.0;
    *mulFreq2ToFreq = 0.0;
  }
  return result;
}


x86 assembly (clang, -O0):
<lingot_signal_frequencies_related>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
mov    %rdi,-0x20(%rbp)
mov    %rsi,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1153 <lingot_signal_frequencies_related+0x43>
jp     1153 <lingot_signal_frequencies_related+0x43>
jmp    12f6 <lingot_signal_frequencies_related+0x1e6>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1170 <lingot_signal_frequencies_related+0x60>
jp     1170 <lingot_signal_frequencies_related+0x60>
jmp    12f6 <lingot_signal_frequencies_related+0x1e6>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11ac <lingot_signal_frequencies_related+0x9c>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe4c(%rip),%xmm0
movsd  %xmm0,-0x58(%rbp)
movl   $0x1,-0x44(%rbp)
cmpl   $0x4,-0x44(%rbp)
jg     12f1 <lingot_signal_frequencies_related+0x1e1>
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x44(%rbp),%xmm1
mulsd  %xmm1,%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    11e8 <lingot_signal_frequencies_related+0xd8>
jmp    12f1 <lingot_signal_frequencies_related+0x1e1>
movsd  -0x40(%rbp),%xmm0
cvtsi2sdl -0x44(%rbp),%xmm1
mulsd  %xmm1,%xmm0
divsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x50(%rbp),%xmm0
call   1030 <round@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
subsd  %xmm1,%xmm0
movaps 0xdf9(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  0xdd0(%rip),%xmm0
ucomisd -0x58(%rbp),%xmm0
jbe    12de <lingot_signal_frequencies_related+0x1ce>
movsd  -0x38(%rbp),%xmm0
ucomisd -0x8(%rbp),%xmm0
jne    1298 <lingot_signal_frequencies_related+0x188>
jp     1298 <lingot_signal_frequencies_related+0x188>
cvtsi2sdl -0x44(%rbp),%xmm1
movsd  0xdaa(%rip),%xmm0
divsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x50(%rbp),%xmm0
call   1030 <round@plt>
movaps %xmm0,%xmm1
movsd  0xd89(%rip),%xmm0
divsd  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    12d2 <lingot_signal_frequencies_related+0x1c2>
movsd  -0x50(%rbp),%xmm0
call   1030 <round@plt>
movaps %xmm0,%xmm1
movsd  0xd63(%rip),%xmm0
divsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
cvtsi2sdl -0x44(%rbp),%xmm1
movsd  0xd4a(%rip),%xmm0
divsd  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x1,-0x2c(%rbp)
jmp    12f1 <lingot_signal_frequencies_related+0x1e1>
jmp    12e3 <lingot_signal_frequencies_related+0x1d3>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11c0 <lingot_signal_frequencies_related+0xb0>
jmp    130c <lingot_signal_frequencies_related+0x1fc>
mov    -0x20(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x28(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
mov    -0x2c(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lingot_signal_frequencies_related>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm0
jne    112e <lingot_signal_frequencies_related+0x1e>
jnp    11ea <lingot_signal_frequencies_related+0xda>
xorpd  %xmm4,%xmm4
ucomisd %xmm4,%xmm1
jne    113e <lingot_signal_frequencies_related+0x2e>
jnp    11ea <lingot_signal_frequencies_related+0xda>
movapd %xmm1,%xmm3
minsd  %xmm0,%xmm3
xor    %ebp,%ebp
ucomisd %xmm3,%xmm2
ja     11f8 <lingot_signal_frequencies_related+0xe8>
movsd  %xmm2,0x8(%rsp)
movsd  %xmm0,0x38(%rsp)
maxsd  %xmm1,%xmm0
movapd %xmm0,0x10(%rsp)
divsd  %xmm3,%xmm0
movapd %xmm0,0x20(%rsp)
movsd  %xmm3,(%rsp)
call   1030 <round@plt>
movapd 0x20(%rsp),%xmm1
subsd  %xmm0,%xmm1
andpd  0xe72(%rip),%xmm1
movapd %xmm1,%xmm2
movsd  0xe7e(%rip),%xmm1
ucomisd %xmm2,%xmm1
jbe    1203 <lingot_signal_frequencies_related+0xf3>
movsd  0xe68(%rip),%xmm4
movsd  (%rsp),%xmm1
ucomisd 0x38(%rsp),%xmm1
movapd %xmm0,%xmm1
jne    11c3 <lingot_signal_frequencies_related+0xb3>
movapd %xmm0,%xmm1
jp     11c3 <lingot_signal_frequencies_related+0xb3>
movapd %xmm4,%xmm1
jne    11cb <lingot_signal_frequencies_related+0xbb>
jp     11cb <lingot_signal_frequencies_related+0xbb>
movapd %xmm0,%xmm4
movsd  0xe3d(%rip),%xmm3
movapd %xmm3,%xmm2
divsd  %xmm1,%xmm2
movsd  %xmm2,(%rbx)
divsd  %xmm4,%xmm3
mov    $0x1,%ebp
jmp    11f3 <lingot_signal_frequencies_related+0xe3>
movq   $0x0,(%rbx)
xor    %ebp,%ebp
movsd  %xmm3,(%r14)
mov    %ebp,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
movsd  0x8(%rsp),%xmm0
addsd  %xmm0,%xmm0
movsd  (%rsp),%xmm1
ucomisd %xmm1,%xmm0
ja     11f8 <lingot_signal_frequencies_related+0xe8>
movapd 0x10(%rsp),%xmm0
addsd  %xmm0,%xmm0
divsd  %xmm1,%xmm0
movapd %xmm0,0x20(%rsp)
call   1030 <round@plt>
movapd 0x20(%rsp),%xmm2
subsd  %xmm0,%xmm2
andpd  0xdbd(%rip),%xmm2
movsd  0xdcd(%rip),%xmm1
ucomisd %xmm2,%xmm1
jbe    125e <lingot_signal_frequencies_related+0x14e>
movsd  0xdc7(%rip),%xmm4
jmp    11a8 <lingot_signal_frequencies_related+0x98>
movsd  0xdc2(%rip),%xmm0
mulsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
ucomisd %xmm1,%xmm0
ja     11f8 <lingot_signal_frequencies_related+0xe8>
movapd 0x10(%rsp),%xmm0
mulsd  0xda3(%rip),%xmm0
divsd  %xmm1,%xmm0
movapd %xmm0,0x20(%rsp)
call   1030 <round@plt>
movsd  0xd7c(%rip),%xmm2
movsd  0xd84(%rip),%xmm4
movapd 0x20(%rsp),%xmm1
subsd  %xmm0,%xmm1
andpd  0xd4a(%rip),%xmm1
ucomisd %xmm1,%xmm2
ja     11a8 <lingot_signal_frequencies_related+0x98>
movsd  0x8(%rsp),%xmm1
mulsd  0xd62(%rip),%xmm1
movsd  (%rsp),%xmm3
ucomisd %xmm3,%xmm1
ja     11f8 <lingot_signal_frequencies_related+0xe8>
movapd 0x10(%rsp),%xmm0
mulsd  0xd45(%rip),%xmm0
divsd  %xmm3,%xmm0
movapd %xmm0,0x10(%rsp)
call   1030 <round@plt>
movsd  0xd2e(%rip),%xmm4
movapd 0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
andpd  0xcec(%rip),%xmm1
movsd  0xcfc(%rip),%xmm2
ucomisd %xmm1,%xmm2
ja     11a8 <lingot_signal_frequencies_related+0x98>
jmp    11f8 <lingot_signal_frequencies_related+0xe8>

LLVM IR (-O0):
@lingot_signal_frequencies_related.tol = internal constant double 5.000000e-02
@lingot_signal_frequencies_related.maxDivisor = internal constant i32 4
define i32 @lingot_signal_frequencies_related(double %0, double %1, double %2, double* %3, double* %4) {
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double*
%10 = alloca double*
%11 = alloca i32
%12 = alloca double
%13 = alloca double
%14 = alloca i32
%15 = alloca double
%16 = alloca double
store double %0, double* %6
store double %1, double* %7
store double %2, double* %8
store double* %3, double** %9
store double* %4, double** %10
store i32 0, i32* %11
%17 = load double, double* %6
%18 = fcmp une double %17, 0.000000e+00
br i1 %18, label %19, label %85
19: ; preds = %5
%20 = load double, double* %7
%21 = fcmp une double %20, 0.000000e+00
br i1 %21, label %22, label %85
22: ; preds = %19
%23 = load double, double* %6
store double %23, double* %12
%24 = load double, double* %7
store double %24, double* %13
%25 = load double, double* %13
%26 = load double, double* %12
%27 = fcmp olt double %25, %26
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = load double, double* %7
store double %29, double* %12
%30 = load double, double* %6
store double %30, double* %13
br label %31
31: ; preds = %28, %22
store double -1.000000e+00, double* %16
store i32 1, i32* %14
br label %32
32: ; preds = %81, %31
%33 = load i32, i32* %14
%34 = icmp sle i32 %33, 4
br i1 %34, label %35, label %84
35: ; preds = %32
%36 = load double, double* %8
%37 = load i32, i32* %14
%38 = sitofp i32 %37 to double
%39 = fmul double %36, %38
%40 = load double, double* %12
%41 = fcmp ogt double %39, %40
br i1 %41, label %42, label %43
42: ; preds = %35
br label %84
43: ; preds = %35
%44 = load double, double* %13
%45 = load i32, i32* %14
%46 = sitofp i32 %45 to double
%47 = fmul double %44, %46
%48 = load double, double* %12
%49 = fdiv double %47, %48
store double %49, double* %15
%50 = load double, double* %15
%51 = load double, double* %15
%52 = call double @llvm.round.f64(double %51)
%53 = fsub double %50, %52
%54 = call double @llvm.fabs.f64(double %53)
store double %54, double* %16
%55 = load double, double* %16
%56 = fcmp olt double %55, 5.000000e-02
br i1 %56, label %57, label %80
57: ; preds = %43
%58 = load double, double* %12
%59 = load double, double* %6
%60 = fcmp oeq double %58, %59
br i1 %60, label %61, label %70
61: ; preds = %57
%62 = load i32, i32* %14
%63 = sitofp i32 %62 to double
%64 = fdiv double 1.000000e+00, %63
%65 = load double*, double** %9
store double %64, double* %65
%66 = load double, double* %15
%67 = call double @llvm.round.f64(double %66)
%68 = fdiv double 1.000000e+00, %67
%69 = load double*, double** %10
store double %68, double* %69
br label %79
70: ; preds = %57
%71 = load double, double* %15
%72 = call double @llvm.round.f64(double %71)
%73 = fdiv double 1.000000e+00, %72
%74 = load double*, double** %9
store double %73, double* %74
%75 = load i32, i32* %14
%76 = sitofp i32 %75 to double
%77 = fdiv double 1.000000e+00, %76
%78 = load double*, double** %10
store double %77, double* %78
br label %79
79: ; preds = %70, %61
store i32 1, i32* %11
br label %84
80: ; preds = %43
br label %81
81: ; preds = %80
%82 = load i32, i32* %14
%83 = add nsw i32 %82, 1
store i32 %83, i32* %14
br label %32
84: ; preds = %79, %42, %32
br label %88
85: ; preds = %19, %5
%86 = load double*, double** %9
store double 0.000000e+00, double* %86
%87 = load double*, double** %10
store double 0.000000e+00, double* %87
br label %88
88: ; preds = %85, %84
%89 = load i32, i32* %11
ret i32 %89
}

LLVM IR (-O2):
define i32 @lingot_signal_frequencies_related(double %0, double %1, double %2, double* nocapture writeonly %3, double* nocapture writeonly %4) {
%6 = fcmp une double %0, 0.000000e+00
%7 = fcmp une double %1, 0.000000e+00
%8 = and i1 %6, %7
br i1 %8, label %9, label %58
9: ; preds = %5
%10 = fcmp olt double %1, %0
%11 = select i1 %10, double %1, double %0
%12 = select i1 %10, double %0, double %1
%13 = fcmp olt double %11, %2
br i1 %13, label %62, label %44
14: ; preds = %44
%15 = fmul double %2, 2.000000e+00
%16 = fcmp ogt double %15, %11
br i1 %16, label %62, label %17
17: ; preds = %14
%18 = fmul double %12, 2.000000e+00
%19 = fdiv double %18, %11
%20 = tail call double @llvm.round.f64(double %19)
%21 = fsub double %19, %20
%22 = tail call double @llvm.fabs.f64(double %21)
%23 = fcmp olt double %22, 5.000000e-02
br i1 %23, label %50, label %24
24: ; preds = %17
%25 = fmul double %2, 3.000000e+00
%26 = fcmp ogt double %25, %11
br i1 %26, label %62, label %27
27: ; preds = %24
%28 = fmul double %12, 3.000000e+00
%29 = fdiv double %28, %11
%30 = tail call double @llvm.round.f64(double %29)
%31 = fsub double %29, %30
%32 = tail call double @llvm.fabs.f64(double %31)
%33 = fcmp olt double %32, 5.000000e-02
br i1 %33, label %50, label %34
34: ; preds = %27
%35 = fmul double %2, 4.000000e+00
%36 = fcmp ogt double %35, %11
br i1 %36, label %62, label %37
37: ; preds = %34
%38 = fmul double %12, 4.000000e+00
%39 = fdiv double %38, %11
%40 = tail call double @llvm.round.f64(double %39)
%41 = fsub double %39, %40
%42 = tail call double @llvm.fabs.f64(double %41)
%43 = fcmp olt double %42, 5.000000e-02
br i1 %43, label %50, label %62
44: ; preds = %9
%45 = fdiv double %12, %11
%46 = tail call double @llvm.round.f64(double %45)
%47 = fsub double %45, %46
%48 = tail call double @llvm.fabs.f64(double %47)
%49 = fcmp olt double %48, 5.000000e-02
br i1 %49, label %50, label %14
50: ; preds = %37, %27, %17, %44
%51 = phi double [ 1.000000e+00, %44 ], [ 2.000000e+00, %17 ], [ 3.000000e+00, %27 ], [ 4.000000e+00, %37 ]
%52 = phi double [ %46, %44 ], [ %20, %17 ], [ %30, %27 ], [ %40, %37 ]
%53 = fcmp oeq double %11, %0
%54 = select i1 %53, double %51, double %52
%55 = select i1 %53, double %52, double %51
%56 = fdiv double 1.000000e+00, %54
store double %56, double* %3
%57 = fdiv double 1.000000e+00, %55
br label %59
58: ; preds = %5
store double 0.000000e+00, double* %3
br label %59
59: ; preds = %58, %50
%60 = phi double [ %57, %50 ], [ 0.000000e+00, %58 ]
%61 = phi i32 [ 1, %50 ], [ 0, %58 ]
store double %60, double* %4
br label %62
62: ; preds = %59, %9, %14, %24, %34, %37
%63 = phi i32 [ 0, %37 ], [ 0, %34 ], [ 0, %24 ], [ 0, %14 ], [ 0, %9 ], [ %61, %59 ]
ret i32 %63
}