; LLVM IR from opensim-org/opensim-core :: Vendors/lepton/src (ExpressionProgram)

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIPN6Lepton9OperationESaIS2_EEC2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6Lepton17ExpressionProgramC2ERKNS_16ParsedExpressionE(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) %1) unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %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
  %11 = getelementptr inbounds %"class.Lepton::ExpressionProgram", ptr %10, i32 0, i32 0
  call void @_ZNSt6vectorIPN6Lepton9OperationESaIS2_EEC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %11) #4
  %12 = getelementptr inbounds %"class.Lepton::ExpressionProgram", ptr %10, i32 0, i32 1
  store i32 0, ptr %12, align 8, !tbaa !9
  %13 = getelementptr inbounds %"class.Lepton::ExpressionProgram", ptr %10, i32 0, i32 2
  store i32 0, ptr %13, align 4, !tbaa !16
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = invoke noundef nonnull align 8 dereferenceable(32) ptr @_ZNK6Lepton16ParsedExpression11getRootNodeEv(ptr noundef nonnull align 8 dereferenceable(32) %14)
          to label %16 unwind label %25

16:                                               ; preds = %2
  invoke void @_ZN6Lepton17ExpressionProgram12buildProgramERKNS_18ExpressionTreeNodeE(ptr noundef nonnull align 8 dereferenceable(32) %10, ptr noundef nonnull align 8 dereferenceable(32) %15)
          to label %17 unwind label %25

17:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !17
  br label %18

18:                                               ; preds = %64, %17
  %19 = load i32, ptr %8, align 4, !tbaa !17
  %20 = getelementptr inbounds %"class.Lepton::ExpressionProgram", ptr %10, i32 0, i32 0
  %21 = call noundef i64 @_ZNKSt6vectorIPN6Lepton9OperationESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %20) #4
  %22 = trunc i64 %21 to i32
  %23 = icmp slt i32 %19, %22
  br i1 %23, label %29, label %24

24:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %67

25:                                               ; preds = %16, %2
  %26 = landingpad { ptr, i32 }
          cleanup
  %27 = extractvalue { ptr, i32 } %26, 0
  store ptr %27, ptr %5, align 8
  %28 = extractvalue { ptr, i32 } %26, 1
  store i32 %28, ptr %6, align 4
  br label %68

29:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %30 = getelementptr inbounds %"class.Lepton::ExpressionProgram", ptr %10, i32 0, i32 0
  %31 = load i32, ptr %8, align 4, !tbaa !17
  %32 = sext i32 %31 to i64
  %33 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIPN6Lepton9OperationESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %30, i64 noundef %32) #4
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  %35 = load ptr, ptr %34, align 8, !tbaa !18
  %36 = getelementptr inbounds ptr, ptr %35, i64 4
  %37 = load ptr, ptr %36, align 8
  %38 = invoke noundef i32 %37(ptr noundef nonnull align 8 dereferenceable(8) %34)
          to label %39 unwind label %47

39:                                               ; preds = %29
  store i32 %38, ptr %9, align 4, !tbaa !17
  %40 = load i32, ptr %9, align 4, !tbaa !17
  %41 = getelementptr inbounds %"class.Lepton::ExpressionProgram", ptr %10, i32 0, i32 1
  %42 = load i32, ptr %41, align 8, !tbaa !9
  %43 = icmp sgt i32 %40, %42
  br i1 %43, label %44, label %51

44:                                               ; preds = %39
  %45 = load i32, ptr %9, align 4, !tbaa !17
  %46 = getelementptr inbounds %"class.Lepton::ExpressionProgram", ptr %10, i32 0, i32 1
  store i32 %45, ptr %46, align 8, !tbaa !9
  br label %51

47:                                               ; preds = %29
  %48 = landingpad { ptr, i32 }
          cleanup
  %49 = extractvalue { ptr, i32 } %48, 0
  store ptr %49, ptr %5, align 8
  %50 = extractvalue { ptr, i32 } %48, 1
  store i32 %50, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %68

51:                                               ; preds = %44, %39
  %52 = load i32, ptr %9, align 4, !tbaa !17
  %53 = sub nsw i32 1, %52
  %54 = load i32, ptr %7, align 4, !tbaa !17
  %55 = add nsw i32 %54, %53
  store i32 %55, ptr %7, align 4, !tbaa !17
  %56 = load i32, ptr %7, align 4, !tbaa !17
  %57 = getelementptr inbounds %"class.Lepton::ExpressionProgram", ptr %10, i32 0, i32 2
  %58 = load i32, ptr %57, align 4, !tbaa !16
  %59 = icmp sgt i32 %56, %58
  br i1 %59, label %60, label %63

60:                                               ; preds = %51
  %61 = load i32, ptr %7, align 4, !tbaa !17
  %62 = getelementptr inbounds %"class.Lepton::ExpressionProgram", ptr %10, i32 0, i32 2
  store i32 %61, ptr %62, align 4, !tbaa !16
  br label %63

63:                                               ; preds = %60, %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %8, align 4, !tbaa !17
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %8, align 4, !tbaa !17
  br label %18, !llvm.loop !20

67:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret void

68:                                               ; preds = %47, %25
  call void @_ZNSt6vectorIPN6Lepton9OperationESaIS2_EED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %11) #4
  br label %69

69:                                               ; preds = %68
  %70 = load ptr, ptr %5, align 8
  %71 = load i32, ptr %6, align 4
  %72 = insertvalue { ptr, i32 } poison, ptr %70, 0
  %73 = insertvalue { ptr, i32 } %72, i32 %71, 1
  resume { ptr, i32 } %73
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6Lepton17ExpressionProgram12buildProgramERKNS_18ExpressionTreeNodeE(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32)) #1 align 2

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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIPN6Lepton9OperationESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIPN6Lepton9OperationESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #0 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIPN6Lepton9OperationESaIS2_EED2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #0 align 2

attributes #0 = { 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 #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !15, i64 24}
!10 = !{!"_ZTSN6Lepton17ExpressionProgramE", !11, i64 0, !15, i64 24, !15, i64 28}
!11 = !{!"_ZTSSt6vectorIPN6Lepton9OperationESaIS2_EE", !12, i64 0}
!12 = !{!"_ZTSSt12_Vector_baseIPN6Lepton9OperationESaIS2_EE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseIPN6Lepton9OperationESaIS2_EE12_Vector_implE", !14, i64 0}
!14 = !{!"_ZTSNSt12_Vector_baseIPN6Lepton9OperationESaIS2_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!15 = !{!"int", !7, i64 0}
!16 = !{!10, !15, i64 28}
!17 = !{!15, !15, i64 0}
!18 = !{!19, !19, i64 0}
!19 = !{!"vtable pointer", !8, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"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"

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIPN6Lepton9OperationESaIS2_EEC2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6Lepton17ExpressionProgramC2ERKNS_16ParsedExpressionE(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) %1) unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  tail call void @_ZNSt6vectorIPN6Lepton9OperationESaIS2_EEC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %0) #3
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 0, ptr %3, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 28
  store i32 0, ptr %4, align 4, !tbaa !15
  %5 = invoke noundef nonnull align 8 dereferenceable(32) ptr @_ZNK6Lepton16ParsedExpression11getRootNodeEv(ptr noundef nonnull align 8 dereferenceable(32) %1)
          to label %6 unwind label %10

6:                                                ; preds = %2
  invoke void @_ZN6Lepton17ExpressionProgram12buildProgramERKNS_18ExpressionTreeNodeE(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) %5)
          to label %.preheader unwind label %10

.preheader:                                       ; preds = %6
  %7 = tail call noundef i64 @_ZNKSt6vectorIPN6Lepton9OperationESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #3
  %8 = trunc i64 %7 to i32
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %29, %.preheader
  ret void

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

.lr.ph:                                           ; preds = %.preheader, %29
  %indvars.iv = phi i64 [ %indvars.iv.next, %29 ], [ 0, %.preheader ]
  %.01318 = phi i32 [ %25, %29 ], [ 0, %.preheader ]
  %12 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIPN6Lepton9OperationESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %indvars.iv) #3
  %13 = load ptr, ptr %12, align 8, !tbaa !16
  %14 = load ptr, ptr %13, align 8, !tbaa !17
  %15 = getelementptr inbounds i8, ptr %14, i64 32
  %16 = load ptr, ptr %15, align 8
  %17 = invoke noundef i32 %16(ptr noundef nonnull align 8 dereferenceable(8) %13)
          to label %18 unwind label %22

18:                                               ; preds = %.lr.ph
  %19 = load i32, ptr %3, align 8, !tbaa !5
  %20 = icmp sgt i32 %17, %19
  br i1 %20, label %21, label %24

21:                                               ; preds = %18
  store i32 %17, ptr %3, align 8, !tbaa !5
  br label %24

22:                                               ; preds = %.lr.ph
  %23 = landingpad { ptr, i32 }
          cleanup
  br label %33

24:                                               ; preds = %21, %18
  %reass.sub = sub i32 %.01318, %17
  %25 = add i32 %reass.sub, 1
  %26 = load i32, ptr %4, align 4, !tbaa !15
  %27 = icmp sgt i32 %25, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %24
  store i32 %25, ptr %4, align 4, !tbaa !15
  br label %29

29:                                               ; preds = %28, %24
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %30 = tail call noundef i64 @_ZNKSt6vectorIPN6Lepton9OperationESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #3
  %sext = shl i64 %30, 32
  %31 = ashr exact i64 %sext, 32
  %32 = icmp slt i64 %indvars.iv.next, %31
  br i1 %32, label %.lr.ph, label %._crit_edge, !llvm.loop !19

33:                                               ; preds = %22, %10
  %.pn = phi { ptr, i32 } [ %23, %22 ], [ %11, %10 ]
  tail call void @_ZNSt6vectorIPN6Lepton9OperationESaIS2_EED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %0) #3
  resume { ptr, i32 } %.pn
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6Lepton17ExpressionProgram12buildProgramERKNS_18ExpressionTreeNodeE(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1 align 2

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIPN6Lepton9OperationESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIPN6Lepton9OperationESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIPN6Lepton9OperationESaIS2_EED2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #0 align 2

attributes #0 = { 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 #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 }

!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, !14, i64 24}
!6 = !{!"_ZTSN6Lepton17ExpressionProgramE", !7, i64 0, !14, i64 24, !14, i64 28}
!7 = !{!"_ZTSSt6vectorIPN6Lepton9OperationESaIS2_EE", !8, i64 0}
!8 = !{!"_ZTSSt12_Vector_baseIPN6Lepton9OperationESaIS2_EE", !9, i64 0}
!9 = !{!"_ZTSNSt12_Vector_baseIPN6Lepton9OperationESaIS2_EE12_Vector_implE", !10, i64 0}
!10 = !{!"_ZTSNSt12_Vector_baseIPN6Lepton9OperationESaIS2_EE17_Vector_impl_dataE", !11, i64 0, !11, i64 8, !11, i64 16}
!11 = !{!"any pointer", !12, i64 0}
!12 = !{!"omnipotent char", !13, i64 0}
!13 = !{!"Simple C++ TBAA"}
!14 = !{!"int", !12, i64 0}
!15 = !{!6, !14, i64 28}
!16 = !{!11, !11, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"vtable pointer", !13, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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