; 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_Ltsolve(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
  %13 = load i64, ptr %6, align 8, !tbaa !5
  %14 = sub nsw i64 %13, 1
  store i64 %14, ptr %11, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %53, %5
  %16 = load i64, ptr %11, align 8, !tbaa !5
  %17 = icmp sge i64 %16, 0
  br i1 %17, label %18, label %56

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

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

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

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

52:                                               ; preds = %23
  br label %53

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

56:                                               ; preds = %15
  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_Ltsolve(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.ph20.preheader, label %._crit_edge

.lr.ph20.preheader:                               ; preds = %5
  %.phi.trans.insert = getelementptr inbounds i64, ptr %1, i64 %0
  %.pre = load i64, ptr %.phi.trans.insert, align 8, !tbaa !5
  br label %.lr.ph20

.loopexit:                                        ; preds = %.prol.loopexit, %.lr.ph.new, %.lr.ph20
  %7 = icmp sgt i64 %.015.in18, 1
  br i1 %7, label %.lr.ph20, label %._crit_edge, !llvm.loop !9

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

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

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

.lr.ph.new:                                       ; preds = %.prol.loopexit, %.lr.ph.new
  %24 = phi double [ %41, %.lr.ph.new ], [ %.unr, %.prol.loopexit ]
  %.016 = phi i64 [ %42, %.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 = getelementptr inbounds i64, ptr %2, i64 %.016
  %28 = load i64, ptr %27, align 8, !tbaa !5
  %29 = getelementptr inbounds double, ptr %4, i64 %28
  %30 = load double, ptr %29, align 8, !tbaa !11
  %31 = fneg double %26
  %32 = tail call double @llvm.fmuladd.f64(double %31, double %30, double %24)
  store double %32, ptr %12, align 8, !tbaa !11
  %33 = add nsw i64 %.016, 1
  %34 = getelementptr inbounds double, ptr %3, i64 %33
  %35 = load double, ptr %34, align 8, !tbaa !11
  %36 = getelementptr inbounds i64, ptr %2, i64 %33
  %37 = load i64, ptr %36, align 8, !tbaa !5
  %38 = getelementptr inbounds double, ptr %4, i64 %37
  %39 = load double, ptr %38, align 8, !tbaa !11
  %40 = fneg double %35
  %41 = tail call double @llvm.fmuladd.f64(double %40, double %39, double %32)
  store double %41, ptr %12, align 8, !tbaa !11
  %42 = add nsw i64 %.016, 2
  %exitcond.not.1 = icmp eq i64 %42, %8
  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,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass