; LLVM IR from ahampriyanshu/algo-ds-101 :: Maths/Calculus/Runge–Kutta_Method/Runge-Kutta.ll (Z11calculate_YRdddS_)

; 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: mustprogress uwtable
define dso_local void @_Z11calculate_YRdddS_(ptr noundef nonnull align 8 dereferenceable(8) %0, double noundef %1, double noundef %2, ptr noundef nonnull align 8 dereferenceable(8) %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca double, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store double %1, ptr %6, align 8, !tbaa !9
  store double %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %15 = load double, ptr %6, align 8, !tbaa !9
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = load double, ptr %16, align 8, !tbaa !9
  %18 = fsub double %15, %17
  %19 = load double, ptr %7, align 8, !tbaa !9
  %20 = fdiv double %18, %19
  %21 = fptosi double %20 to i32
  store i32 %21, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !11
  br label %22

22:                                               ; preds = %86, %4
  %23 = load i32, ptr %10, align 4, !tbaa !11
  %24 = load i32, ptr %9, align 4, !tbaa !11
  %25 = icmp slt i32 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %89

27:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load double, ptr %28, align 8, !tbaa !9
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = load double, ptr %30, align 8, !tbaa !9
  %32 = call noundef double @_ZL5dx_dtdd(double noundef %29, double noundef %31)
  store double %32, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load double, ptr %33, align 8, !tbaa !9
  %35 = load double, ptr %7, align 8, !tbaa !9
  %36 = fdiv double %35, 2.000000e+00
  %37 = fadd double %34, %36
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = load double, ptr %38, align 8, !tbaa !9
  %40 = load double, ptr %7, align 8, !tbaa !9
  %41 = load double, ptr %11, align 8, !tbaa !9
  %42 = fmul double %40, %41
  %43 = fdiv double %42, 2.000000e+00
  %44 = fadd double %39, %43
  %45 = call noundef double @_ZL5dx_dtdd(double noundef %37, double noundef %44)
  store double %45, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = load double, ptr %46, align 8, !tbaa !9
  %48 = load double, ptr %7, align 8, !tbaa !9
  %49 = fdiv double %48, 2.000000e+00
  %50 = fadd double %47, %49
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = load double, ptr %51, align 8, !tbaa !9
  %53 = load double, ptr %7, align 8, !tbaa !9
  %54 = load double, ptr %12, align 8, !tbaa !9
  %55 = fmul double %53, %54
  %56 = fdiv double %55, 2.000000e+00
  %57 = fadd double %52, %56
  %58 = call noundef double @_ZL5dx_dtdd(double noundef %50, double noundef %57)
  store double %58, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = load double, ptr %59, align 8, !tbaa !9
  %61 = load double, ptr %7, align 8, !tbaa !9
  %62 = fadd double %60, %61
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = load double, ptr %63, align 8, !tbaa !9
  %65 = load double, ptr %7, align 8, !tbaa !9
  %66 = load double, ptr %13, align 8, !tbaa !9
  %67 = call double @llvm.fmuladd.f64(double %65, double %66, double %64)
  %68 = call noundef double @_ZL5dx_dtdd(double noundef %62, double noundef %67)
  store double %68, ptr %14, align 8, !tbaa !9
  %69 = load double, ptr %11, align 8, !tbaa !9
  %70 = load double, ptr %12, align 8, !tbaa !9
  %71 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %70, double %69)
  %72 = load double, ptr %13, align 8, !tbaa !9
  %73 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %72, double %71)
  %74 = load double, ptr %14, align 8, !tbaa !9
  %75 = fadd double %73, %74
  %76 = load double, ptr %7, align 8, !tbaa !9
  %77 = fmul double %75, %76
  %78 = fdiv double %77, 6.000000e+00
  %79 = load ptr, ptr %8, align 8, !tbaa !5
  %80 = load double, ptr %79, align 8, !tbaa !9
  %81 = fadd double %80, %78
  store double %81, ptr %79, align 8, !tbaa !9
  %82 = load double, ptr %7, align 8, !tbaa !9
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = load double, ptr %83, align 8, !tbaa !9
  %85 = fadd double %84, %82
  store double %85, ptr %83, align 8, !tbaa !9
  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
  br label %86

86:                                               ; preds = %27
  %87 = load i32, ptr %10, align 4, !tbaa !11
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %10, align 4, !tbaa !11
  br label %22, !llvm.loop !13

89:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef double @_ZL5dx_dtdd(double noundef, double noundef) #2

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

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

attributes #0 = { mustprogress 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 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !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 nounwind uwtable
define dso_local void @_Z11calculate_YRdddS_(ptr nocapture noundef nonnull align 8 dereferenceable(8) %0, double noundef %1, double noundef %2, ptr nocapture noundef nonnull align 8 dereferenceable(8) %3) local_unnamed_addr #0 {
  %5 = load double, ptr %0, align 8, !tbaa !5
  %6 = fsub double %1, %5
  %7 = fdiv double %6, %2
  %8 = fptosi double %7 to i32
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4
  %10 = fmul double %2, 5.000000e-01
  br label %11

._crit_edge:                                      ; preds = %11, %4
  ret void

11:                                               ; preds = %.lr.ph, %11
  %12 = phi double [ %5, %.lr.ph ], [ %42, %11 ]
  %.030 = phi i32 [ 0, %.lr.ph ], [ %43, %11 ]
  %13 = load double, ptr %3, align 8, !tbaa !5
  %14 = tail call noundef double @_ZL5dx_dtdd(double noundef %12, double noundef %13)
  %15 = load double, ptr %0, align 8, !tbaa !5
  %16 = fadd double %10, %15
  %17 = load double, ptr %3, align 8, !tbaa !5
  %18 = fmul double %14, %2
  %19 = fmul double %18, 5.000000e-01
  %20 = fadd double %17, %19
  %21 = tail call noundef double @_ZL5dx_dtdd(double noundef %16, double noundef %20)
  %22 = load double, ptr %0, align 8, !tbaa !5
  %23 = fadd double %10, %22
  %24 = load double, ptr %3, align 8, !tbaa !5
  %25 = fmul double %21, %2
  %26 = fmul double %25, 5.000000e-01
  %27 = fadd double %24, %26
  %28 = tail call noundef double @_ZL5dx_dtdd(double noundef %23, double noundef %27)
  %29 = load double, ptr %0, align 8, !tbaa !5
  %30 = fadd double %29, %2
  %31 = load double, ptr %3, align 8, !tbaa !5
  %32 = tail call double @llvm.fmuladd.f64(double %2, double %28, double %31)
  %33 = tail call noundef double @_ZL5dx_dtdd(double noundef %30, double noundef %32)
  %34 = tail call double @llvm.fmuladd.f64(double %21, double 2.000000e+00, double %14)
  %35 = tail call double @llvm.fmuladd.f64(double %28, double 2.000000e+00, double %34)
  %36 = fadd double %35, %33
  %37 = fmul double %36, %2
  %38 = fdiv double %37, 6.000000e+00
  %39 = load double, ptr %3, align 8, !tbaa !5
  %40 = fadd double %39, %38
  store double %40, ptr %3, align 8, !tbaa !5
  %41 = load double, ptr %0, align 8, !tbaa !5
  %42 = fadd double %41, %2
  store double %42, ptr %0, align 8, !tbaa !5
  %43 = add nuw nsw i32 %.030, 1
  %exitcond.not = icmp eq i32 %43, %8
  br i1 %exitcond.not, label %._crit_edge, label %11, !llvm.loop !9
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef double @_ZL5dx_dtdd(double noundef, 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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass