; LLVM IR from Derek-TH-Wang/quadruped_ctrl :: src/osqp/src (lin_alg)

; 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.csc = type { i64, i64, i64, ptr, ptr, ptr, i64 }

; 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: nounwind uwtable
define dso_local void @mat_postmult_diag(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  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 8, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 0, ptr %5, align 8, !tbaa !9
  br label %7

7:                                                ; preds = %46, %2
  %8 = load i64, ptr %5, align 8, !tbaa !9
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.csc, ptr %9, i32 0, i32 2
  %11 = load i64, ptr %10, align 8, !tbaa !11
  %12 = icmp slt i64 %8, %11
  br i1 %12, label %13, label %49

13:                                               ; preds = %7
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.csc, ptr %14, i32 0, i32 3
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %17 = load i64, ptr %5, align 8, !tbaa !9
  %18 = getelementptr inbounds i64, ptr %16, i64 %17
  %19 = load i64, ptr %18, align 8, !tbaa !9
  store i64 %19, ptr %6, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %42, %13
  %21 = load i64, ptr %6, align 8, !tbaa !9
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.csc, ptr %22, i32 0, i32 3
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  %25 = load i64, ptr %5, align 8, !tbaa !9
  %26 = add nsw i64 %25, 1
  %27 = getelementptr inbounds i64, ptr %24, i64 %26
  %28 = load i64, ptr %27, align 8, !tbaa !9
  %29 = icmp slt i64 %21, %28
  br i1 %29, label %30, label %45

30:                                               ; preds = %20
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load i64, ptr %5, align 8, !tbaa !9
  %33 = getelementptr inbounds double, ptr %31, i64 %32
  %34 = load double, ptr %33, align 8, !tbaa !14
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.csc, ptr %35, i32 0, i32 5
  %37 = load ptr, ptr %36, align 8, !tbaa !16
  %38 = load i64, ptr %6, align 8, !tbaa !9
  %39 = getelementptr inbounds double, ptr %37, i64 %38
  %40 = load double, ptr %39, align 8, !tbaa !14
  %41 = fmul double %40, %34
  store double %41, ptr %39, align 8, !tbaa !14
  br label %42

42:                                               ; preds = %30
  %43 = load i64, ptr %6, align 8, !tbaa !9
  %44 = add nsw i64 %43, 1
  store i64 %44, ptr %6, align 8, !tbaa !9
  br label %20, !llvm.loop !17

45:                                               ; preds = %20
  br label %46

46:                                               ; preds = %45
  %47 = load i64, ptr %5, align 8, !tbaa !9
  %48 = add nsw i64 %47, 1
  store i64 %48, ptr %5, align 8, !tbaa !9
  br label %7, !llvm.loop !19

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

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 }

!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 long", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"", !10, i64 0, !10, i64 8, !10, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !10, i64 48}
!13 = !{!12, !6, i64 24}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !7, i64 0}
!16 = !{!12, !6, i64 40}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


; 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(readwrite, inaccessiblemem: none) uwtable
define dso_local void @mat_postmult_diag(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = icmp sgt i64 %4, 0
  br i1 %5, label %.lr.ph15, label %._crit_edge

.lr.ph15:                                         ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %0, i64 40
  %.pre = load i64, ptr %7, align 8, !tbaa !12
  %9 = shl i64 %4, 3
  %scevgep18 = getelementptr i8, ptr %1, i64 %9
  br label %10

.loopexit:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block, %10
  %exitcond16.not = icmp eq i64 %12, %4
  br i1 %exitcond16.not, label %._crit_edge, label %10, !llvm.loop !13

10:                                               ; preds = %.lr.ph15, %.loopexit
  %11 = phi i64 [ %.pre, %.lr.ph15 ], [ %14, %.loopexit ]
  %.01214 = phi i64 [ 0, %.lr.ph15 ], [ %12, %.loopexit ]
  %12 = add nuw nsw i64 %.01214, 1
  %13 = getelementptr inbounds i64, ptr %7, i64 %12
  %14 = load i64, ptr %13, align 8, !tbaa !12
  %15 = icmp slt i64 %11, %14
  br i1 %15, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %10
  %16 = getelementptr inbounds double, ptr %1, i64 %.01214
  %17 = load ptr, ptr %8, align 8, !tbaa !15
  %18 = sub i64 %14, %11
  %min.iters.check = icmp ult i64 %18, 4
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %.lr.ph
  %19 = shl i64 %11, 3
  %scevgep = getelementptr i8, ptr %17, i64 %19
  %20 = shl i64 %14, 3
  %scevgep17 = getelementptr i8, ptr %17, i64 %20
  %bound0 = icmp ult ptr %scevgep, %scevgep18
  %bound1 = icmp ugt ptr %scevgep17, %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 %18, -4
  %ind.end = add i64 %11, %n.vec
  %21 = load double, ptr %16, align 8, !tbaa !16, !alias.scope !18
  %broadcast.splatinsert20 = insertelement <2 x double> poison, double %21, i64 0
  %broadcast.splat21 = shufflevector <2 x double> %broadcast.splatinsert20, <2 x double> poison, <2 x i32> zeroinitializer
  %22 = getelementptr double, ptr %17, i64 %11
  br label %vector.body

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

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

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %.lr.ph
  %.013.ph = phi i64 [ %11, %vector.memcheck ], [ %11, %.lr.ph ], [ %ind.end, %middle.block ]
  %28 = sub i64 %14, %.013.ph
  %xtraiter = and i64 %28, 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
  %.013.prol = phi i64 [ %33, %scalar.ph.prol ], [ %.013.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %29 = load double, ptr %16, align 8, !tbaa !16
  %30 = getelementptr inbounds double, ptr %17, i64 %.013.prol
  %31 = load double, ptr %30, align 8, !tbaa !16
  %32 = fmul double %29, %31
  store double %32, ptr %30, align 8, !tbaa !16
  %33 = add nsw i64 %.013.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 !26

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %.013.unr = phi i64 [ %.013.ph, %scalar.ph.preheader ], [ %33, %scalar.ph.prol ]
  %34 = sub i64 %.013.ph, %14
  %35 = icmp ugt i64 %34, -4
  br i1 %35, label %.loopexit, label %scalar.ph.preheader.new

scalar.ph.preheader.new:                          ; preds = %scalar.ph.prol.loopexit
  %invariant.gep = getelementptr i8, ptr %17, i64 8
  %invariant.gep22 = getelementptr i8, ptr %17, i64 16
  %invariant.gep24 = getelementptr i8, ptr %17, i64 24
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph, %scalar.ph.preheader.new
  %.013 = phi i64 [ %.013.unr, %scalar.ph.preheader.new ], [ %49, %scalar.ph ]
  %36 = load double, ptr %16, align 8, !tbaa !16
  %37 = getelementptr inbounds double, ptr %17, i64 %.013
  %38 = load double, ptr %37, align 8, !tbaa !16
  %39 = fmul double %36, %38
  store double %39, ptr %37, align 8, !tbaa !16
  %40 = load double, ptr %16, align 8, !tbaa !16
  %gep = getelementptr double, ptr %invariant.gep, i64 %.013
  %41 = load double, ptr %gep, align 8, !tbaa !16
  %42 = fmul double %40, %41
  store double %42, ptr %gep, align 8, !tbaa !16
  %43 = load double, ptr %16, align 8, !tbaa !16
  %gep23 = getelementptr double, ptr %invariant.gep22, i64 %.013
  %44 = load double, ptr %gep23, align 8, !tbaa !16
  %45 = fmul double %43, %44
  store double %45, ptr %gep23, align 8, !tbaa !16
  %46 = load double, ptr %16, align 8, !tbaa !16
  %gep25 = getelementptr double, ptr %invariant.gep24, i64 %.013
  %47 = load double, ptr %gep25, align 8, !tbaa !16
  %48 = fmul double %46, %47
  store double %48, ptr %gep25, align 8, !tbaa !16
  %49 = add nsw i64 %.013, 4
  %exitcond.not.3 = icmp eq i64 %49, %14
  br i1 %exitcond.not.3, label %.loopexit, label %scalar.ph, !llvm.loop !28

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

attributes #0 = { 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 16}
!6 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !7, i64 48}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 24}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!6, !10, i64 40}
!16 = !{!17, !17, i64 0}
!17 = !{!"double", !8, i64 0}
!18 = !{!19}
!19 = distinct !{!19, !20}
!20 = distinct !{!20, !"LVerDomain"}
!21 = !{!22}
!22 = distinct !{!22, !20}
!23 = distinct !{!23, !14, !24, !25}
!24 = !{!"llvm.loop.isvectorized", i32 1}
!25 = !{!"llvm.loop.unroll.runtime.disable"}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.unroll.disable"}
!28 = distinct !{!28, !14, !24}


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