#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 */
scalar_t__ fuzzyEquals(int /*<<< orphan*/, double);
long *getFactors(double);
int /*<<< orphan*/ getValue(double *, size_t, double);
double getXFactorising(double *equation, size_t degree) {
  long *factA = getFactors(equation[degree]);
  long *factD = getFactors(equation[0]);
  for (long i = 0, a; (a = factA[i]) != 0; i++)
    for (long j = 0, d; (d = factD[j]) != 0; j++) {
      double q = (double)d / a;
      if (fuzzyEquals(getValue(equation, degree, q), 0.0))
        return q;
      if (fuzzyEquals(getValue(equation, degree, -q), 0.0))
        return -q;
    }
  return 0.0;
}


x86 assembly (clang, -O0):
<getXFactorising>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1050 <getFactors@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
call   1050 <getFactors@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     1284 <getXFactorising+0x154>
movq   $0x0,-0x40(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
je     126e <getXFactorising+0x13e>
cvtsi2sdq -0x48(%rbp),%xmm0
cvtsi2sdq -0x38(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movsd  -0x50(%rbp),%xmm0
call   1030 <getValue@plt>
mov    %eax,%edi
xorps  %xmm0,%xmm0
call   1040 <fuzzyEquals@plt>
cmp    $0x0,%rax
je     11f5 <getXFactorising+0xc5>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    128c <getXFactorising+0x15c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movsd  -0x50(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1030 <getValue@plt>
mov    %eax,%edi
xorps  %xmm0,%xmm0
call   1040 <fuzzyEquals@plt>
cmp    $0x0,%rax
je     1258 <getXFactorising+0x128>
movsd  -0x50(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    128c <getXFactorising+0x15c>
jmp    125d <getXFactorising+0x12d>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    1191 <getXFactorising+0x61>
jmp    1273 <getXFactorising+0x143>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    116f <getXFactorising+0x3f>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getXFactorising>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movsd  (%rdi,%rsi,8),%xmm0
call   1050 <getFactors@plt>
mov    %rax,%rbp
movsd  (%rbx),%xmm0
call   1050 <getFactors@plt>
mov    %rax,%r12
mov    %rbp,0x18(%rsp)
mov    0x0(%rbp),%rax
test   %rax,%rax
je     1233 <getXFactorising+0x103>
mov    %r12,%r15
add    $0x8,%r15
xor    %ebp,%ebp
jmp    1197 <getXFactorising+0x67>
nopw   0x0(%rax,%rax,1)
mov    0x18(%rsp),%rax
mov    0x8(%rax,%rbp,8),%rax
add    $0x1,%rbp
test   %rax,%rax
je     1233 <getXFactorising+0x103>
mov    (%r12),%rcx
test   %rcx,%rcx
je     1180 <getXFactorising+0x50>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,0x20(%rsp)
mov    %r15,%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2sd %rcx,%xmm0
divsd  0x20(%rsp),%xmm0
mov    %rbx,%rdi
mov    %r14,%rsi
movapd %xmm0,(%rsp)
call   1030 <getValue@plt>
xorpd  %xmm0,%xmm0
mov    %eax,%edi
call   1040 <fuzzyEquals@plt>
test   %rax,%rax
jne    122d <getXFactorising+0xfd>
movapd (%rsp),%xmm0
xorpd  0xe05(%rip),%xmm0
mov    %rbx,%rdi
mov    %r14,%rsi
movapd %xmm0,(%rsp)
call   1030 <getValue@plt>
xorpd  %xmm0,%xmm0
mov    %eax,%edi
call   1040 <fuzzyEquals@plt>
test   %rax,%rax
jne    122d <getXFactorising+0xfd>
mov    0x0(%r13),%rcx
add    $0x8,%r13
test   %rcx,%rcx
jne    11c0 <getXFactorising+0x90>
jmp    1180 <getXFactorising+0x50>
movaps (%rsp),%xmm0
jmp    1237 <getXFactorising+0x107>
xorpd  %xmm0,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @getXFactorising(double* %0, i64 %1) {
%3 = alloca double
%4 = alloca double*
%5 = alloca i64
%6 = alloca i64*
%7 = alloca i64*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca double
store double* %0, double** %4
store i64 %1, i64* %5
%13 = load double*, double** %4
%14 = load i64, i64* %5
%15 = getelementptr inbounds double, double* %13, i64 %14
%16 = load double, double* %15
%17 = call i64* @getFactors(double %16)
store i64* %17, i64** %6
%18 = load double*, double** %4
%19 = getelementptr inbounds double, double* %18, i64 0
%20 = load double, double* %19
%21 = call i64* @getFactors(double %20)
store i64* %21, i64** %7
store i64 0, i64* %8
br label %22
22: ; preds = %65, %2
%23 = load i64*, i64** %6
%24 = load i64, i64* %8
%25 = getelementptr inbounds i64, i64* %23, i64 %24
%26 = load i64, i64* %25
store i64 %26, i64* %9
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %68
28: ; preds = %22
store i64 0, i64* %10
br label %29
29: ; preds = %61, %28
%30 = load i64*, i64** %7
%31 = load i64, i64* %10
%32 = getelementptr inbounds i64, i64* %30, i64 %31
%33 = load i64, i64* %32
store i64 %33, i64* %11
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %64
35: ; preds = %29
%36 = load i64, i64* %11
%37 = sitofp i64 %36 to double
%38 = load i64, i64* %9
%39 = sitofp i64 %38 to double
%40 = fdiv double %37, %39
store double %40, double* %12
%41 = load double*, double** %4
%42 = load i64, i64* %5
%43 = load double, double* %12
%44 = call i32 @getValue(double* %41, i64 %42, double %43)
%45 = call i64 @fuzzyEquals(i32 %44, double 0.000000e+00)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %35
%48 = load double, double* %12
store double %48, double* %3
br label %69
49: ; preds = %35
%50 = load double*, double** %4
%51 = load i64, i64* %5
%52 = load double, double* %12
%53 = fneg double %52
%54 = call i32 @getValue(double* %50, i64 %51, double %53)
%55 = call i64 @fuzzyEquals(i32 %54, double 0.000000e+00)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %49
%58 = load double, double* %12
%59 = fneg double %58
store double %59, double* %3
br label %69
60: ; preds = %49
br label %61
61: ; preds = %60
%62 = load i64, i64* %10
%63 = add nsw i64 %62, 1
store i64 %63, i64* %10
br label %29
64: ; preds = %29
br label %65
65: ; preds = %64
%66 = load i64, i64* %8
%67 = add nsw i64 %66, 1
store i64 %67, i64* %8
br label %22
68: ; preds = %22
store double 0.000000e+00, double* %3
br label %69
69: ; preds = %68, %57, %47
%70 = load double, double* %3
ret double %70
}

LLVM IR (-O2):
define double @getXFactorising(double* %0, i64 %1) {
%3 = getelementptr inbounds double, double* %0, i64 %1
%4 = load double, double* %3
%5 = tail call i64* @getFactors(double %4)
%6 = load double, double* %0
%7 = tail call i64* @getFactors(double %6)
%8 = load i64, i64* %5
%9 = icmp eq i64 %8, 0
br i1 %9, label %40, label %10
10: ; preds = %2, %35
%11 = phi i64 [ %38, %35 ], [ %8, %2 ]
%12 = phi i64 [ %36, %35 ], [ 0, %2 ]
%13 = load i64, i64* %7
%14 = icmp eq i64 %13, 0
br i1 %14, label %35, label %15
15: ; preds = %10
%16 = sitofp i64 %11 to double
br label %21
17: ; preds = %29
%18 = getelementptr inbounds i64, i64* %7, i64 %34
%19 = load i64, i64* %18
%20 = icmp eq i64 %19, 0
br i1 %20, label %35, label %21
21: ; preds = %15, %17
%22 = phi i64 [ %13, %15 ], [ %19, %17 ]
%23 = phi i64 [ 0, %15 ], [ %34, %17 ]
%24 = sitofp i64 %22 to double
%25 = fdiv double %24, %16
%26 = tail call i32 @getValue(double* %0, i64 %1, double %25)
%27 = tail call i64 @fuzzyEquals(i32 %26, double 0.000000e+00)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %40
29: ; preds = %21
%30 = fneg double %25
%31 = tail call i32 @getValue(double* %0, i64 %1, double %30)
%32 = tail call i64 @fuzzyEquals(i32 %31, double 0.000000e+00)
%33 = icmp eq i64 %32, 0
%34 = add nuw nsw i64 %23, 1
br i1 %33, label %17, label %40
35: ; preds = %17, %10
%36 = add nuw nsw i64 %12, 1
%37 = getelementptr inbounds i64, i64* %5, i64 %36
%38 = load i64, i64* %37
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %10
40: ; preds = %35, %21, %29, %2
%41 = phi double [ 0.000000e+00, %2 ], [ %25, %21 ], [ %30, %29 ], [ 0.000000e+00, %35 ]
ret double %41
}