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

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

; Function Attrs: nounwind
declare double @pow(double noundef, double noundef) #0

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

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZN10SimTKIpopt25IpoptCalculatedQuantities14CalcNormOfTypeENS_9ENormTypeERKNS_6VectorES4_(ptr noundef nonnull align 8 dereferenceable(2025) %0, i32 noundef %1, ptr noundef nonnull align 8 dereferenceable(205) %2, ptr noundef nonnull align 8 dereferenceable(205) %3) #2 align 2 {
  %5 = alloca double, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  %10 = load ptr, ptr %6, align 8
  %11 = load i32, ptr %7, align 4, !tbaa !9
  switch i32 %11, label %33 [
    i32 0, label %12
    i32 1, label %18
    i32 2, label %27
  ]

12:                                               ; preds = %4
  %13 = load ptr, ptr %8, align 8, !tbaa !5
  %14 = call noundef double @_ZNK10SimTKIpopt6Vector4AsumEv(ptr noundef nonnull align 8 dereferenceable(205) %13)
  %15 = load ptr, ptr %9, align 8, !tbaa !5
  %16 = call noundef double @_ZNK10SimTKIpopt6Vector4AsumEv(ptr noundef nonnull align 8 dereferenceable(205) %15)
  %17 = fadd double %14, %16
  store double %17, ptr %5, align 8
  br label %34

18:                                               ; preds = %4
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = call noundef double @_ZNK10SimTKIpopt6Vector4Nrm2Ev(ptr noundef nonnull align 8 dereferenceable(205) %19)
  %21 = call double @pow(double noundef %20, double noundef 2.000000e+00) #4
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = call noundef double @_ZNK10SimTKIpopt6Vector4Nrm2Ev(ptr noundef nonnull align 8 dereferenceable(205) %22)
  %24 = call double @pow(double noundef %23, double noundef 2.000000e+00) #4
  %25 = fadd double %21, %24
  %26 = call double @sqrt(double noundef %25) #4
  store double %26, ptr %5, align 8
  br label %34

27:                                               ; preds = %4
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = call noundef double @_ZNK10SimTKIpopt6Vector4AmaxEv(ptr noundef nonnull align 8 dereferenceable(205) %28)
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  %31 = call noundef double @_ZNK10SimTKIpopt6Vector4AmaxEv(ptr noundef nonnull align 8 dereferenceable(205) %30)
  %32 = call noundef double @_ZN10SimTKIpopt3MaxEdd(double noundef %29, double noundef %31)
  store double %32, ptr %5, align 8
  br label %34

33:                                               ; preds = %4
  store double 0.000000e+00, ptr %5, align 8
  br label %34

34:                                               ; preds = %33, %27, %18, %12
  %35 = load double, ptr %5, align 8
  ret double %35
}

; Function Attrs: nounwind
declare double @sqrt(double noundef) #0

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZN10SimTKIpopt3MaxEdd(double noundef, double noundef) #3

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

attributes #0 = { nounwind "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 = { 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 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_ZTSN10SimTKIpopt9ENormTypeE", !7, i64 0}


; 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 double @_ZNK10SimTKIpopt6Vector4AsumEv(ptr noundef nonnull align 8 dereferenceable(205)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZN10SimTKIpopt25IpoptCalculatedQuantities14CalcNormOfTypeENS_9ENormTypeERKNS_6VectorES4_(ptr nocapture noundef nonnull readnone align 8 dereferenceable(2025) %0, i32 noundef %1, ptr noundef nonnull align 8 dereferenceable(205) %2, ptr noundef nonnull align 8 dereferenceable(205) %3) local_unnamed_addr #1 align 2 {
  switch i32 %1, label %17 [
    i32 0, label %5
    i32 1, label %9
    i32 2, label %13
  ]

5:                                                ; preds = %4
  %6 = tail call noundef double @_ZNK10SimTKIpopt6Vector4AsumEv(ptr noundef nonnull align 8 dereferenceable(205) %2)
  %7 = tail call noundef double @_ZNK10SimTKIpopt6Vector4AsumEv(ptr noundef nonnull align 8 dereferenceable(205) %3)
  %8 = fadd double %6, %7
  br label %17

9:                                                ; preds = %4
  %10 = tail call noundef double @_ZNK10SimTKIpopt6Vector4Nrm2Ev(ptr noundef nonnull align 8 dereferenceable(205) %2)
  %square = fmul double %10, %10
  %11 = tail call noundef double @_ZNK10SimTKIpopt6Vector4Nrm2Ev(ptr noundef nonnull align 8 dereferenceable(205) %3)
  %square8 = fmul double %11, %11
  %12 = fadd double %square, %square8
  %sqrt = tail call double @llvm.sqrt.f64(double %12)
  br label %17

13:                                               ; preds = %4
  %14 = tail call noundef double @_ZNK10SimTKIpopt6Vector4AmaxEv(ptr noundef nonnull align 8 dereferenceable(205) %2)
  %15 = tail call noundef double @_ZNK10SimTKIpopt6Vector4AmaxEv(ptr noundef nonnull align 8 dereferenceable(205) %3)
  %16 = tail call noundef double @_ZN10SimTKIpopt3MaxEdd(double noundef %14, double noundef %15)
  br label %17

17:                                               ; preds = %4, %13, %9, %5
  %.0 = phi double [ %16, %13 ], [ %sqrt, %9 ], [ %8, %5 ], [ 0.000000e+00, %4 ]
  ret double %.0
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZN10SimTKIpopt3MaxEdd(double noundef, double noundef) local_unnamed_addr #2

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

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

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" }
attributes #2 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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)"}


; Effective O3 passes: AggressiveInstCombinePass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass