; 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_VLinearCombination_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 i64, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = 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
  store ptr null, ptr %13, align 8, !tbaa !9
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = mul i64 %16, 8
  %18 = call noalias ptr @malloc(i64 noundef %17) #6
  store ptr %18, ptr %13, align 8, !tbaa !9
  %19 = load ptr, ptr %13, align 8, !tbaa !9
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %4
  store i32 1, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %79

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

23:                                               ; preds = %74, %22
  %24 = load i64, ptr %10, align 8, !tbaa !11
  %25 = load ptr, ptr %9, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct._generic_N_Vector, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !13
  %28 = getelementptr inbounds %struct._N_VectorContent_ManyVector, ptr %27, i32 0, i32 0
  %29 = load i64, ptr %28, align 8, !tbaa !15
  %30 = icmp slt i64 %24, %29
  br i1 %30, label %31, label %77

31:                                               ; preds = %23
  store i64 0, ptr %11, align 8, !tbaa !11
  br label %32

32:                                               ; preds = %52, %31
  %33 = load i64, ptr %11, align 8, !tbaa !11
  %34 = load i32, ptr %6, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = icmp slt i64 %33, %35
  br i1 %36, label %37, label %55

37:                                               ; preds = %32
  %38 = load ptr, ptr %8, align 8, !tbaa !9
  %39 = load i64, ptr %11, align 8, !tbaa !11
  %40 = getelementptr inbounds ptr, ptr %38, i64 %39
  %41 = load ptr, ptr %40, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct._generic_N_Vector, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !13
  %44 = getelementptr inbounds %struct._N_VectorContent_ManyVector, ptr %43, i32 0, i32 2
  %45 = load ptr, ptr %44, align 8, !tbaa !17
  %46 = load i64, ptr %10, align 8, !tbaa !11
  %47 = getelementptr inbounds ptr, ptr %45, i64 %46
  %48 = load ptr, ptr %47, align 8, !tbaa !9
  %49 = load ptr, ptr %13, align 8, !tbaa !9
  %50 = load i64, ptr %11, align 8, !tbaa !11
  %51 = getelementptr inbounds ptr, ptr %49, i64 %50
  store ptr %48, ptr %51, align 8, !tbaa !9
  br label %52

52:                                               ; preds = %37
  %53 = load i64, ptr %11, align 8, !tbaa !11
  %54 = add nsw i64 %53, 1
  store i64 %54, ptr %11, align 8, !tbaa !11
  br label %32, !llvm.loop !18

55:                                               ; preds = %32
  %56 = load i32, ptr %6, align 4, !tbaa !5
  %57 = load ptr, ptr %7, align 8, !tbaa !9
  %58 = load ptr, ptr %13, align 8, !tbaa !9
  %59 = load ptr, ptr %9, align 8, !tbaa !9
  %60 = getelementptr inbounds %struct._generic_N_Vector, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %60, align 8, !tbaa !13
  %62 = getelementptr inbounds %struct._N_VectorContent_ManyVector, ptr %61, i32 0, i32 2
  %63 = load ptr, ptr %62, align 8, !tbaa !17
  %64 = load i64, ptr %10, align 8, !tbaa !11
  %65 = getelementptr inbounds ptr, ptr %63, i64 %64
  %66 = load ptr, ptr %65, align 8, !tbaa !9
  %67 = call i32 @N_VLinearCombination(i32 noundef %56, ptr noundef %57, ptr noundef %58, ptr noundef %66)
  store i32 %67, ptr %12, align 4, !tbaa !5
  %68 = load i32, ptr %12, align 4, !tbaa !5
  %69 = icmp ne i32 %68, 0
  br i1 %69, label %70, label %73

70:                                               ; preds = %55
  %71 = load ptr, ptr %13, align 8, !tbaa !9
  call void @free(ptr noundef %71) #5
  %72 = load i32, ptr %12, align 4, !tbaa !5
  store i32 %72, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %79

73:                                               ; preds = %55
  br label %74

74:                                               ; preds = %73
  %75 = load i64, ptr %10, align 8, !tbaa !11
  %76 = add nsw i64 %75, 1
  store i64 %76, ptr %10, align 8, !tbaa !11
  br label %23, !llvm.loop !20

77:                                               ; preds = %23
  %78 = load ptr, ptr %13, align 8, !tbaa !9
  call void @free(ptr noundef %78) #5
  store i32 0, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %79

79:                                               ; preds = %77, %70, %21
  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
  %80 = load i32, ptr %5, align 4
  ret i32 %80
}

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

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

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

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 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 #3 = { 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 #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: nounwind uwtable
define dso_local i32 @N_VLinearCombination_ManyVector(i32 noundef %0, ptr noundef %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3) local_unnamed_addr #0 {
  %5 = sext i32 %0 to i64
  %6 = shl nsw i64 %5, 3
  %7 = tail call noalias ptr @malloc(i64 noundef %6) #4
  %8 = icmp eq ptr %7, null
  br i1 %8, label %62, label %.preheader26

.preheader26:                                     ; preds = %4
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = load i64, ptr %9, align 8, !tbaa !10
  %11 = icmp sgt i64 %10, 0
  br i1 %11, label %.preheader.lr.ph, label %.sink.split

.preheader.lr.ph:                                 ; preds = %.preheader26
  %12 = icmp sgt i32 %0, 0
  br i1 %12, label %.preheader.us.preheader, label %.preheader

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %xtraiter = and i64 %5, 1
  %13 = icmp eq i32 %0, 1
  %unroll_iter = and i64 %5, 2147483646
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %33
  %14 = phi ptr [ %35, %33 ], [ %9, %.preheader.us.preheader ]
  %.02328.us = phi i64 [ %34, %33 ], [ 0, %.preheader.us.preheader ]
  br i1 %13, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %.preheader.us.new
  %.02227.us = phi i64 [ %32, %.preheader.us.new ], [ 0, %.preheader.us ]
  %niter = phi i64 [ %niter.next.1, %.preheader.us.new ], [ 0, %.preheader.us ]
  %15 = getelementptr inbounds ptr, ptr %2, i64 %.02227.us
  %16 = load ptr, ptr %15, align 8, !tbaa !14
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 16
  %19 = load ptr, ptr %18, align 8, !tbaa !15
  %20 = getelementptr inbounds ptr, ptr %19, i64 %.02328.us
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  %22 = getelementptr inbounds ptr, ptr %7, i64 %.02227.us
  store ptr %21, ptr %22, align 8, !tbaa !14
  %23 = or disjoint i64 %.02227.us, 1
  %24 = getelementptr inbounds ptr, ptr %2, i64 %23
  %25 = load ptr, ptr %24, align 8, !tbaa !14
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %26, i64 16
  %28 = load ptr, ptr %27, align 8, !tbaa !15
  %29 = getelementptr inbounds ptr, ptr %28, i64 %.02328.us
  %30 = load ptr, ptr %29, align 8, !tbaa !14
  %31 = getelementptr inbounds ptr, ptr %7, i64 %23
  store ptr %30, ptr %31, align 8, !tbaa !14
  %32 = add nuw nsw i64 %.02227.us, 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 %._crit_edge.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !16

33:                                               ; preds = %._crit_edge.us
  %34 = add nuw nsw i64 %.02328.us, 1
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = load i64, ptr %35, align 8, !tbaa !10
  %37 = icmp slt i64 %34, %36
  br i1 %37, label %.preheader.us, label %.sink.split, !llvm.loop !18

._crit_edge.us.unr-lcssa:                         ; preds = %.preheader.us.new, %.preheader.us
  %.02227.us.unr = phi i64 [ 0, %.preheader.us ], [ %32, %.preheader.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %._crit_edge.us.epilog-lcssa

._crit_edge.us.epilog-lcssa:                      ; preds = %._crit_edge.us.unr-lcssa
  %38 = getelementptr inbounds ptr, ptr %2, i64 %.02227.us.unr
  %39 = load ptr, ptr %38, align 8, !tbaa !14
  %40 = load ptr, ptr %39, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %40, i64 16
  %42 = load ptr, ptr %41, align 8, !tbaa !15
  %43 = getelementptr inbounds ptr, ptr %42, i64 %.02328.us
  %44 = load ptr, ptr %43, align 8, !tbaa !14
  %45 = getelementptr inbounds ptr, ptr %7, i64 %.02227.us.unr
  store ptr %44, ptr %45, align 8, !tbaa !14
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %._crit_edge.us.unr-lcssa, %._crit_edge.us.epilog-lcssa
  %46 = getelementptr inbounds i8, ptr %14, i64 16
  %47 = load ptr, ptr %46, align 8, !tbaa !15
  %48 = getelementptr inbounds ptr, ptr %47, i64 %.02328.us
  %49 = load ptr, ptr %48, align 8, !tbaa !14
  %50 = tail call i32 @N_VLinearCombination(i32 noundef %0, ptr noundef %1, ptr noundef nonnull %7, ptr noundef %49) #5
  %.not.us = icmp eq i32 %50, 0
  br i1 %.not.us, label %33, label %.sink.split

51:                                               ; preds = %.preheader
  %52 = add nuw nsw i64 %.02328, 1
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = load i64, ptr %53, align 8, !tbaa !10
  %55 = icmp slt i64 %52, %54
  br i1 %55, label %.preheader, label %.sink.split, !llvm.loop !18

.preheader:                                       ; preds = %.preheader.lr.ph, %51
  %56 = phi ptr [ %53, %51 ], [ %9, %.preheader.lr.ph ]
  %.02328 = phi i64 [ %52, %51 ], [ 0, %.preheader.lr.ph ]
  %57 = getelementptr inbounds i8, ptr %56, i64 16
  %58 = load ptr, ptr %57, align 8, !tbaa !15
  %59 = getelementptr inbounds ptr, ptr %58, i64 %.02328
  %60 = load ptr, ptr %59, align 8, !tbaa !14
  %61 = tail call i32 @N_VLinearCombination(i32 noundef %0, ptr noundef %1, ptr noundef nonnull %7, ptr noundef %60) #5
  %.not = icmp eq i32 %61, 0
  br i1 %.not, label %51, label %.sink.split

.sink.split:                                      ; preds = %51, %.preheader, %33, %._crit_edge.us, %.preheader26
  %.0.ph = phi i32 [ 0, %.preheader26 ], [ %50, %._crit_edge.us ], [ 0, %33 ], [ %61, %.preheader ], [ 0, %51 ]
  tail call void @free(ptr noundef %7) #5
  br label %62

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

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

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

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


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