; 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 allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

; 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 void @free(ptr noundef) #2

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

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

19:                                               ; preds = %4
  store ptr null, ptr %14, align 8, !tbaa !9
  store ptr null, ptr %13, align 8, !tbaa !9
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = mul i64 %21, 8
  %23 = call noalias ptr @malloc(i64 noundef %22) #6
  store ptr %23, ptr %13, align 8, !tbaa !9
  %24 = load i32, ptr %6, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = mul i64 %25, 8
  %27 = call noalias ptr @malloc(i64 noundef %26) #6
  store ptr %27, ptr %14, align 8, !tbaa !9
  %28 = load ptr, ptr %13, align 8, !tbaa !9
  %29 = icmp eq ptr %28, null
  br i1 %29, label %33, label %30

30:                                               ; preds = %19
  %31 = load ptr, ptr %14, align 8, !tbaa !9
  %32 = icmp eq ptr %31, null
  br i1 %32, label %33, label %34

33:                                               ; preds = %30, %19
  store i32 1, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %102

34:                                               ; preds = %30
  store i64 0, ptr %10, align 8, !tbaa !11
  br label %35

35:                                               ; preds = %96, %34
  %36 = load i64, ptr %10, align 8, !tbaa !11
  %37 = load ptr, ptr %8, align 8, !tbaa !9
  %38 = getelementptr inbounds ptr, ptr %37, i64 0
  %39 = load ptr, ptr %38, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct._generic_N_Vector, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !13
  %42 = getelementptr inbounds %struct._N_VectorContent_ManyVector, ptr %41, i32 0, i32 0
  %43 = load i64, ptr %42, align 8, !tbaa !15
  %44 = icmp slt i64 %36, %43
  br i1 %44, label %45, label %99

45:                                               ; preds = %35
  store i64 0, ptr %11, align 8, !tbaa !11
  br label %46

46:                                               ; preds = %80, %45
  %47 = load i64, ptr %11, align 8, !tbaa !11
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = icmp slt i64 %47, %49
  br i1 %50, label %51, label %83

51:                                               ; preds = %46
  %52 = load ptr, ptr %8, align 8, !tbaa !9
  %53 = load i64, ptr %11, 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 !13
  %58 = getelementptr inbounds %struct._N_VectorContent_ManyVector, ptr %57, i32 0, i32 2
  %59 = load ptr, ptr %58, align 8, !tbaa !17
  %60 = load i64, ptr %10, align 8, !tbaa !11
  %61 = getelementptr inbounds ptr, ptr %59, i64 %60
  %62 = load ptr, ptr %61, align 8, !tbaa !9
  %63 = load ptr, ptr %13, align 8, !tbaa !9
  %64 = load i64, ptr %11, align 8, !tbaa !11
  %65 = getelementptr inbounds ptr, ptr %63, i64 %64
  store ptr %62, ptr %65, align 8, !tbaa !9
  %66 = load ptr, ptr %9, align 8, !tbaa !9
  %67 = load i64, ptr %11, 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 !13
  %72 = getelementptr inbounds %struct._N_VectorContent_ManyVector, ptr %71, i32 0, i32 2
  %73 = load ptr, ptr %72, align 8, !tbaa !17
  %74 = load i64, ptr %10, align 8, !tbaa !11
  %75 = getelementptr inbounds ptr, ptr %73, i64 %74
  %76 = load ptr, ptr %75, align 8, !tbaa !9
  %77 = load ptr, ptr %14, align 8, !tbaa !9
  %78 = load i64, ptr %11, align 8, !tbaa !11
  %79 = getelementptr inbounds ptr, ptr %77, i64 %78
  store ptr %76, ptr %79, align 8, !tbaa !9
  br label %80

80:                                               ; preds = %51
  %81 = load i64, ptr %11, align 8, !tbaa !11
  %82 = add nsw i64 %81, 1
  store i64 %82, ptr %11, align 8, !tbaa !11
  br label %46, !llvm.loop !18

83:                                               ; preds = %46
  %84 = load i32, ptr %6, align 4, !tbaa !5
  %85 = load ptr, ptr %7, align 8, !tbaa !9
  %86 = load ptr, ptr %13, align 8, !tbaa !9
  %87 = load ptr, ptr %14, align 8, !tbaa !9
  %88 = call i32 @N_VScaleVectorArray(i32 noundef %84, ptr noundef %85, ptr noundef %86, ptr noundef %87)
  store i32 %88, ptr %12, align 4, !tbaa !5
  %89 = load i32, ptr %12, align 4, !tbaa !5
  %90 = icmp ne i32 %89, 0
  br i1 %90, label %91, label %95

91:                                               ; preds = %83
  %92 = load ptr, ptr %13, align 8, !tbaa !9
  call void @free(ptr noundef %92) #5
  %93 = load ptr, ptr %14, align 8, !tbaa !9
  call void @free(ptr noundef %93) #5
  %94 = load i32, ptr %12, align 4, !tbaa !5
  store i32 %94, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %102

95:                                               ; preds = %83
  br label %96

96:                                               ; preds = %95
  %97 = load i64, ptr %10, align 8, !tbaa !11
  %98 = add nsw i64 %97, 1
  store i64 %98, ptr %10, align 8, !tbaa !11
  br label %35, !llvm.loop !20

99:                                               ; preds = %35
  %100 = load ptr, ptr %13, align 8, !tbaa !9
  call void @free(ptr noundef %100) #5
  %101 = load ptr, ptr %14, align 8, !tbaa !9
  call void @free(ptr noundef %101) #5
  store i32 0, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %102

102:                                              ; preds = %99, %91, %33, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  %103 = load i32, ptr %5, align 4
  ret i32 %103
}

declare i32 @N_VScaleVectorArray(i32 noundef, ptr noundef, ptr noundef, ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind allocsize(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 = { 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 #4 = { "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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }

!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, !10, i64 0}
!14 = !{!"_generic_N_Vector", !10, i64 0, !10, i64 8, !10, i64 16}
!15 = !{!16, !12, i64 0}
!16 = !{!"_N_VectorContent_ManyVector", !12, i64 0, !12, i64 8, !10, i64 16, !6, i64 24}
!17 = !{!16, !10, i64 16}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


; 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 allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @N_VScaleVectorArray_ManyVector(i32 noundef %0, ptr noundef %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3) local_unnamed_addr #2 {
  %5 = icmp slt i32 %0, 1
  br i1 %5, label %76, label %6

6:                                                ; preds = %4
  %7 = zext nneg i32 %0 to i64
  %8 = shl nuw nsw i64 %7, 3
  %9 = tail call noalias ptr @malloc(i64 noundef %8) #4
  %10 = tail call noalias ptr @malloc(i64 noundef %8) #4
  %11 = icmp eq ptr %9, null
  %12 = icmp eq ptr %10, null
  %or.cond = or i1 %11, %12
  br i1 %or.cond, label %76, label %.preheader38

.preheader38:                                     ; preds = %6
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  %15 = load i64, ptr %14, align 8, !tbaa !11
  %16 = icmp sgt i64 %15, 0
  br i1 %16, label %.preheader.preheader, label %.sink.split

.preheader.preheader:                             ; preds = %.preheader38
  %xtraiter = and i64 %7, 1
  %17 = icmp eq i32 %0, 1
  %unroll_iter = and i64 %7, 2147483646
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader

18:                                               ; preds = %74
  %19 = add nuw nsw i64 %.03340, 1
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = load i64, ptr %21, align 8, !tbaa !11
  %23 = icmp slt i64 %19, %22
  br i1 %23, label %.preheader, label %.sink.split, !llvm.loop !15

.preheader:                                       ; preds = %.preheader.preheader, %18
  %.03340 = phi i64 [ %19, %18 ], [ 0, %.preheader.preheader ]
  br i1 %17, label %.unr-lcssa, label %.preheader.new

.preheader.new:                                   ; preds = %.preheader, %.preheader.new
  %.03239 = phi i64 [ %57, %.preheader.new ], [ 0, %.preheader ]
  %niter = phi i64 [ %niter.next.1, %.preheader.new ], [ 0, %.preheader ]
  %24 = getelementptr inbounds ptr, ptr %2, i64 %.03239
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  %27 = getelementptr inbounds i8, ptr %26, i64 16
  %28 = load ptr, ptr %27, align 8, !tbaa !17
  %29 = getelementptr inbounds ptr, ptr %28, i64 %.03340
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  %31 = getelementptr inbounds ptr, ptr %9, i64 %.03239
  store ptr %30, ptr %31, align 8, !tbaa !5
  %32 = getelementptr inbounds ptr, ptr %3, i64 %.03239
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  %34 = load ptr, ptr %33, align 8, !tbaa !9
  %35 = getelementptr inbounds i8, ptr %34, i64 16
  %36 = load ptr, ptr %35, align 8, !tbaa !17
  %37 = getelementptr inbounds ptr, ptr %36, i64 %.03340
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  %39 = getelementptr inbounds ptr, ptr %10, i64 %.03239
  store ptr %38, ptr %39, align 8, !tbaa !5
  %40 = or disjoint i64 %.03239, 1
  %41 = getelementptr inbounds ptr, ptr %2, i64 %40
  %42 = load ptr, ptr %41, align 8, !tbaa !5
  %43 = load ptr, ptr %42, align 8, !tbaa !9
  %44 = getelementptr inbounds i8, ptr %43, i64 16
  %45 = load ptr, ptr %44, align 8, !tbaa !17
  %46 = getelementptr inbounds ptr, ptr %45, i64 %.03340
  %47 = load ptr, ptr %46, align 8, !tbaa !5
  %48 = getelementptr inbounds ptr, ptr %9, i64 %40
  store ptr %47, ptr %48, align 8, !tbaa !5
  %49 = getelementptr inbounds ptr, ptr %3, i64 %40
  %50 = load ptr, ptr %49, align 8, !tbaa !5
  %51 = load ptr, ptr %50, align 8, !tbaa !9
  %52 = getelementptr inbounds i8, ptr %51, i64 16
  %53 = load ptr, ptr %52, align 8, !tbaa !17
  %54 = getelementptr inbounds ptr, ptr %53, i64 %.03340
  %55 = load ptr, ptr %54, align 8, !tbaa !5
  %56 = getelementptr inbounds ptr, ptr %10, i64 %40
  store ptr %55, ptr %56, align 8, !tbaa !5
  %57 = add nuw nsw i64 %.03239, 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 %.unr-lcssa, label %.preheader.new, !llvm.loop !18

.unr-lcssa:                                       ; preds = %.preheader.new, %.preheader
  %.03239.unr = phi i64 [ 0, %.preheader ], [ %57, %.preheader.new ]
  br i1 %lcmp.mod.not, label %74, label %.epilog-lcssa

.epilog-lcssa:                                    ; preds = %.unr-lcssa
  %58 = getelementptr inbounds ptr, ptr %2, i64 %.03239.unr
  %59 = load ptr, ptr %58, align 8, !tbaa !5
  %60 = load ptr, ptr %59, align 8, !tbaa !9
  %61 = getelementptr inbounds i8, ptr %60, i64 16
  %62 = load ptr, ptr %61, align 8, !tbaa !17
  %63 = getelementptr inbounds ptr, ptr %62, i64 %.03340
  %64 = load ptr, ptr %63, align 8, !tbaa !5
  %65 = getelementptr inbounds ptr, ptr %9, i64 %.03239.unr
  store ptr %64, ptr %65, align 8, !tbaa !5
  %66 = getelementptr inbounds ptr, ptr %3, i64 %.03239.unr
  %67 = load ptr, ptr %66, align 8, !tbaa !5
  %68 = load ptr, ptr %67, align 8, !tbaa !9
  %69 = getelementptr inbounds i8, ptr %68, i64 16
  %70 = load ptr, ptr %69, align 8, !tbaa !17
  %71 = getelementptr inbounds ptr, ptr %70, i64 %.03340
  %72 = load ptr, ptr %71, align 8, !tbaa !5
  %73 = getelementptr inbounds ptr, ptr %10, i64 %.03239.unr
  store ptr %72, ptr %73, align 8, !tbaa !5
  br label %74

74:                                               ; preds = %.unr-lcssa, %.epilog-lcssa
  %75 = tail call i32 @N_VScaleVectorArray(i32 noundef %0, ptr noundef %1, ptr noundef nonnull %9, ptr noundef nonnull %10) #5
  %.not = icmp eq i32 %75, 0
  br i1 %.not, label %18, label %.sink.split

.sink.split:                                      ; preds = %18, %74, %.preheader38
  %.0.ph = phi i32 [ 0, %.preheader38 ], [ %75, %74 ], [ 0, %18 ]
  tail call void @free(ptr noundef %9) #5
  tail call void @free(ptr noundef %10) #5
  br label %76

76:                                               ; preds = %.sink.split, %6, %4
  %.0 = phi i32 [ 0, %4 ], [ 1, %6 ], [ %.0.ph, %.sink.split ]
  ret i32 %.0
}

declare i32 @N_VScaleVectorArray(i32 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { "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 allocsize(0) }
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, !6, i64 0}
!10 = !{!"_generic_N_Vector", !6, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!12, !13, i64 0}
!12 = !{!"_N_VectorContent_ManyVector", !13, i64 0, !13, i64 8, !6, i64 16, !14, i64 24}
!13 = !{!"long", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!12, !6, i64 16}
!18 = distinct !{!18, !16}


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