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

15:                                               ; preds = %4
  store i32 0, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %87

16:                                               ; preds = %4
  store i64 0, ptr %10, align 8, !tbaa !11
  br label %17

17:                                               ; preds = %35, %16
  %18 = load i64, ptr %10, align 8, !tbaa !11
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = icmp slt i64 %18, %20
  br i1 %21, label %22, label %38

22:                                               ; preds = %17
  %23 = load ptr, ptr %7, align 8, !tbaa !9
  %24 = load i64, ptr %10, align 8, !tbaa !11
  %25 = getelementptr inbounds ptr, ptr %23, i64 %24
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  %27 = load ptr, ptr %8, align 8, !tbaa !9
  %28 = load i64, ptr %10, align 8, !tbaa !11
  %29 = getelementptr inbounds ptr, ptr %27, i64 %28
  %30 = load ptr, ptr %29, align 8, !tbaa !9
  %31 = call double @N_VWSqrSumLocal(ptr noundef %26, ptr noundef %30)
  %32 = load ptr, ptr %9, align 8, !tbaa !9
  %33 = load i64, ptr %10, align 8, !tbaa !11
  %34 = getelementptr inbounds double, ptr %32, i64 %33
  store double %31, ptr %34, align 8, !tbaa !13
  br label %35

35:                                               ; preds = %22
  %36 = load i64, ptr %10, align 8, !tbaa !11
  %37 = add nsw i64 %36, 1
  store i64 %37, ptr %10, align 8, !tbaa !11
  br label %17, !llvm.loop !15

38:                                               ; preds = %17
  store i32 0, ptr %11, align 4, !tbaa !5
  store i64 0, ptr %10, align 8, !tbaa !11
  br label %39

39:                                               ; preds = %82, %38
  %40 = load i64, ptr %10, align 8, !tbaa !11
  %41 = load i32, ptr %6, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = icmp slt i64 %40, %42
  br i1 %43, label %44, label %85

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

60:                                               ; preds = %44
  br label %77

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

77:                                               ; preds = %61, %60
  %78 = phi double [ 0.000000e+00, %60 ], [ %76, %61 ]
  %79 = load ptr, ptr %9, align 8, !tbaa !9
  %80 = load i64, ptr %10, align 8, !tbaa !11
  %81 = getelementptr inbounds double, ptr %79, i64 %80
  store double %78, ptr %81, align 8, !tbaa !13
  br label %82

82:                                               ; preds = %77
  %83 = load i64, ptr %10, align 8, !tbaa !11
  %84 = add nsw i64 %83, 1
  store i64 %84, ptr %10, align 8, !tbaa !11
  br label %39, !llvm.loop !21

85:                                               ; preds = %39
  %86 = load i32, ptr %11, align 4, !tbaa !5
  store i32 %86, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %87

87:                                               ; preds = %85, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %88 = load i32, ptr %5, align 4
  ret i32 %88
}

; 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_VWSqrSumLocal(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_VWrmsNormVectorArray_ManyVector(i32 noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, ptr nocapture noundef %3) local_unnamed_addr #0 {
  %5 = icmp slt i32 %0, 1
  br i1 %5, label %.loopexit, label %.preheader27

.preheader27:                                     ; preds = %4
  %6 = zext nneg i32 %0 to i64
  br label %7

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

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

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

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

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

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

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

42:                                               ; preds = %40, %.preheader.1
  %43 = phi double [ %41, %40 ], [ 0.000000e+00, %.preheader.1 ]
  store double %43, ptr %30, align 8, !tbaa !9
  %44 = add nuw nsw i64 %.129, 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 = %42, %.preheader.preheader
  %.129.unr = phi i64 [ 0, %.preheader.preheader ], [ %44, %42 ]
  %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
  %45 = getelementptr inbounds double, ptr %3, i64 %.129.unr
  %46 = load double, ptr %45, align 8, !tbaa !9
  %47 = getelementptr inbounds ptr, ptr %1, i64 %.129.unr
  %48 = load ptr, ptr %47, align 8, !tbaa !5
  %49 = load ptr, ptr %48, align 8, !tbaa !13
  %50 = getelementptr inbounds i8, ptr %49, i64 8
  %51 = load i64, ptr %50, align 8, !tbaa !15
  %52 = sitofp i64 %51 to double
  %53 = fdiv double %46, %52
  %54 = fcmp ugt double %53, 0.000000e+00
  br i1 %54, label %55, label %.loopexit.loopexit.epilog-lcssa

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

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

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

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

declare double @N_VWSqrSumLocal(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