; LLVM IR from cvxgrp/scs :: linsys/external/qdldl (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(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #2 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca double, align 8
  store i32 %0, ptr %6, align 4, !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 4, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %14 = load i32, ptr %6, align 4, !tbaa !5
  %15 = sub nsw i32 %14, 1
  store i32 %15, ptr %11, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %66, %5
  %17 = load i32, ptr %11, align 4, !tbaa !5
  %18 = icmp sge i32 %17, 0
  br i1 %18, label %19, label %69

19:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %20 = load ptr, ptr %10, align 8, !tbaa !9
  %21 = load i32, ptr %11, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds double, ptr %20, i64 %22
  %24 = load double, ptr %23, align 8, !tbaa !11
  store double %24, ptr %13, align 8, !tbaa !11
  %25 = load ptr, ptr %7, align 8, !tbaa !9
  %26 = load i32, ptr %11, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds i32, ptr %25, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  store i32 %29, ptr %12, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %57, %19
  %31 = load i32, ptr %12, align 4, !tbaa !5
  %32 = load ptr, ptr %7, align 8, !tbaa !9
  %33 = load i32, ptr %11, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds i32, ptr %32, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = icmp slt i32 %31, %37
  br i1 %38, label %39, label %60

39:                                               ; preds = %30
  %40 = load ptr, ptr %9, align 8, !tbaa !9
  %41 = load i32, ptr %12, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds double, ptr %40, i64 %42
  %44 = load double, ptr %43, align 8, !tbaa !11
  %45 = load ptr, ptr %10, align 8, !tbaa !9
  %46 = load ptr, ptr %8, align 8, !tbaa !9
  %47 = load i32, ptr %12, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i32, ptr %46, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds double, ptr %45, i64 %51
  %53 = load double, ptr %52, align 8, !tbaa !11
  %54 = load double, ptr %13, align 8, !tbaa !11
  %55 = fneg double %44
  %56 = call double @llvm.fmuladd.f64(double %55, double %53, double %54)
  store double %56, ptr %13, align 8, !tbaa !11
  br label %57

57:                                               ; preds = %39
  %58 = load i32, ptr %12, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %12, align 4, !tbaa !5
  br label %30, !llvm.loop !13

60:                                               ; preds = %30
  %61 = load double, ptr %13, align 8, !tbaa !11
  %62 = load ptr, ptr %10, align 8, !tbaa !9
  %63 = load i32, ptr %11, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds double, ptr %62, i64 %64
  store double %61, ptr %65, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  br label %66

66:                                               ; preds = %60
  %67 = load i32, ptr %11, align 4, !tbaa !5
  %68 = add nsw i32 %67, -1
  store i32 %68, ptr %11, align 4, !tbaa !5
  br label %16, !llvm.loop !15

69:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, 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 = !{!"int", !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(i32 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 i32 %0, 0
  br i1 %6, label %.lr.ph27.preheader, label %._crit_edge28

.lr.ph27.preheader:                               ; preds = %5
  %7 = zext nneg i32 %0 to i64
  %.phi.trans.insert = getelementptr inbounds i32, ptr %1, i64 %7
  %.pre = load i32, ptr %.phi.trans.insert, align 4, !tbaa !5
  br label %.lr.ph27

.lr.ph27:                                         ; preds = %.lr.ph27.preheader, %._crit_edge
  %8 = phi i32 [ %.pre, %.lr.ph27.preheader ], [ %12, %._crit_edge ]
  %indvars.iv30 = phi i64 [ %7, %.lr.ph27.preheader ], [ %indvars.iv.next31, %._crit_edge ]
  %indvars.iv.next31 = add nsw i64 %indvars.iv30, -1
  %9 = getelementptr inbounds double, ptr %4, i64 %indvars.iv.next31
  %10 = load double, ptr %9, align 8, !tbaa !9
  %11 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv.next31
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = icmp slt i32 %12, %8
  br i1 %13, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.lr.ph27
  %14 = sext i32 %12 to i64
  %wide.trip.count = sext i32 %8 to i64
  %15 = sub nsw i64 %wide.trip.count, %14
  %xtraiter = and i64 %15, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader
  %16 = getelementptr inbounds double, ptr %3, i64 %14
  %17 = load double, ptr %16, align 8, !tbaa !9
  %18 = getelementptr inbounds i32, ptr %2, i64 %14
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds double, ptr %4, i64 %20
  %22 = load double, ptr %21, align 8, !tbaa !9
  %23 = fneg double %17
  %24 = tail call double @llvm.fmuladd.f64(double %23, double %22, double %10)
  %indvars.iv.next.prol = add nsw i64 %14, 1
  br label %.lr.ph.prol.loopexit

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.lcssa.unr = phi double [ poison, %.lr.ph.preheader ], [ %24, %.lr.ph.prol ]
  %indvars.iv.unr = phi i64 [ %14, %.lr.ph.preheader ], [ %indvars.iv.next.prol, %.lr.ph.prol ]
  %.022.unr = phi double [ %10, %.lr.ph.preheader ], [ %24, %.lr.ph.prol ]
  %25 = add nsw i64 %wide.trip.count, -1
  %26 = icmp eq i64 %25, %14
  br i1 %26, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %.lr.ph ], [ %indvars.iv.unr, %.lr.ph.prol.loopexit ]
  %.022 = phi double [ %44, %.lr.ph ], [ %.022.unr, %.lr.ph.prol.loopexit ]
  %27 = getelementptr inbounds double, ptr %3, i64 %indvars.iv
  %28 = load double, ptr %27, align 8, !tbaa !9
  %29 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds double, ptr %4, i64 %31
  %33 = load double, ptr %32, align 8, !tbaa !9
  %34 = fneg double %28
  %35 = tail call double @llvm.fmuladd.f64(double %34, double %33, double %.022)
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %36 = getelementptr inbounds double, ptr %3, i64 %indvars.iv.next
  %37 = load double, ptr %36, align 8, !tbaa !9
  %38 = getelementptr inbounds i32, ptr %2, i64 %indvars.iv.next
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds double, ptr %4, i64 %40
  %42 = load double, ptr %41, align 8, !tbaa !9
  %43 = fneg double %37
  %44 = tail call double @llvm.fmuladd.f64(double %43, double %42, double %35)
  %indvars.iv.next.1 = add nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, %wide.trip.count
  br i1 %exitcond.not.1, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %.lr.ph27
  %.0.lcssa = phi double [ %10, %.lr.ph27 ], [ %.lcssa.unr, %.lr.ph.prol.loopexit ], [ %44, %.lr.ph ]
  store double %.0.lcssa, ptr %9, align 8, !tbaa !9
  %45 = icmp sgt i64 %indvars.iv30, 1
  br i1 %45, label %.lr.ph27, label %._crit_edge28, !llvm.loop !13

._crit_edge28:                                    ; preds = %._crit_edge, %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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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