; LLVM IR from opensim-org/opensim-core :: Vendors/lepton/src/ParsedExpression.ll (ZNK6Lepton16ParsedExpression8optimizeEv)

; 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.Lepton::ParsedExpression" = type { %"class.Lepton::ExpressionTreeNode" }
%"class.Lepton::ExpressionTreeNode" = type { ptr, %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<Lepton::ExpressionTreeNode, std::allocator<Lepton::ExpressionTreeNode>>::_Vector_impl" }
%"struct.std::_Vector_base<Lepton::ExpressionTreeNode, std::allocator<Lepton::ExpressionTreeNode>>::_Vector_impl" = type { %"struct.std::_Vector_base<Lepton::ExpressionTreeNode, std::allocator<Lepton::ExpressionTreeNode>>::_Vector_impl_data" }
%"struct.std::_Vector_base<Lepton::ExpressionTreeNode, std::allocator<Lepton::ExpressionTreeNode>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(32) ptr @_ZNK6Lepton16ParsedExpression11getRootNodeEv(ptr noundef nonnull align 8 dereferenceable(32)) #0 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK6Lepton16ParsedExpression8optimizeEv(ptr dead_on_unwind noalias writable sret(%"class.Lepton::ParsedExpression") align 8 %0, ptr noundef nonnull align 8 dereferenceable(32) %1) #0 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %"class.Lepton::ExpressionTreeNode", align 8
  %6 = alloca %"class.Lepton::ExpressionTreeNode", align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr %5) #4
  %11 = call noundef nonnull align 8 dereferenceable(32) ptr @_ZNK6Lepton16ParsedExpression11getRootNodeEv(ptr noundef nonnull align 8 dereferenceable(32) %10)
  call void @_ZN6Lepton16ParsedExpression34precalculateConstantSubexpressionsERKNS_18ExpressionTreeNodeE(ptr dead_on_unwind writable sret(%"class.Lepton::ExpressionTreeNode") align 8 %5, ptr noundef nonnull align 8 dereferenceable(32) %11)
  br label %12

12:                                               ; preds = %31, %2
  br label %13

13:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 32, ptr %6) #4
  invoke void @_ZN6Lepton16ParsedExpression27substituteSimplerExpressionERKNS_18ExpressionTreeNodeE(ptr dead_on_unwind writable sret(%"class.Lepton::ExpressionTreeNode") align 8 %6, ptr noundef nonnull align 8 dereferenceable(32) %5)
          to label %14 unwind label %18

14:                                               ; preds = %13
  %15 = invoke noundef zeroext i1 @_ZNK6Lepton18ExpressionTreeNodeeqERKS0_(ptr noundef nonnull align 8 dereferenceable(32) %6, ptr noundef nonnull align 8 dereferenceable(32) %5)
          to label %16 unwind label %22

16:                                               ; preds = %14
  br i1 %15, label %17, label %26

17:                                               ; preds = %16
  store i32 3, ptr %9, align 4
  br label %29

18:                                               ; preds = %13
  %19 = landingpad { ptr, i32 }
          cleanup
  %20 = extractvalue { ptr, i32 } %19, 0
  store ptr %20, ptr %7, align 8
  %21 = extractvalue { ptr, i32 } %19, 1
  store i32 %21, ptr %8, align 4
  br label %32

22:                                               ; preds = %26, %14
  %23 = landingpad { ptr, i32 }
          cleanup
  %24 = extractvalue { ptr, i32 } %23, 0
  store ptr %24, ptr %7, align 8
  %25 = extractvalue { ptr, i32 } %23, 1
  store i32 %25, ptr %8, align 4
  call void @_ZN6Lepton18ExpressionTreeNodeD1Ev(ptr noundef nonnull align 8 dereferenceable(32) %6) #4
  br label %32

26:                                               ; preds = %16
  %27 = invoke noundef nonnull align 8 dereferenceable(32) ptr @_ZN6Lepton18ExpressionTreeNodeaSERKS0_(ptr noundef nonnull align 8 dereferenceable(32) %5, ptr noundef nonnull align 8 dereferenceable(32) %6)
          to label %28 unwind label %22

28:                                               ; preds = %26
  store i32 0, ptr %9, align 4
  br label %29

29:                                               ; preds = %28, %17
  call void @_ZN6Lepton18ExpressionTreeNodeD1Ev(ptr noundef nonnull align 8 dereferenceable(32) %6) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %6) #4
  %30 = load i32, ptr %9, align 4
  switch i32 %30, label %45 [
    i32 0, label %31
    i32 3, label %33
  ]

31:                                               ; preds = %29
  br label %12, !llvm.loop !9

32:                                               ; preds = %22, %18
  call void @llvm.lifetime.end.p0(i64 32, ptr %6) #4
  br label %39

33:                                               ; preds = %29
  invoke void @_ZN6Lepton16ParsedExpressionC1ERKNS_18ExpressionTreeNodeE(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) %5)
          to label %34 unwind label %35

34:                                               ; preds = %33
  store i32 1, ptr %9, align 4
  call void @_ZN6Lepton18ExpressionTreeNodeD1Ev(ptr noundef nonnull align 8 dereferenceable(32) %5) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %5) #4
  ret void

35:                                               ; preds = %33
  %36 = landingpad { ptr, i32 }
          cleanup
  %37 = extractvalue { ptr, i32 } %36, 0
  store ptr %37, ptr %7, align 8
  %38 = extractvalue { ptr, i32 } %36, 1
  store i32 %38, ptr %8, align 4
  br label %39

39:                                               ; preds = %35, %32
  call void @_ZN6Lepton18ExpressionTreeNodeD1Ev(ptr noundef nonnull align 8 dereferenceable(32) %5) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %5) #4
  br label %40

40:                                               ; preds = %39
  %41 = load ptr, ptr %7, align 8
  %42 = load i32, ptr %8, align 4
  %43 = insertvalue { ptr, i32 } poison, ptr %41, 0
  %44 = insertvalue { ptr, i32 } %43, i32 %42, 1
  resume { ptr, i32 } %44

45:                                               ; preds = %29
  unreachable
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6Lepton16ParsedExpression34precalculateConstantSubexpressionsERKNS_18ExpressionTreeNodeE(ptr dead_on_unwind noalias writable sret(%"class.Lepton::ExpressionTreeNode") align 8, ptr noundef nonnull align 8 dereferenceable(32)) #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6Lepton16ParsedExpression27substituteSimplerExpressionERKNS_18ExpressionTreeNodeE(ptr dead_on_unwind noalias writable sret(%"class.Lepton::ExpressionTreeNode") align 8, ptr noundef nonnull align 8 dereferenceable(32)) #0 align 2

declare noundef zeroext i1 @_ZNK6Lepton18ExpressionTreeNodeeqERKS0_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32)) #2

declare noundef nonnull align 8 dereferenceable(32) ptr @_ZN6Lepton18ExpressionTreeNodeaSERKS0_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32)) #2

; Function Attrs: nounwind
declare void @_ZN6Lepton18ExpressionTreeNodeD1Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #3

declare void @_ZN6Lepton16ParsedExpressionC1ERKNS_18ExpressionTreeNodeE(ptr, ptr)

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 "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 = distinct !{!9, !10}
!10 = !{!"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"

%"class.Lepton::ParsedExpression" = type { %"class.Lepton::ExpressionTreeNode" }
%"class.Lepton::ExpressionTreeNode" = type { ptr, %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<Lepton::ExpressionTreeNode, std::allocator<Lepton::ExpressionTreeNode>>::_Vector_impl" }
%"struct.std::_Vector_base<Lepton::ExpressionTreeNode, std::allocator<Lepton::ExpressionTreeNode>>::_Vector_impl" = type { %"struct.std::_Vector_base<Lepton::ExpressionTreeNode, std::allocator<Lepton::ExpressionTreeNode>>::_Vector_impl_data" }
%"struct.std::_Vector_base<Lepton::ExpressionTreeNode, std::allocator<Lepton::ExpressionTreeNode>>::_Vector_impl_data" = type { ptr, ptr, ptr }

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK6Lepton16ParsedExpression8optimizeEv(ptr dead_on_unwind noalias writable sret(%"class.Lepton::ParsedExpression") align 8 %0, ptr noundef nonnull align 8 dereferenceable(32) %1) local_unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca %"class.Lepton::ExpressionTreeNode", align 8
  %4 = alloca %"class.Lepton::ExpressionTreeNode", align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #4
  %5 = tail call noundef nonnull align 8 dereferenceable(32) ptr @_ZNK6Lepton16ParsedExpression11getRootNodeEv(ptr noundef nonnull align 8 dereferenceable(32) %1)
  call void @_ZN6Lepton16ParsedExpression34precalculateConstantSubexpressionsERKNS_18ExpressionTreeNodeE(ptr dead_on_unwind nonnull writable sret(%"class.Lepton::ExpressionTreeNode") align 8 %3, ptr noundef nonnull align 8 dereferenceable(32) %5)
  br label %6

6:                                                ; preds = %16, %2
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #4
  invoke void @_ZN6Lepton16ParsedExpression27substituteSimplerExpressionERKNS_18ExpressionTreeNodeE(ptr dead_on_unwind nonnull writable sret(%"class.Lepton::ExpressionTreeNode") align 8 %4, ptr noundef nonnull align 8 dereferenceable(32) %3)
          to label %7 unwind label %10

7:                                                ; preds = %6
  %8 = invoke noundef zeroext i1 @_ZNK6Lepton18ExpressionTreeNodeeqERKS0_(ptr noundef nonnull align 8 dereferenceable(32) %4, ptr noundef nonnull align 8 dereferenceable(32) %3)
          to label %9 unwind label %12

9:                                                ; preds = %7
  br i1 %8, label %18, label %14

10:                                               ; preds = %6
  %11 = landingpad { ptr, i32 }
          cleanup
  br label %17

12:                                               ; preds = %14, %7
  %13 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN6Lepton18ExpressionTreeNodeD1Ev(ptr noundef nonnull align 8 dereferenceable(32) %4) #4
  br label %17

14:                                               ; preds = %9
  %15 = invoke noundef nonnull align 8 dereferenceable(32) ptr @_ZN6Lepton18ExpressionTreeNodeaSERKS0_(ptr noundef nonnull align 8 dereferenceable(32) %3, ptr noundef nonnull align 8 dereferenceable(32) %4)
          to label %16 unwind label %12

16:                                               ; preds = %14
  call void @_ZN6Lepton18ExpressionTreeNodeD1Ev(ptr noundef nonnull align 8 dereferenceable(32) %4) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #4
  br label %6

17:                                               ; preds = %12, %10
  %.pn = phi { ptr, i32 } [ %13, %12 ], [ %11, %10 ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #4
  br label %22

18:                                               ; preds = %9
  call void @_ZN6Lepton18ExpressionTreeNodeD1Ev(ptr noundef nonnull align 8 dereferenceable(32) %4) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #4
  invoke void @_ZN6Lepton16ParsedExpressionC1ERKNS_18ExpressionTreeNodeE(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) %3)
          to label %19 unwind label %20

19:                                               ; preds = %18
  call void @_ZN6Lepton18ExpressionTreeNodeD1Ev(ptr noundef nonnull align 8 dereferenceable(32) %3) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #4
  ret void

20:                                               ; preds = %18
  %21 = landingpad { ptr, i32 }
          cleanup
  br label %22

22:                                               ; preds = %20, %17
  %.pn7 = phi { ptr, i32 } [ %21, %20 ], [ %.pn, %17 ]
  call void @_ZN6Lepton18ExpressionTreeNodeD1Ev(ptr noundef nonnull align 8 dereferenceable(32) %3) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #4
  resume { ptr, i32 } %.pn7
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6Lepton16ParsedExpression34precalculateConstantSubexpressionsERKNS_18ExpressionTreeNodeE(ptr dead_on_unwind noalias writable sret(%"class.Lepton::ExpressionTreeNode") align 8, ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6Lepton16ParsedExpression27substituteSimplerExpressionERKNS_18ExpressionTreeNodeE(ptr dead_on_unwind noalias writable sret(%"class.Lepton::ExpressionTreeNode") align 8, ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #0 align 2

declare noundef zeroext i1 @_ZNK6Lepton18ExpressionTreeNodeeqERKS0_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #2

declare noundef nonnull align 8 dereferenceable(32) ptr @_ZN6Lepton18ExpressionTreeNodeaSERKS0_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #2

; Function Attrs: nounwind
declare void @_ZN6Lepton18ExpressionTreeNodeD1Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #3

declare void @_ZN6Lepton16ParsedExpressionC1ERKNS_18ExpressionTreeNodeE(ptr, ptr) local_unnamed_addr

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 "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)"}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass