; 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_premult_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 = %51, %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 %54

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 = %47, %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 %50

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

47:                                               ; preds = %30
  %48 = load i64, ptr %6, align 8, !tbaa !9
  %49 = add nsw i64 %48, 1
  store i64 %49, ptr %6, align 8, !tbaa !9
  br label %20, !llvm.loop !18

50:                                               ; preds = %20
  br label %51

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

54:                                               ; 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 = !{!12, !6, i64 32}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !7, i64 0}
!17 = !{!12, !6, i64 40}
!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: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @mat_premult_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.ph16, label %._crit_edge

.lr.ph16:                                         ; 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 32
  %9 = getelementptr inbounds i8, ptr %0, i64 40
  %.pre = load i64, ptr %7, align 8, !tbaa !12
  br label %10

.loopexit:                                        ; preds = %.prol.loopexit, %.lr.ph.new, %10
  %exitcond17.not = icmp eq i64 %12, %4
  br i1 %exitcond17.not, label %._crit_edge, label %10, !llvm.loop !13

10:                                               ; preds = %.lr.ph16, %.loopexit
  %11 = phi i64 [ %.pre, %.lr.ph16 ], [ %14, %.loopexit ]
  %.01315 = phi i64 [ 0, %.lr.ph16 ], [ %12, %.loopexit ]
  %12 = add nuw nsw i64 %.01315, 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 = load ptr, ptr %8, align 8, !tbaa !15
  %17 = load ptr, ptr %9, align 8, !tbaa !16
  %18 = sub i64 %14, %11
  %.neg = add i64 %11, 1
  %xtraiter = and i64 %18, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.prol.loopexit, label %.prol.loopexit.unr-lcssa

.prol.loopexit.unr-lcssa:                         ; preds = %.lr.ph
  %19 = getelementptr inbounds i64, ptr %16, i64 %11
  %20 = load i64, ptr %19, align 8, !tbaa !12
  %21 = getelementptr inbounds double, ptr %1, i64 %20
  %22 = load double, ptr %21, align 8, !tbaa !17
  %23 = getelementptr inbounds double, ptr %17, i64 %11
  %24 = load double, ptr %23, align 8, !tbaa !17
  %25 = fmul double %22, %24
  store double %25, ptr %23, align 8, !tbaa !17
  %26 = add nsw i64 %11, 1
  br label %.prol.loopexit

.prol.loopexit:                                   ; preds = %.prol.loopexit.unr-lcssa, %.lr.ph
  %.014.unr = phi i64 [ %11, %.lr.ph ], [ %26, %.prol.loopexit.unr-lcssa ]
  %27 = icmp eq i64 %14, %.neg
  br i1 %27, label %.loopexit, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.prol.loopexit, %.lr.ph.new
  %.014 = phi i64 [ %43, %.lr.ph.new ], [ %.014.unr, %.prol.loopexit ]
  %28 = getelementptr inbounds i64, ptr %16, i64 %.014
  %29 = load i64, ptr %28, align 8, !tbaa !12
  %30 = getelementptr inbounds double, ptr %1, i64 %29
  %31 = load double, ptr %30, align 8, !tbaa !17
  %32 = getelementptr inbounds double, ptr %17, i64 %.014
  %33 = load double, ptr %32, align 8, !tbaa !17
  %34 = fmul double %31, %33
  store double %34, ptr %32, align 8, !tbaa !17
  %35 = add nsw i64 %.014, 1
  %36 = getelementptr inbounds i64, ptr %16, i64 %35
  %37 = load i64, ptr %36, align 8, !tbaa !12
  %38 = getelementptr inbounds double, ptr %1, i64 %37
  %39 = load double, ptr %38, align 8, !tbaa !17
  %40 = getelementptr inbounds double, ptr %17, i64 %35
  %41 = load double, ptr %40, align 8, !tbaa !17
  %42 = fmul double %39, %41
  store double %42, ptr %40, align 8, !tbaa !17
  %43 = add nsw i64 %.014, 2
  %exitcond.not.1 = icmp eq i64 %43, %14
  br i1 %exitcond.not.1, label %.loopexit, label %.lr.ph.new, !llvm.loop !19

._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 32}
!16 = !{!6, !10, i64 40}
!17 = !{!18, !18, i64 0}
!18 = !{!"double", !8, i64 0}
!19 = distinct !{!19, !14}


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