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

; 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

8:                                                ; preds = %34, %3
  %9 = load i64, ptr %7, align 8, !tbaa !9
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.csc, ptr %10, i32 0, i32 3
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = load ptr, ptr %5, 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 = getelementptr inbounds i64, ptr %12, i64 %15
  %17 = load i64, ptr %16, align 8, !tbaa !9
  %18 = icmp slt i64 %9, %17
  br i1 %18, label %19, label %37

19:                                               ; preds = %8
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.csc, ptr %20, i32 0, i32 5
  %22 = load ptr, ptr %21, align 8, !tbaa !14
  %23 = load i64, ptr %7, align 8, !tbaa !9
  %24 = getelementptr inbounds double, ptr %22, i64 %23
  %25 = load double, ptr %24, align 8, !tbaa !15
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.csc, ptr %26, i32 0, i32 5
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load i64, ptr %7, align 8, !tbaa !9
  %31 = getelementptr inbounds i64, ptr %29, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !9
  %33 = getelementptr inbounds double, ptr %28, i64 %32
  store double %25, ptr %33, align 8, !tbaa !15
  br label %34

34:                                               ; preds = %19
  %35 = load i64, ptr %7, align 8, !tbaa !9
  %36 = add nsw i64 %35, 1
  store i64 %36, ptr %7, align 8, !tbaa !9
  br label %8, !llvm.loop !17

37:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !6, i64 24}
!12 = !{!"", !10, i64 0, !10, i64 8, !10, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !10, i64 48}
!13 = !{!12, !10, i64 16}
!14 = !{!12, !6, i64 40}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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(readwrite, inaccessiblemem: none) uwtable
define dso_local void @update_KKT_A(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %1, i64 24
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %1, i64 16
  %7 = load i64, ptr %6, align 8, !tbaa !11
  %8 = getelementptr inbounds i64, ptr %5, i64 %7
  %9 = load i64, ptr %8, align 8, !tbaa !12
  %10 = icmp sgt i64 %9, 0
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %11 = getelementptr inbounds i8, ptr %1, i64 40
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  %13 = getelementptr inbounds i8, ptr %0, i64 40
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  %xtraiter = and i64 %9, 3
  %15 = icmp ult i64 %9, 4
  br i1 %15, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %9, 9223372036854775804
  br label %16

16:                                               ; preds = %16, %.lr.ph.new
  %.08 = phi i64 [ 0, %.lr.ph.new ], [ %40, %16 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %16 ]
  %17 = getelementptr inbounds double, ptr %12, i64 %.08
  %18 = load double, ptr %17, align 8, !tbaa !14
  %19 = getelementptr inbounds i64, ptr %2, i64 %.08
  %20 = load i64, ptr %19, align 8, !tbaa !12
  %21 = getelementptr inbounds double, ptr %14, i64 %20
  store double %18, ptr %21, align 8, !tbaa !14
  %22 = or disjoint i64 %.08, 1
  %23 = getelementptr inbounds double, ptr %12, i64 %22
  %24 = load double, ptr %23, align 8, !tbaa !14
  %25 = getelementptr inbounds i64, ptr %2, i64 %22
  %26 = load i64, ptr %25, align 8, !tbaa !12
  %27 = getelementptr inbounds double, ptr %14, i64 %26
  store double %24, ptr %27, align 8, !tbaa !14
  %28 = or disjoint i64 %.08, 2
  %29 = getelementptr inbounds double, ptr %12, i64 %28
  %30 = load double, ptr %29, align 8, !tbaa !14
  %31 = getelementptr inbounds i64, ptr %2, i64 %28
  %32 = load i64, ptr %31, align 8, !tbaa !12
  %33 = getelementptr inbounds double, ptr %14, i64 %32
  store double %30, ptr %33, align 8, !tbaa !14
  %34 = or disjoint i64 %.08, 3
  %35 = getelementptr inbounds double, ptr %12, i64 %34
  %36 = load double, ptr %35, align 8, !tbaa !14
  %37 = getelementptr inbounds i64, ptr %2, i64 %34
  %38 = load i64, ptr %37, align 8, !tbaa !12
  %39 = getelementptr inbounds double, ptr %14, i64 %38
  store double %36, ptr %39, align 8, !tbaa !14
  %40 = add nuw nsw i64 %.08, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %16, !llvm.loop !16

._crit_edge.loopexit.unr-lcssa:                   ; preds = %16, %.lr.ph
  %.08.unr = phi i64 [ 0, %.lr.ph ], [ %40, %16 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader
  %.08.epil = phi i64 [ %46, %.epil.preheader ], [ %.08.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %41 = getelementptr inbounds double, ptr %12, i64 %.08.epil
  %42 = load double, ptr %41, align 8, !tbaa !14
  %43 = getelementptr inbounds i64, ptr %2, i64 %.08.epil
  %44 = load i64, ptr %43, align 8, !tbaa !12
  %45 = getelementptr inbounds double, ptr %14, i64 %44
  store double %42, ptr %45, align 8, !tbaa !14
  %46 = add nuw nsw i64 %.08.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.epil.preheader, !llvm.loop !18

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader, %3
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(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, !10, i64 24}
!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, !7, i64 16}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !10, i64 40}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !8, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.unroll.disable"}


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