; LLVM IR from simbody/simbody :: SimTKmath/Optimizers/src/IpOpt (IpCompoundMatrix)

; 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.SimTKIpopt::CompoundMatrixSpace" = type <{ %"class.SimTKIpopt::MatrixSpace.base", i32, i32, i8, [3 x i8], %"class.std::vector.16", %"class.std::vector.21", %"class.std::vector.26", %"class.std::vector.26", i8, [7 x i8] }>
%"class.SimTKIpopt::MatrixSpace.base" = type { %"class.SimTKIpopt::ReferencedObject.base", i32, i32 }
%"class.SimTKIpopt::ReferencedObject.base" = type <{ ptr, i32 }>
%"class.std::vector.16" = type { %"struct.std::_Vector_base.17" }
%"struct.std::_Vector_base.17" = type { %"struct.std::_Vector_base<std::vector<SimTKIpopt::SmartPtr<const SimTKIpopt::MatrixSpace>>, std::allocator<std::vector<SimTKIpopt::SmartPtr<const SimTKIpopt::MatrixSpace>>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::vector<SimTKIpopt::SmartPtr<const SimTKIpopt::MatrixSpace>>, std::allocator<std::vector<SimTKIpopt::SmartPtr<const SimTKIpopt::MatrixSpace>>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::vector<SimTKIpopt::SmartPtr<const SimTKIpopt::MatrixSpace>>, std::allocator<std::vector<SimTKIpopt::SmartPtr<const SimTKIpopt::MatrixSpace>>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::vector<SimTKIpopt::SmartPtr<const SimTKIpopt::MatrixSpace>>, std::allocator<std::vector<SimTKIpopt::SmartPtr<const SimTKIpopt::MatrixSpace>>>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.21" = type { %"struct.std::_Vector_base.22" }
%"struct.std::_Vector_base.22" = type { %"struct.std::_Vector_base<std::vector<bool>, std::allocator<std::vector<bool>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::vector<bool>, std::allocator<std::vector<bool>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::vector<bool>, std::allocator<std::vector<bool>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::vector<bool>, std::allocator<std::vector<bool>>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.26" = type { %"struct.std::_Vector_base.27" }
%"struct.std::_Vector_base.27" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; 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: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZNK10SimTKIpopt19CompoundMatrixSpace13DimensionsSetEv(ptr noundef nonnull align 8 dereferenceable(129) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %9 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #2
  store i8 1, ptr %5, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %32, %1
  %11 = load i32, ptr %6, align 4, !tbaa !9
  %12 = getelementptr inbounds %"class.SimTKIpopt::CompoundMatrixSpace", ptr %9, i32 0, i32 1
  %13 = load i32, ptr %12, align 4, !tbaa !13
  %14 = icmp slt i32 %11, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %10
  store i32 2, ptr %7, align 4
  br label %35

16:                                               ; preds = %10
  %17 = getelementptr inbounds %"class.SimTKIpopt::CompoundMatrixSpace", ptr %9, i32 0, i32 7
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %17, i64 noundef %19) #2
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = icmp eq i32 %21, -1
  br i1 %22, label %23, label %24

23:                                               ; preds = %16
  store i8 0, ptr %5, align 1, !tbaa !11
  store i32 2, ptr %7, align 4
  br label %35

24:                                               ; preds = %16
  %25 = getelementptr inbounds %"class.SimTKIpopt::CompoundMatrixSpace", ptr %9, i32 0, i32 7
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %25, i64 noundef %27) #2
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %30 = load i32, ptr %3, align 4, !tbaa !9
  %31 = add nsw i32 %30, %29
  store i32 %31, ptr %3, align 4, !tbaa !9
  br label %32

32:                                               ; preds = %24
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %6, align 4, !tbaa !9
  br label %10, !llvm.loop !29

35:                                               ; preds = %23, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %36

36:                                               ; preds = %35
  %37 = load i8, ptr %5, align 1, !tbaa !11, !range !31, !noundef !32
  %38 = trunc i8 %37 to i1
  br i1 %38, label %39, label %67

39:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %62, %39
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = getelementptr inbounds %"class.SimTKIpopt::CompoundMatrixSpace", ptr %9, i32 0, i32 2
  %43 = load i32, ptr %42, align 8, !tbaa !33
  %44 = icmp slt i32 %41, %43
  br i1 %44, label %46, label %45

45:                                               ; preds = %40
  store i32 5, ptr %7, align 4
  br label %65

46:                                               ; preds = %40
  %47 = getelementptr inbounds %"class.SimTKIpopt::CompoundMatrixSpace", ptr %9, i32 0, i32 8
  %48 = load i32, ptr %8, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %47, i64 noundef %49) #2
  %51 = load i32, ptr %50, align 4, !tbaa !9
  %52 = icmp eq i32 %51, -1
  br i1 %52, label %53, label %54

53:                                               ; preds = %46
  store i8 0, ptr %5, align 1, !tbaa !11
  store i32 5, ptr %7, align 4
  br label %65

54:                                               ; preds = %46
  %55 = getelementptr inbounds %"class.SimTKIpopt::CompoundMatrixSpace", ptr %9, i32 0, i32 8
  %56 = load i32, ptr %8, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %55, i64 noundef %57) #2
  %59 = load i32, ptr %58, align 4, !tbaa !9
  %60 = load i32, ptr %4, align 4, !tbaa !9
  %61 = add nsw i32 %60, %59
  store i32 %61, ptr %4, align 4, !tbaa !9
  br label %62

62:                                               ; preds = %54
  %63 = load i32, ptr %8, align 4, !tbaa !9
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %8, align 4, !tbaa !9
  br label %40, !llvm.loop !34

65:                                               ; preds = %53, %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %66

66:                                               ; preds = %65
  br label %67

67:                                               ; preds = %66, %36
  %68 = load i8, ptr %5, align 1, !tbaa !11, !range !31, !noundef !32
  %69 = trunc i8 %68 to i1
  br i1 %69, label %70, label %71

70:                                               ; preds = %67
  br label %71

71:                                               ; preds = %70, %67
  %72 = load i8, ptr %5, align 1, !tbaa !11, !range !31, !noundef !32
  %73 = trunc i8 %72 to i1
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i1 %73
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!14, !10, i64 20}
!14 = !{!"_ZTSN10SimTKIpopt19CompoundMatrixSpaceE", !15, i64 0, !10, i64 20, !10, i64 24, !12, i64 28, !17, i64 32, !21, i64 56, !25, i64 80, !25, i64 104, !12, i64 128}
!15 = !{!"_ZTSN10SimTKIpopt11MatrixSpaceE", !16, i64 0, !10, i64 12, !10, i64 16}
!16 = !{!"_ZTSN10SimTKIpopt16ReferencedObjectE", !10, i64 8}
!17 = !{!"_ZTSSt6vectorIS_IN10SimTKIpopt8SmartPtrIKNS0_11MatrixSpaceEEESaIS4_EESaIS6_EE", !18, i64 0}
!18 = !{!"_ZTSSt12_Vector_baseISt6vectorIN10SimTKIpopt8SmartPtrIKNS1_11MatrixSpaceEEESaIS5_EESaIS7_EE", !19, i64 0}
!19 = !{!"_ZTSNSt12_Vector_baseISt6vectorIN10SimTKIpopt8SmartPtrIKNS1_11MatrixSpaceEEESaIS5_EESaIS7_EE12_Vector_implE", !20, i64 0}
!20 = !{!"_ZTSNSt12_Vector_baseISt6vectorIN10SimTKIpopt8SmartPtrIKNS1_11MatrixSpaceEEESaIS5_EESaIS7_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!21 = !{!"_ZTSSt6vectorIS_IbSaIbEESaIS1_EE", !22, i64 0}
!22 = !{!"_ZTSSt12_Vector_baseISt6vectorIbSaIbEESaIS2_EE", !23, i64 0}
!23 = !{!"_ZTSNSt12_Vector_baseISt6vectorIbSaIbEESaIS2_EE12_Vector_implE", !24, i64 0}
!24 = !{!"_ZTSNSt12_Vector_baseISt6vectorIbSaIbEESaIS2_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!25 = !{!"_ZTSSt6vectorIiSaIiEE", !26, i64 0}
!26 = !{!"_ZTSSt12_Vector_baseIiSaIiEE", !27, i64 0}
!27 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE12_Vector_implE", !28, i64 0}
!28 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!29 = distinct !{!29, !30}
!30 = !{!"llvm.loop.mustprogress"}
!31 = !{i8 0, i8 2}
!32 = !{}
!33 = !{!14, !10, i64 24}
!34 = distinct !{!34, !30}


; 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: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZNK10SimTKIpopt19CompoundMatrixSpace13DimensionsSetEv(ptr noundef nonnull align 8 dereferenceable(129) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 20
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph, label %.preheader

.lr.ph:                                           ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 80
  br label %10

.preheader:                                       ; preds = %14, %1
  %6 = getelementptr inbounds i8, ptr %0, i64 104
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = load i32, ptr %7, align 8, !tbaa !26
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph21, label %.thread

10:                                               ; preds = %.lr.ph, %14
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %14 ]
  %11 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %5, i64 noundef %indvars.iv) #1
  %12 = load i32, ptr %11, align 4, !tbaa !27
  %13 = icmp eq i32 %12, -1
  br i1 %13, label %.thread, label %14

14:                                               ; preds = %10
  %15 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %5, i64 noundef %indvars.iv) #1
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = icmp slt i64 %indvars.iv.next, %17
  br i1 %18, label %10, label %.preheader, !llvm.loop !28

.lr.ph21:                                         ; preds = %.preheader, %21
  %indvars.iv26 = phi i64 [ %indvars.iv.next27, %21 ], [ 0, %.preheader ]
  %19 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %6, i64 noundef %indvars.iv26) #1
  %20 = load i32, ptr %19, align 4, !tbaa !27
  %.not = icmp ne i32 %20, -1
  br i1 %.not, label %21, label %.thread

21:                                               ; preds = %.lr.ph21
  %22 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNKSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %6, i64 noundef %indvars.iv26) #1
  %indvars.iv.next27 = add nuw nsw i64 %indvars.iv26, 1
  %23 = load i32, ptr %7, align 8, !tbaa !26
  %24 = sext i32 %23 to i64
  %25 = icmp slt i64 %indvars.iv.next27, %24
  br i1 %25, label %.lr.ph21, label %.thread, !llvm.loop !30

.thread:                                          ; preds = %10, %.lr.ph21, %21, %.preheader
  %.2 = phi i1 [ true, %.preheader ], [ %.not, %21 ], [ %.not, %.lr.ph21 ], [ false, %10 ]
  ret i1 %.2
}

attributes #0 = { mustprogress 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 = { 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, !9, i64 20}
!6 = !{!"_ZTSN10SimTKIpopt19CompoundMatrixSpaceE", !7, i64 0, !9, i64 20, !9, i64 24, !12, i64 28, !13, i64 32, !18, i64 56, !22, i64 80, !22, i64 104, !12, i64 128}
!7 = !{!"_ZTSN10SimTKIpopt11MatrixSpaceE", !8, i64 0, !9, i64 12, !9, i64 16}
!8 = !{!"_ZTSN10SimTKIpopt16ReferencedObjectE", !9, i64 8}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{!"bool", !10, i64 0}
!13 = !{!"_ZTSSt6vectorIS_IN10SimTKIpopt8SmartPtrIKNS0_11MatrixSpaceEEESaIS4_EESaIS6_EE", !14, i64 0}
!14 = !{!"_ZTSSt12_Vector_baseISt6vectorIN10SimTKIpopt8SmartPtrIKNS1_11MatrixSpaceEEESaIS5_EESaIS7_EE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseISt6vectorIN10SimTKIpopt8SmartPtrIKNS1_11MatrixSpaceEEESaIS5_EESaIS7_EE12_Vector_implE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseISt6vectorIN10SimTKIpopt8SmartPtrIKNS1_11MatrixSpaceEEESaIS5_EESaIS7_EE17_Vector_impl_dataE", !17, i64 0, !17, i64 8, !17, i64 16}
!17 = !{!"any pointer", !10, i64 0}
!18 = !{!"_ZTSSt6vectorIS_IbSaIbEESaIS1_EE", !19, i64 0}
!19 = !{!"_ZTSSt12_Vector_baseISt6vectorIbSaIbEESaIS2_EE", !20, i64 0}
!20 = !{!"_ZTSNSt12_Vector_baseISt6vectorIbSaIbEESaIS2_EE12_Vector_implE", !21, i64 0}
!21 = !{!"_ZTSNSt12_Vector_baseISt6vectorIbSaIbEESaIS2_EE17_Vector_impl_dataE", !17, i64 0, !17, i64 8, !17, i64 16}
!22 = !{!"_ZTSSt6vectorIiSaIiEE", !23, i64 0}
!23 = !{!"_ZTSSt12_Vector_baseIiSaIiEE", !24, i64 0}
!24 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE12_Vector_implE", !25, i64 0}
!25 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE17_Vector_impl_dataE", !17, i64 0, !17, i64 8, !17, i64 16}
!26 = !{!6, !9, i64 24}
!27 = !{!9, !9, i64 0}
!28 = distinct !{!28, !29}
!29 = !{!"llvm.loop.mustprogress"}
!30 = distinct !{!30, !29}


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