; LLVM IR from sympiler/nasoq :: src/QP/osqp_utils.ll (ZN5nasoq17mat_postmult_diagEPNS_12sympiler_CSCEPKd)

; 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.nasoq::sympiler_CSC" = type { i64, i64, i64, ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i32, i32 }

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN5nasoq17mat_postmult_diagEPNS_12sympiler_CSCEPKd(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %51, %2
  %8 = load i32, ptr %5, align 4, !tbaa !9
  %9 = sext i32 %8 to i64
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %"struct.nasoq::sympiler_CSC", ptr %10, i32 0, i32 1
  %12 = load i64, ptr %11, align 8, !tbaa !11
  %13 = icmp ult i64 %9, %12
  br i1 %13, label %14, label %54

14:                                               ; preds = %7
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %"struct.nasoq::sympiler_CSC", ptr %15, i32 0, i32 3
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds i32, ptr %17, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !9
  store i32 %21, ptr %6, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %47, %14
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %"struct.nasoq::sympiler_CSC", ptr %24, i32 0, i32 3
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = add nsw i32 %27, 1
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds i32, ptr %26, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !9
  %32 = icmp slt i32 %23, %31
  br i1 %32, label %33, label %50

33:                                               ; preds = %22
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds double, ptr %34, i64 %36
  %38 = load double, ptr %37, align 8, !tbaa !15
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %"struct.nasoq::sympiler_CSC", ptr %39, i32 0, i32 6
  %41 = load ptr, ptr %40, align 8, !tbaa !17
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds double, ptr %41, i64 %43
  %45 = load double, ptr %44, align 8, !tbaa !15
  %46 = fmul double %45, %38
  store double %46, ptr %44, align 8, !tbaa !15
  br label %47

47:                                               ; preds = %33
  %48 = load i32, ptr %6, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %6, align 4, !tbaa !9
  br label %22, !llvm.loop !18

50:                                               ; preds = %22
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %5, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %5, align 4, !tbaa !9
  br label %7, !llvm.loop !20

54:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 8}
!12 = !{!"_ZTSN5nasoq12sympiler_CSCE", !13, i64 0, !13, i64 8, !13, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !10, i64 80, !10, i64 84}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !6, i64 24}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !7, i64 0}
!17 = !{!12, !6, i64 48}
!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: mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN5nasoq17mat_postmult_diagEPNS_12sympiler_CSCEPKd(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph16

.lr.ph16:                                         ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load ptr, ptr %5, align 8, !tbaa !12
  %7 = getelementptr inbounds i8, ptr %0, i64 48
  %.pre = load i32, ptr %6, align 4, !tbaa !13
  %8 = shl i64 %4, 3
  %scevgep23 = getelementptr i8, ptr %1, i64 %8
  br label %9

.loopexit:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block, %9
  %exitcond21.not = icmp eq i64 %indvars.iv.next19, %4
  br i1 %exitcond21.not, label %._crit_edge, label %9, !llvm.loop !14

9:                                                ; preds = %.lr.ph16, %.loopexit
  %10 = phi i32 [ %.pre, %.lr.ph16 ], [ %12, %.loopexit ]
  %indvars.iv18 = phi i64 [ 0, %.lr.ph16 ], [ %indvars.iv.next19, %.loopexit ]
  %indvars.iv.next19 = add nuw nsw i64 %indvars.iv18, 1
  %11 = getelementptr inbounds i32, ptr %6, i64 %indvars.iv.next19
  %12 = load i32, ptr %11, align 4, !tbaa !13
  %13 = icmp slt i32 %10, %12
  br i1 %13, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %9
  %14 = getelementptr inbounds double, ptr %1, i64 %indvars.iv18
  %15 = load ptr, ptr %7, align 8, !tbaa !16
  %16 = sext i32 %10 to i64
  %wide.trip.count = sext i32 %12 to i64
  %17 = sub nsw i64 %wide.trip.count, %16
  %min.iters.check = icmp ult i64 %17, 4
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %.lr.ph
  %18 = shl nsw i64 %16, 3
  %scevgep = getelementptr i8, ptr %15, i64 %18
  %19 = shl nsw i64 %wide.trip.count, 3
  %scevgep22 = getelementptr i8, ptr %15, i64 %19
  %bound0 = icmp ult ptr %scevgep, %scevgep23
  %bound1 = icmp ugt ptr %scevgep22, %1
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %17, -4
  %ind.end = add nsw i64 %n.vec, %16
  %20 = load double, ptr %14, align 8, !tbaa !17, !alias.scope !19
  %broadcast.splatinsert25 = insertelement <2 x double> poison, double %20, i64 0
  %broadcast.splat26 = shufflevector <2 x double> %broadcast.splatinsert25, <2 x double> poison, <2 x i32> zeroinitializer
  %invariant.gep = getelementptr double, ptr %15, i64 %16
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %gep = getelementptr double, ptr %invariant.gep, i64 %index
  %21 = getelementptr inbounds i8, ptr %gep, i64 16
  %wide.load = load <2 x double>, ptr %gep, align 8, !tbaa !17, !alias.scope !22, !noalias !19
  %wide.load24 = load <2 x double>, ptr %21, align 8, !tbaa !17, !alias.scope !22, !noalias !19
  %22 = fmul <2 x double> %broadcast.splat26, %wide.load
  %23 = fmul <2 x double> %broadcast.splat26, %wide.load24
  store <2 x double> %22, ptr %gep, align 8, !tbaa !17, !alias.scope !22, !noalias !19
  store <2 x double> %23, ptr %21, align 8, !tbaa !17, !alias.scope !22, !noalias !19
  %index.next = add nuw i64 %index, 4
  %24 = icmp eq i64 %index.next, %n.vec
  br i1 %24, label %middle.block, label %vector.body, !llvm.loop !24

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %17, %n.vec
  br i1 %cmp.n, label %.loopexit, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %.lr.ph
  %indvars.iv.ph = phi i64 [ %16, %vector.memcheck ], [ %16, %.lr.ph ], [ %ind.end, %middle.block ]
  %25 = sub nsw i64 %wide.trip.count, %indvars.iv.ph
  %xtraiter = and i64 %25, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader, %scalar.ph.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %scalar.ph.prol ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %26 = load double, ptr %14, align 8, !tbaa !17
  %27 = getelementptr inbounds double, ptr %15, i64 %indvars.iv.prol
  %28 = load double, ptr %27, align 8, !tbaa !17
  %29 = fmul double %26, %28
  store double %29, ptr %27, align 8, !tbaa !17
  %indvars.iv.next.prol = add nsw i64 %indvars.iv.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol, !llvm.loop !27

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol ]
  %30 = sub nsw i64 %indvars.iv.ph, %wide.trip.count
  %31 = icmp ugt i64 %30, -4
  br i1 %31, label %.loopexit, label %scalar.ph.preheader.new

scalar.ph.preheader.new:                          ; preds = %scalar.ph.prol.loopexit
  %invariant.gep27 = getelementptr i8, ptr %15, i64 8
  %invariant.gep29 = getelementptr i8, ptr %15, i64 16
  %invariant.gep31 = getelementptr i8, ptr %15, i64 24
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph, %scalar.ph.preheader.new
  %indvars.iv = phi i64 [ %indvars.iv.unr, %scalar.ph.preheader.new ], [ %indvars.iv.next.3, %scalar.ph ]
  %32 = load double, ptr %14, align 8, !tbaa !17
  %33 = getelementptr inbounds double, ptr %15, i64 %indvars.iv
  %34 = load double, ptr %33, align 8, !tbaa !17
  %35 = fmul double %32, %34
  store double %35, ptr %33, align 8, !tbaa !17
  %36 = load double, ptr %14, align 8, !tbaa !17
  %gep28 = getelementptr double, ptr %invariant.gep27, i64 %indvars.iv
  %37 = load double, ptr %gep28, align 8, !tbaa !17
  %38 = fmul double %36, %37
  store double %38, ptr %gep28, align 8, !tbaa !17
  %39 = load double, ptr %14, align 8, !tbaa !17
  %gep30 = getelementptr double, ptr %invariant.gep29, i64 %indvars.iv
  %40 = load double, ptr %gep30, align 8, !tbaa !17
  %41 = fmul double %39, %40
  store double %41, ptr %gep30, align 8, !tbaa !17
  %42 = load double, ptr %14, align 8, !tbaa !17
  %gep32 = getelementptr double, ptr %invariant.gep31, i64 %indvars.iv
  %43 = load double, ptr %gep32, align 8, !tbaa !17
  %44 = fmul double %42, %43
  store double %44, ptr %gep32, align 8, !tbaa !17
  %indvars.iv.next.3 = add nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, %wide.trip.count
  br i1 %exitcond.not.3, label %.loopexit, label %scalar.ph, !llvm.loop !29

._crit_edge:                                      ; preds = %.loopexit, %2
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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, !7, i64 8}
!6 = !{!"_ZTSN5nasoq12sympiler_CSCE", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !11, i64 64, !11, i64 68, !11, i64 72, !11, i64 76, !11, i64 80, !11, i64 84}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !10, i64 24}
!13 = !{!11, !11, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!6, !10, i64 48}
!17 = !{!18, !18, i64 0}
!18 = !{!"double", !8, i64 0}
!19 = !{!20}
!20 = distinct !{!20, !21}
!21 = distinct !{!21, !"LVerDomain"}
!22 = !{!23}
!23 = distinct !{!23, !21}
!24 = distinct !{!24, !15, !25, !26}
!25 = !{!"llvm.loop.isvectorized", i32 1}
!26 = !{!"llvm.loop.unroll.runtime.disable"}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.unroll.disable"}
!29 = distinct !{!29, !15, !25}


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