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

; 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_ipvec(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 i32, ptr %10, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds double, ptr %24, i64 %26
  %28 = load double, ptr %27, align 8, !tbaa !11
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %38

32:                                               ; preds = %23
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = load i32, ptr %10, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds i32, ptr %33, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !9
  br label %40

38:                                               ; preds = %23
  %39 = load i32, ptr %10, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %38, %32
  %41 = phi i32 [ %37, %32 ], [ %39, %38 ]
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds double, ptr %29, i64 %42
  store double %28, ptr %43, align 8, !tbaa !11
  br label %44

44:                                               ; preds = %40
  %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_ipvec(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 double, ptr %1, i64 %indvars.iv
  %35 = load double, ptr %34, align 8, !tbaa !5
  %36 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv
  %37 = load i32, ptr %36, align 4, !tbaa !16
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds double, ptr %2, i64 %38
  store double %35, ptr %39, align 8, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %40 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next
  %41 = load double, ptr %40, align 8, !tbaa !5
  %42 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next
  %43 = load i32, ptr %42, align 4, !tbaa !16
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds double, ptr %2, i64 %44
  store double %41, ptr %45, align 8, !tbaa !5
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %46 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next.1
  %47 = load double, ptr %46, align 8, !tbaa !5
  %48 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next.1
  %49 = load i32, ptr %48, align 4, !tbaa !16
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds double, ptr %2, i64 %50
  store double %47, ptr %51, align 8, !tbaa !5
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %52 = getelementptr inbounds double, ptr %1, i64 %indvars.iv.next.2
  %53 = load double, ptr %52, align 8, !tbaa !5
  %54 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next.2
  %55 = load i32, ptr %54, align 4, !tbaa !16
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds double, ptr %2, i64 %56
  store double %53, 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 double, ptr %1, i64 %indvars.iv.epil
  %59 = load double, ptr %58, align 8, !tbaa !5
  %60 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.epil
  %61 = load i32, ptr %60, align 4, !tbaa !16
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds double, ptr %2, i64 %62
  store double %59, 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: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass