; 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
define dso_local void @_ZNK10SimTKIpopt17MultiVectorMatrix14MultVectorImplEdRKNS_6VectorEdRS1_(ptr noundef nonnull align 8 dereferenceable(128) %0, double noundef %1, ptr noundef nonnull align 8 dereferenceable(205) %2, double noundef %3, ptr noundef nonnull align 8 dereferenceable(205) %4) unnamed_addr #1 align 2 {
  %6 = alloca ptr, align 8
  %7 = alloca double, align 8
  %8 = alloca ptr, align 8
  %9 = alloca double, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca double, align 8
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store double %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store double %3, ptr %9, align 8, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !5
  %16 = load ptr, ptr %6, align 8
  %17 = load double, ptr %9, align 8, !tbaa !9
  %18 = fcmp une double %17, 0.000000e+00
  br i1 %18, label %19, label %22

19:                                               ; preds = %5
  %20 = load ptr, ptr %10, align 8, !tbaa !5
  %21 = load double, ptr %9, align 8, !tbaa !9
  call void @_ZN10SimTKIpopt6Vector4ScalEd(ptr noundef nonnull align 8 dereferenceable(205) %20, double noundef %21)
  br label %24

22:                                               ; preds = %5
  %23 = load ptr, ptr %10, align 8, !tbaa !5
  call void @_ZN10SimTKIpopt6Vector3SetEd(ptr noundef nonnull align 8 dereferenceable(205) %23, double noundef 0.000000e+00)
  br label %24

24:                                               ; preds = %22, %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #7
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = icmp eq ptr %25, null
  br i1 %26, label %29, label %27

27:                                               ; preds = %24
  %28 = call ptr @__dynamic_cast(ptr %25, ptr @_ZTIN10SimTKIpopt6VectorE, ptr @_ZTIN10SimTKIpopt11DenseVectorE, i64 0) #7
  br label %30

29:                                               ; preds = %24
  br label %30

30:                                               ; preds = %29, %27
  %31 = phi ptr [ %28, %27 ], [ null, %29 ]
  store ptr %31, ptr %11, align 8, !tbaa !5
  %32 = load ptr, ptr %11, align 8, !tbaa !5
  %33 = call noundef zeroext i1 @_ZNK10SimTKIpopt11DenseVector13IsHomogeneousEv(ptr noundef nonnull align 8 dereferenceable(240) %32)
  br i1 %33, label %34, label %53

34:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #7
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  %36 = call noundef double @_ZNK10SimTKIpopt11DenseVector6ScalarEv(ptr noundef nonnull align 8 dereferenceable(240) %35)
  store double %36, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #7
  store i32 0, ptr %13, align 4, !tbaa !11
  br label %37

37:                                               ; preds = %49, %34
  %38 = load i32, ptr %13, align 4, !tbaa !11
  %39 = call noundef i32 @_ZNK10SimTKIpopt6Matrix5NColsEv(ptr noundef nonnull align 8 dereferenceable(69) %16)
  %40 = icmp slt i32 %38, %39
  br i1 %40, label %42, label %41

41:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #7
  br label %52

42:                                               ; preds = %37
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = load double, ptr %7, align 8, !tbaa !9
  %45 = load double, ptr %12, align 8, !tbaa !9
  %46 = fmul double %44, %45
  %47 = load i32, ptr %13, align 4, !tbaa !11
  %48 = call noundef ptr @_ZNK10SimTKIpopt17MultiVectorMatrix8ConstVecEi(ptr noundef nonnull align 8 dereferenceable(128) %16, i32 noundef %47)
  call void @_ZN10SimTKIpopt6Vector12AddOneVectorEdRKS0_d(ptr noundef nonnull align 8 dereferenceable(205) %43, double noundef %46, ptr noundef nonnull align 8 dereferenceable(205) %48, double noundef 1.000000e+00)
  br label %49

49:                                               ; preds = %42
  %50 = load i32, ptr %13, align 4, !tbaa !11
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %13, align 4, !tbaa !11
  br label %37, !llvm.loop !13

52:                                               ; preds = %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #7
  br label %76

53:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #7
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = call noundef ptr @_ZNK10SimTKIpopt11DenseVector6ValuesEv(ptr noundef nonnull align 8 dereferenceable(240) %54)
  store ptr %55, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #7
  store i32 0, ptr %15, align 4, !tbaa !11
  br label %56

56:                                               ; preds = %72, %53
  %57 = load i32, ptr %15, align 4, !tbaa !11
  %58 = call noundef i32 @_ZNK10SimTKIpopt6Matrix5NColsEv(ptr noundef nonnull align 8 dereferenceable(69) %16)
  %59 = icmp slt i32 %57, %58
  br i1 %59, label %61, label %60

60:                                               ; preds = %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #7
  br label %75

61:                                               ; preds = %56
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  %63 = load double, ptr %7, align 8, !tbaa !9
  %64 = load ptr, ptr %14, align 8, !tbaa !5
  %65 = load i32, ptr %15, align 4, !tbaa !11
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds double, ptr %64, i64 %66
  %68 = load double, ptr %67, align 8, !tbaa !9
  %69 = fmul double %63, %68
  %70 = load i32, ptr %15, align 4, !tbaa !11
  %71 = call noundef ptr @_ZNK10SimTKIpopt17MultiVectorMatrix8ConstVecEi(ptr noundef nonnull align 8 dereferenceable(128) %16, i32 noundef %70)
  call void @_ZN10SimTKIpopt6Vector12AddOneVectorEdRKS0_d(ptr noundef nonnull align 8 dereferenceable(205) %62, double noundef %69, ptr noundef nonnull align 8 dereferenceable(205) %71, double noundef 1.000000e+00)
  br label %72

72:                                               ; preds = %61
  %73 = load i32, ptr %15, align 4, !tbaa !11
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %15, align 4, !tbaa !11
  br label %56, !llvm.loop !15

75:                                               ; preds = %60
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #7
  br label %76

76:                                               ; preds = %75, %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #7
  ret void
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN10SimTKIpopt6Vector3SetEd(ptr noundef nonnull align 8 dereferenceable(205), double noundef) #3 align 2

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

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

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN10SimTKIpopt6Vector12AddOneVectorEdRKS0_d(ptr noundef nonnull align 8 dereferenceable(205), double noundef, ptr noundef nonnull align 8 dereferenceable(205), double noundef) #3 align 2

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

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

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 = { 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 #4 = { nounwind willreturn memory(read) }
attributes #5 = { 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 = { 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
define dso_local void @_ZNK10SimTKIpopt17MultiVectorMatrix14MultVectorImplEdRKNS_6VectorEdRS1_(ptr noundef nonnull align 8 dereferenceable(128) %0, double noundef %1, ptr noundef nonnull align 8 dereferenceable(205) %2, double noundef %3, ptr noundef nonnull align 8 dereferenceable(205) %4) unnamed_addr #0 align 2 {
  %6 = fcmp une double %3, 0.000000e+00
  br i1 %6, label %7, label %8

7:                                                ; preds = %5
  tail call void @_ZN10SimTKIpopt6Vector4ScalEd(ptr noundef nonnull align 8 dereferenceable(205) %4, double noundef %3)
  br label %9

8:                                                ; preds = %5
  tail call void @_ZN10SimTKIpopt6Vector3SetEd(ptr noundef nonnull align 8 dereferenceable(205) %4, double noundef 0.000000e+00)
  br label %9

9:                                                ; preds = %7, %8
  %10 = tail call ptr @__dynamic_cast(ptr nonnull %2, ptr nonnull @_ZTIN10SimTKIpopt6VectorE, ptr nonnull @_ZTIN10SimTKIpopt11DenseVectorE, i64 0) #6
  %11 = tail call noundef zeroext i1 @_ZNK10SimTKIpopt11DenseVector13IsHomogeneousEv(ptr noundef nonnull align 8 dereferenceable(240) %10)
  br i1 %11, label %12, label %22

12:                                               ; preds = %9
  %13 = tail call noundef double @_ZNK10SimTKIpopt11DenseVector6ScalarEv(ptr noundef nonnull align 8 dereferenceable(240) %10)
  %14 = tail call noundef i32 @_ZNK10SimTKIpopt6Matrix5NColsEv(ptr noundef nonnull align 8 dereferenceable(69) %0)
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %.lr.ph26, label %.loopexit

.lr.ph26:                                         ; preds = %12
  %16 = fmul double %13, %1
  br label %17

17:                                               ; preds = %.lr.ph26, %17
  %.02125 = phi i32 [ 0, %.lr.ph26 ], [ %19, %17 ]
  %18 = tail call noundef ptr @_ZNK10SimTKIpopt17MultiVectorMatrix8ConstVecEi(ptr noundef nonnull align 8 dereferenceable(128) %0, i32 noundef %.02125)
  tail call void @_ZN10SimTKIpopt6Vector12AddOneVectorEdRKS0_d(ptr noundef nonnull align 8 dereferenceable(205) %4, double noundef %16, ptr noundef nonnull align 8 dereferenceable(205) %18, double noundef 1.000000e+00)
  %19 = add nuw nsw i32 %.02125, 1
  %20 = tail call noundef i32 @_ZNK10SimTKIpopt6Matrix5NColsEv(ptr noundef nonnull align 8 dereferenceable(69) %0)
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %17, label %.loopexit, !llvm.loop !5

22:                                               ; preds = %9
  %23 = tail call noundef ptr @_ZNK10SimTKIpopt11DenseVector6ValuesEv(ptr noundef nonnull align 8 dereferenceable(240) %10)
  %24 = tail call noundef i32 @_ZNK10SimTKIpopt6Matrix5NColsEv(ptr noundef nonnull align 8 dereferenceable(69) %0)
  %25 = icmp sgt i32 %24, 0
  br i1 %25, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %22, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %22 ]
  %26 = getelementptr inbounds double, ptr %23, i64 %indvars.iv
  %27 = load double, ptr %26, align 8, !tbaa !7
  %28 = fmul double %27, %1
  %29 = trunc nuw nsw i64 %indvars.iv to i32
  %30 = tail call noundef ptr @_ZNK10SimTKIpopt17MultiVectorMatrix8ConstVecEi(ptr noundef nonnull align 8 dereferenceable(128) %0, i32 noundef %29)
  tail call void @_ZN10SimTKIpopt6Vector12AddOneVectorEdRKS0_d(ptr noundef nonnull align 8 dereferenceable(205) %4, double noundef %28, ptr noundef nonnull align 8 dereferenceable(205) %30, double noundef 1.000000e+00)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %31 = tail call noundef i32 @_ZNK10SimTKIpopt6Matrix5NColsEv(ptr noundef nonnull align 8 dereferenceable(69) %0)
  %32 = sext i32 %31 to i64
  %33 = icmp slt i64 %indvars.iv.next, %32
  br i1 %33, label %.lr.ph, label %.loopexit, !llvm.loop !11

.loopexit:                                        ; preds = %.lr.ph, %17, %22, %12
  ret void
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN10SimTKIpopt6Vector3SetEd(ptr noundef nonnull align 8 dereferenceable(205), double noundef) local_unnamed_addr #2 align 2

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

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

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN10SimTKIpopt6Vector12AddOneVectorEdRKS0_d(ptr noundef nonnull align 8 dereferenceable(205), double noundef, ptr noundef nonnull align 8 dereferenceable(205), double noundef) local_unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZNK10SimTKIpopt17MultiVectorMatrix8ConstVecEi(ptr noundef nonnull align 8 dereferenceable(128), i32 noundef) local_unnamed_addr #2 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

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 = { 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 #3 = { mustprogress nofree 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 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,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass