; LLVM IR from stan-dev/math :: lib/sundials_6.1.1/src/nvector/manyvector (nvector_manyvector)

; 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"

%struct._generic_N_Vector = type { ptr, ptr, ptr }
%struct._N_VectorContent_ManyVector = type { i64, i64, ptr, i32 }

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

; Function Attrs: nounwind uwtable
define dso_local i32 @N_VWrmsNormMaskVectorArray_ManyVector(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %15 = load i32, ptr %7, align 4, !tbaa !5
  %16 = icmp sle i32 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %5
  store i32 0, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %90

18:                                               ; preds = %5
  store i64 0, ptr %12, align 8, !tbaa !11
  br label %19

19:                                               ; preds = %38, %18
  %20 = load i64, ptr %12, align 8, !tbaa !11
  %21 = load i32, ptr %7, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = icmp slt i64 %20, %22
  br i1 %23, label %24, label %41

24:                                               ; preds = %19
  %25 = load ptr, ptr %8, align 8, !tbaa !9
  %26 = load i64, ptr %12, align 8, !tbaa !11
  %27 = getelementptr inbounds ptr, ptr %25, i64 %26
  %28 = load ptr, ptr %27, align 8, !tbaa !9
  %29 = load ptr, ptr %9, align 8, !tbaa !9
  %30 = load i64, ptr %12, align 8, !tbaa !11
  %31 = getelementptr inbounds ptr, ptr %29, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !9
  %33 = load ptr, ptr %10, align 8, !tbaa !9
  %34 = call double @N_VWSqrSumMaskLocal(ptr noundef %28, ptr noundef %32, ptr noundef %33)
  %35 = load ptr, ptr %11, align 8, !tbaa !9
  %36 = load i64, ptr %12, align 8, !tbaa !11
  %37 = getelementptr inbounds double, ptr %35, i64 %36
  store double %34, ptr %37, align 8, !tbaa !13
  br label %38

38:                                               ; preds = %24
  %39 = load i64, ptr %12, align 8, !tbaa !11
  %40 = add nsw i64 %39, 1
  store i64 %40, ptr %12, align 8, !tbaa !11
  br label %19, !llvm.loop !15

41:                                               ; preds = %19
  store i32 0, ptr %13, align 4, !tbaa !5
  store i64 0, ptr %12, align 8, !tbaa !11
  br label %42

42:                                               ; preds = %85, %41
  %43 = load i64, ptr %12, align 8, !tbaa !11
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = icmp slt i64 %43, %45
  br i1 %46, label %47, label %88

47:                                               ; preds = %42
  %48 = load ptr, ptr %11, align 8, !tbaa !9
  %49 = load i64, ptr %12, align 8, !tbaa !11
  %50 = getelementptr inbounds double, ptr %48, i64 %49
  %51 = load double, ptr %50, align 8, !tbaa !13
  %52 = load ptr, ptr %8, align 8, !tbaa !9
  %53 = load i64, ptr %12, align 8, !tbaa !11
  %54 = getelementptr inbounds ptr, ptr %52, i64 %53
  %55 = load ptr, ptr %54, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct._generic_N_Vector, ptr %55, i32 0, i32 0
  %57 = load ptr, ptr %56, align 8, !tbaa !17
  %58 = getelementptr inbounds %struct._N_VectorContent_ManyVector, ptr %57, i32 0, i32 1
  %59 = load i64, ptr %58, align 8, !tbaa !19
  %60 = sitofp i64 %59 to double
  %61 = fdiv double %51, %60
  %62 = fcmp ole double %61, 0.000000e+00
  br i1 %62, label %63, label %64

63:                                               ; preds = %47
  br label %80

64:                                               ; preds = %47
  %65 = load ptr, ptr %11, align 8, !tbaa !9
  %66 = load i64, ptr %12, align 8, !tbaa !11
  %67 = getelementptr inbounds double, ptr %65, i64 %66
  %68 = load double, ptr %67, align 8, !tbaa !13
  %69 = load ptr, ptr %8, align 8, !tbaa !9
  %70 = load i64, ptr %12, align 8, !tbaa !11
  %71 = getelementptr inbounds ptr, ptr %69, i64 %70
  %72 = load ptr, ptr %71, align 8, !tbaa !9
  %73 = getelementptr inbounds %struct._generic_N_Vector, ptr %72, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !17
  %75 = getelementptr inbounds %struct._N_VectorContent_ManyVector, ptr %74, i32 0, i32 1
  %76 = load i64, ptr %75, align 8, !tbaa !19
  %77 = sitofp i64 %76 to double
  %78 = fdiv double %68, %77
  %79 = call double @sqrt(double noundef %78) #4
  br label %80

80:                                               ; preds = %64, %63
  %81 = phi double [ 0.000000e+00, %63 ], [ %79, %64 ]
  %82 = load ptr, ptr %11, align 8, !tbaa !9
  %83 = load i64, ptr %12, align 8, !tbaa !11
  %84 = getelementptr inbounds double, ptr %82, i64 %83
  store double %81, ptr %84, align 8, !tbaa !13
  br label %85

85:                                               ; preds = %80
  %86 = load i64, ptr %12, align 8, !tbaa !11
  %87 = add nsw i64 %86, 1
  store i64 %87, ptr %12, align 8, !tbaa !11
  br label %42, !llvm.loop !21

88:                                               ; preds = %42
  %89 = load i32, ptr %13, align 4, !tbaa !5
  store i32 %89, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %90

90:                                               ; preds = %88, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  %91 = load i32, ptr %6, align 4
  ret i32 %91
}

; 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) #2

declare double @N_VWSqrSumMaskLocal(ptr noundef, ptr noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #3 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!18, !10, i64 0}
!18 = !{!"_generic_N_Vector", !10, i64 0, !10, i64 8, !10, i64 16}
!19 = !{!20, !12, i64 8}
!20 = !{!"_N_VectorContent_ManyVector", !12, i64 0, !12, i64 8, !10, i64 16, !6, i64 24}
!21 = distinct !{!21, !16}


; 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: nounwind uwtable
define dso_local noundef i32 @N_VWrmsNormMaskVectorArray_ManyVector(i32 noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, ptr noundef %3, ptr nocapture noundef %4) local_unnamed_addr #0 {
  %6 = icmp slt i32 %0, 1
  br i1 %6, label %.loopexit, label %.preheader28

.preheader28:                                     ; preds = %5
  %7 = zext nneg i32 %0 to i64
  br label %8

8:                                                ; preds = %.preheader28, %8
  %.02529 = phi i64 [ 0, %.preheader28 ], [ %15, %8 ]
  %9 = getelementptr inbounds ptr, ptr %1, i64 %.02529
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = getelementptr inbounds ptr, ptr %2, i64 %.02529
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = tail call double @N_VWSqrSumMaskLocal(ptr noundef %10, ptr noundef %12, ptr noundef %3) #3
  %14 = getelementptr inbounds double, ptr %4, i64 %.02529
  store double %13, ptr %14, align 8, !tbaa !9
  %15 = add nuw nsw i64 %.02529, 1
  %exitcond.not = icmp eq i64 %15, %7
  br i1 %exitcond.not, label %.preheader.preheader, label %8, !llvm.loop !11

.preheader.preheader:                             ; preds = %8
  %xtraiter = and i64 %7, 1
  %16 = icmp eq i32 %0, 1
  br i1 %16, label %.loopexit.loopexit.unr-lcssa, label %.preheader.preheader.new

.preheader.preheader.new:                         ; preds = %.preheader.preheader
  %unroll_iter = and i64 %7, 2147483646
  br label %.preheader

.preheader:                                       ; preds = %43, %.preheader.preheader.new
  %.130 = phi i64 [ 0, %.preheader.preheader.new ], [ %45, %43 ]
  %niter = phi i64 [ 0, %.preheader.preheader.new ], [ %niter.next.1, %43 ]
  %17 = getelementptr inbounds double, ptr %4, i64 %.130
  %18 = load double, ptr %17, align 8, !tbaa !9
  %19 = getelementptr inbounds ptr, ptr %1, i64 %.130
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = getelementptr inbounds i8, ptr %21, i64 8
  %23 = load i64, ptr %22, align 8, !tbaa !15
  %24 = sitofp i64 %23 to double
  %25 = fdiv double %18, %24
  %26 = fcmp ugt double %25, 0.000000e+00
  br i1 %26, label %27, label %.preheader.1

27:                                               ; preds = %.preheader
  %28 = tail call double @sqrt(double noundef %25) #3
  br label %.preheader.1

.preheader.1:                                     ; preds = %.preheader, %27
  %29 = phi double [ %28, %27 ], [ 0.000000e+00, %.preheader ]
  store double %29, ptr %17, align 8, !tbaa !9
  %30 = or disjoint i64 %.130, 1
  %31 = getelementptr inbounds double, ptr %4, i64 %30
  %32 = load double, ptr %31, align 8, !tbaa !9
  %33 = getelementptr inbounds ptr, ptr %1, i64 %30
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  %35 = load ptr, ptr %34, align 8, !tbaa !13
  %36 = getelementptr inbounds i8, ptr %35, i64 8
  %37 = load i64, ptr %36, align 8, !tbaa !15
  %38 = sitofp i64 %37 to double
  %39 = fdiv double %32, %38
  %40 = fcmp ugt double %39, 0.000000e+00
  br i1 %40, label %41, label %43

41:                                               ; preds = %.preheader.1
  %42 = tail call double @sqrt(double noundef %39) #3
  br label %43

43:                                               ; preds = %41, %.preheader.1
  %44 = phi double [ %42, %41 ], [ 0.000000e+00, %.preheader.1 ]
  store double %44, ptr %31, align 8, !tbaa !9
  %45 = add nuw nsw i64 %.130, 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 %.loopexit.loopexit.unr-lcssa, label %.preheader, !llvm.loop !19

.loopexit.loopexit.unr-lcssa:                     ; preds = %43, %.preheader.preheader
  %.130.unr = phi i64 [ 0, %.preheader.preheader ], [ %45, %43 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.preheader.epil

.preheader.epil:                                  ; preds = %.loopexit.loopexit.unr-lcssa
  %46 = getelementptr inbounds double, ptr %4, i64 %.130.unr
  %47 = load double, ptr %46, align 8, !tbaa !9
  %48 = getelementptr inbounds ptr, ptr %1, i64 %.130.unr
  %49 = load ptr, ptr %48, align 8, !tbaa !5
  %50 = load ptr, ptr %49, align 8, !tbaa !13
  %51 = getelementptr inbounds i8, ptr %50, i64 8
  %52 = load i64, ptr %51, align 8, !tbaa !15
  %53 = sitofp i64 %52 to double
  %54 = fdiv double %47, %53
  %55 = fcmp ugt double %54, 0.000000e+00
  br i1 %55, label %56, label %.loopexit.loopexit.epilog-lcssa

56:                                               ; preds = %.preheader.epil
  %57 = tail call double @sqrt(double noundef %54) #3
  br label %.loopexit.loopexit.epilog-lcssa

.loopexit.loopexit.epilog-lcssa:                  ; preds = %56, %.preheader.epil
  %58 = phi double [ %57, %56 ], [ 0.000000e+00, %.preheader.epil ]
  store double %58, ptr %46, align 8, !tbaa !9
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit.epilog-lcssa, %.loopexit.loopexit.unr-lcssa, %5
  ret i32 0
}

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

declare double @N_VWSqrSumMaskLocal(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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 = { 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 #2 = { "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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !6, i64 0}
!14 = !{!"_generic_N_Vector", !6, i64 0, !6, i64 8, !6, i64 16}
!15 = !{!16, !17, i64 8}
!16 = !{!"_N_VectorContent_ManyVector", !17, i64 0, !17, i64 8, !6, i64 16, !18, i64 24}
!17 = !{!"long", !7, i64 0}
!18 = !{!"int", !7, i64 0}
!19 = distinct !{!19, !12}


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