; LLVM IR from Derek-TH-Wang/quadruped_ctrl :: src/osqp/src (proj)

; 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.OSQPWorkspace = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, i64 }
%struct.OSQPData = type { i64, i64, ptr, ptr, ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local void @project(ptr noundef %0, ptr noundef %1) #0 {
  %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
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.OSQPWorkspace, ptr %7, i32 0, i32 0
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = getelementptr inbounds %struct.OSQPData, ptr %9, i32 0, i32 1
  %11 = load i64, ptr %10, align 8, !tbaa !12
  store i64 %11, ptr %6, align 8, !tbaa !14
  store i64 0, ptr %5, align 8, !tbaa !14
  br label %12

12:                                               ; preds = %99, %2
  %13 = load i64, ptr %5, align 8, !tbaa !14
  %14 = load i64, ptr %6, align 8, !tbaa !14
  %15 = icmp slt i64 %13, %14
  br i1 %15, label %16, label %102

16:                                               ; preds = %12
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = load i64, ptr %5, align 8, !tbaa !14
  %19 = getelementptr inbounds double, ptr %17, i64 %18
  %20 = load double, ptr %19, align 8, !tbaa !15
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.OSQPWorkspace, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.OSQPData, ptr %23, i32 0, i32 5
  %25 = load ptr, ptr %24, align 8, !tbaa !17
  %26 = load i64, ptr %5, align 8, !tbaa !14
  %27 = getelementptr inbounds double, ptr %25, i64 %26
  %28 = load double, ptr %27, align 8, !tbaa !15
  %29 = fcmp ogt double %20, %28
  br i1 %29, label %30, label %35

30:                                               ; preds = %16
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load i64, ptr %5, align 8, !tbaa !14
  %33 = getelementptr inbounds double, ptr %31, i64 %32
  %34 = load double, ptr %33, align 8, !tbaa !15
  br label %44

35:                                               ; preds = %16
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.OSQPWorkspace, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.OSQPData, ptr %38, i32 0, i32 5
  %40 = load ptr, ptr %39, align 8, !tbaa !17
  %41 = load i64, ptr %5, align 8, !tbaa !14
  %42 = getelementptr inbounds double, ptr %40, i64 %41
  %43 = load double, ptr %42, align 8, !tbaa !15
  br label %44

44:                                               ; preds = %35, %30
  %45 = phi double [ %34, %30 ], [ %43, %35 ]
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.OSQPWorkspace, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.OSQPData, ptr %48, i32 0, i32 6
  %50 = load ptr, ptr %49, align 8, !tbaa !18
  %51 = load i64, ptr %5, align 8, !tbaa !14
  %52 = getelementptr inbounds double, ptr %50, i64 %51
  %53 = load double, ptr %52, align 8, !tbaa !15
  %54 = fcmp olt double %45, %53
  br i1 %54, label %55, label %85

55:                                               ; preds = %44
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = load i64, ptr %5, align 8, !tbaa !14
  %58 = getelementptr inbounds double, ptr %56, i64 %57
  %59 = load double, ptr %58, align 8, !tbaa !15
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.OSQPWorkspace, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !9
  %63 = getelementptr inbounds %struct.OSQPData, ptr %62, i32 0, i32 5
  %64 = load ptr, ptr %63, align 8, !tbaa !17
  %65 = load i64, ptr %5, align 8, !tbaa !14
  %66 = getelementptr inbounds double, ptr %64, i64 %65
  %67 = load double, ptr %66, align 8, !tbaa !15
  %68 = fcmp ogt double %59, %67
  br i1 %68, label %69, label %74

69:                                               ; preds = %55
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = load i64, ptr %5, align 8, !tbaa !14
  %72 = getelementptr inbounds double, ptr %70, i64 %71
  %73 = load double, ptr %72, align 8, !tbaa !15
  br label %83

74:                                               ; preds = %55
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.OSQPWorkspace, ptr %75, i32 0, i32 0
  %77 = load ptr, ptr %76, align 8, !tbaa !9
  %78 = getelementptr inbounds %struct.OSQPData, ptr %77, i32 0, i32 5
  %79 = load ptr, ptr %78, align 8, !tbaa !17
  %80 = load i64, ptr %5, align 8, !tbaa !14
  %81 = getelementptr inbounds double, ptr %79, i64 %80
  %82 = load double, ptr %81, align 8, !tbaa !15
  br label %83

83:                                               ; preds = %74, %69
  %84 = phi double [ %73, %69 ], [ %82, %74 ]
  br label %94

85:                                               ; preds = %44
  %86 = load ptr, ptr %3, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.OSQPWorkspace, ptr %86, i32 0, i32 0
  %88 = load ptr, ptr %87, align 8, !tbaa !9
  %89 = getelementptr inbounds %struct.OSQPData, ptr %88, i32 0, i32 6
  %90 = load ptr, ptr %89, align 8, !tbaa !18
  %91 = load i64, ptr %5, align 8, !tbaa !14
  %92 = getelementptr inbounds double, ptr %90, i64 %91
  %93 = load double, ptr %92, align 8, !tbaa !15
  br label %94

94:                                               ; preds = %85, %83
  %95 = phi double [ %84, %83 ], [ %93, %85 ]
  %96 = load ptr, ptr %4, align 8, !tbaa !5
  %97 = load i64, ptr %5, align 8, !tbaa !14
  %98 = getelementptr inbounds double, ptr %96, i64 %97
  store double %95, ptr %98, align 8, !tbaa !15
  br label %99

99:                                               ; preds = %94
  %100 = load i64, ptr %5, align 8, !tbaa !14
  %101 = add nsw i64 %100, 1
  store i64 %101, ptr %5, align 8, !tbaa !14
  br label %12, !llvm.loop !19

102:                                              ; preds = %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!10 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !11, i64 224, !11, i64 232}
!11 = !{!"long long", !7, i64 0}
!12 = !{!13, !11, i64 8}
!13 = !{!"", !11, i64 0, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!14 = !{!11, !11, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !7, i64 0}
!17 = !{!13, !6, i64 40}
!18 = !{!13, !6, i64 48}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; 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(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @project(ptr nocapture noundef readonly %0, ptr nocapture noundef %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 8
  %5 = load i64, ptr %4, align 8, !tbaa !11
  %6 = icmp sgt i64 %5, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2
  %7 = getelementptr inbounds i8, ptr %3, i64 40
  %8 = load ptr, ptr %7, align 8, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %3, i64 48
  %10 = load ptr, ptr %9, align 8, !tbaa !14
  %min.iters.check = icmp ult i64 %5, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %.lr.ph
  %11 = shl i64 %5, 3
  %scevgep = getelementptr i8, ptr %1, i64 %11
  %scevgep32 = getelementptr i8, ptr %8, i64 %11
  %scevgep33 = getelementptr i8, ptr %10, i64 %11
  %bound0 = icmp ugt ptr %scevgep32, %1
  %bound1 = icmp ult ptr %8, %scevgep
  %found.conflict = and i1 %bound0, %bound1
  %bound034 = icmp ugt ptr %scevgep33, %1
  %bound135 = icmp ult ptr %10, %scevgep
  %found.conflict36 = and i1 %bound034, %bound135
  %conflict.rdx = or i1 %found.conflict, %found.conflict36
  br i1 %conflict.rdx, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %5, 9223372036854775804
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %12 = getelementptr inbounds double, ptr %1, i64 %index
  %13 = getelementptr inbounds i8, ptr %12, i64 16
  %wide.load = load <2 x double>, ptr %12, align 8, !tbaa !15, !alias.scope !17, !noalias !20
  %wide.load37 = load <2 x double>, ptr %13, align 8, !tbaa !15, !alias.scope !17, !noalias !20
  %14 = getelementptr inbounds double, ptr %8, i64 %index
  %15 = getelementptr inbounds i8, ptr %14, i64 16
  %wide.load38 = load <2 x double>, ptr %14, align 8, !tbaa !15, !alias.scope !23
  %wide.load39 = load <2 x double>, ptr %15, align 8, !tbaa !15, !alias.scope !23
  %16 = fcmp ogt <2 x double> %wide.load, %wide.load38
  %17 = fcmp ogt <2 x double> %wide.load37, %wide.load39
  %18 = select <2 x i1> %16, <2 x double> %wide.load, <2 x double> %wide.load38
  %19 = select <2 x i1> %17, <2 x double> %wide.load37, <2 x double> %wide.load39
  %20 = getelementptr inbounds double, ptr %10, i64 %index
  %21 = getelementptr inbounds i8, ptr %20, i64 16
  %wide.load40 = load <2 x double>, ptr %20, align 8, !tbaa !15, !alias.scope !24
  %wide.load41 = load <2 x double>, ptr %21, align 8, !tbaa !15, !alias.scope !24
  %22 = fcmp olt <2 x double> %18, %wide.load40
  %23 = fcmp olt <2 x double> %19, %wide.load41
  %24 = select <2 x i1> %22, <2 x double> %18, <2 x double> %wide.load40
  %25 = select <2 x i1> %23, <2 x double> %19, <2 x double> %wide.load41
  store <2 x double> %24, ptr %12, align 8, !tbaa !15, !alias.scope !17, !noalias !20
  store <2 x double> %25, ptr %13, align 8, !tbaa !15, !alias.scope !17, !noalias !20
  %index.next = add nuw i64 %index, 4
  %26 = icmp eq i64 %index.next, %n.vec
  br i1 %26, label %middle.block, label %vector.body, !llvm.loop !25

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %5, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %.lr.ph
  %.031.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %.031 = phi i64 [ %36, %scalar.ph ], [ %.031.ph, %scalar.ph.preheader ]
  %27 = getelementptr inbounds double, ptr %1, i64 %.031
  %28 = load double, ptr %27, align 8, !tbaa !15
  %29 = getelementptr inbounds double, ptr %8, i64 %.031
  %30 = load double, ptr %29, align 8, !tbaa !15
  %31 = fcmp ogt double %28, %30
  %. = select i1 %31, double %28, double %30
  %32 = getelementptr inbounds double, ptr %10, i64 %.031
  %33 = load double, ptr %32, align 8, !tbaa !15
  %34 = fcmp olt double %., %33
  %35 = select i1 %34, double %., double %33
  store double %35, ptr %27, align 8, !tbaa !15
  %36 = add nuw nsw i64 %.031, 1
  %exitcond.not = icmp eq i64 %36, %5
  br i1 %exitcond.not, label %._crit_edge, label %scalar.ph, !llvm.loop !29

._crit_edge:                                      ; preds = %scalar.ph, %middle.block, %2
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, argmem: 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 0}
!6 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !7, i64 120, !7, i64 128, !7, i64 136, !7, i64 144, !7, i64 152, !7, i64 160, !7, i64 168, !7, i64 176, !7, i64 184, !7, i64 192, !7, i64 200, !7, i64 208, !7, i64 216, !10, i64 224, !10, i64 232}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"", !10, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48}
!13 = !{!12, !7, i64 40}
!14 = !{!12, !7, i64 48}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !8, i64 0}
!17 = !{!18}
!18 = distinct !{!18, !19}
!19 = distinct !{!19, !"LVerDomain"}
!20 = !{!21, !22}
!21 = distinct !{!21, !19}
!22 = distinct !{!22, !19}
!23 = !{!21}
!24 = !{!22}
!25 = distinct !{!25, !26, !27, !28}
!26 = !{!"llvm.loop.mustprogress"}
!27 = !{!"llvm.loop.isvectorized", i32 1}
!28 = !{!"llvm.loop.unroll.runtime.disable"}
!29 = distinct !{!29, !26, !27}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass