; LLVM IR from rdguez-mariano/fast_imas_IPOL :: libUSAC/utils/FundmatrixFunctions.ll (ZN6FTools7rroots3EPdS0_)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind
declare double @sqrt(double noundef) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN6FTools7rroots3EPdS0_(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca double, align 8
  %15 = alloca double, align 8
  %16 = alloca double, align 8
  %17 = alloca double, align 8
  %18 = alloca double, align 8
  %19 = alloca double, align 8
  %20 = alloca double, align 8
  %21 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #4
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds double, ptr %22, i64 1
  %24 = load double, ptr %23, align 8, !tbaa !9
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = load double, ptr %25, align 8, !tbaa !9
  %27 = fdiv double %24, %26
  store double %27, ptr %6, align 8, !tbaa !9
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds double, ptr %28, i64 2
  %30 = load double, ptr %29, align 8, !tbaa !9
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load double, ptr %31, align 8, !tbaa !9
  %33 = fdiv double %30, %32
  store double %33, ptr %7, align 8, !tbaa !9
  %34 = load double, ptr %6, align 8, !tbaa !9
  %35 = load double, ptr %6, align 8, !tbaa !9
  %36 = fmul double %34, %35
  store double %36, ptr %8, align 8, !tbaa !9
  %37 = load double, ptr %6, align 8, !tbaa !9
  %38 = fdiv double %37, 3.000000e+00
  store double %38, ptr %9, align 8, !tbaa !9
  %39 = load double, ptr %7, align 8, !tbaa !9
  %40 = load double, ptr %8, align 8, !tbaa !9
  %41 = fneg double %40
  %42 = call double @llvm.fmuladd.f64(double 3.000000e+00, double %39, double %41)
  %43 = fdiv double %42, 9.000000e+00
  store double %43, ptr %13, align 8, !tbaa !9
  %44 = load double, ptr %8, align 8, !tbaa !9
  %45 = fmul double 2.000000e+00, %44
  %46 = load double, ptr %6, align 8, !tbaa !9
  %47 = fmul double %45, %46
  %48 = fdiv double %47, 2.700000e+01
  %49 = load double, ptr %6, align 8, !tbaa !9
  %50 = load double, ptr %7, align 8, !tbaa !9
  %51 = fmul double %49, %50
  %52 = fdiv double %51, 3.000000e+00
  %53 = fsub double %48, %52
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds double, ptr %54, i64 3
  %56 = load double, ptr %55, align 8, !tbaa !9
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = load double, ptr %57, align 8, !tbaa !9
  %59 = fdiv double %56, %58
  %60 = fadd double %53, %59
  %61 = fdiv double %60, 2.000000e+00
  store double %61, ptr %14, align 8, !tbaa !9
  %62 = load double, ptr %14, align 8, !tbaa !9
  %63 = load double, ptr %14, align 8, !tbaa !9
  %64 = load double, ptr %13, align 8, !tbaa !9
  %65 = load double, ptr %13, align 8, !tbaa !9
  %66 = fmul double %64, %65
  %67 = load double, ptr %13, align 8, !tbaa !9
  %68 = fmul double %66, %67
  %69 = call double @llvm.fmuladd.f64(double %62, double %63, double %68)
  store double %69, ptr %15, align 8, !tbaa !9
  %70 = load double, ptr %15, align 8, !tbaa !9
  %71 = fcmp ogt double %70, 0.000000e+00
  br i1 %71, label %72, label %103

72:                                               ; preds = %2
  %73 = load double, ptr %15, align 8, !tbaa !9
  %74 = call double @sqrt(double noundef %73) #4
  %75 = load double, ptr %14, align 8, !tbaa !9
  %76 = fsub double %74, %75
  store double %76, ptr %16, align 8, !tbaa !9
  %77 = load double, ptr %16, align 8, !tbaa !9
  %78 = fcmp ogt double %77, 0.000000e+00
  br i1 %78, label %79, label %90

79:                                               ; preds = %72
  %80 = load double, ptr %16, align 8, !tbaa !9
  %81 = call double @pow(double noundef %80, double noundef 0x3FD5555555555555) #4
  store double %81, ptr %10, align 8, !tbaa !9
  %82 = load double, ptr %10, align 8, !tbaa !9
  %83 = load double, ptr %13, align 8, !tbaa !9
  %84 = load double, ptr %10, align 8, !tbaa !9
  %85 = fdiv double %83, %84
  %86 = fsub double %82, %85
  %87 = load double, ptr %9, align 8, !tbaa !9
  %88 = fsub double %86, %87
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  store double %88, ptr %89, align 8, !tbaa !9
  br label %102

90:                                               ; preds = %72
  %91 = load double, ptr %16, align 8, !tbaa !9
  %92 = fneg double %91
  %93 = call double @pow(double noundef %92, double noundef 0x3FD5555555555555) #4
  store double %93, ptr %10, align 8, !tbaa !9
  %94 = load double, ptr %13, align 8, !tbaa !9
  %95 = load double, ptr %10, align 8, !tbaa !9
  %96 = fdiv double %94, %95
  %97 = load double, ptr %10, align 8, !tbaa !9
  %98 = fsub double %96, %97
  %99 = load double, ptr %9, align 8, !tbaa !9
  %100 = fsub double %98, %99
  %101 = load ptr, ptr %5, align 8, !tbaa !5
  store double %100, ptr %101, align 8, !tbaa !9
  br label %102

102:                                              ; preds = %90, %79
  store i32 1, ptr %3, align 4
  store i32 1, ptr %21, align 4
  br label %164

103:                                              ; preds = %2
  %104 = load double, ptr %14, align 8, !tbaa !9
  %105 = fcmp ogt double %104, 0.000000e+00
  br i1 %105, label %106, label %107

106:                                              ; preds = %103
  store double 1.000000e+00, ptr %12, align 8, !tbaa !9
  br label %108

107:                                              ; preds = %103
  store double -1.000000e+00, ptr %12, align 8, !tbaa !9
  br label %108

108:                                              ; preds = %107, %106
  %109 = load double, ptr %12, align 8, !tbaa !9
  %110 = load double, ptr %13, align 8, !tbaa !9
  %111 = fneg double %110
  %112 = call double @sqrt(double noundef %111) #4
  %113 = fmul double %109, %112
  store double %113, ptr %19, align 8, !tbaa !9
  %114 = load double, ptr %19, align 8, !tbaa !9
  %115 = fmul double %114, 2.000000e+00
  store double %115, ptr %20, align 8, !tbaa !9
  %116 = load double, ptr %14, align 8, !tbaa !9
  %117 = load double, ptr %19, align 8, !tbaa !9
  %118 = load double, ptr %19, align 8, !tbaa !9
  %119 = fmul double %117, %118
  %120 = load double, ptr %19, align 8, !tbaa !9
  %121 = fmul double %119, %120
  %122 = fdiv double %116, %121
  store double %122, ptr %17, align 8, !tbaa !9
  %123 = load double, ptr %17, align 8, !tbaa !9
  %124 = fcmp ogt double %123, 1.000000e+00
  br i1 %124, label %125, label %126

125:                                              ; preds = %108
  store double 1.000000e+00, ptr %17, align 8, !tbaa !9
  br label %131

126:                                              ; preds = %108
  %127 = load double, ptr %17, align 8, !tbaa !9
  %128 = fcmp olt double %127, -1.000000e+00
  br i1 %128, label %129, label %130

129:                                              ; preds = %126
  store double -1.000000e+00, ptr %17, align 8, !tbaa !9
  br label %130

130:                                              ; preds = %129, %126
  br label %131

131:                                              ; preds = %130, %125
  %132 = load double, ptr %17, align 8, !tbaa !9
  %133 = call double @acos(double noundef %132) #4
  %134 = fdiv double %133, 3.000000e+00
  store double %134, ptr %18, align 8, !tbaa !9
  store double 0x3FF0C152382D7361, ptr %11, align 8, !tbaa !9
  %135 = load double, ptr %20, align 8, !tbaa !9
  %136 = fneg double %135
  %137 = load double, ptr %18, align 8, !tbaa !9
  %138 = call double @cos(double noundef %137) #4
  %139 = load double, ptr %9, align 8, !tbaa !9
  %140 = fneg double %139
  %141 = call double @llvm.fmuladd.f64(double %136, double %138, double %140)
  %142 = load ptr, ptr %5, align 8, !tbaa !5
  %143 = getelementptr inbounds double, ptr %142, i64 0
  store double %141, ptr %143, align 8, !tbaa !9
  %144 = load double, ptr %20, align 8, !tbaa !9
  %145 = load double, ptr %11, align 8, !tbaa !9
  %146 = load double, ptr %18, align 8, !tbaa !9
  %147 = fsub double %145, %146
  %148 = call double @cos(double noundef %147) #4
  %149 = load double, ptr %9, align 8, !tbaa !9
  %150 = fneg double %149
  %151 = call double @llvm.fmuladd.f64(double %144, double %148, double %150)
  %152 = load ptr, ptr %5, align 8, !tbaa !5
  %153 = getelementptr inbounds double, ptr %152, i64 1
  store double %151, ptr %153, align 8, !tbaa !9
  %154 = load double, ptr %20, align 8, !tbaa !9
  %155 = load double, ptr %11, align 8, !tbaa !9
  %156 = load double, ptr %18, align 8, !tbaa !9
  %157 = fadd double %155, %156
  %158 = call double @cos(double noundef %157) #4
  %159 = load double, ptr %9, align 8, !tbaa !9
  %160 = fneg double %159
  %161 = call double @llvm.fmuladd.f64(double %154, double %158, double %160)
  %162 = load ptr, ptr %5, align 8, !tbaa !5
  %163 = getelementptr inbounds double, ptr %162, i64 2
  store double %161, ptr %163, align 8, !tbaa !9
  store i32 3, ptr %3, align 4
  store i32 1, ptr %21, align 4
  br label %164

164:                                              ; preds = %131, %102
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %165 = load i32, ptr %3, align 4
  ret i32 %165
}

; Function Attrs: nounwind
declare double @pow(double noundef, double noundef) #1

; Function Attrs: nounwind
declare double @acos(double noundef) #1

; Function Attrs: nounwind
declare double @cos(double noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write, argmem: readwrite) uwtable
define dso_local noundef range(i32 1, 4) i32 @_ZN6FTools7rroots3EPdS0_(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load double, ptr %0, align 8, !tbaa !5
  %5 = load <2 x double>, ptr %3, align 8, !tbaa !5
  %6 = insertelement <2 x double> poison, double %4, i64 0
  %7 = shufflevector <2 x double> %6, <2 x double> poison, <2 x i32> zeroinitializer
  %8 = fdiv <2 x double> %5, %7
  %9 = extractelement <2 x double> %8, i64 0
  %10 = fmul <2 x double> %8, %8
  %11 = extractelement <2 x double> %10, i64 0
  %12 = fdiv double %9, 3.000000e+00
  %13 = fneg double %11
  %14 = extractelement <2 x double> %8, i64 1
  %15 = tail call double @llvm.fmuladd.f64(double %14, double 3.000000e+00, double %13)
  %16 = fdiv double %15, 9.000000e+00
  %17 = fmul double %11, 2.000000e+00
  %18 = fmul double %9, %17
  %19 = fmul double %9, %14
  %20 = fdiv double %19, 3.000000e+00
  %21 = getelementptr inbounds i8, ptr %0, i64 24
  %22 = load double, ptr %21, align 8, !tbaa !5
  %23 = insertelement <2 x double> poison, double %22, i64 0
  %24 = insertelement <2 x double> %23, double %18, i64 1
  %25 = insertelement <2 x double> <double poison, double 2.700000e+01>, double %4, i64 0
  %26 = fdiv <2 x double> %24, %25
  %27 = extractelement <2 x double> %26, i64 1
  %28 = fsub double %27, %20
  %29 = extractelement <2 x double> %26, i64 0
  %30 = fadd double %29, %28
  %31 = fmul double %30, 5.000000e-01
  %32 = fmul double %16, %16
  %33 = fmul double %16, %32
  %34 = tail call double @llvm.fmuladd.f64(double %31, double %31, double %33)
  %35 = fcmp ogt double %34, 0.000000e+00
  br i1 %35, label %36, label %50

36:                                               ; preds = %2
  %37 = tail call double @sqrt(double noundef %34) #3
  %38 = fsub double %37, %31
  %39 = fcmp ogt double %38, 0.000000e+00
  br i1 %39, label %40, label %44

40:                                               ; preds = %36
  %41 = tail call double @pow(double noundef %38, double noundef 0x3FD5555555555555) #3
  %42 = fdiv double %16, %41
  %43 = fsub double %41, %42
  br label %49

44:                                               ; preds = %36
  %45 = fneg double %38
  %46 = tail call double @pow(double noundef %45, double noundef 0x3FD5555555555555) #3
  %47 = fdiv double %16, %46
  %48 = fsub double %47, %46
  br label %49

49:                                               ; preds = %44, %40
  %.pn = phi double [ %48, %44 ], [ %43, %40 ]
  %storemerge = fsub double %.pn, %12
  store double %storemerge, ptr %1, align 8, !tbaa !5
  br label %79

50:                                               ; preds = %2
  %51 = fcmp ogt double %31, 0.000000e+00
  %52 = fneg double %16
  %53 = tail call double @sqrt(double noundef %52) #3
  %54 = fneg double %53
  %55 = select i1 %51, double %53, double %54
  %56 = fmul double %55, 2.000000e+00
  %57 = fmul double %55, %55
  %58 = fmul double %55, %57
  %59 = fdiv double %31, %58
  %60 = fcmp ogt double %59, 1.000000e+00
  br i1 %60, label %64, label %61

61:                                               ; preds = %50
  %62 = fcmp olt double %59, -1.000000e+00
  br i1 %62, label %63, label %64

63:                                               ; preds = %61
  br label %64

64:                                               ; preds = %50, %61, %63
  %.062 = phi double [ -1.000000e+00, %63 ], [ %59, %61 ], [ 1.000000e+00, %50 ]
  %65 = tail call double @acos(double noundef %.062) #3
  %66 = fdiv double %65, 3.000000e+00
  %67 = fneg double %56
  %68 = tail call double @cos(double noundef %66) #3
  %69 = fneg double %12
  %70 = tail call double @llvm.fmuladd.f64(double %67, double %68, double %69)
  store double %70, ptr %1, align 8, !tbaa !5
  %71 = fsub double 0x3FF0C152382D7361, %66
  %72 = tail call double @cos(double noundef %71) #3
  %73 = tail call double @llvm.fmuladd.f64(double %56, double %72, double %69)
  %74 = getelementptr inbounds i8, ptr %1, i64 8
  store double %73, ptr %74, align 8, !tbaa !5
  %75 = fadd double %66, 0x3FF0C152382D7361
  %76 = tail call double @cos(double noundef %75) #3
  %77 = tail call double @llvm.fmuladd.f64(double %56, double %76, double %69)
  %78 = getelementptr inbounds i8, ptr %1, i64 16
  store double %77, ptr %78, align 8, !tbaa !5
  br label %79

79:                                               ; preds = %64, %49
  %.0 = phi i32 [ 1, %49 ], [ 3, %64 ]
  ret i32 %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @pow(double noundef, double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @acos(double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @cos(double noundef) local_unnamed_addr #0

attributes #0 = { mustprogress nofree nounwind willreturn memory(write) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { mustprogress nofree nounwind willreturn memory(write, argmem: readwrite) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass,VectorCombinePass