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

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

@_ZTIN10SimTKIpopt6VectorE = external dso_local constant { ptr, ptr, ptr }, align 8
@_ZTIN10SimTKIpopt11DenseVectorE = external constant 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 uwtable
declare dso_local void @_ZN10SimTKIpopt12TaggedObject13ObjectChangedEv(ptr noundef nonnull align 8 dereferenceable(56)) #1 align 2

declare void @_ZN10SimTKIpopt6Vector4ScalEd(ptr noundef nonnull align 8 dereferenceable(205), double noundef) #2

; Function Attrs: nounwind willreturn memory(read)
declare ptr @__dynamic_cast(ptr, ptr, ptr, i64) #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK10SimTKIpopt11DenseVector13IsHomogeneousEv(ptr noundef nonnull align 8 dereferenceable(240)) #4 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK10SimTKIpopt11DenseVector6ScalarEv(ptr noundef nonnull align 8 dereferenceable(240)) #4 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZNK10SimTKIpopt6Matrix5NColsEv(ptr noundef nonnull align 8 dereferenceable(69)) #5 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK10SimTKIpopt11DenseVector6ValuesEv(ptr noundef nonnull align 8 dereferenceable(240)) #6 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN10SimTKIpopt17MultiVectorMatrix3VecEi(ptr noundef nonnull align 8 dereferenceable(128), i32 noundef) #6 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10SimTKIpopt17MultiVectorMatrix12ScaleColumnsERKNS_6VectorE(ptr noundef nonnull align 8 dereferenceable(128) %0, ptr noundef nonnull align 8 dereferenceable(205) %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %10 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #7
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %15, label %13

13:                                               ; preds = %2
  %14 = call ptr @__dynamic_cast(ptr %11, ptr @_ZTIN10SimTKIpopt6VectorE, ptr @_ZTIN10SimTKIpopt11DenseVectorE, i64 0) #7
  br label %16

15:                                               ; preds = %2
  br label %16

16:                                               ; preds = %15, %13
  %17 = phi ptr [ %14, %13 ], [ null, %15 ]
  store ptr %17, ptr %5, align 8, !tbaa !5
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = call noundef zeroext i1 @_ZNK10SimTKIpopt11DenseVector13IsHomogeneousEv(ptr noundef nonnull align 8 dereferenceable(240) %18)
  br i1 %19, label %20, label %36

20:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #7
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = call noundef double @_ZNK10SimTKIpopt11DenseVector6ScalarEv(ptr noundef nonnull align 8 dereferenceable(240) %21)
  store double %22, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #7
  store i32 0, ptr %7, align 4, !tbaa !11
  br label %23

23:                                               ; preds = %32, %20
  %24 = load i32, ptr %7, align 4, !tbaa !11
  %25 = call noundef i32 @_ZNK10SimTKIpopt6Matrix5NColsEv(ptr noundef nonnull align 8 dereferenceable(69) %10)
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %28, label %27

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

28:                                               ; preds = %23
  %29 = load i32, ptr %7, align 4, !tbaa !11
  %30 = call noundef ptr @_ZN10SimTKIpopt17MultiVectorMatrix3VecEi(ptr noundef nonnull align 8 dereferenceable(128) %10, i32 noundef %29)
  %31 = load double, ptr %6, align 8, !tbaa !9
  call void @_ZN10SimTKIpopt6Vector4ScalEd(ptr noundef nonnull align 8 dereferenceable(205) %30, double noundef %31)
  br label %32

32:                                               ; preds = %28
  %33 = load i32, ptr %7, align 4, !tbaa !11
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %7, align 4, !tbaa !11
  br label %23, !llvm.loop !13

35:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #7
  br label %56

36:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #7
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = call noundef ptr @_ZNK10SimTKIpopt11DenseVector6ValuesEv(ptr noundef nonnull align 8 dereferenceable(240) %37)
  store ptr %38, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #7
  store i32 0, ptr %9, align 4, !tbaa !11
  br label %39

39:                                               ; preds = %52, %36
  %40 = load i32, ptr %9, align 4, !tbaa !11
  %41 = call noundef i32 @_ZNK10SimTKIpopt6Matrix5NColsEv(ptr noundef nonnull align 8 dereferenceable(69) %10)
  %42 = icmp slt i32 %40, %41
  br i1 %42, label %44, label %43

43:                                               ; preds = %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #7
  br label %55

44:                                               ; preds = %39
  %45 = load i32, ptr %9, align 4, !tbaa !11
  %46 = call noundef ptr @_ZN10SimTKIpopt17MultiVectorMatrix3VecEi(ptr noundef nonnull align 8 dereferenceable(128) %10, i32 noundef %45)
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = load i32, ptr %9, align 4, !tbaa !11
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds double, ptr %47, i64 %49
  %51 = load double, ptr %50, align 8, !tbaa !9
  call void @_ZN10SimTKIpopt6Vector4ScalEd(ptr noundef nonnull align 8 dereferenceable(205) %46, double noundef %51)
  br label %52

52:                                               ; preds = %44
  %53 = load i32, ptr %9, align 4, !tbaa !11
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %9, align 4, !tbaa !11
  br label %39, !llvm.loop !15

55:                                               ; preds = %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #7
  br label %56

56:                                               ; preds = %55, %35
  call void @_ZN10SimTKIpopt12TaggedObject13ObjectChangedEv(ptr noundef nonnull align 8 dereferenceable(56) %10)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #7
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 willreturn memory(read) }
attributes #4 = { 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 #5 = { 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 #6 = { inlinehint 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 #7 = { 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 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

@_ZTIN10SimTKIpopt6VectorE = external dso_local constant { ptr, ptr, ptr }, align 8
@_ZTIN10SimTKIpopt11DenseVectorE = external constant ptr

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN10SimTKIpopt12TaggedObject13ObjectChangedEv(ptr noundef nonnull align 8 dereferenceable(56)) local_unnamed_addr #0 align 2

declare void @_ZN10SimTKIpopt6Vector4ScalEd(ptr noundef nonnull align 8 dereferenceable(205), double noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(read)
declare ptr @__dynamic_cast(ptr, ptr, ptr, i64) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK10SimTKIpopt11DenseVector13IsHomogeneousEv(ptr noundef nonnull align 8 dereferenceable(240)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK10SimTKIpopt11DenseVector6ScalarEv(ptr noundef nonnull align 8 dereferenceable(240)) local_unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZNK10SimTKIpopt6Matrix5NColsEv(ptr noundef nonnull align 8 dereferenceable(69)) local_unnamed_addr #4 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK10SimTKIpopt11DenseVector6ValuesEv(ptr noundef nonnull align 8 dereferenceable(240)) local_unnamed_addr #5 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN10SimTKIpopt17MultiVectorMatrix3VecEi(ptr noundef nonnull align 8 dereferenceable(128), i32 noundef) local_unnamed_addr #5 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10SimTKIpopt17MultiVectorMatrix12ScaleColumnsERKNS_6VectorE(ptr noundef nonnull align 8 dereferenceable(128) %0, ptr noundef nonnull align 8 dereferenceable(205) %1) local_unnamed_addr #0 align 2 {
  %3 = tail call ptr @__dynamic_cast(ptr nonnull %1, ptr nonnull @_ZTIN10SimTKIpopt6VectorE, ptr nonnull @_ZTIN10SimTKIpopt11DenseVectorE, i64 0) #6
  %4 = tail call noundef zeroext i1 @_ZNK10SimTKIpopt11DenseVector13IsHomogeneousEv(ptr noundef nonnull align 8 dereferenceable(240) %3)
  br i1 %4, label %5, label %13

5:                                                ; preds = %2
  %6 = tail call noundef double @_ZNK10SimTKIpopt11DenseVector6ScalarEv(ptr noundef nonnull align 8 dereferenceable(240) %3)
  %7 = tail call noundef i32 @_ZNK10SimTKIpopt6Matrix5NColsEv(ptr noundef nonnull align 8 dereferenceable(69) %0)
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph17, label %.loopexit

.lr.ph17:                                         ; preds = %5, %.lr.ph17
  %.01316 = phi i32 [ %10, %.lr.ph17 ], [ 0, %5 ]
  %9 = tail call noundef ptr @_ZN10SimTKIpopt17MultiVectorMatrix3VecEi(ptr noundef nonnull align 8 dereferenceable(128) %0, i32 noundef %.01316)
  tail call void @_ZN10SimTKIpopt6Vector4ScalEd(ptr noundef nonnull align 8 dereferenceable(205) %9, double noundef %6)
  %10 = add nuw nsw i32 %.01316, 1
  %11 = tail call noundef i32 @_ZNK10SimTKIpopt6Matrix5NColsEv(ptr noundef nonnull align 8 dereferenceable(69) %0)
  %12 = icmp slt i32 %10, %11
  br i1 %12, label %.lr.ph17, label %.loopexit, !llvm.loop !5

13:                                               ; preds = %2
  %14 = tail call noundef ptr @_ZNK10SimTKIpopt11DenseVector6ValuesEv(ptr noundef nonnull align 8 dereferenceable(240) %3)
  %15 = tail call noundef i32 @_ZNK10SimTKIpopt6Matrix5NColsEv(ptr noundef nonnull align 8 dereferenceable(69) %0)
  %16 = icmp sgt i32 %15, 0
  br i1 %16, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %13, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %13 ]
  %17 = trunc nuw nsw i64 %indvars.iv to i32
  %18 = tail call noundef ptr @_ZN10SimTKIpopt17MultiVectorMatrix3VecEi(ptr noundef nonnull align 8 dereferenceable(128) %0, i32 noundef %17)
  %19 = getelementptr inbounds double, ptr %14, i64 %indvars.iv
  %20 = load double, ptr %19, align 8, !tbaa !7
  tail call void @_ZN10SimTKIpopt6Vector4ScalEd(ptr noundef nonnull align 8 dereferenceable(205) %18, double noundef %20)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %21 = tail call noundef i32 @_ZNK10SimTKIpopt6Matrix5NColsEv(ptr noundef nonnull align 8 dereferenceable(69) %0)
  %22 = sext i32 %21 to i64
  %23 = icmp slt i64 %indvars.iv.next, %22
  br i1 %23, label %.lr.ph, label %.loopexit, !llvm.loop !11

.loopexit:                                        ; preds = %.lr.ph, %.lr.ph17, %13, %5
  tail call void @_ZN10SimTKIpopt12TaggedObject13ObjectChangedEv(ptr noundef nonnull align 8 dereferenceable(56) %0)
  ret void
}

attributes #0 = { 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 = { "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 nofree nounwind willreturn memory(read) }
attributes #3 = { 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 #4 = { 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 #5 = { inlinehint 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 #6 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"double", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = distinct !{!11, !6}


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