; LLVM IR from Derek-TH-Wang/quadruped_ctrl :: src/osqp/lin_sys/direct/qdldl/qdldl_sources/src (qdldl)

; 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: 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

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

13:                                               ; preds = %52, %5
  %14 = load i64, ptr %11, align 8, !tbaa !5
  %15 = load i64, ptr %6, align 8, !tbaa !5
  %16 = icmp slt i64 %14, %15
  br i1 %16, label %17, label %55

17:                                               ; preds = %13
  %18 = load ptr, ptr %7, align 8, !tbaa !9
  %19 = load i64, ptr %11, align 8, !tbaa !5
  %20 = getelementptr inbounds i64, ptr %18, i64 %19
  %21 = load i64, ptr %20, align 8, !tbaa !5
  store i64 %21, ptr %12, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %48, %17
  %23 = load i64, ptr %12, align 8, !tbaa !5
  %24 = load ptr, ptr %7, align 8, !tbaa !9
  %25 = load i64, ptr %11, align 8, !tbaa !5
  %26 = add nsw i64 %25, 1
  %27 = getelementptr inbounds i64, ptr %24, i64 %26
  %28 = load i64, ptr %27, align 8, !tbaa !5
  %29 = icmp slt i64 %23, %28
  br i1 %29, label %30, label %51

30:                                               ; preds = %22
  %31 = load ptr, ptr %9, align 8, !tbaa !9
  %32 = load i64, ptr %12, align 8, !tbaa !5
  %33 = getelementptr inbounds double, ptr %31, i64 %32
  %34 = load double, ptr %33, align 8, !tbaa !11
  %35 = load ptr, ptr %10, align 8, !tbaa !9
  %36 = load i64, ptr %11, align 8, !tbaa !5
  %37 = getelementptr inbounds double, ptr %35, i64 %36
  %38 = load double, ptr %37, align 8, !tbaa !11
  %39 = load ptr, ptr %10, align 8, !tbaa !9
  %40 = load ptr, ptr %8, align 8, !tbaa !9
  %41 = load i64, ptr %12, align 8, !tbaa !5
  %42 = getelementptr inbounds i64, ptr %40, i64 %41
  %43 = load i64, ptr %42, align 8, !tbaa !5
  %44 = getelementptr inbounds double, ptr %39, i64 %43
  %45 = load double, ptr %44, align 8, !tbaa !11
  %46 = fneg double %34
  %47 = call double @llvm.fmuladd.f64(double %46, double %38, double %45)
  store double %47, ptr %44, align 8, !tbaa !11
  br label %48

48:                                               ; preds = %30
  %49 = load i64, ptr %12, align 8, !tbaa !5
  %50 = add nsw i64 %49, 1
  store i64 %50, ptr %12, align 8, !tbaa !5
  br label %22, !llvm.loop !13

51:                                               ; preds = %22
  br label %52

52:                                               ; preds = %51
  %53 = load i64, ptr %11, align 8, !tbaa !5
  %54 = add nsw i64 %53, 1
  store i64 %54, ptr %11, align 8, !tbaa !5
  br label %13, !llvm.loop !15

55:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #3 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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 nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @QDLDL_Lsolve(i64 noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3, ptr nocapture noundef %4) local_unnamed_addr #1 {
  %6 = icmp sgt i64 %0, 0
  br i1 %6, label %.lr.ph18.preheader, label %._crit_edge

.lr.ph18.preheader:                               ; preds = %5
  %.pre = load i64, ptr %1, align 8, !tbaa !5
  br label %.lr.ph18

.loopexit:                                        ; preds = %.prol.loopexit, %.lr.ph.new, %.lr.ph18
  %exitcond19.not = icmp eq i64 %8, %0
  br i1 %exitcond19.not, label %._crit_edge, label %.lr.ph18, !llvm.loop !9

.lr.ph18:                                         ; preds = %.lr.ph18.preheader, %.loopexit
  %7 = phi i64 [ %10, %.loopexit ], [ %.pre, %.lr.ph18.preheader ]
  %.01517 = phi i64 [ %8, %.loopexit ], [ 0, %.lr.ph18.preheader ]
  %8 = add nuw nsw i64 %.01517, 1
  %9 = getelementptr inbounds i64, ptr %1, i64 %8
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %11 = icmp slt i64 %7, %10
  br i1 %11, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph18
  %12 = getelementptr inbounds double, ptr %4, i64 %.01517
  %13 = sub i64 %10, %7
  %.neg = add i64 %7, 1
  %xtraiter = and i64 %13, 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
  %14 = getelementptr inbounds double, ptr %3, i64 %7
  %15 = load double, ptr %14, align 8, !tbaa !11
  %16 = load double, ptr %12, align 8, !tbaa !11
  %17 = getelementptr inbounds i64, ptr %2, i64 %7
  %18 = load i64, ptr %17, align 8, !tbaa !5
  %19 = getelementptr inbounds double, ptr %4, i64 %18
  %20 = load double, ptr %19, align 8, !tbaa !11
  %21 = fneg double %15
  %22 = tail call double @llvm.fmuladd.f64(double %21, double %16, double %20)
  store double %22, ptr %19, align 8, !tbaa !11
  %23 = add nsw i64 %7, 1
  br label %.prol.loopexit

.prol.loopexit:                                   ; preds = %.prol.loopexit.unr-lcssa, %.lr.ph
  %.016.unr = phi i64 [ %7, %.lr.ph ], [ %23, %.prol.loopexit.unr-lcssa ]
  %24 = icmp eq i64 %10, %.neg
  br i1 %24, label %.loopexit, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.prol.loopexit, %.lr.ph.new
  %.016 = phi i64 [ %44, %.lr.ph.new ], [ %.016.unr, %.prol.loopexit ]
  %25 = getelementptr inbounds double, ptr %3, i64 %.016
  %26 = load double, ptr %25, align 8, !tbaa !11
  %27 = load double, ptr %12, align 8, !tbaa !11
  %28 = getelementptr inbounds i64, ptr %2, i64 %.016
  %29 = load i64, ptr %28, align 8, !tbaa !5
  %30 = getelementptr inbounds double, ptr %4, i64 %29
  %31 = load double, ptr %30, align 8, !tbaa !11
  %32 = fneg double %26
  %33 = tail call double @llvm.fmuladd.f64(double %32, double %27, double %31)
  store double %33, ptr %30, align 8, !tbaa !11
  %34 = add nsw i64 %.016, 1
  %35 = getelementptr inbounds double, ptr %3, i64 %34
  %36 = load double, ptr %35, align 8, !tbaa !11
  %37 = load double, ptr %12, align 8, !tbaa !11
  %38 = getelementptr inbounds i64, ptr %2, i64 %34
  %39 = load i64, ptr %38, align 8, !tbaa !5
  %40 = getelementptr inbounds double, ptr %4, i64 %39
  %41 = load double, ptr %40, align 8, !tbaa !11
  %42 = fneg double %36
  %43 = tail call double @llvm.fmuladd.f64(double %42, double %37, double %41)
  store double %43, ptr %40, align 8, !tbaa !11
  %44 = add nsw i64 %.016, 2
  %exitcond.not.1 = icmp eq i64 %44, %10
  br i1 %exitcond.not.1, label %.loopexit, label %.lr.ph.new, !llvm.loop !13

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !10}


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