; LLVM IR from PymZoR/S-curve-Planner :: lib (bbpr)

; 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: nounwind uwtable
define dso_local i32 @roots(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  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 4, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  %16 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %16, ptr %14, align 4, !tbaa !9
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %140, %4
  %18 = load i32, ptr %14, align 4, !tbaa !9
  %19 = icmp sgt i32 %18, 1
  br i1 %19, label %20, label %143

20:                                               ; preds = %17
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = load i32, ptr %14, align 4, !tbaa !9
  %23 = sub nsw i32 %22, 2
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds double, ptr %21, i64 %24
  %26 = load double, ptr %25, align 8, !tbaa !11
  %27 = fmul double -5.000000e-01, %26
  store double %27, ptr %10, align 8, !tbaa !11
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load i32, ptr %14, align 4, !tbaa !9
  %30 = sub nsw i32 %29, 1
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds double, ptr %28, i64 %31
  %33 = load double, ptr %32, align 8, !tbaa !11
  store double %33, ptr %11, align 8, !tbaa !11
  %34 = load double, ptr %10, align 8, !tbaa !11
  %35 = load double, ptr %10, align 8, !tbaa !11
  %36 = load double, ptr %11, align 8, !tbaa !11
  %37 = fneg double %36
  %38 = call double @llvm.fmuladd.f64(double %34, double %35, double %37)
  store double %38, ptr %12, align 8, !tbaa !11
  %39 = load double, ptr %12, align 8, !tbaa !11
  %40 = fcmp olt double %39, 0.000000e+00
  br i1 %40, label %41, label %72

41:                                               ; preds = %20
  %42 = load double, ptr %12, align 8, !tbaa !11
  %43 = fneg double %42
  %44 = call double @sqrt(double noundef %43) #4
  store double %44, ptr %9, align 8, !tbaa !11
  %45 = load double, ptr %10, align 8, !tbaa !11
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = load i32, ptr %14, align 4, !tbaa !9
  %48 = sub nsw i32 %47, 2
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds double, ptr %46, i64 %49
  store double %45, ptr %50, align 8, !tbaa !11
  %51 = load double, ptr %9, align 8, !tbaa !11
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = load i32, ptr %14, align 4, !tbaa !9
  %54 = sub nsw i32 %53, 2
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds double, ptr %52, i64 %55
  store double %51, ptr %56, align 8, !tbaa !11
  %57 = load double, ptr %10, align 8, !tbaa !11
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = load i32, ptr %14, align 4, !tbaa !9
  %60 = sub nsw i32 %59, 1
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds double, ptr %58, i64 %61
  store double %57, ptr %62, align 8, !tbaa !11
  %63 = load double, ptr %9, align 8, !tbaa !11
  %64 = fneg double %63
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = load i32, ptr %14, align 4, !tbaa !9
  %67 = sub nsw i32 %66, 1
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds double, ptr %65, i64 %68
  store double %64, ptr %69, align 8, !tbaa !11
  %70 = load i32, ptr %15, align 4, !tbaa !9
  %71 = add nsw i32 %70, 2
  store i32 %71, ptr %15, align 4, !tbaa !9
  br label %140

72:                                               ; preds = %20
  %73 = load double, ptr %12, align 8, !tbaa !11
  %74 = call double @sqrt(double noundef %73) #4
  store double %74, ptr %9, align 8, !tbaa !11
  %75 = load double, ptr %10, align 8, !tbaa !11
  %76 = call double @llvm.fabs.f64(double %75)
  %77 = load double, ptr %9, align 8, !tbaa !11
  %78 = fadd double %76, %77
  %79 = load ptr, ptr %7, align 8, !tbaa !5
  %80 = load i32, ptr %14, align 4, !tbaa !9
  %81 = sub nsw i32 %80, 2
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds double, ptr %79, i64 %82
  store double %78, ptr %83, align 8, !tbaa !11
  %84 = load double, ptr %10, align 8, !tbaa !11
  %85 = fcmp olt double %84, 0.000000e+00
  br i1 %85, label %86, label %99

86:                                               ; preds = %72
  %87 = load ptr, ptr %7, align 8, !tbaa !5
  %88 = load i32, ptr %14, align 4, !tbaa !9
  %89 = sub nsw i32 %88, 2
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds double, ptr %87, i64 %90
  %92 = load double, ptr %91, align 8, !tbaa !11
  %93 = fneg double %92
  %94 = load ptr, ptr %7, align 8, !tbaa !5
  %95 = load i32, ptr %14, align 4, !tbaa !9
  %96 = sub nsw i32 %95, 2
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds double, ptr %94, i64 %97
  store double %93, ptr %98, align 8, !tbaa !11
  br label %99

99:                                               ; preds = %86, %72
  %100 = load ptr, ptr %7, align 8, !tbaa !5
  %101 = load i32, ptr %14, align 4, !tbaa !9
  %102 = sub nsw i32 %101, 2
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds double, ptr %100, i64 %103
  %105 = load double, ptr %104, align 8, !tbaa !11
  %106 = fcmp oeq double %105, 0.000000e+00
  br i1 %106, label %107, label %113

107:                                              ; preds = %99
  %108 = load ptr, ptr %7, align 8, !tbaa !5
  %109 = load i32, ptr %14, align 4, !tbaa !9
  %110 = sub nsw i32 %109, 1
  %111 = sext i32 %110 to i64
  %112 = getelementptr inbounds double, ptr %108, i64 %111
  store double 0.000000e+00, ptr %112, align 8, !tbaa !11
  br label %129

113:                                              ; preds = %99
  %114 = load double, ptr %11, align 8, !tbaa !11
  %115 = load ptr, ptr %7, align 8, !tbaa !5
  %116 = load i32, ptr %14, align 4, !tbaa !9
  %117 = sub nsw i32 %116, 2
  %118 = sext i32 %117 to i64
  %119 = getelementptr inbounds double, ptr %115, i64 %118
  %120 = load double, ptr %119, align 8, !tbaa !11
  %121 = fdiv double %114, %120
  %122 = load ptr, ptr %7, align 8, !tbaa !5
  %123 = load i32, ptr %14, align 4, !tbaa !9
  %124 = sub nsw i32 %123, 1
  %125 = sext i32 %124 to i64
  %126 = getelementptr inbounds double, ptr %122, i64 %125
  store double %121, ptr %126, align 8, !tbaa !11
  %127 = load i32, ptr %15, align 4, !tbaa !9
  %128 = add nsw i32 %127, 2
  store i32 %128, ptr %15, align 4, !tbaa !9
  br label %129

129:                                              ; preds = %113, %107
  %130 = load ptr, ptr %8, align 8, !tbaa !5
  %131 = load i32, ptr %14, align 4, !tbaa !9
  %132 = sub nsw i32 %131, 2
  %133 = sext i32 %132 to i64
  %134 = getelementptr inbounds double, ptr %130, i64 %133
  store double 0.000000e+00, ptr %134, align 8, !tbaa !11
  %135 = load ptr, ptr %8, align 8, !tbaa !5
  %136 = load i32, ptr %14, align 4, !tbaa !9
  %137 = sub nsw i32 %136, 1
  %138 = sext i32 %137 to i64
  %139 = getelementptr inbounds double, ptr %135, i64 %138
  store double 0.000000e+00, ptr %139, align 8, !tbaa !11
  br label %140

140:                                              ; preds = %129, %41
  %141 = load i32, ptr %14, align 4, !tbaa !9
  %142 = sub nsw i32 %141, 2
  store i32 %142, ptr %14, align 4, !tbaa !9
  br label %17, !llvm.loop !13

143:                                              ; preds = %17
  %144 = load i32, ptr %14, align 4, !tbaa !9
  %145 = icmp eq i32 %144, 1
  br i1 %145, label %146, label %157

146:                                              ; preds = %143
  %147 = load ptr, ptr %5, align 8, !tbaa !5
  %148 = getelementptr inbounds double, ptr %147, i64 0
  %149 = load double, ptr %148, align 8, !tbaa !11
  %150 = fneg double %149
  %151 = load ptr, ptr %7, align 8, !tbaa !5
  %152 = getelementptr inbounds double, ptr %151, i64 0
  store double %150, ptr %152, align 8, !tbaa !11
  %153 = load ptr, ptr %8, align 8, !tbaa !5
  %154 = getelementptr inbounds double, ptr %153, i64 0
  store double 0.000000e+00, ptr %154, align 8, !tbaa !11
  %155 = load i32, ptr %15, align 4, !tbaa !9
  %156 = add nsw i32 %155, 1
  store i32 %156, ptr %15, align 4, !tbaa !9
  br label %157

157:                                              ; preds = %146, %143
  %158 = load i32, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, 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
  ret i32 %158
}

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

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

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

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; 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: nofree nounwind memory(write, argmem: readwrite) uwtable
define dso_local i32 @roots(ptr nocapture noundef readonly %0, i32 noundef %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %5 = icmp sgt i32 %1, 1
  br i1 %5, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %4
  %6 = zext nneg i32 %1 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %37
  %indvars.iv = phi i64 [ %6, %.lr.ph.preheader ], [ %indvars.iv.next, %37 ]
  %.059 = phi i32 [ 0, %.lr.ph.preheader ], [ %.2, %37 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -2
  %7 = getelementptr inbounds double, ptr %0, i64 %indvars.iv.next
  %8 = load double, ptr %7, align 8, !tbaa !5
  %9 = fmul double %8, -5.000000e-01
  %10 = add nsw i64 %indvars.iv, -1
  %11 = getelementptr inbounds double, ptr %0, i64 %10
  %12 = load double, ptr %11, align 8, !tbaa !5
  %13 = fneg double %12
  %14 = tail call double @llvm.fmuladd.f64(double %9, double %9, double %13)
  %15 = fcmp olt double %14, 0.000000e+00
  br i1 %15, label %16, label %25

16:                                               ; preds = %.lr.ph
  %17 = fneg double %14
  %18 = tail call double @sqrt(double noundef %17) #3
  %19 = getelementptr inbounds double, ptr %2, i64 %indvars.iv.next
  store double %9, ptr %19, align 8, !tbaa !5
  %20 = getelementptr inbounds double, ptr %3, i64 %indvars.iv.next
  store double %18, ptr %20, align 8, !tbaa !5
  %21 = getelementptr inbounds double, ptr %2, i64 %10
  store double %9, ptr %21, align 8, !tbaa !5
  %22 = fneg double %18
  %23 = getelementptr inbounds double, ptr %3, i64 %10
  store double %22, ptr %23, align 8, !tbaa !5
  %24 = add nsw i32 %.059, 2
  br label %37

25:                                               ; preds = %.lr.ph
  %26 = tail call double @sqrt(double noundef %14) #3
  %27 = tail call double @llvm.fabs.f64(double %9)
  %28 = fadd double %27, %26
  %29 = getelementptr inbounds double, ptr %2, i64 %indvars.iv.next
  %30 = fcmp olt double %9, 0.000000e+00
  %31 = fneg double %28
  %storemerge = select i1 %30, double %31, double %28
  store double %storemerge, ptr %29, align 8, !tbaa !5
  %32 = fcmp oeq double %28, 0.000000e+00
  %33 = fdiv double %12, %storemerge
  %34 = add nsw i32 %.059, 2
  %.sink = select i1 %32, double 0.000000e+00, double %33
  %.1 = select i1 %32, i32 %.059, i32 %34
  %35 = getelementptr inbounds double, ptr %2, i64 %10
  store double %.sink, ptr %35, align 8
  %36 = getelementptr inbounds double, ptr %3, i64 %indvars.iv.next
  store <2 x double> zeroinitializer, ptr %36, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %25, %16
  %.2 = phi i32 [ %24, %16 ], [ %.1, %25 ]
  %38 = icmp ugt i64 %indvars.iv, 3
  br i1 %38, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !9

._crit_edge.loopexit:                             ; preds = %37
  %39 = trunc nuw nsw i64 %indvars.iv.next to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %4
  %.054.lcssa = phi i32 [ %1, %4 ], [ %39, %._crit_edge.loopexit ]
  %.0.lcssa = phi i32 [ 0, %4 ], [ %.2, %._crit_edge.loopexit ]
  %40 = icmp eq i32 %.054.lcssa, 1
  br i1 %40, label %41, label %45

41:                                               ; preds = %._crit_edge
  %42 = load double, ptr %0, align 8, !tbaa !5
  %43 = fneg double %42
  store double %43, ptr %2, align 8, !tbaa !5
  store double 0.000000e+00, ptr %3, align 8, !tbaa !5
  %44 = add nsw i32 %.0.lcssa, 1
  br label %45

45:                                               ; preds = %41, %._crit_edge
  %.3 = phi i32 [ %44, %41 ], [ %.0.lcssa, %._crit_edge ]
  ret i32 %.3
}

; 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)
declare double @sqrt(double noundef) local_unnamed_addr #2

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

attributes #0 = { nofree nounwind 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 #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass