; LLVM IR from YuchenHHH/Sparse-linear-systems :: Source (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 i64 @cs_ipvec(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) #0 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %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 i64 %3, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, 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 i64 0, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %45

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

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

23:                                               ; preds = %19
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = load i64, ptr %10, align 8, !tbaa !9
  %26 = getelementptr inbounds double, ptr %24, i64 %25
  %27 = load double, ptr %26, align 8, !tbaa !11
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %36

31:                                               ; preds = %23
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load i64, ptr %10, align 8, !tbaa !9
  %34 = getelementptr inbounds i64, ptr %32, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !9
  br label %38

36:                                               ; preds = %23
  %37 = load i64, ptr %10, align 8, !tbaa !9
  br label %38

38:                                               ; preds = %36, %31
  %39 = phi i64 [ %35, %31 ], [ %37, %36 ]
  %40 = getelementptr inbounds double, ptr %28, i64 %39
  store double %27, ptr %40, align 8, !tbaa !11
  br label %41

41:                                               ; preds = %38
  %42 = load i64, ptr %10, align 8, !tbaa !9
  %43 = add nsw i64 %42, 1
  store i64 %43, ptr %10, align 8, !tbaa !9
  br label %19, !llvm.loop !13

44:                                               ; preds = %19
  store i64 1, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %45

45:                                               ; preds = %44, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  %46 = load i64, ptr %5, align 8
  ret i64 %46
}

; 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 = !{!"long", !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(i64 0, 2) i64 @cs_ipvec(ptr noundef readonly %0, ptr noundef readonly %1, ptr noundef writeonly %2, i64 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 i64 %3, 0
  br i1 %9, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.lr.ph.split.us.preheader, label %.lr.ph.split.preheader

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

.lr.ph.split.preheader.new:                       ; preds = %.lr.ph.split.preheader
  %unroll_iter = and i64 %3, 9223372036854775804
  br label %.lr.ph.split

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

vector.ph:                                        ; preds = %.lr.ph.split.us.preheader
  %n.vec = and i64 %3, 9223372036854775804
  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.load22 = 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.load22, 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, %3
  br i1 %cmp.n, label %.loopexit, label %.lr.ph.split.us.preheader24

.lr.ph.split.us.preheader24:                      ; preds = %middle.block, %.lr.ph.split.us.preheader
  %.017.us.ph = phi i64 [ 0, %.lr.ph.split.us.preheader ], [ %n.vec, %middle.block ]
  %xtraiter26 = and i64 %3, 3
  %lcmp.mod27.not = icmp eq i64 %xtraiter26, 0
  br i1 %lcmp.mod27.not, label %.lr.ph.split.us.prol.loopexit, label %.lr.ph.split.us.prol

.lr.ph.split.us.prol:                             ; preds = %.lr.ph.split.us.preheader24, %.lr.ph.split.us.prol
  %.017.us.prol = phi i64 [ %20, %.lr.ph.split.us.prol ], [ %.017.us.ph, %.lr.ph.split.us.preheader24 ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.split.us.prol ], [ 0, %.lr.ph.split.us.preheader24 ]
  %17 = getelementptr inbounds double, ptr %1, i64 %.017.us.prol
  %18 = load double, ptr %17, align 8, !tbaa !5
  %19 = getelementptr inbounds double, ptr %2, i64 %.017.us.prol
  store double %18, ptr %19, align 8, !tbaa !5
  %20 = add nuw nsw i64 %.017.us.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter26
  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.preheader24
  %.017.us.unr = phi i64 [ %.017.us.ph, %.lr.ph.split.us.preheader24 ], [ %20, %.lr.ph.split.us.prol ]
  %21 = sub nsw i64 %.017.us.ph, %3
  %22 = icmp ugt i64 %21, -4
  br i1 %22, label %.loopexit, label %.lr.ph.split.us

.lr.ph.split.us:                                  ; preds = %.lr.ph.split.us.prol.loopexit, %.lr.ph.split.us
  %.017.us = phi i64 [ %38, %.lr.ph.split.us ], [ %.017.us.unr, %.lr.ph.split.us.prol.loopexit ]
  %23 = getelementptr inbounds double, ptr %1, i64 %.017.us
  %24 = load double, ptr %23, align 8, !tbaa !5
  %25 = getelementptr inbounds double, ptr %2, i64 %.017.us
  store double %24, ptr %25, align 8, !tbaa !5
  %26 = add nuw nsw i64 %.017.us, 1
  %27 = getelementptr inbounds double, ptr %1, i64 %26
  %28 = load double, ptr %27, align 8, !tbaa !5
  %29 = getelementptr inbounds double, ptr %2, i64 %26
  store double %28, ptr %29, align 8, !tbaa !5
  %30 = add nuw nsw i64 %.017.us, 2
  %31 = getelementptr inbounds double, ptr %1, i64 %30
  %32 = load double, ptr %31, align 8, !tbaa !5
  %33 = getelementptr inbounds double, ptr %2, i64 %30
  store double %32, ptr %33, align 8, !tbaa !5
  %34 = add nuw nsw i64 %.017.us, 3
  %35 = getelementptr inbounds double, ptr %1, i64 %34
  %36 = load double, ptr %35, align 8, !tbaa !5
  %37 = getelementptr inbounds double, ptr %2, i64 %34
  store double %36, ptr %37, align 8, !tbaa !5
  %38 = add nuw nsw i64 %.017.us, 4
  %exitcond19.not.3 = icmp eq i64 %38, %3
  br i1 %exitcond19.not.3, label %.loopexit, label %.lr.ph.split.us, !llvm.loop !15

.lr.ph.split:                                     ; preds = %.lr.ph.split, %.lr.ph.split.preheader.new
  %.017 = phi i64 [ 0, %.lr.ph.split.preheader.new ], [ %62, %.lr.ph.split ]
  %niter = phi i64 [ 0, %.lr.ph.split.preheader.new ], [ %niter.next.3, %.lr.ph.split ]
  %39 = getelementptr inbounds double, ptr %1, i64 %.017
  %40 = load double, ptr %39, align 8, !tbaa !5
  %41 = getelementptr inbounds i64, ptr %0, i64 %.017
  %42 = load i64, ptr %41, align 8, !tbaa !16
  %43 = getelementptr inbounds double, ptr %2, i64 %42
  store double %40, ptr %43, align 8, !tbaa !5
  %44 = or disjoint i64 %.017, 1
  %45 = getelementptr inbounds double, ptr %1, i64 %44
  %46 = load double, ptr %45, align 8, !tbaa !5
  %47 = getelementptr inbounds i64, ptr %0, i64 %44
  %48 = load i64, ptr %47, align 8, !tbaa !16
  %49 = getelementptr inbounds double, ptr %2, i64 %48
  store double %46, ptr %49, align 8, !tbaa !5
  %50 = or disjoint i64 %.017, 2
  %51 = getelementptr inbounds double, ptr %1, i64 %50
  %52 = load double, ptr %51, align 8, !tbaa !5
  %53 = getelementptr inbounds i64, ptr %0, i64 %50
  %54 = load i64, ptr %53, align 8, !tbaa !16
  %55 = getelementptr inbounds double, ptr %2, i64 %54
  store double %52, ptr %55, align 8, !tbaa !5
  %56 = or disjoint i64 %.017, 3
  %57 = getelementptr inbounds double, ptr %1, i64 %56
  %58 = load double, ptr %57, align 8, !tbaa !5
  %59 = getelementptr inbounds i64, ptr %0, i64 %56
  %60 = load i64, ptr %59, align 8, !tbaa !16
  %61 = getelementptr inbounds double, ptr %2, i64 %60
  store double %58, ptr %61, align 8, !tbaa !5
  %62 = add nuw nsw i64 %.017, 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.loopexit25.unr-lcssa, label %.lr.ph.split, !llvm.loop !18

.loopexit.loopexit25.unr-lcssa:                   ; preds = %.lr.ph.split, %.lr.ph.split.preheader
  %.017.unr = phi i64 [ 0, %.lr.ph.split.preheader ], [ %62, %.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.loopexit25.unr-lcssa, %.lr.ph.split.epil
  %.017.epil = phi i64 [ %68, %.lr.ph.split.epil ], [ %.017.unr, %.loopexit.loopexit25.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.split.epil ], [ 0, %.loopexit.loopexit25.unr-lcssa ]
  %63 = getelementptr inbounds double, ptr %1, i64 %.017.epil
  %64 = load double, ptr %63, align 8, !tbaa !5
  %65 = getelementptr inbounds i64, ptr %0, i64 %.017.epil
  %66 = load i64, ptr %65, align 8, !tbaa !16
  %67 = getelementptr inbounds double, ptr %2, i64 %66
  store double %64, ptr %67, align 8, !tbaa !5
  %68 = add nuw nsw i64 %.017.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.loopexit25.unr-lcssa, %.lr.ph.split.epil, %.lr.ph.split.us.prol.loopexit, %.lr.ph.split.us, %middle.block, %.preheader, %4
  %.013 = phi i64 [ 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.loopexit25.unr-lcssa ]
  ret i64 %.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 = !{!"long", !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