; LLVM IR from Tencent-RoboticsX/jbdl :: src/jbdl/experimental/qpoases/src/Matrices.ll (ZNK7qpOASES15SparseMatrixRow4fullEv)

; 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"

%"class.qpOASES::SparseMatrixRow" = type { ptr, i32, i32, ptr, ptr, ptr, ptr, %"class.qpOASES::Matrix.base" }
%"class.qpOASES::Matrix.base" = type <{ ptr, i32 }>

; 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 { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #1

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZNK7qpOASES15SparseMatrixRow4fullEv(ptr noundef nonnull align 8 dereferenceable(48) %0) unnamed_addr #3 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %7 = getelementptr inbounds %"class.qpOASES::SparseMatrixRow", ptr %6, i32 0, i32 1
  %8 = load i32, ptr %7, align 8, !tbaa !9
  %9 = getelementptr inbounds %"class.qpOASES::SparseMatrixRow", ptr %6, i32 0, i32 2
  %10 = load i32, ptr %9, align 4, !tbaa !12
  %11 = mul nsw i32 %8, %10
  %12 = sext i32 %11 to i64
  %13 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %12, i64 8)
  %14 = extractvalue { i64, i1 } %13, 1
  %15 = extractvalue { i64, i1 } %13, 0
  %16 = select i1 %14, i64 -1, i64 %15
  %17 = call noalias noundef nonnull ptr @_Znam(i64 noundef %16) #5
  store ptr %17, ptr %5, align 8, !tbaa !5
  store i32 0, ptr %3, align 4, !tbaa !13
  br label %18

18:                                               ; preds = %31, %1
  %19 = load i32, ptr %3, align 4, !tbaa !13
  %20 = getelementptr inbounds %"class.qpOASES::SparseMatrixRow", ptr %6, i32 0, i32 2
  %21 = load i32, ptr %20, align 4, !tbaa !12
  %22 = getelementptr inbounds %"class.qpOASES::SparseMatrixRow", ptr %6, i32 0, i32 1
  %23 = load i32, ptr %22, align 8, !tbaa !9
  %24 = mul nsw i32 %21, %23
  %25 = icmp slt i32 %19, %24
  br i1 %25, label %26, label %34

26:                                               ; preds = %18
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = load i32, ptr %3, align 4, !tbaa !13
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds double, ptr %27, i64 %29
  store double 0.000000e+00, ptr %30, align 8, !tbaa !14
  br label %31

31:                                               ; preds = %26
  %32 = load i32, ptr %3, align 4, !tbaa !13
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %3, align 4, !tbaa !13
  br label %18, !llvm.loop !16

34:                                               ; preds = %18
  store i32 0, ptr %3, align 4, !tbaa !13
  br label %35

35:                                               ; preds = %82, %34
  %36 = load i32, ptr %3, align 4, !tbaa !13
  %37 = getelementptr inbounds %"class.qpOASES::SparseMatrixRow", ptr %6, i32 0, i32 1
  %38 = load i32, ptr %37, align 8, !tbaa !9
  %39 = icmp slt i32 %36, %38
  br i1 %39, label %40, label %85

40:                                               ; preds = %35
  %41 = getelementptr inbounds %"class.qpOASES::SparseMatrixRow", ptr %6, i32 0, i32 3
  %42 = load ptr, ptr %41, align 8, !tbaa !18
  %43 = load i32, ptr %3, align 4, !tbaa !13
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds i32, ptr %42, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !13
  store i32 %46, ptr %4, align 4, !tbaa !13
  br label %47

47:                                               ; preds = %78, %40
  %48 = load i32, ptr %4, align 4, !tbaa !13
  %49 = getelementptr inbounds %"class.qpOASES::SparseMatrixRow", ptr %6, i32 0, i32 3
  %50 = load ptr, ptr %49, align 8, !tbaa !18
  %51 = load i32, ptr %3, align 4, !tbaa !13
  %52 = add nsw i32 %51, 1
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds i32, ptr %50, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !13
  %56 = icmp slt i32 %48, %55
  br i1 %56, label %57, label %81

57:                                               ; preds = %47
  %58 = getelementptr inbounds %"class.qpOASES::SparseMatrixRow", ptr %6, i32 0, i32 6
  %59 = load ptr, ptr %58, align 8, !tbaa !19
  %60 = load i32, ptr %4, align 4, !tbaa !13
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds double, ptr %59, i64 %61
  %63 = load double, ptr %62, align 8, !tbaa !14
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %"class.qpOASES::SparseMatrixRow", ptr %6, i32 0, i32 4
  %66 = load ptr, ptr %65, align 8, !tbaa !20
  %67 = load i32, ptr %4, align 4, !tbaa !13
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds i32, ptr %66, i64 %68
  %70 = load i32, ptr %69, align 4, !tbaa !13
  %71 = load i32, ptr %3, align 4, !tbaa !13
  %72 = getelementptr inbounds %"class.qpOASES::SparseMatrixRow", ptr %6, i32 0, i32 2
  %73 = load i32, ptr %72, align 4, !tbaa !12
  %74 = mul nsw i32 %71, %73
  %75 = add nsw i32 %70, %74
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds double, ptr %64, i64 %76
  store double %63, ptr %77, align 8, !tbaa !14
  br label %78

78:                                               ; preds = %57
  %79 = load i32, ptr %4, align 4, !tbaa !13
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %4, align 4, !tbaa !13
  br label %47, !llvm.loop !21

81:                                               ; preds = %47
  br label %82

82:                                               ; preds = %81
  %83 = load i32, ptr %3, align 4, !tbaa !13
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %3, align 4, !tbaa !13
  br label %35, !llvm.loop !22

85:                                               ; preds = %35
  %86 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret ptr %86
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nobuiltin allocsize(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 = { mustprogress 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 #4 = { nounwind }
attributes #5 = { builtin allocsize(0) }

!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++ TBAA"}
!9 = !{!10, !11, i64 8}
!10 = !{!"_ZTSN7qpOASES15SparseMatrixRowE", !11, i64 8, !11, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 12}
!13 = !{!11, !11, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!10, !6, i64 16}
!19 = !{!10, !6, i64 40}
!20 = !{!10, !6, i64 24}
!21 = distinct !{!21, !17}
!22 = distinct !{!22, !17}


; 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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noalias noundef nonnull ptr @_ZNK7qpOASES15SparseMatrixRow4fullEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(48) %0) unnamed_addr #1 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 12
  %5 = load i32, ptr %4, align 4, !tbaa !11
  %6 = mul nsw i32 %5, %3
  %7 = sext i32 %6 to i64
  %8 = icmp slt i32 %6, 0
  %9 = shl nsw i64 %7, 3
  %10 = select i1 %8, i64 -1, i64 %9
  %11 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %10) #3
  %12 = icmp sgt i32 %6, 0
  br i1 %12, label %.lr.ph.preheader, label %.preheader

.lr.ph.preheader:                                 ; preds = %1
  %13 = zext nneg i32 %6 to i64
  %14 = shl nuw nsw i64 %13, 3
  tail call void @llvm.memset.p0.i64(ptr nonnull align 8 %11, i8 0, i64 %14, i1 false), !tbaa !12
  br label %.preheader

.preheader:                                       ; preds = %.lr.ph.preheader, %1
  %15 = icmp sgt i32 %3, 0
  br i1 %15, label %.lr.ph20, label %._crit_edge

.lr.ph20:                                         ; preds = %.preheader
  %16 = getelementptr inbounds i8, ptr %0, i64 16
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  %18 = getelementptr inbounds i8, ptr %0, i64 40
  %19 = load ptr, ptr %18, align 8
  %20 = getelementptr inbounds i8, ptr %0, i64 24
  %21 = load ptr, ptr %20, align 8
  %22 = sext i32 %5 to i64
  %wide.trip.count26 = zext nneg i32 %3 to i64
  %.pre = load i32, ptr %17, align 4, !tbaa !15
  br label %23

.loopexit:                                        ; preds = %.prol.loopexit, %.lr.ph18.new, %23
  %exitcond27.not = icmp eq i64 %indvars.iv.next24, %wide.trip.count26
  br i1 %exitcond27.not, label %._crit_edge, label %23, !llvm.loop !16

23:                                               ; preds = %.lr.ph20, %.loopexit
  %24 = phi i32 [ %.pre, %.lr.ph20 ], [ %26, %.loopexit ]
  %indvars.iv23 = phi i64 [ 0, %.lr.ph20 ], [ %indvars.iv.next24, %.loopexit ]
  %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
  %25 = getelementptr inbounds i32, ptr %17, i64 %indvars.iv.next24
  %26 = load i32, ptr %25, align 4, !tbaa !15
  %27 = icmp slt i32 %24, %26
  br i1 %27, label %.lr.ph18, label %.loopexit

.lr.ph18:                                         ; preds = %23
  %28 = mul nsw i64 %indvars.iv23, %22
  %29 = sext i32 %24 to i64
  %wide.trip.count = sext i32 %26 to i64
  %30 = getelementptr double, ptr %11, i64 %28
  %31 = sub nsw i64 %wide.trip.count, %29
  %xtraiter = and i64 %31, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.prol.loopexit, label %.prol.preheader

.prol.preheader:                                  ; preds = %.lr.ph18, %.prol.preheader
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %.prol.preheader ], [ %29, %.lr.ph18 ]
  %prol.iter = phi i64 [ %prol.iter.next, %.prol.preheader ], [ 0, %.lr.ph18 ]
  %32 = getelementptr inbounds double, ptr %19, i64 %indvars.iv.prol
  %33 = load double, ptr %32, align 8, !tbaa !12
  %34 = getelementptr inbounds i32, ptr %21, i64 %indvars.iv.prol
  %35 = load i32, ptr %34, align 4, !tbaa !15
  %36 = sext i32 %35 to i64
  %37 = getelementptr double, ptr %30, i64 %36
  store double %33, ptr %37, align 8, !tbaa !12
  %indvars.iv.next.prol = add nsw i64 %indvars.iv.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.prol.loopexit, label %.prol.preheader, !llvm.loop !18

.prol.loopexit:                                   ; preds = %.prol.preheader, %.lr.ph18
  %indvars.iv.unr = phi i64 [ %29, %.lr.ph18 ], [ %indvars.iv.next.prol, %.prol.preheader ]
  %38 = sub nsw i64 %29, %wide.trip.count
  %39 = icmp ugt i64 %38, -4
  br i1 %39, label %.loopexit, label %.lr.ph18.new

.lr.ph18.new:                                     ; preds = %.prol.loopexit, %.lr.ph18.new
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %.lr.ph18.new ], [ %indvars.iv.unr, %.prol.loopexit ]
  %40 = getelementptr inbounds double, ptr %19, i64 %indvars.iv
  %41 = load double, ptr %40, align 8, !tbaa !12
  %42 = getelementptr inbounds i32, ptr %21, i64 %indvars.iv
  %43 = load i32, ptr %42, align 4, !tbaa !15
  %44 = sext i32 %43 to i64
  %45 = getelementptr double, ptr %30, i64 %44
  store double %41, ptr %45, align 8, !tbaa !12
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %46 = getelementptr inbounds double, ptr %19, i64 %indvars.iv.next
  %47 = load double, ptr %46, align 8, !tbaa !12
  %48 = getelementptr inbounds i32, ptr %21, i64 %indvars.iv.next
  %49 = load i32, ptr %48, align 4, !tbaa !15
  %50 = sext i32 %49 to i64
  %51 = getelementptr double, ptr %30, i64 %50
  store double %47, ptr %51, align 8, !tbaa !12
  %indvars.iv.next.1 = add nsw i64 %indvars.iv, 2
  %52 = getelementptr inbounds double, ptr %19, i64 %indvars.iv.next.1
  %53 = load double, ptr %52, align 8, !tbaa !12
  %54 = getelementptr inbounds i32, ptr %21, i64 %indvars.iv.next.1
  %55 = load i32, ptr %54, align 4, !tbaa !15
  %56 = sext i32 %55 to i64
  %57 = getelementptr double, ptr %30, i64 %56
  store double %53, ptr %57, align 8, !tbaa !12
  %indvars.iv.next.2 = add nsw i64 %indvars.iv, 3
  %58 = getelementptr inbounds double, ptr %19, i64 %indvars.iv.next.2
  %59 = load double, ptr %58, align 8, !tbaa !12
  %60 = getelementptr inbounds i32, ptr %21, i64 %indvars.iv.next.2
  %61 = load i32, ptr %60, align 4, !tbaa !15
  %62 = sext i32 %61 to i64
  %63 = getelementptr double, ptr %30, i64 %62
  store double %59, ptr %63, align 8, !tbaa !12
  %indvars.iv.next.3 = add nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, %wide.trip.count
  br i1 %exitcond.not.3, label %.loopexit, label %.lr.ph18.new, !llvm.loop !20

._crit_edge:                                      ; preds = %.loopexit, %.preheader
  ret ptr %11
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #0 = { nobuiltin allocsize(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 = { mustprogress 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { builtin allocsize(0) }

!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 8}
!6 = !{!"_ZTSN7qpOASES15SparseMatrixRowE", !7, i64 8, !7, i64 12, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 12}
!12 = !{!13, !13, i64 0}
!13 = !{!"double", !8, i64 0}
!14 = !{!6, !10, i64 16}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.unroll.disable"}
!20 = distinct !{!20, !17}


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