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

23:                                               ; preds = %6
  store i32 0, ptr %7, align 4
  store i32 1, ptr %20, align 4
  br label %132

24:                                               ; preds = %6
  store ptr null, ptr %19, align 8, !tbaa !11
  store ptr null, ptr %18, align 8, !tbaa !11
  store ptr null, ptr %17, align 8, !tbaa !11
  %25 = load i32, ptr %8, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = mul i64 %26, 8
  %28 = call noalias ptr @malloc(i64 noundef %27) #6
  store ptr %28, ptr %17, align 8, !tbaa !11
  %29 = load i32, ptr %8, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = mul i64 %30, 8
  %32 = call noalias ptr @malloc(i64 noundef %31) #6
  store ptr %32, ptr %18, align 8, !tbaa !11
  %33 = load i32, ptr %8, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = mul i64 %34, 8
  %36 = call noalias ptr @malloc(i64 noundef %35) #6
  store ptr %36, ptr %19, align 8, !tbaa !11
  %37 = load ptr, ptr %17, align 8, !tbaa !11
  %38 = icmp eq ptr %37, null
  br i1 %38, label %45, label %39

39:                                               ; preds = %24
  %40 = load ptr, ptr %18, align 8, !tbaa !11
  %41 = icmp eq ptr %40, null
  br i1 %41, label %45, label %42

42:                                               ; preds = %39
  %43 = load ptr, ptr %19, align 8, !tbaa !11
  %44 = icmp eq ptr %43, null
  br i1 %44, label %45, label %46

45:                                               ; preds = %42, %39, %24
  store i32 1, ptr %7, align 4
  store i32 1, ptr %20, align 4
  br label %132

46:                                               ; preds = %42
  store i64 0, ptr %14, align 8, !tbaa !13
  br label %47

47:                                               ; preds = %125, %46
  %48 = load i64, ptr %14, align 8, !tbaa !13
  %49 = load ptr, ptr %10, align 8, !tbaa !11
  %50 = getelementptr inbounds ptr, ptr %49, i64 0
  %51 = load ptr, ptr %50, align 8, !tbaa !11
  %52 = getelementptr inbounds %struct._generic_N_Vector, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !15
  %54 = getelementptr inbounds %struct._N_VectorContent_ManyVector, ptr %53, i32 0, i32 0
  %55 = load i64, ptr %54, align 8, !tbaa !17
  %56 = icmp slt i64 %48, %55
  br i1 %56, label %57, label %128

57:                                               ; preds = %47
  store i64 0, ptr %15, align 8, !tbaa !13
  br label %58

58:                                               ; preds = %106, %57
  %59 = load i64, ptr %15, align 8, !tbaa !13
  %60 = load i32, ptr %8, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = icmp slt i64 %59, %61
  br i1 %62, label %63, label %109

63:                                               ; preds = %58
  %64 = load ptr, ptr %10, align 8, !tbaa !11
  %65 = load i64, ptr %15, align 8, !tbaa !13
  %66 = getelementptr inbounds ptr, ptr %64, i64 %65
  %67 = load ptr, ptr %66, align 8, !tbaa !11
  %68 = getelementptr inbounds %struct._generic_N_Vector, ptr %67, i32 0, i32 0
  %69 = load ptr, ptr %68, align 8, !tbaa !15
  %70 = getelementptr inbounds %struct._N_VectorContent_ManyVector, ptr %69, i32 0, i32 2
  %71 = load ptr, ptr %70, align 8, !tbaa !19
  %72 = load i64, ptr %14, align 8, !tbaa !13
  %73 = getelementptr inbounds ptr, ptr %71, i64 %72
  %74 = load ptr, ptr %73, align 8, !tbaa !11
  %75 = load ptr, ptr %17, align 8, !tbaa !11
  %76 = load i64, ptr %15, align 8, !tbaa !13
  %77 = getelementptr inbounds ptr, ptr %75, i64 %76
  store ptr %74, ptr %77, align 8, !tbaa !11
  %78 = load ptr, ptr %12, align 8, !tbaa !11
  %79 = load i64, ptr %15, align 8, !tbaa !13
  %80 = getelementptr inbounds ptr, ptr %78, i64 %79
  %81 = load ptr, ptr %80, align 8, !tbaa !11
  %82 = getelementptr inbounds %struct._generic_N_Vector, ptr %81, i32 0, i32 0
  %83 = load ptr, ptr %82, align 8, !tbaa !15
  %84 = getelementptr inbounds %struct._N_VectorContent_ManyVector, ptr %83, i32 0, i32 2
  %85 = load ptr, ptr %84, align 8, !tbaa !19
  %86 = load i64, ptr %14, align 8, !tbaa !13
  %87 = getelementptr inbounds ptr, ptr %85, i64 %86
  %88 = load ptr, ptr %87, align 8, !tbaa !11
  %89 = load ptr, ptr %18, align 8, !tbaa !11
  %90 = load i64, ptr %15, align 8, !tbaa !13
  %91 = getelementptr inbounds ptr, ptr %89, i64 %90
  store ptr %88, ptr %91, align 8, !tbaa !11
  %92 = load ptr, ptr %13, align 8, !tbaa !11
  %93 = load i64, ptr %15, align 8, !tbaa !13
  %94 = getelementptr inbounds ptr, ptr %92, i64 %93
  %95 = load ptr, ptr %94, align 8, !tbaa !11
  %96 = getelementptr inbounds %struct._generic_N_Vector, ptr %95, i32 0, i32 0
  %97 = load ptr, ptr %96, align 8, !tbaa !15
  %98 = getelementptr inbounds %struct._N_VectorContent_ManyVector, ptr %97, i32 0, i32 2
  %99 = load ptr, ptr %98, align 8, !tbaa !19
  %100 = load i64, ptr %14, align 8, !tbaa !13
  %101 = getelementptr inbounds ptr, ptr %99, i64 %100
  %102 = load ptr, ptr %101, align 8, !tbaa !11
  %103 = load ptr, ptr %19, align 8, !tbaa !11
  %104 = load i64, ptr %15, align 8, !tbaa !13
  %105 = getelementptr inbounds ptr, ptr %103, i64 %104
  store ptr %102, ptr %105, align 8, !tbaa !11
  br label %106

106:                                              ; preds = %63
  %107 = load i64, ptr %15, align 8, !tbaa !13
  %108 = add nsw i64 %107, 1
  store i64 %108, ptr %15, align 8, !tbaa !13
  br label %58, !llvm.loop !20

109:                                              ; preds = %58
  %110 = load i32, ptr %8, align 4, !tbaa !5
  %111 = load double, ptr %9, align 8, !tbaa !9
  %112 = load ptr, ptr %17, align 8, !tbaa !11
  %113 = load double, ptr %11, align 8, !tbaa !9
  %114 = load ptr, ptr %18, align 8, !tbaa !11
  %115 = load ptr, ptr %19, align 8, !tbaa !11
  %116 = call i32 @N_VLinearSumVectorArray(i32 noundef %110, double noundef %111, ptr noundef %112, double noundef %113, ptr noundef %114, ptr noundef %115)
  store i32 %116, ptr %16, align 4, !tbaa !5
  %117 = load i32, ptr %16, align 4, !tbaa !5
  %118 = icmp ne i32 %117, 0
  br i1 %118, label %119, label %124

119:                                              ; preds = %109
  %120 = load ptr, ptr %17, align 8, !tbaa !11
  call void @free(ptr noundef %120) #5
  %121 = load ptr, ptr %18, align 8, !tbaa !11
  call void @free(ptr noundef %121) #5
  %122 = load ptr, ptr %19, align 8, !tbaa !11
  call void @free(ptr noundef %122) #5
  %123 = load i32, ptr %16, align 4, !tbaa !5
  store i32 %123, ptr %7, align 4
  store i32 1, ptr %20, align 4
  br label %132

124:                                              ; preds = %109
  br label %125

125:                                              ; preds = %124
  %126 = load i64, ptr %14, align 8, !tbaa !13
  %127 = add nsw i64 %126, 1
  store i64 %127, ptr %14, align 8, !tbaa !13
  br label %47, !llvm.loop !22

128:                                              ; preds = %47
  %129 = load ptr, ptr %17, align 8, !tbaa !11
  call void @free(ptr noundef %129) #5
  %130 = load ptr, ptr %18, align 8, !tbaa !11
  call void @free(ptr noundef %130) #5
  %131 = load ptr, ptr %19, align 8, !tbaa !11
  call void @free(ptr noundef %131) #5
  store i32 0, ptr %7, align 4
  store i32 1, ptr %20, align 4
  br label %132

132:                                              ; preds = %128, %119, %45, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  %133 = load i32, ptr %7, align 4
  ret i32 %133
}

declare i32 @N_VLinearSumVectorArray(i32 noundef, double noundef, ptr noundef, double 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 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !12, i64 0}
!16 = !{!"_generic_N_Vector", !12, i64 0, !12, i64 8, !12, i64 16}
!17 = !{!18, !14, i64 0}
!18 = !{!"_N_VectorContent_ManyVector", !14, i64 0, !14, i64 8, !12, i64 16, !6, i64 24}
!19 = !{!18, !12, i64 16}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}


; 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_VLinearSumVectorArray_ManyVector(i32 noundef %0, double noundef %1, ptr nocapture noundef readonly %2, double noundef %3, ptr nocapture noundef readonly %4, ptr nocapture noundef readonly %5) local_unnamed_addr #2 {
  %7 = icmp slt i32 %0, 1
  br i1 %7, label %55, label %8

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

.preheader52:                                     ; preds = %8
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = load i64, ptr %18, align 8, !tbaa !11
  %20 = icmp sgt i64 %19, 0
  br i1 %20, label %.preheader, label %.sink.split

21:                                               ; preds = %53
  %22 = add nuw nsw i64 %.04654, 1
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = load i64, ptr %24, align 8, !tbaa !11
  %26 = icmp slt i64 %22, %25
  br i1 %26, label %.preheader, label %.sink.split, !llvm.loop !15

.preheader:                                       ; preds = %.preheader52, %21
  %.04654 = phi i64 [ %22, %21 ], [ 0, %.preheader52 ]
  br label %27

27:                                               ; preds = %.preheader, %27
  %.04553 = phi i64 [ 0, %.preheader ], [ %52, %27 ]
  %28 = getelementptr inbounds ptr, ptr %2, i64 %.04553
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = load ptr, ptr %29, align 8, !tbaa !9
  %31 = getelementptr inbounds i8, ptr %30, i64 16
  %32 = load ptr, ptr %31, align 8, !tbaa !17
  %33 = getelementptr inbounds ptr, ptr %32, i64 %.04654
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  %35 = getelementptr inbounds ptr, ptr %11, i64 %.04553
  store ptr %34, ptr %35, align 8, !tbaa !5
  %36 = getelementptr inbounds ptr, ptr %4, i64 %.04553
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  %38 = load ptr, ptr %37, align 8, !tbaa !9
  %39 = getelementptr inbounds i8, ptr %38, i64 16
  %40 = load ptr, ptr %39, align 8, !tbaa !17
  %41 = getelementptr inbounds ptr, ptr %40, i64 %.04654
  %42 = load ptr, ptr %41, align 8, !tbaa !5
  %43 = getelementptr inbounds ptr, ptr %12, i64 %.04553
  store ptr %42, ptr %43, align 8, !tbaa !5
  %44 = getelementptr inbounds ptr, ptr %5, i64 %.04553
  %45 = load ptr, ptr %44, align 8, !tbaa !5
  %46 = load ptr, ptr %45, align 8, !tbaa !9
  %47 = getelementptr inbounds i8, ptr %46, i64 16
  %48 = load ptr, ptr %47, align 8, !tbaa !17
  %49 = getelementptr inbounds ptr, ptr %48, i64 %.04654
  %50 = load ptr, ptr %49, align 8, !tbaa !5
  %51 = getelementptr inbounds ptr, ptr %13, i64 %.04553
  store ptr %50, ptr %51, align 8, !tbaa !5
  %52 = add nuw nsw i64 %.04553, 1
  %exitcond.not = icmp eq i64 %52, %9
  br i1 %exitcond.not, label %53, label %27, !llvm.loop !18

53:                                               ; preds = %27
  %54 = tail call i32 @N_VLinearSumVectorArray(i32 noundef %0, double noundef %1, ptr noundef nonnull %11, double noundef %3, ptr noundef nonnull %12, ptr noundef nonnull %13) #5
  %.not = icmp eq i32 %54, 0
  br i1 %.not, label %21, label %.sink.split

.sink.split:                                      ; preds = %21, %53, %.preheader52
  %.0.ph = phi i32 [ 0, %.preheader52 ], [ %54, %53 ], [ 0, %21 ]
  tail call void @free(ptr noundef %11) #5
  tail call void @free(ptr noundef %12) #5
  tail call void @free(ptr noundef %13) #5
  br label %55

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

declare i32 @N_VLinearSumVectorArray(i32 noundef, double noundef, ptr noundef, double 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,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass