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

; 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 @_ZN7qpOASES12SparseMatrix14createDiagInfoEv(ptr noundef nonnull align 8 dereferenceable(48) %0) #3 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = 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
  %6 = getelementptr inbounds %"class.qpOASES::SparseMatrix", ptr %5, i32 0, i32 5
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %67

9:                                                ; preds = %1
  %10 = getelementptr inbounds %"class.qpOASES::SparseMatrix", ptr %5, i32 0, i32 2
  %11 = load i32, ptr %10, align 4, !tbaa !12
  %12 = sext i32 %11 to i64
  %13 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %12, i64 4)
  %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
  %18 = getelementptr inbounds %"class.qpOASES::SparseMatrix", ptr %5, i32 0, i32 5
  store ptr %17, ptr %18, align 8, !tbaa !9
  store i32 0, ptr %4, align 4, !tbaa !13
  br label %19

19:                                               ; preds = %63, %9
  %20 = load i32, ptr %4, align 4, !tbaa !13
  %21 = getelementptr inbounds %"class.qpOASES::SparseMatrix", ptr %5, i32 0, i32 2
  %22 = load i32, ptr %21, align 4, !tbaa !12
  %23 = icmp slt i32 %20, %22
  br i1 %23, label %24, label %66

24:                                               ; preds = %19
  %25 = getelementptr inbounds %"class.qpOASES::SparseMatrix", ptr %5, i32 0, i32 4
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  %27 = load i32, ptr %4, align 4, !tbaa !13
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds i32, ptr %26, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !13
  store i32 %30, ptr %3, align 4, !tbaa !13
  br label %31

31:                                               ; preds = %53, %24
  %32 = load i32, ptr %3, align 4, !tbaa !13
  %33 = getelementptr inbounds %"class.qpOASES::SparseMatrix", ptr %5, i32 0, i32 4
  %34 = load ptr, ptr %33, align 8, !tbaa !14
  %35 = load i32, ptr %4, align 4, !tbaa !13
  %36 = add nsw i32 %35, 1
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i32, ptr %34, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !13
  %40 = icmp slt i32 %32, %39
  br i1 %40, label %41, label %50

41:                                               ; preds = %31
  %42 = getelementptr inbounds %"class.qpOASES::SparseMatrix", ptr %5, i32 0, i32 3
  %43 = load ptr, ptr %42, align 8, !tbaa !15
  %44 = load i32, ptr %3, align 4, !tbaa !13
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds i32, ptr %43, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !13
  %48 = load i32, ptr %4, align 4, !tbaa !13
  %49 = icmp slt i32 %47, %48
  br label %50

50:                                               ; preds = %41, %31
  %51 = phi i1 [ false, %31 ], [ %49, %41 ]
  br i1 %51, label %52, label %56

52:                                               ; preds = %50
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %3, align 4, !tbaa !13
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %3, align 4, !tbaa !13
  br label %31, !llvm.loop !16

56:                                               ; preds = %50
  %57 = load i32, ptr %3, align 4, !tbaa !13
  %58 = getelementptr inbounds %"class.qpOASES::SparseMatrix", ptr %5, i32 0, i32 5
  %59 = load ptr, ptr %58, align 8, !tbaa !9
  %60 = load i32, ptr %4, align 4, !tbaa !13
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds i32, ptr %59, i64 %61
  store i32 %57, ptr %62, align 4, !tbaa !13
  br label %63

63:                                               ; preds = %56
  %64 = load i32, ptr %4, align 4, !tbaa !13
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %4, align 4, !tbaa !13
  br label %19, !llvm.loop !18

66:                                               ; preds = %19
  br label %67

67:                                               ; preds = %66, %1
  %68 = getelementptr inbounds %"class.qpOASES::SparseMatrix", ptr %5, i32 0, i32 5
  %69 = load ptr, ptr %68, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret ptr %69
}

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, !6, i64 32}
!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 = !{!10, !6, i64 24}
!15 = !{!10, !6, i64 16}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !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 noundef nonnull ptr @_ZN7qpOASES12SparseMatrix14createDiagInfoEv(ptr nocapture noundef nonnull align 8 dereferenceable(48) %0) local_unnamed_addr #1 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 32
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %5, label %.loopexit

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 12
  %7 = load i32, ptr %6, align 4, !tbaa !11
  %8 = sext i32 %7 to i64
  %9 = icmp slt i32 %7, 0
  %10 = shl nsw i64 %8, 2
  %11 = select i1 %9, i64 -1, i64 %10
  %12 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %11) #2
  store ptr %12, ptr %2, align 8, !tbaa !5
  %13 = icmp sgt i32 %7, 0
  br i1 %13, label %.lr.ph17, label %.loopexit

.lr.ph17:                                         ; preds = %5
  %14 = getelementptr inbounds i8, ptr %0, i64 24
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  %16 = getelementptr inbounds i8, ptr %0, i64 16
  %17 = load ptr, ptr %16, align 8
  %wide.trip.count22 = zext nneg i32 %7 to i64
  br label %18

18:                                               ; preds = %.lr.ph17, %.critedge
  %indvars.iv19 = phi i64 [ 0, %.lr.ph17 ], [ %indvars.iv.next20, %.critedge ]
  %19 = getelementptr inbounds i32, ptr %15, i64 %indvars.iv19
  %20 = load i32, ptr %19, align 4, !tbaa !13
  %indvars.iv.next20 = add nuw nsw i64 %indvars.iv19, 1
  %21 = getelementptr inbounds i32, ptr %15, i64 %indvars.iv.next20
  %22 = load i32, ptr %21, align 4, !tbaa !13
  %23 = icmp slt i32 %20, %22
  br i1 %23, label %.lr.ph.preheader, label %.critedge

.lr.ph.preheader:                                 ; preds = %18
  %24 = sext i32 %20 to i64
  %wide.trip.count = sext i32 %22 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %29
  %indvars.iv = phi i64 [ %24, %.lr.ph.preheader ], [ %indvars.iv.next, %29 ]
  %25 = getelementptr inbounds i32, ptr %17, i64 %indvars.iv
  %26 = load i32, ptr %25, align 4, !tbaa !13
  %27 = sext i32 %26 to i64
  %28 = icmp sgt i64 %indvars.iv19, %27
  br i1 %28, label %29, label %.critedge.loopexit.split.loop.exit24

29:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.critedge, label %.lr.ph, !llvm.loop !14

.critedge.loopexit.split.loop.exit24:             ; preds = %.lr.ph
  %30 = trunc nsw i64 %indvars.iv to i32
  br label %.critedge

.critedge:                                        ; preds = %29, %.critedge.loopexit.split.loop.exit24, %18
  %.010.lcssa = phi i32 [ %20, %18 ], [ %30, %.critedge.loopexit.split.loop.exit24 ], [ %22, %29 ]
  %31 = getelementptr inbounds i32, ptr %12, i64 %indvars.iv19
  store i32 %.010.lcssa, ptr %31, align 4, !tbaa !13
  %exitcond23.not = icmp eq i64 %indvars.iv.next20, %wide.trip.count22
  br i1 %exitcond23.not, label %.loopexit, label %18, !llvm.loop !16

.loopexit:                                        ; preds = %.critedge, %5, %1
  %32 = phi ptr [ %12, %5 ], [ %3, %1 ], [ %12, %.critedge ]
  ret ptr %32
}

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 = { 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, !10, i64 32}
!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 = !{!6, !10, i64 24}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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