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

; 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::Node" = type { ptr }
%"class.SimTK::Xml::node_iterator" = type <{ %"class.SimTK::Xml::Node", i32, [4 x i8] }>

; 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 nounwind uwtable
declare dso_local void @_ZN5SimTK3Xml4NodeC2EPNS_9TiXmlNodeE(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZL17nodeTypeIsAllowedN5SimTK3Xml8NodeTypeENS_9TiXmlNode8NodeTypeE(i32 noundef, i32 noundef) #1

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

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull align 8 dereferenceable(12) ptr @_ZN5SimTK3Xml13node_iteratormmEv(ptr noundef nonnull align 8 dereferenceable(12) %0) #2 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca %"class.SimTK::Xml::Node", align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %8 = getelementptr inbounds %"class.SimTK::Xml::node_iterator", ptr %7, i32 0, i32 0
  %9 = call noundef nonnull align 8 dereferenceable(104) ptr @_ZN5SimTK3Xml4Node9updTiNodeEv(ptr noundef nonnull align 8 dereferenceable(8) %8)
  %10 = call noundef ptr @_ZN5SimTK9TiXmlNode15PreviousSiblingEv(ptr noundef nonnull align 8 dereferenceable(104) %9)
  store ptr %10, ptr %3, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %23, %1
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %21

14:                                               ; preds = %11
  %15 = getelementptr inbounds %"class.SimTK::Xml::node_iterator", ptr %7, i32 0, i32 1
  %16 = load i32, ptr %15, align 8, !tbaa !9
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = call noundef i32 @_ZNK5SimTK9TiXmlNode4TypeEv(ptr noundef nonnull align 8 dereferenceable(104) %17)
  %19 = call noundef zeroext i1 @_ZL17nodeTypeIsAllowedN5SimTK3Xml8NodeTypeENS_9TiXmlNode8NodeTypeE(i32 noundef %16, i32 noundef %18)
  %20 = xor i1 %19, true
  br label %21

21:                                               ; preds = %14, %11
  %22 = phi i1 [ false, %11 ], [ %20, %14 ]
  br i1 %22, label %23, label %26

23:                                               ; preds = %21
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = call noundef ptr @_ZN5SimTK9TiXmlNode15PreviousSiblingEv(ptr noundef nonnull align 8 dereferenceable(104) %24)
  store ptr %25, ptr %3, align 8, !tbaa !5
  br label %11, !llvm.loop !13

26:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_ZN5SimTK3Xml4NodeC2EPNS_9TiXmlNodeE(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef %27)
  %28 = getelementptr inbounds %"class.SimTK::Xml::node_iterator", ptr %7, i32 0, i32 0
  %29 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZN5SimTK3Xml4NodeaSERKS1_(ptr noundef nonnull align 8 dereferenceable(8) %28, ptr noundef nonnull align 8 dereferenceable(8) %4)
          to label %30 unwind label %31

30:                                               ; preds = %26
  call void @_ZN5SimTK3Xml4NodeD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret ptr %7

31:                                               ; preds = %26
  %32 = landingpad { ptr, i32 }
          cleanup
  %33 = extractvalue { ptr, i32 } %32, 0
  store ptr %33, ptr %5, align 8
  %34 = extractvalue { ptr, i32 } %32, 1
  store i32 %34, ptr %6, align 4
  call void @_ZN5SimTK3Xml4NodeD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  br label %35

35:                                               ; preds = %31
  %36 = load ptr, ptr %5, align 8
  %37 = load i32, ptr %6, align 4
  %38 = insertvalue { ptr, i32 } poison, ptr %36, 0
  %39 = insertvalue { ptr, i32 } %38, i32 %37, 1
  resume { ptr, i32 } %39
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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, !12, i64 8}
!10 = !{!"_ZTSN5SimTK3Xml13node_iteratorE", !11, i64 0, !12, i64 8}
!11 = !{!"_ZTSN5SimTK3Xml4NodeE", !6, i64 0}
!12 = !{!"_ZTSN5SimTK3Xml8NodeTypeE", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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::Node" = type { ptr }

; 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 nounwind uwtable
declare dso_local void @_ZN5SimTK3Xml4NodeC2EPNS_9TiXmlNodeE(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZL17nodeTypeIsAllowedN5SimTK3Xml8NodeTypeENS_9TiXmlNode8NodeTypeE(i32 noundef, i32 noundef) local_unnamed_addr #1

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

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

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef nonnull align 8 dereferenceable(12) ptr @_ZN5SimTK3Xml13node_iteratormmEv(ptr noundef nonnull returned align 8 dereferenceable(12) %0) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca %"class.SimTK::Xml::Node", align 8
  %3 = tail call noundef nonnull align 8 dereferenceable(104) ptr @_ZN5SimTK3Xml4Node9updTiNodeEv(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %4 = tail call noundef ptr @_ZN5SimTK9TiXmlNode15PreviousSiblingEv(ptr noundef nonnull align 8 dereferenceable(104) %3)
  %.not5 = icmp eq ptr %4, null
  br i1 %.not5, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  br label %6

6:                                                ; preds = %.lr.ph, %10
  %.06 = phi ptr [ %4, %.lr.ph ], [ %11, %10 ]
  %7 = load i32, ptr %5, align 8, !tbaa !5
  %8 = tail call noundef i32 @_ZNK5SimTK9TiXmlNode4TypeEv(ptr noundef nonnull align 8 dereferenceable(104) %.06)
  %9 = tail call noundef zeroext i1 @_ZL17nodeTypeIsAllowedN5SimTK3Xml8NodeTypeENS_9TiXmlNode8NodeTypeE(i32 noundef %7, i32 noundef %8)
  br i1 %9, label %.critedge, label %10

10:                                               ; preds = %6
  %11 = tail call noundef ptr @_ZN5SimTK9TiXmlNode15PreviousSiblingEv(ptr noundef nonnull align 8 dereferenceable(104) %.06)
  %.not = icmp eq ptr %11, null
  br i1 %.not, label %.critedge, label %6, !llvm.loop !12

.critedge:                                        ; preds = %6, %10, %1
  %.0.lcssa = phi ptr [ null, %1 ], [ null, %10 ], [ %.06, %6 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #2
  call void @_ZN5SimTK3Xml4NodeC2EPNS_9TiXmlNodeE(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef %.0.lcssa)
  %12 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN5SimTK3Xml4NodeaSERKS1_(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull align 8 dereferenceable(8) %2)
  call void @_ZN5SimTK3Xml4NodeD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %2) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #2
  ret ptr %0
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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, !11, i64 8}
!6 = !{!"_ZTSN5SimTK3Xml13node_iteratorE", !7, i64 0, !11, i64 8}
!7 = !{!"_ZTSN5SimTK3Xml4NodeE", !8, i64 0}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"_ZTSN5SimTK3Xml8NodeTypeE", !9, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass