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

; 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 double @quad_form(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca double, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store double 0.000000e+00, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store i64 0, ptr %8, align 8, !tbaa !11
  br label %11

11:                                               ; preds = %92, %2
  %12 = load i64, ptr %8, align 8, !tbaa !11
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.csc, ptr %13, i32 0, i32 2
  %15 = load i64, ptr %14, align 8, !tbaa !13
  %16 = icmp slt i64 %12, %15
  br i1 %16, label %17, label %95

17:                                               ; preds = %11
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.csc, ptr %18, i32 0, i32 3
  %20 = load ptr, ptr %19, align 8, !tbaa !15
  %21 = load i64, ptr %8, align 8, !tbaa !11
  %22 = getelementptr inbounds i64, ptr %20, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !11
  store i64 %23, ptr %9, align 8, !tbaa !11
  br label %24

24:                                               ; preds = %88, %17
  %25 = load i64, ptr %9, align 8, !tbaa !11
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.csc, ptr %26, i32 0, i32 3
  %28 = load ptr, ptr %27, align 8, !tbaa !15
  %29 = load i64, ptr %8, align 8, !tbaa !11
  %30 = add nsw i64 %29, 1
  %31 = getelementptr inbounds i64, ptr %28, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !11
  %33 = icmp slt i64 %25, %32
  br i1 %33, label %34, label %91

34:                                               ; preds = %24
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.csc, ptr %35, i32 0, i32 4
  %37 = load ptr, ptr %36, align 8, !tbaa !16
  %38 = load i64, ptr %9, align 8, !tbaa !11
  %39 = getelementptr inbounds i64, ptr %37, i64 %38
  %40 = load i64, ptr %39, align 8, !tbaa !11
  store i64 %40, ptr %7, align 8, !tbaa !11
  %41 = load i64, ptr %7, align 8, !tbaa !11
  %42 = load i64, ptr %8, align 8, !tbaa !11
  %43 = icmp eq i64 %41, %42
  br i1 %43, label %44, label %63

44:                                               ; preds = %34
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.csc, ptr %45, i32 0, i32 5
  %47 = load ptr, ptr %46, align 8, !tbaa !17
  %48 = load i64, ptr %9, align 8, !tbaa !11
  %49 = getelementptr inbounds double, ptr %47, i64 %48
  %50 = load double, ptr %49, align 8, !tbaa !9
  %51 = fmul double 5.000000e-01, %50
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = load i64, ptr %7, align 8, !tbaa !11
  %54 = getelementptr inbounds double, ptr %52, i64 %53
  %55 = load double, ptr %54, align 8, !tbaa !9
  %56 = fmul double %51, %55
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = load i64, ptr %7, align 8, !tbaa !11
  %59 = getelementptr inbounds double, ptr %57, i64 %58
  %60 = load double, ptr %59, align 8, !tbaa !9
  %61 = load double, ptr %6, align 8, !tbaa !9
  %62 = call double @llvm.fmuladd.f64(double %56, double %60, double %61)
  store double %62, ptr %6, align 8, !tbaa !9
  br label %87

63:                                               ; preds = %34
  %64 = load i64, ptr %7, align 8, !tbaa !11
  %65 = load i64, ptr %8, align 8, !tbaa !11
  %66 = icmp slt i64 %64, %65
  br i1 %66, label %67, label %85

67:                                               ; preds = %63
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.csc, ptr %68, i32 0, i32 5
  %70 = load ptr, ptr %69, align 8, !tbaa !17
  %71 = load i64, ptr %9, align 8, !tbaa !11
  %72 = getelementptr inbounds double, ptr %70, i64 %71
  %73 = load double, ptr %72, align 8, !tbaa !9
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = load i64, ptr %7, align 8, !tbaa !11
  %76 = getelementptr inbounds double, ptr %74, i64 %75
  %77 = load double, ptr %76, align 8, !tbaa !9
  %78 = fmul double %73, %77
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = load i64, ptr %8, align 8, !tbaa !11
  %81 = getelementptr inbounds double, ptr %79, i64 %80
  %82 = load double, ptr %81, align 8, !tbaa !9
  %83 = load double, ptr %6, align 8, !tbaa !9
  %84 = call double @llvm.fmuladd.f64(double %78, double %82, double %83)
  store double %84, ptr %6, align 8, !tbaa !9
  br label %86

85:                                               ; preds = %63
  store double 0.000000e+00, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %97

86:                                               ; preds = %67
  br label %87

87:                                               ; preds = %86, %44
  br label %88

88:                                               ; preds = %87
  %89 = load i64, ptr %9, align 8, !tbaa !11
  %90 = add nsw i64 %89, 1
  store i64 %90, ptr %9, align 8, !tbaa !11
  br label %24, !llvm.loop !18

91:                                               ; preds = %24
  br label %92

92:                                               ; preds = %91
  %93 = load i64, ptr %8, align 8, !tbaa !11
  %94 = add nsw i64 %93, 1
  store i64 %94, ptr %8, align 8, !tbaa !11
  br label %11, !llvm.loop !20

95:                                               ; preds = %11
  %96 = load double, ptr %6, align 8, !tbaa !9
  store double %96, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %97

97:                                               ; preds = %95, %85
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %98 = load double, ptr %3, align 8
  ret double %98
}

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 = !{!"any pointer", !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 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !12, i64 16}
!14 = !{!"", !12, i64 0, !12, i64 8, !12, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !12, i64 48}
!15 = !{!14, !6, i64 24}
!16 = !{!14, !6, i64 32}
!17 = !{!14, !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: 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(read, inaccessiblemem: none) uwtable
define dso_local double @quad_form(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %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.ph45, label %.loopexit35

.lr.ph45:                                         ; 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 = %41, %10
  %.1.lcssa = phi double [ %.03243, %10 ], [ %.2, %41 ]
  %exitcond48.not = icmp eq i64 %12, %4
  br i1 %exitcond48.not, label %.loopexit35, label %10, !llvm.loop !13

10:                                               ; preds = %.lr.ph45, %.loopexit
  %11 = phi i64 [ %.pre, %.lr.ph45 ], [ %14, %.loopexit ]
  %.03044 = phi i64 [ 0, %.lr.ph45 ], [ %12, %.loopexit ]
  %.03243 = phi double [ 0.000000e+00, %.lr.ph45 ], [ %.1.lcssa, %.loopexit ]
  %12 = add nuw nsw i64 %.03044, 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 = getelementptr inbounds double, ptr %1, i64 %.03044
  br label %18

18:                                               ; preds = %.lr.ph, %41
  %.041 = phi i64 [ %11, %.lr.ph ], [ %42, %41 ]
  %.140 = phi double [ %.03243, %.lr.ph ], [ %.2, %41 ]
  %19 = getelementptr inbounds i64, ptr %16, i64 %.041
  %20 = load i64, ptr %19, align 8, !tbaa !12
  %21 = icmp eq i64 %20, %.03044
  br i1 %21, label %22, label %30

22:                                               ; preds = %18
  %23 = load ptr, ptr %9, align 8, !tbaa !16
  %24 = getelementptr inbounds double, ptr %23, i64 %.041
  %25 = load double, ptr %24, align 8, !tbaa !17
  %26 = fmul double %25, 5.000000e-01
  %27 = load double, ptr %17, align 8, !tbaa !17
  %28 = fmul double %26, %27
  %29 = tail call double @llvm.fmuladd.f64(double %28, double %27, double %.140)
  br label %41

30:                                               ; preds = %18
  %31 = icmp slt i64 %20, %.03044
  br i1 %31, label %32, label %.loopexit35

32:                                               ; preds = %30
  %33 = load ptr, ptr %9, align 8, !tbaa !16
  %34 = getelementptr inbounds double, ptr %33, i64 %.041
  %35 = load double, ptr %34, align 8, !tbaa !17
  %36 = getelementptr inbounds double, ptr %1, i64 %20
  %37 = load double, ptr %36, align 8, !tbaa !17
  %38 = fmul double %35, %37
  %39 = load double, ptr %17, align 8, !tbaa !17
  %40 = tail call double @llvm.fmuladd.f64(double %38, double %39, double %.140)
  br label %41

41:                                               ; preds = %22, %32
  %.2 = phi double [ %29, %22 ], [ %40, %32 ]
  %42 = add i64 %.041, 1
  %exitcond.not = icmp eq i64 %42, %14
  br i1 %exitcond.not, label %.loopexit, label %18, !llvm.loop !19

.loopexit35:                                      ; preds = %.loopexit, %30, %2
  %.031 = phi double [ 0.000000e+00, %2 ], [ 0.000000e+00, %30 ], [ %.1.lcssa, %.loopexit ]
  ret double %.031
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nofree norecurse nosync nounwind memory(read, 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,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass