; LLVM IR from bonamarton/phys_num :: RK4_attractors (RK4adaptiveAttractors)

; 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 @pow(double noundef, double noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @RK4basic(ptr noundef, ptr noundef, ptr noundef, i32 noundef, double noundef, double noundef, ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

; Function Attrs: nounwind uwtable
define dso_local void @RK4StepAdaptive(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4, double noundef %5, ptr noundef %6) #2 {
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca double, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca ptr, align 8
  %17 = alloca i64, align 8
  %18 = alloca i64, align 8
  %19 = alloca i64, align 8
  %20 = alloca i64, align 8
  %21 = alloca double, align 8
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store i32 %2, ptr %10, align 4, !tbaa !9
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  store double %5, ptr %13, align 8, !tbaa !11
  store ptr %6, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  %22 = load i32, ptr %10, align 4, !tbaa !9
  %23 = zext i32 %22 to i64
  %24 = call ptr @llvm.stacksave.p0()
  store ptr %24, ptr %16, align 8
  %25 = alloca double, i64 %23, align 16
  store i64 %23, ptr %17, align 8
  %26 = load i32, ptr %10, align 4, !tbaa !9
  %27 = zext i32 %26 to i64
  %28 = alloca double, i64 %27, align 16
  store i64 %27, ptr %18, align 8
  %29 = load i32, ptr %10, align 4, !tbaa !9
  %30 = zext i32 %29 to i64
  %31 = alloca double, i64 %30, align 16
  store i64 %30, ptr %19, align 8
  %32 = load i32, ptr %10, align 4, !tbaa !9
  %33 = zext i32 %32 to i64
  %34 = alloca double, i64 %33, align 16
  store i64 %33, ptr %20, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #5
  store double 0.000000e+00, ptr %21, align 8, !tbaa !11
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = load i32, ptr %10, align 4, !tbaa !9
  %38 = load ptr, ptr %11, align 8, !tbaa !5
  %39 = load double, ptr %38, align 8, !tbaa !11
  %40 = load ptr, ptr %12, align 8, !tbaa !5
  %41 = load double, ptr %40, align 8, !tbaa !11
  %42 = load ptr, ptr %14, align 8, !tbaa !5
  call void @RK4basic(ptr noundef %35, ptr noundef %36, ptr noundef %25, i32 noundef %37, double noundef %39, double noundef %41, ptr noundef %42)
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = load i32, ptr %10, align 4, !tbaa !9
  %46 = load ptr, ptr %11, align 8, !tbaa !5
  %47 = load double, ptr %46, align 8, !tbaa !11
  %48 = load ptr, ptr %12, align 8, !tbaa !5
  %49 = load double, ptr %48, align 8, !tbaa !11
  %50 = fdiv double %49, 2.000000e+00
  %51 = load ptr, ptr %14, align 8, !tbaa !5
  call void @RK4basic(ptr noundef %43, ptr noundef %44, ptr noundef %28, i32 noundef %45, double noundef %47, double noundef %50, ptr noundef %51)
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = load i32, ptr %10, align 4, !tbaa !9
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = load double, ptr %54, align 8, !tbaa !11
  %56 = load ptr, ptr %12, align 8, !tbaa !5
  %57 = load double, ptr %56, align 8, !tbaa !11
  %58 = fdiv double %57, 2.000000e+00
  %59 = load ptr, ptr %14, align 8, !tbaa !5
  call void @RK4basic(ptr noundef %52, ptr noundef %28, ptr noundef %31, i32 noundef %53, double noundef %55, double noundef %58, ptr noundef %59)
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %60

60:                                               ; preds = %98, %7
  %61 = load i32, ptr %15, align 4, !tbaa !9
  %62 = load i32, ptr %10, align 4, !tbaa !9
  %63 = icmp slt i32 %61, %62
  br i1 %63, label %64, label %101

64:                                               ; preds = %60
  %65 = load i32, ptr %15, align 4, !tbaa !9
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds double, ptr %31, i64 %66
  %68 = load double, ptr %67, align 8, !tbaa !11
  %69 = load ptr, ptr %9, align 8, !tbaa !5
  %70 = load i32, ptr %15, align 4, !tbaa !9
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds double, ptr %69, i64 %71
  store double %68, ptr %72, align 8, !tbaa !11
  %73 = load i32, ptr %15, align 4, !tbaa !9
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds double, ptr %31, i64 %74
  %76 = load double, ptr %75, align 8, !tbaa !11
  %77 = load i32, ptr %15, align 4, !tbaa !9
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds double, ptr %25, i64 %78
  %80 = load double, ptr %79, align 8, !tbaa !11
  %81 = fsub double %76, %80
  %82 = call double @llvm.fabs.f64(double %81)
  %83 = load i32, ptr %15, align 4, !tbaa !9
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds double, ptr %34, i64 %84
  store double %82, ptr %85, align 8, !tbaa !11
  %86 = load i32, ptr %15, align 4, !tbaa !9
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds double, ptr %34, i64 %87
  %89 = load double, ptr %88, align 8, !tbaa !11
  %90 = load double, ptr %21, align 8, !tbaa !11
  %91 = fcmp ogt double %89, %90
  br i1 %91, label %92, label %97

92:                                               ; preds = %64
  %93 = load i32, ptr %15, align 4, !tbaa !9
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds double, ptr %34, i64 %94
  %96 = load double, ptr %95, align 8, !tbaa !11
  store double %96, ptr %21, align 8, !tbaa !11
  br label %97

97:                                               ; preds = %92, %64
  br label %98

98:                                               ; preds = %97
  %99 = load i32, ptr %15, align 4, !tbaa !9
  %100 = add nsw i32 %99, 1
  store i32 %100, ptr %15, align 4, !tbaa !9
  br label %60, !llvm.loop !13

101:                                              ; preds = %60
  %102 = load ptr, ptr %12, align 8, !tbaa !5
  %103 = load double, ptr %102, align 8, !tbaa !11
  %104 = load ptr, ptr %11, align 8, !tbaa !5
  %105 = load double, ptr %104, align 8, !tbaa !11
  %106 = fadd double %105, %103
  store double %106, ptr %104, align 8, !tbaa !11
  %107 = load double, ptr %13, align 8, !tbaa !11
  %108 = load double, ptr %21, align 8, !tbaa !11
  %109 = fdiv double %107, %108
  %110 = call double @pow(double noundef %109, double noundef 2.000000e-01) #5
  %111 = load ptr, ptr %12, align 8, !tbaa !5
  %112 = load double, ptr %111, align 8, !tbaa !11
  %113 = fmul double %112, %110
  store double %113, ptr %111, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #5
  %114 = load ptr, ptr %16, align 8
  call void @llvm.stackrestore.p0(ptr %114)
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  ret void
}

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

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 = { 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 #3 = { nocallback nofree nosync nounwind willreturn }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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: mustprogress nofree nounwind willreturn memory(write)
declare double @pow(double noundef, double noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @RK4basic(ptr noundef, ptr noundef, ptr noundef, i32 noundef, double noundef, double noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @RK4StepAdaptive(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr nocapture noundef %3, ptr nocapture noundef %4, double noundef %5, ptr noundef %6) local_unnamed_addr #1 {
  %8 = zext i32 %2 to i64
  %9 = alloca double, i64 %8, align 16
  %10 = alloca double, i64 %8, align 16
  %11 = alloca double, i64 %8, align 16
  %12 = load double, ptr %3, align 8, !tbaa !5
  %13 = load double, ptr %4, align 8, !tbaa !5
  call void @RK4basic(ptr noundef %0, ptr noundef %1, ptr noundef nonnull %9, i32 noundef %2, double noundef %12, double noundef %13, ptr noundef %6)
  %14 = load double, ptr %3, align 8, !tbaa !5
  %15 = load double, ptr %4, align 8, !tbaa !5
  %16 = fmul double %15, 5.000000e-01
  call void @RK4basic(ptr noundef %0, ptr noundef %1, ptr noundef nonnull %10, i32 noundef %2, double noundef %14, double noundef %16, ptr noundef %6)
  %17 = load double, ptr %3, align 8, !tbaa !5
  %18 = load double, ptr %4, align 8, !tbaa !5
  %19 = fmul double %18, 5.000000e-01
  call void @RK4basic(ptr noundef %0, ptr noundef nonnull %10, ptr noundef nonnull %11, i32 noundef %2, double noundef %17, double noundef %19, ptr noundef %6)
  %20 = icmp sgt i32 %2, 0
  br i1 %20, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %7
  %21 = shl nuw nsw i64 %8, 3
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %1, ptr nonnull align 16 %11, i64 %21, i1 false), !tbaa !5
  %xtraiter = and i64 %8, 1
  %22 = icmp eq i32 %2, 1
  br i1 %22, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %8, 2147483646
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %.lr.ph ]
  %.041 = phi double [ 0.000000e+00, %.lr.ph.preheader.new ], [ %.1.1, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %23 = getelementptr inbounds double, ptr %11, i64 %indvars.iv
  %24 = load double, ptr %23, align 16, !tbaa !5
  %25 = getelementptr inbounds double, ptr %9, i64 %indvars.iv
  %26 = load double, ptr %25, align 16, !tbaa !5
  %27 = fsub double %24, %26
  %28 = call double @llvm.fabs.f64(double %27)
  %29 = fcmp ogt double %28, %.041
  %.1 = select i1 %29, double %28, double %.041
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %30 = getelementptr inbounds double, ptr %11, i64 %indvars.iv.next
  %31 = load double, ptr %30, align 8, !tbaa !5
  %32 = getelementptr inbounds double, ptr %9, i64 %indvars.iv.next
  %33 = load double, ptr %32, align 8, !tbaa !5
  %34 = fsub double %31, %33
  %35 = call double @llvm.fabs.f64(double %34)
  %36 = fcmp ogt double %35, %.1
  %.1.1 = select i1 %36, double %35, double %.1
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !9

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.1.lcssa.ph = phi double [ poison, %.lr.ph.preheader ], [ %.1.1, %.lr.ph ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.1, %.lr.ph ]
  %.041.unr = phi double [ 0.000000e+00, %.lr.ph.preheader ], [ %.1.1, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %37 = getelementptr inbounds double, ptr %11, i64 %indvars.iv.unr
  %38 = load double, ptr %37, align 8, !tbaa !5
  %39 = getelementptr inbounds double, ptr %9, i64 %indvars.iv.unr
  %40 = load double, ptr %39, align 8, !tbaa !5
  %41 = fsub double %38, %40
  %42 = call double @llvm.fabs.f64(double %41)
  %43 = fcmp ogt double %42, %.041.unr
  %.1.epil = select i1 %43, double %42, double %.041.unr
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.loopexit.unr-lcssa, %7
  %.0.lcssa = phi double [ 0.000000e+00, %7 ], [ %.1.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %.1.epil, %.lr.ph.epil ]
  %44 = load double, ptr %4, align 8, !tbaa !5
  %45 = load double, ptr %3, align 8, !tbaa !5
  %46 = fadd double %44, %45
  store double %46, ptr %3, align 8, !tbaa !5
  %47 = fdiv double %5, %.0.lcssa
  %48 = call double @pow(double noundef %47, double noundef 2.000000e-01) #4
  %49 = load double, ptr %4, align 8, !tbaa !5
  %50 = fmul double %48, %49
  store double %50, ptr %4, align 8, !tbaa !5
  ret void
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass