; 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: nounwind willreturn memory(read)
declare ptr @__dynamic_cast(ptr, ptr, ptr, i64) #1

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK10SimTKIpopt17MultiVectorMatrix19TransMultVectorImplEdRKNS_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 #3 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 ptr, align 8
  %13 = alloca i32, align 4
  %14 = 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
  %15 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %16 = load ptr, ptr %10, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %20, label %18

18:                                               ; preds = %5
  %19 = call ptr @__dynamic_cast(ptr %16, ptr @_ZTIN10SimTKIpopt6VectorE, ptr @_ZTIN10SimTKIpopt11DenseVectorE, i64 0) #5
  br label %21

20:                                               ; preds = %5
  br label %21

21:                                               ; preds = %20, %18
  %22 = phi ptr [ %19, %18 ], [ null, %20 ]
  store ptr %22, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %23 = load ptr, ptr %11, align 8, !tbaa !5
  %24 = call noundef ptr @_ZN10SimTKIpopt11DenseVector6ValuesEv(ptr noundef nonnull align 8 dereferenceable(240) %23)
  store ptr %24, ptr %12, align 8, !tbaa !5
  %25 = load double, ptr %9, align 8, !tbaa !9
  %26 = fcmp une double %25, 0.000000e+00
  br i1 %26, label %27, label %55

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

28:                                               ; preds = %51, %27
  %29 = load i32, ptr %13, align 4, !tbaa !11
  %30 = call noundef i32 @_ZNK10SimTKIpopt6Matrix5NColsEv(ptr noundef nonnull align 8 dereferenceable(69) %15)
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  br label %54

33:                                               ; preds = %28
  %34 = load double, ptr %7, align 8, !tbaa !9
  %35 = load i32, ptr %13, align 4, !tbaa !11
  %36 = call noundef ptr @_ZNK10SimTKIpopt17MultiVectorMatrix8ConstVecEi(ptr noundef nonnull align 8 dereferenceable(128) %15, i32 noundef %35)
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = call noundef double @_ZNK10SimTKIpopt6Vector3DotERKS0_(ptr noundef nonnull align 8 dereferenceable(205) %36, ptr noundef nonnull align 8 dereferenceable(205) %37)
  %39 = load double, ptr %9, align 8, !tbaa !9
  %40 = load ptr, ptr %12, align 8, !tbaa !5
  %41 = load i32, ptr %13, align 4, !tbaa !11
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds double, ptr %40, i64 %42
  %44 = load double, ptr %43, align 8, !tbaa !9
  %45 = fmul double %39, %44
  %46 = call double @llvm.fmuladd.f64(double %34, double %38, double %45)
  %47 = load ptr, ptr %12, align 8, !tbaa !5
  %48 = load i32, ptr %13, align 4, !tbaa !11
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds double, ptr %47, i64 %49
  store double %46, ptr %50, align 8, !tbaa !9
  br label %51

51:                                               ; preds = %33
  %52 = load i32, ptr %13, align 4, !tbaa !11
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %13, align 4, !tbaa !11
  br label %28, !llvm.loop !13

54:                                               ; preds = %32
  br label %76

55:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  store i32 0, ptr %14, align 4, !tbaa !11
  br label %56

56:                                               ; preds = %72, %55
  %57 = load i32, ptr %14, align 4, !tbaa !11
  %58 = call noundef i32 @_ZNK10SimTKIpopt6Matrix5NColsEv(ptr noundef nonnull align 8 dereferenceable(69) %15)
  %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 %14) #5
  br label %75

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

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

75:                                               ; preds = %60
  br label %76

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

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind willreturn memory(read) }
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 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 nofree nounwind willreturn memory(read)
declare ptr @__dynamic_cast(ptr, ptr, ptr, i64) local_unnamed_addr #0

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK10SimTKIpopt17MultiVectorMatrix19TransMultVectorImplEdRKNS_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 #2 align 2 {
  %6 = tail call ptr @__dynamic_cast(ptr nonnull %4, ptr nonnull @_ZTIN10SimTKIpopt6VectorE, ptr nonnull @_ZTIN10SimTKIpopt11DenseVectorE, i64 0) #4
  %7 = tail call noundef ptr @_ZN10SimTKIpopt11DenseVector6ValuesEv(ptr noundef nonnull align 8 dereferenceable(240) %6)
  %8 = fcmp une double %3, 0.000000e+00
  %9 = tail call noundef i32 @_ZNK10SimTKIpopt6Matrix5NColsEv(ptr noundef nonnull align 8 dereferenceable(69) %0)
  %10 = icmp sgt i32 %9, 0
  br i1 %8, label %.preheader, label %.preheader22

.preheader22:                                     ; preds = %5
  br i1 %10, label %.lr.ph, label %.loopexit

.preheader:                                       ; preds = %5
  br i1 %10, label %.lr.ph26, label %.loopexit

.lr.ph26:                                         ; preds = %.preheader, %.lr.ph26
  %indvars.iv29 = phi i64 [ %indvars.iv.next30, %.lr.ph26 ], [ 0, %.preheader ]
  %11 = trunc nuw nsw i64 %indvars.iv29 to i32
  %12 = tail call noundef ptr @_ZNK10SimTKIpopt17MultiVectorMatrix8ConstVecEi(ptr noundef nonnull align 8 dereferenceable(128) %0, i32 noundef %11)
  %13 = tail call noundef double @_ZNK10SimTKIpopt6Vector3DotERKS0_(ptr noundef nonnull align 8 dereferenceable(205) %12, ptr noundef nonnull align 8 dereferenceable(205) %2)
  %14 = getelementptr inbounds double, ptr %7, i64 %indvars.iv29
  %15 = load double, ptr %14, align 8, !tbaa !5
  %16 = fmul double %15, %3
  %17 = tail call double @llvm.fmuladd.f64(double %1, double %13, double %16)
  store double %17, ptr %14, align 8, !tbaa !5
  %indvars.iv.next30 = add nuw nsw i64 %indvars.iv29, 1
  %18 = tail call noundef i32 @_ZNK10SimTKIpopt6Matrix5NColsEv(ptr noundef nonnull align 8 dereferenceable(69) %0)
  %19 = sext i32 %18 to i64
  %20 = icmp slt i64 %indvars.iv.next30, %19
  br i1 %20, label %.lr.ph26, label %.loopexit, !llvm.loop !9

.lr.ph:                                           ; preds = %.preheader22, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader22 ]
  %21 = trunc nuw nsw i64 %indvars.iv to i32
  %22 = tail call noundef ptr @_ZNK10SimTKIpopt17MultiVectorMatrix8ConstVecEi(ptr noundef nonnull align 8 dereferenceable(128) %0, i32 noundef %21)
  %23 = tail call noundef double @_ZNK10SimTKIpopt6Vector3DotERKS0_(ptr noundef nonnull align 8 dereferenceable(205) %22, ptr noundef nonnull align 8 dereferenceable(205) %2)
  %24 = fmul double %23, %1
  %25 = getelementptr inbounds double, ptr %7, i64 %indvars.iv
  store double %24, ptr %25, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %26 = tail call noundef i32 @_ZNK10SimTKIpopt6Matrix5NColsEv(ptr noundef nonnull align 8 dereferenceable(69) %0)
  %27 = sext i32 %26 to i64
  %28 = icmp slt i64 %indvars.iv.next, %27
  br i1 %28, label %.lr.ph, label %.loopexit, !llvm.loop !11

.loopexit:                                        ; preds = %.lr.ph, %.lr.ph26, %.preheader22, %.preheader
  ret void
}

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

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #3

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


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