; LLVM IR from simbody/simbody :: SimTKcommon/src/Xml.ll (ZN5SimTK3Xml7Element20getOptionalAttributeERKNS_6StringE)

; 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.SimTK::Xml::Attribute" = type { ptr }
%"class.SimTK::Xml::attribute_iterator" = type { %"class.SimTK::Xml::Attribute" }

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

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) #0

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

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

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

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

13:                                               ; preds = %45, %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  invoke void @_ZNK5SimTK3Xml7Element13attribute_endEv(ptr dead_on_unwind writable sret(%"class.SimTK::Xml::attribute_iterator") align 8 %8, ptr noundef nonnull align 8 dereferenceable(8) %12)
          to label %14 unwind label %18

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

16:                                               ; preds = %14
  call void @_ZN5SimTK3Xml18attribute_iteratorD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br i1 %15, label %27, label %17

17:                                               ; preds = %16
  store i32 2, ptr %11, align 4
  br label %46

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

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

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

27:                                               ; preds = %16
  %28 = invoke noundef ptr @_ZNK5SimTK3Xml18attribute_iteratorptEv(ptr noundef nonnull align 8 dereferenceable(8) %7)
          to label %29 unwind label %38

29:                                               ; preds = %27
  %30 = invoke noundef nonnull align 8 dereferenceable(32) ptr @_ZNK5SimTK3Xml9Attribute7getNameEv(ptr noundef nonnull align 8 dereferenceable(8) %28)
          to label %31 unwind label %38

31:                                               ; preds = %29
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = call noundef zeroext i1 @_ZSteqIcEN9__gnu_cxx11__enable_ifIXsr9__is_charIT_EE7__valueEbE6__typeERKNSt7__cxx1112basic_stringIS2_St11char_traitsIS2_ESaIS2_EEESC_(ptr noundef nonnull align 8 dereferenceable(32) %30, ptr noundef nonnull align 8 dereferenceable(32) %32) #4
  br i1 %33, label %34, label %42

34:                                               ; preds = %31
  %35 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZNK5SimTK3Xml18attribute_iteratordeEv(ptr noundef nonnull align 8 dereferenceable(8) %7)
          to label %36 unwind label %38

36:                                               ; preds = %34
  invoke void @_ZN5SimTK3Xml9AttributeC2ERKS1_(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull align 8 dereferenceable(8) %35)
          to label %37 unwind label %38

37:                                               ; preds = %36
  store i32 1, ptr %11, align 4
  br label %46

38:                                               ; preds = %43, %36, %34, %29, %27
  %39 = landingpad { ptr, i32 }
          cleanup
  %40 = extractvalue { ptr, i32 } %39, 0
  store ptr %40, ptr %9, align 8
  %41 = extractvalue { ptr, i32 } %39, 1
  store i32 %41, ptr %10, align 4
  br label %48

42:                                               ; preds = %31
  br label %43

43:                                               ; preds = %42
  %44 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZN5SimTK3Xml18attribute_iteratorppEv(ptr noundef nonnull align 8 dereferenceable(8) %7)
          to label %45 unwind label %38

45:                                               ; preds = %43
  br label %13, !llvm.loop !9

46:                                               ; preds = %37, %17
  call void @_ZN5SimTK3Xml18attribute_iteratorD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %47 = load i32, ptr %11, align 4
  switch i32 %47, label %56 [
    i32 2, label %49
    i32 1, label %50
  ]

48:                                               ; preds = %38, %26
  call void @_ZN5SimTK3Xml18attribute_iteratorD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %51

49:                                               ; preds = %46
  call void @_ZN5SimTK3Xml9AttributeC2EPNS_14TiXmlAttributeE(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef null)
  br label %50

50:                                               ; preds = %49, %46
  ret void

51:                                               ; preds = %48
  %52 = load ptr, ptr %9, align 8
  %53 = load i32, ptr %10, align 4
  %54 = insertvalue { ptr, i32 } poison, ptr %52, 0
  %55 = insertvalue { ptr, i32 } %54, i32 %53, 1
  resume { ptr, i32 } %55

56:                                               ; preds = %46
  unreachable
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5SimTK3Xml7Element15attribute_beginEv(ptr dead_on_unwind noalias writable sret(%"class.SimTK::Xml::attribute_iterator") align 8, ptr noundef nonnull align 8 dereferenceable(8)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNK5SimTK3Xml18attribute_iteratorneERKS1_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK5SimTK3Xml7Element13attribute_endEv(ptr dead_on_unwind noalias writable sret(%"class.SimTK::Xml::attribute_iterator") align 8, ptr noundef nonnull align 8 dereferenceable(8)) #1 align 2

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZSteqIcEN9__gnu_cxx11__enable_ifIXsr9__is_charIT_EE7__valueEbE6__typeERKNSt7__cxx1112basic_stringIS2_St11char_traitsIS2_ESaIS2_EEESC_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32)) #3

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5SimTK3Xml9AttributeC2EPNS_14TiXmlAttributeE(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) unnamed_addr #2 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 = { 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 = { 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 = 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.SimTK::Xml::Attribute" = type { ptr }
%"class.SimTK::Xml::attribute_iterator" = type { %"class.SimTK::Xml::Attribute" }

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

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) #0

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5SimTK3Xml7Element20getOptionalAttributeERKNS_6StringE(ptr dead_on_unwind noalias writable sret(%"class.SimTK::Xml::Attribute") align 8 %0, ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull align 8 dereferenceable(32) %2) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca %"class.SimTK::Xml::attribute_iterator", align 8
  %5 = alloca %"class.SimTK::Xml::attribute_iterator", align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  call void @_ZN5SimTK3Xml7Element15attribute_beginEv(ptr dead_on_unwind nonnull writable sret(%"class.SimTK::Xml::attribute_iterator") align 8 %4, ptr noundef nonnull align 8 dereferenceable(8) %1)
  br label %6

6:                                                ; preds = %22, %3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  invoke void @_ZNK5SimTK3Xml7Element13attribute_endEv(ptr dead_on_unwind nonnull writable sret(%"class.SimTK::Xml::attribute_iterator") align 8 %5, ptr noundef nonnull align 8 dereferenceable(8) %1)
          to label %7 unwind label %10

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

9:                                                ; preds = %7
  call void @_ZN5SimTK3Xml18attribute_iteratorD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  br i1 %8, label %15, label %27

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

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

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

15:                                               ; preds = %9
  %16 = call noundef ptr @_ZNK5SimTK3Xml18attribute_iteratorptEv(ptr noundef nonnull align 8 dereferenceable(8) %4)
  %17 = invoke noundef nonnull align 8 dereferenceable(32) ptr @_ZNK5SimTK3Xml9Attribute7getNameEv(ptr noundef nonnull align 8 dereferenceable(8) %16)
          to label %18 unwind label %20

18:                                               ; preds = %15
  %19 = call noundef zeroext i1 @_ZSteqIcEN9__gnu_cxx11__enable_ifIXsr9__is_charIT_EE7__valueEbE6__typeERKNSt7__cxx1112basic_stringIS2_St11char_traitsIS2_ESaIS2_EEESC_(ptr noundef nonnull align 8 dereferenceable(32) %17, ptr noundef nonnull align 8 dereferenceable(32) %2) #4
  br i1 %19, label %24, label %22

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

22:                                               ; preds = %18
  %23 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZN5SimTK3Xml18attribute_iteratorppEv(ptr noundef nonnull align 8 dereferenceable(8) %4)
          to label %6 unwind label %20, !llvm.loop !5

24:                                               ; preds = %18
  %25 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK5SimTK3Xml18attribute_iteratordeEv(ptr noundef nonnull align 8 dereferenceable(8) %4)
  call void @_ZN5SimTK3Xml9AttributeC2ERKS1_(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull align 8 dereferenceable(8) %25)
  call void @_ZN5SimTK3Xml18attribute_iteratorD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  br label %28

26:                                               ; preds = %20, %14
  %.pn8 = phi { ptr, i32 } [ %21, %20 ], [ %.pn, %14 ]
  call void @_ZN5SimTK3Xml18attribute_iteratorD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  resume { ptr, i32 } %.pn8

27:                                               ; preds = %9
  call void @_ZN5SimTK3Xml18attribute_iteratorD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  call void @_ZN5SimTK3Xml9AttributeC2EPNS_14TiXmlAttributeE(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef null)
  br label %28

28:                                               ; preds = %24, %27
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5SimTK3Xml7Element15attribute_beginEv(ptr dead_on_unwind noalias writable sret(%"class.SimTK::Xml::attribute_iterator") align 8, ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNK5SimTK3Xml18attribute_iteratorneERKS1_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK5SimTK3Xml7Element13attribute_endEv(ptr dead_on_unwind noalias writable sret(%"class.SimTK::Xml::attribute_iterator") align 8, ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1 align 2

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZSteqIcEN9__gnu_cxx11__enable_ifIXsr9__is_charIT_EE7__valueEbE6__typeERKNSt7__cxx1112basic_stringIS2_St11char_traitsIS2_ESaIS2_EEESC_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #3

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

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

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

attributes #0 = { mustprogress 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 = { 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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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