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

; 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::SparseMatrix" = 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 @_ZNK7qpOASES12SparseMatrix4fullEv(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::SparseMatrix", ptr %6, i32 0, i32 1
  %8 = load i32, ptr %7, align 8, !tbaa !9
  %9 = getelementptr inbounds %"class.qpOASES::SparseMatrix", 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::SparseMatrix", ptr %6, i32 0, i32 2
  %21 = load i32, ptr %20, align 4, !tbaa !12
  %22 = getelementptr inbounds %"class.qpOASES::SparseMatrix", 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 %4, align 4, !tbaa !13
  br label %35

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

40:                                               ; preds = %35
  %41 = getelementptr inbounds %"class.qpOASES::SparseMatrix", ptr %6, i32 0, i32 4
  %42 = load ptr, ptr %41, align 8, !tbaa !18
  %43 = load i32, ptr %4, 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 %3, align 4, !tbaa !13
  br label %47

47:                                               ; preds = %78, %40
  %48 = load i32, ptr %3, align 4, !tbaa !13
  %49 = getelementptr inbounds %"class.qpOASES::SparseMatrix", ptr %6, i32 0, i32 4
  %50 = load ptr, ptr %49, align 8, !tbaa !18
  %51 = load i32, ptr %4, 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::SparseMatrix", ptr %6, i32 0, i32 6
  %59 = load ptr, ptr %58, align 8, !tbaa !19
  %60 = load i32, ptr %3, 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::SparseMatrix", ptr %6, i32 0, i32 3
  %66 = load ptr, ptr %65, align 8, !tbaa !20
  %67 = load i32, ptr %3, 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 = getelementptr inbounds %"class.qpOASES::SparseMatrix", ptr %6, i32 0, i32 2
  %72 = load i32, ptr %71, align 4, !tbaa !12
  %73 = mul nsw i32 %70, %72
  %74 = load i32, ptr %4, align 4, !tbaa !13
  %75 = add nsw i32 %73, %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 %3, align 4, !tbaa !13
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %3, align 4, !tbaa !13
  br label %47, !llvm.loop !21

81:                                               ; preds = %47
  br label %82

82:                                               ; preds = %81
  %83 = load i32, ptr %4, align 4, !tbaa !13
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %4, 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 = !{!"_ZTSN7qpOASES12SparseMatrixE", !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 24}
!19 = !{!10, !6, i64 40}
!20 = !{!10, !6, i64 16}
!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 @_ZNK7qpOASES12SparseMatrix4fullEv(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 %5, 0
  br i1 %15, label %.lr.ph20, label %._crit_edge

.lr.ph20:                                         ; preds = %.preheader
  %16 = getelementptr inbounds i8, ptr %0, i64 24
  %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 16
  %21 = load ptr, ptr %20, align 8
  %wide.trip.count26 = zext nneg i32 %5 to i64
  %.pre = load i32, ptr %17, align 4, !tbaa !15
  br label %22

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

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

.lr.ph18.preheader:                               ; preds = %22
  %27 = sext i32 %23 to i64
  %wide.trip.count = sext i32 %25 to i64
  %28 = trunc nuw nsw i64 %indvars.iv23 to i32
  %29 = sub nsw i64 %wide.trip.count, %27
  %xtraiter = and i64 %29, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph18.prol.loopexit, label %.lr.ph18.prol

.lr.ph18.prol:                                    ; preds = %.lr.ph18.preheader
  %30 = getelementptr inbounds double, ptr %19, i64 %27
  %31 = load double, ptr %30, align 8, !tbaa !12
  %32 = getelementptr inbounds i32, ptr %21, i64 %27
  %33 = load i32, ptr %32, align 4, !tbaa !15
  %34 = mul nsw i32 %33, %5
  %35 = add nsw i32 %34, %28
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds double, ptr %11, i64 %36
  store double %31, ptr %37, align 8, !tbaa !12
  %indvars.iv.next.prol = add nsw i64 %27, 1
  br label %.lr.ph18.prol.loopexit

.lr.ph18.prol.loopexit:                           ; preds = %.lr.ph18.prol, %.lr.ph18.preheader
  %indvars.iv.unr = phi i64 [ %27, %.lr.ph18.preheader ], [ %indvars.iv.next.prol, %.lr.ph18.prol ]
  %38 = add nsw i64 %wide.trip.count, -1
  %39 = icmp eq i64 %38, %27
  br i1 %39, label %.loopexit, label %.lr.ph18

.lr.ph18:                                         ; preds = %.lr.ph18.prol.loopexit, %.lr.ph18
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %.lr.ph18 ], [ %indvars.iv.unr, %.lr.ph18.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 = mul nsw i32 %43, %5
  %45 = add nsw i32 %44, %28
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds double, ptr %11, i64 %46
  store double %41, ptr %47, align 8, !tbaa !12
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %48 = getelementptr inbounds double, ptr %19, i64 %indvars.iv.next
  %49 = load double, ptr %48, align 8, !tbaa !12
  %50 = getelementptr inbounds i32, ptr %21, i64 %indvars.iv.next
  %51 = load i32, ptr %50, align 4, !tbaa !15
  %52 = mul nsw i32 %51, %5
  %53 = add nsw i32 %52, %28
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds double, ptr %11, i64 %54
  store double %49, ptr %55, align 8, !tbaa !12
  %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 %.loopexit, label %.lr.ph18, !llvm.loop !18

._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 = !{!"_ZTSN7qpOASES12SparseMatrixE", !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 24}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


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