; LLVM IR from MRPT/mrpt :: libs/math/src/CSparse (cs_pvec)

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

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

14:                                               ; preds = %4
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %18, label %17

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

18:                                               ; preds = %14
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %44, %18
  %20 = load i32, ptr %10, align 4, !tbaa !9
  %21 = load i32, ptr %9, align 4, !tbaa !9
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %23, label %47

23:                                               ; preds = %19
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %33

27:                                               ; preds = %23
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = load i32, ptr %10, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i32, ptr %28, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !9
  br label %35

33:                                               ; preds = %23
  %34 = load i32, ptr %10, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %33, %27
  %36 = phi i32 [ %32, %27 ], [ %34, %33 ]
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds double, ptr %24, i64 %37
  %39 = load double, ptr %38, align 8, !tbaa !11
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = load i32, ptr %10, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds double, ptr %40, i64 %42
  store double %39, ptr %43, align 8, !tbaa !11
  br label %44

44:                                               ; preds = %35
  %45 = load i32, ptr %10, align 4, !tbaa !9
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %10, align 4, !tbaa !9
  br label %19, !llvm.loop !13

47:                                               ; preds = %19
  store i32 1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %48

48:                                               ; preds = %47, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  %49 = load i32, ptr %5, align 4
  ret i32 %49
}

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; 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: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local range(i32 0, 2) i32 @cs_pvec(ptr noundef readonly %0, ptr noundef readonly %1, ptr noundef writeonly %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = ptrtoint ptr %1 to i64
  %6 = ptrtoint ptr %2 to i64
  %7 = icmp ne ptr %2, null
  %8 = icmp ne ptr %1, null
  %or.cond = and i1 %8, %7
  br i1 %or.cond, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %4
  %9 = icmp sgt i32 %3, 0
  br i1 %9, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %.not = icmp eq ptr %0, null
  %wide.trip.count23 = zext nneg i32 %3 to i64
  br i1 %.not, label %.lr.ph.split.us.preheader, label %.lr.ph.split.preheader

.lr.ph.split.preheader:                           ; preds = %.lr.ph
  %xtraiter = and i64 %wide.trip.count23, 3
  %10 = icmp ult i32 %3, 4
  br i1 %10, label %.loopexit.loopexit30.unr-lcssa, label %.lr.ph.split.preheader.new

.lr.ph.split.preheader.new:                       ; preds = %.lr.ph.split.preheader
  %unroll_iter = and i64 %wide.trip.count23, 2147483644
  br label %.lr.ph.split

.lr.ph.split.us.preheader:                        ; preds = %.lr.ph
  %min.iters.check = icmp ult i32 %3, 6
  %11 = sub i64 %6, %5
  %diff.check = icmp ult i64 %11, 32
  %or.cond28 = or i1 %min.iters.check, %diff.check
  br i1 %or.cond28, label %.lr.ph.split.us.preheader29, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.split.us.preheader
  %n.vec = and i64 %wide.trip.count23, 2147483644
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %12 = getelementptr inbounds double, ptr %1, i64 %index
  %13 = getelementptr inbounds i8, ptr %12, i64 16
  %wide.load = load <2 x double>, ptr %12, align 8, !tbaa !5
  %wide.load27 = load <2 x double>, ptr %13, align 8, !tbaa !5
  %14 = getelementptr inbounds double, ptr %2, i64 %index
  %15 = getelementptr inbounds i8, ptr %14, i64 16
  store <2 x double> %wide.load, ptr %14, align 8, !tbaa !5
  store <2 x double> %wide.load27, ptr %15, align 8, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %16 = icmp eq i64 %index.next, %n.vec
  br i1 %16, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count23
  br i1 %cmp.n, label %.loopexit, label %.lr.ph.split.us.preheader29

.lr.ph.split.us.preheader29:                      ; preds = %middle.block, %.lr.ph.split.us.preheader
  %indvars.iv20.ph = phi i64 [ 0, %.lr.ph.split.us.preheader ], [ %n.vec, %middle.block ]
  %xtraiter31 = and i64 %wide.trip.count23, 3
  %lcmp.mod32.not = icmp eq i64 %xtraiter31, 0
  br i1 %lcmp.mod32.not, label %.lr.ph.split.us.prol.loopexit, label %.lr.ph.split.us.prol

.lr.ph.split.us.prol:                             ; preds = %.lr.ph.split.us.preheader29, %.lr.ph.split.us.prol
  %indvars.iv20.prol = phi i64 [ %indvars.iv.next21.prol, %.lr.ph.split.us.prol ], [ %indvars.iv20.ph, %.lr.ph.split.us.preheader29 ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.split.us.prol ], [ 0, %.lr.ph.split.us.preheader29 ]
  %17 = getelementptr inbounds double, ptr %1, i64 %indvars.iv20.prol
  %18 = load double, ptr %17, align 8, !tbaa !5
  %19 = getelementptr inbounds double, ptr %2, i64 %indvars.iv20.prol
  store double %18, ptr %19, align 8, !tbaa !5
  %indvars.iv.next21.prol = add nuw nsw i64 %indvars.iv20.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter31
  br i1 %prol.iter.cmp.not, label %.lr.ph.split.us.prol.loopexit, label %.lr.ph.split.us.prol, !llvm.loop !13

.lr.ph.split.us.prol.loopexit:                    ; preds = %.lr.ph.split.us.prol, %.lr.ph.split.us.preheader29
  %indvars.iv20.unr = phi i64 [ %indvars.iv20.ph, %.lr.ph.split.us.preheader29 ], [ %indvars.iv.next21.prol, %.lr.ph.split.us.prol ]
  %20 = sub nsw i64 %indvars.iv20.ph, %wide.trip.count23
  %21 = icmp ugt i64 %20, -4
  br i1 %21, label %.loopexit, label %.lr.ph.split.us

.lr.ph.split.us:                                  ; preds = %.lr.ph.split.us.prol.loopexit, %.lr.ph.split.us
  %indvars.iv20 = phi i64 [ %indvars.iv.next21.3, %.lr.ph.split.us ], [ %indvars.iv20.unr, %.lr.ph.split.us.prol.loopexit ]
  %22 = getelementptr inbounds double, ptr %1, i64 %indvars.iv20
  %23 = load double, ptr %22, align 8, !tbaa !5
  %24 = getelementptr inbounds double, ptr %2, i64 %indvars.iv20
  store double %23, ptr %24, align 8, !tbaa !5
  %indvars.iv.next21 = add nuw nsw i64 %indvars.iv20, 1
  %25 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next21
  %26 = load double, ptr %25, align 8, !tbaa !5
  %27 = getelementptr inbounds double, ptr %2, i64 %indvars.iv.next21
  store double %26, ptr %27, align 8, !tbaa !5
  %indvars.iv.next21.1 = add nuw nsw i64 %indvars.iv20, 2
  %28 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next21.1
  %29 = load double, ptr %28, align 8, !tbaa !5
  %30 = getelementptr inbounds double, ptr %2, i64 %indvars.iv.next21.1
  store double %29, ptr %30, align 8, !tbaa !5
  %indvars.iv.next21.2 = add nuw nsw i64 %indvars.iv20, 3
  %31 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next21.2
  %32 = load double, ptr %31, align 8, !tbaa !5
  %33 = getelementptr inbounds double, ptr %2, i64 %indvars.iv.next21.2
  store double %32, ptr %33, align 8, !tbaa !5
  %indvars.iv.next21.3 = add nuw nsw i64 %indvars.iv20, 4
  %exitcond24.not.3 = icmp eq i64 %indvars.iv.next21.3, %wide.trip.count23
  br i1 %exitcond24.not.3, label %.loopexit, label %.lr.ph.split.us, !llvm.loop !15

.lr.ph.split:                                     ; preds = %.lr.ph.split, %.lr.ph.split.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.split.preheader.new ], [ %indvars.iv.next.3, %.lr.ph.split ]
  %niter = phi i64 [ 0, %.lr.ph.split.preheader.new ], [ %niter.next.3, %.lr.ph.split ]
  %34 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv
  %35 = load i32, ptr %34, align 4, !tbaa !16
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds double, ptr %1, i64 %36
  %38 = load double, ptr %37, align 8, !tbaa !5
  %39 = getelementptr inbounds double, ptr %2, i64 %indvars.iv
  store double %38, ptr %39, align 8, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %40 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next
  %41 = load i32, ptr %40, align 4, !tbaa !16
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds double, ptr %1, i64 %42
  %44 = load double, ptr %43, align 8, !tbaa !5
  %45 = getelementptr inbounds double, ptr %2, i64 %indvars.iv.next
  store double %44, ptr %45, align 8, !tbaa !5
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %46 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next.1
  %47 = load i32, ptr %46, align 4, !tbaa !16
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds double, ptr %1, i64 %48
  %50 = load double, ptr %49, align 8, !tbaa !5
  %51 = getelementptr inbounds double, ptr %2, i64 %indvars.iv.next.1
  store double %50, ptr %51, align 8, !tbaa !5
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %52 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next.2
  %53 = load i32, ptr %52, align 4, !tbaa !16
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds double, ptr %1, i64 %54
  %56 = load double, ptr %55, align 8, !tbaa !5
  %57 = getelementptr inbounds double, ptr %2, i64 %indvars.iv.next.2
  store double %56, ptr %57, align 8, !tbaa !5
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.loopexit.loopexit30.unr-lcssa, label %.lr.ph.split, !llvm.loop !18

.loopexit.loopexit30.unr-lcssa:                   ; preds = %.lr.ph.split, %.lr.ph.split.preheader
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.split.preheader ], [ %indvars.iv.next.3, %.lr.ph.split ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.lr.ph.split.epil

.lr.ph.split.epil:                                ; preds = %.loopexit.loopexit30.unr-lcssa, %.lr.ph.split.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.split.epil ], [ %indvars.iv.unr, %.loopexit.loopexit30.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.split.epil ], [ 0, %.loopexit.loopexit30.unr-lcssa ]
  %58 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.epil
  %59 = load i32, ptr %58, align 4, !tbaa !16
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds double, ptr %1, i64 %60
  %62 = load double, ptr %61, align 8, !tbaa !5
  %63 = getelementptr inbounds double, ptr %2, i64 %indvars.iv.epil
  store double %62, ptr %63, align 8, !tbaa !5
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.loopexit, label %.lr.ph.split.epil, !llvm.loop !19

.loopexit:                                        ; preds = %.loopexit.loopexit30.unr-lcssa, %.lr.ph.split.epil, %.lr.ph.split.us.prol.loopexit, %.lr.ph.split.us, %middle.block, %.preheader, %4
  %.013 = phi i32 [ 0, %4 ], [ 1, %.preheader ], [ 1, %middle.block ], [ 1, %.lr.ph.split.us ], [ 1, %.lr.ph.split.us.prol.loopexit ], [ 1, %.lr.ph.split.epil ], [ 1, %.loopexit.loopexit30.unr-lcssa ]
  ret i32 %.013
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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" }

!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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.unroll.disable"}
!15 = distinct !{!15, !10, !11}
!16 = !{!17, !17, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = distinct !{!18, !10}
!19 = distinct !{!19, !14}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass