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

; 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::DenseVector" = type { %"class.SimTKIpopt::Vector.base", ptr, ptr, i8, i8, double }
%"class.SimTKIpopt::Vector.base" = type <{ %"class.SimTKIpopt::TaggedObject", %"class.SimTKIpopt::SmartPtr", %"class.SimTKIpopt::CachedResults", i32, [4 x i8], double, i32, [4 x i8], double, i32, [4 x i8], double, i32, [4 x i8], double, i32, [4 x i8], double, i32, [4 x i8], double, i32, [4 x i8], double, i32, i8 }>
%"class.SimTKIpopt::TaggedObject" = type { %"class.SimTKIpopt::ReferencedObject.base", %"class.SimTKIpopt::Subject", i32, i32 }
%"class.SimTKIpopt::ReferencedObject.base" = type <{ ptr, i32 }>
%"class.SimTKIpopt::Subject" = type { ptr, %"class.std::vector.0" }
%"class.std::vector.0" = type { %"struct.std::_Vector_base.1" }
%"struct.std::_Vector_base.1" = type { %"struct.std::_Vector_base<SimTKIpopt::Observer *, std::allocator<SimTKIpopt::Observer *>>::_Vector_impl" }
%"struct.std::_Vector_base<SimTKIpopt::Observer *, std::allocator<SimTKIpopt::Observer *>>::_Vector_impl" = type { %"struct.std::_Vector_base<SimTKIpopt::Observer *, std::allocator<SimTKIpopt::Observer *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<SimTKIpopt::Observer *, std::allocator<SimTKIpopt::Observer *>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.SimTKIpopt::SmartPtr" = type { ptr }
%"class.SimTKIpopt::CachedResults" = type { ptr, i32, 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: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZNK10SimTKIpopt6Vector3DimEv(ptr noundef nonnull align 8 dereferenceable(205)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10SimTKIpopt11DenseVector25ElementWiseReciprocalImplEv(ptr noundef nonnull align 8 dereferenceable(240) %0) unnamed_addr #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  %5 = getelementptr inbounds %"class.SimTKIpopt::DenseVector", ptr %4, i32 0, i32 4
  %6 = load i8, ptr %5, align 1, !tbaa !9, !range !24, !noundef !25
  %7 = trunc i8 %6 to i1
  br i1 %7, label %8, label %13

8:                                                ; preds = %1
  %9 = getelementptr inbounds %"class.SimTKIpopt::DenseVector", ptr %4, i32 0, i32 5
  %10 = load double, ptr %9, align 8, !tbaa !26
  %11 = fdiv double 1.000000e+00, %10
  %12 = getelementptr inbounds %"class.SimTKIpopt::DenseVector", ptr %4, i32 0, i32 5
  store double %11, ptr %12, align 8, !tbaa !26
  br label %36

13:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !27
  br label %14

14:                                               ; preds = %32, %13
  %15 = load i32, ptr %3, align 4, !tbaa !27
  %16 = call noundef i32 @_ZNK10SimTKIpopt6Vector3DimEv(ptr noundef nonnull align 8 dereferenceable(205) %4)
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %35

19:                                               ; preds = %14
  %20 = getelementptr inbounds %"class.SimTKIpopt::DenseVector", ptr %4, i32 0, i32 2
  %21 = load ptr, ptr %20, align 8, !tbaa !28
  %22 = load i32, ptr %3, align 4, !tbaa !27
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds double, ptr %21, i64 %23
  %25 = load double, ptr %24, align 8, !tbaa !29
  %26 = fdiv double 1.000000e+00, %25
  %27 = getelementptr inbounds %"class.SimTKIpopt::DenseVector", ptr %4, i32 0, i32 2
  %28 = load ptr, ptr %27, align 8, !tbaa !28
  %29 = load i32, ptr %3, align 4, !tbaa !27
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds double, ptr %28, i64 %30
  store double %26, ptr %31, align 8, !tbaa !29
  br label %32

32:                                               ; preds = %19
  %33 = load i32, ptr %3, align 4, !tbaa !27
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %3, align 4, !tbaa !27
  br label %14, !llvm.loop !30

35:                                               ; preds = %18
  br label %36

36:                                               ; preds = %35, %8
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 = { 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 #3 = { 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, !23, i64 225}
!10 = !{!"_ZTSN10SimTKIpopt11DenseVectorE", !11, i64 0, !6, i64 208, !6, i64 216, !23, i64 224, !23, i64 225, !22, i64 232}
!11 = !{!"_ZTSN10SimTKIpopt6VectorE", !12, i64 0, !20, i64 56, !21, i64 64, !14, i64 88, !22, i64 96, !14, i64 104, !22, i64 112, !14, i64 120, !22, i64 128, !14, i64 136, !22, i64 144, !14, i64 152, !22, i64 160, !14, i64 168, !22, i64 176, !14, i64 184, !22, i64 192, !14, i64 200, !23, i64 204}
!12 = !{!"_ZTSN10SimTKIpopt12TaggedObjectE", !13, i64 0, !15, i64 16, !14, i64 48, !14, i64 52}
!13 = !{!"_ZTSN10SimTKIpopt16ReferencedObjectE", !14, i64 8}
!14 = !{!"int", !7, i64 0}
!15 = !{!"_ZTSN10SimTKIpopt7SubjectE", !16, i64 8}
!16 = !{!"_ZTSSt6vectorIPN10SimTKIpopt8ObserverESaIS2_EE", !17, i64 0}
!17 = !{!"_ZTSSt12_Vector_baseIPN10SimTKIpopt8ObserverESaIS2_EE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseIPN10SimTKIpopt8ObserverESaIS2_EE12_Vector_implE", !19, i64 0}
!19 = !{!"_ZTSNSt12_Vector_baseIPN10SimTKIpopt8ObserverESaIS2_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!20 = !{!"_ZTSN10SimTKIpopt8SmartPtrIKNS_11VectorSpaceEEE", !6, i64 0}
!21 = !{!"_ZTSN10SimTKIpopt13CachedResultsIdEE", !14, i64 8, !6, i64 16}
!22 = !{!"double", !7, i64 0}
!23 = !{!"bool", !7, i64 0}
!24 = !{i8 0, i8 2}
!25 = !{}
!26 = !{!10, !22, i64 232}
!27 = !{!14, !14, i64 0}
!28 = !{!10, !6, i64 216}
!29 = !{!22, !22, i64 0}
!30 = distinct !{!30, !31}
!31 = !{!"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: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZNK10SimTKIpopt6Vector3DimEv(ptr noundef nonnull align 8 dereferenceable(205)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10SimTKIpopt11DenseVector25ElementWiseReciprocalImplEv(ptr noundef nonnull align 8 dereferenceable(240) %0) unnamed_addr #1 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 225
  %3 = load i8, ptr %2, align 1, !tbaa !5, !range !23, !noundef !24
  %4 = trunc nuw i8 %3 to i1
  br i1 %4, label %8, label %.preheader

.preheader:                                       ; preds = %1
  %5 = tail call noundef i32 @_ZNK10SimTKIpopt6Vector3DimEv(ptr noundef nonnull align 8 dereferenceable(205) %0)
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %7 = getelementptr inbounds i8, ptr %0, i64 216
  br label %12

8:                                                ; preds = %1
  %9 = getelementptr inbounds i8, ptr %0, i64 232
  %10 = load double, ptr %9, align 8, !tbaa !25
  %11 = fdiv double 1.000000e+00, %10
  store double %11, ptr %9, align 8, !tbaa !25
  br label %.loopexit

12:                                               ; preds = %.lr.ph, %12
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %12 ]
  %13 = load ptr, ptr %7, align 8, !tbaa !26
  %14 = getelementptr inbounds double, ptr %13, i64 %indvars.iv
  %15 = load double, ptr %14, align 8, !tbaa !27
  %16 = fdiv double 1.000000e+00, %15
  store double %16, ptr %14, align 8, !tbaa !27
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %17 = tail call noundef i32 @_ZNK10SimTKIpopt6Vector3DimEv(ptr noundef nonnull align 8 dereferenceable(205) %0)
  %18 = sext i32 %17 to i64
  %19 = icmp slt i64 %indvars.iv.next, %18
  br i1 %19, label %12, label %.loopexit, !llvm.loop !28

.loopexit:                                        ; preds = %12, %.preheader, %8
  ret void
}

attributes #0 = { inlinehint 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 #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" }

!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, !22, i64 225}
!6 = !{!"_ZTSN10SimTKIpopt11DenseVectorE", !7, i64 0, !18, i64 208, !18, i64 216, !22, i64 224, !22, i64 225, !21, i64 232}
!7 = !{!"_ZTSN10SimTKIpopt6VectorE", !8, i64 0, !19, i64 56, !20, i64 64, !10, i64 88, !21, i64 96, !10, i64 104, !21, i64 112, !10, i64 120, !21, i64 128, !10, i64 136, !21, i64 144, !10, i64 152, !21, i64 160, !10, i64 168, !21, i64 176, !10, i64 184, !21, i64 192, !10, i64 200, !22, i64 204}
!8 = !{!"_ZTSN10SimTKIpopt12TaggedObjectE", !9, i64 0, !13, i64 16, !10, i64 48, !10, i64 52}
!9 = !{!"_ZTSN10SimTKIpopt16ReferencedObjectE", !10, i64 8}
!10 = !{!"int", !11, i64 0}
!11 = !{!"omnipotent char", !12, i64 0}
!12 = !{!"Simple C++ TBAA"}
!13 = !{!"_ZTSN10SimTKIpopt7SubjectE", !14, i64 8}
!14 = !{!"_ZTSSt6vectorIPN10SimTKIpopt8ObserverESaIS2_EE", !15, i64 0}
!15 = !{!"_ZTSSt12_Vector_baseIPN10SimTKIpopt8ObserverESaIS2_EE", !16, i64 0}
!16 = !{!"_ZTSNSt12_Vector_baseIPN10SimTKIpopt8ObserverESaIS2_EE12_Vector_implE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseIPN10SimTKIpopt8ObserverESaIS2_EE17_Vector_impl_dataE", !18, i64 0, !18, i64 8, !18, i64 16}
!18 = !{!"any pointer", !11, i64 0}
!19 = !{!"_ZTSN10SimTKIpopt8SmartPtrIKNS_11VectorSpaceEEE", !18, i64 0}
!20 = !{!"_ZTSN10SimTKIpopt13CachedResultsIdEE", !10, i64 8, !18, i64 16}
!21 = !{!"double", !11, i64 0}
!22 = !{!"bool", !11, i64 0}
!23 = !{i8 0, i8 2}
!24 = !{}
!25 = !{!6, !21, i64 232}
!26 = !{!6, !18, i64 216}
!27 = !{!21, !21, i64 0}
!28 = distinct !{!28, !29}
!29 = !{!"llvm.loop.mustprogress"}


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