; LLVM IR from simbody/simbody :: SimTKcommon/src/tinyxml.ll (ZNK5SimTK13TiXmlDocument6CopyToEPS0_)

; 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::TiXmlDocument" = type { %"class.SimTK::TiXmlNode", i8, i32, %"class.SimTK::String", i32, %"struct.SimTK::TiXmlCursor", i8, %"class.SimTK::String" }
%"class.SimTK::TiXmlNode" = type { %"class.SimTK::TiXmlBase", ptr, i32, ptr, ptr, %"class.SimTK::String", ptr, ptr }
%"class.SimTK::TiXmlBase" = type { ptr, %"struct.SimTK::TiXmlCursor", ptr }
%"struct.SimTK::TiXmlCursor" = type { i32, i32 }
%"class.SimTK::String" = type { %"class.std::__cxx11::basic_string" }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

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

; 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 void @_ZNK5SimTK9TiXmlNode6CopyToEPS0_(ptr noundef nonnull align 8 dereferenceable(104), ptr noundef) #1 align 2

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK5SimTK13TiXmlDocument6CopyToEPS0_(ptr noundef nonnull align 8 dereferenceable(192) %0, ptr noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZNK5SimTK9TiXmlNode6CopyToEPS0_(ptr noundef nonnull align 8 dereferenceable(104) %6, ptr noundef %7)
  %8 = getelementptr inbounds %"class.SimTK::TiXmlDocument", ptr %6, i32 0, i32 1
  %9 = load i8, ptr %8, align 8, !tbaa !9, !range !21, !noundef !22
  %10 = trunc i8 %9 to i1
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %"class.SimTK::TiXmlDocument", ptr %11, i32 0, i32 1
  %13 = zext i1 %10 to i8
  store i8 %13, ptr %12, align 8, !tbaa !9
  %14 = getelementptr inbounds %"class.SimTK::TiXmlDocument", ptr %6, i32 0, i32 2
  %15 = load i32, ptr %14, align 4, !tbaa !23
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %"class.SimTK::TiXmlDocument", ptr %16, i32 0, i32 2
  store i32 %15, ptr %17, align 4, !tbaa !23
  %18 = getelementptr inbounds %"class.SimTK::TiXmlDocument", ptr %6, i32 0, i32 3
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %"class.SimTK::TiXmlDocument", ptr %19, i32 0, i32 3
  %21 = call noundef nonnull align 8 dereferenceable(32) ptr @_ZN5SimTK6StringaSERKS0_(ptr noundef nonnull align 8 dereferenceable(32) %20, ptr noundef nonnull align 8 dereferenceable(32) %18)
  %22 = getelementptr inbounds %"class.SimTK::TiXmlDocument", ptr %6, i32 0, i32 4
  %23 = load i32, ptr %22, align 8, !tbaa !24
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %"class.SimTK::TiXmlDocument", ptr %24, i32 0, i32 4
  store i32 %23, ptr %25, align 8, !tbaa !24
  %26 = getelementptr inbounds %"class.SimTK::TiXmlDocument", ptr %6, i32 0, i32 5
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %"class.SimTK::TiXmlDocument", ptr %27, i32 0, i32 5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %28, ptr align 4 %26, i64 8, i1 false), !tbaa.struct !25
  %29 = getelementptr inbounds %"class.SimTK::TiXmlDocument", ptr %6, i32 0, i32 6
  %30 = load i8, ptr %29, align 4, !tbaa !27, !range !21, !noundef !22
  %31 = trunc i8 %30 to i1
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %"class.SimTK::TiXmlDocument", ptr %32, i32 0, i32 6
  %34 = zext i1 %31 to i8
  store i8 %34, ptr %33, align 4, !tbaa !27
  %35 = getelementptr inbounds %"class.SimTK::TiXmlDocument", ptr %6, i32 0, i32 7
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %"class.SimTK::TiXmlDocument", ptr %36, i32 0, i32 7
  %38 = call noundef nonnull align 8 dereferenceable(32) ptr @_ZN5SimTK6StringaSERKS0_(ptr noundef nonnull align 8 dereferenceable(32) %37, ptr noundef nonnull align 8 dereferenceable(32) %35)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  store ptr null, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %"class.SimTK::TiXmlNode", ptr %6, i32 0, i32 3
  %40 = load ptr, ptr %39, align 8, !tbaa !28
  store ptr %40, ptr %5, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %52, %2
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = icmp ne ptr %42, null
  br i1 %43, label %44, label %55

44:                                               ; preds = %41
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = load ptr, ptr %46, align 8, !tbaa !29
  %48 = getelementptr inbounds ptr, ptr %47, i64 16
  %49 = load ptr, ptr %48, align 8
  %50 = call noundef ptr %49(ptr noundef nonnull align 8 dereferenceable(104) %46)
  %51 = call noundef ptr @_ZN5SimTK9TiXmlNode12LinkEndChildEPS0_(ptr noundef nonnull align 8 dereferenceable(104) %45, ptr noundef %50)
  br label %52

52:                                               ; preds = %44
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = call noundef ptr @_ZN5SimTK9TiXmlNode11NextSiblingEv(ptr noundef nonnull align 8 dereferenceable(104) %53)
  store ptr %54, ptr %5, align 8, !tbaa !5
  br label %41, !llvm.loop !31

55:                                               ; preds = %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

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 = { 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 #3 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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, !20, i64 104}
!10 = !{!"_ZTSN5SimTK13TiXmlDocumentE", !11, i64 0, !20, i64 104, !14, i64 108, !16, i64 112, !14, i64 144, !13, i64 148, !20, i64 156, !16, i64 160}
!11 = !{!"_ZTSN5SimTK9TiXmlNodeE", !12, i64 0, !6, i64 24, !15, i64 32, !6, i64 40, !6, i64 48, !16, i64 56, !6, i64 88, !6, i64 96}
!12 = !{!"_ZTSN5SimTK9TiXmlBaseE", !13, i64 8, !6, i64 16}
!13 = !{!"_ZTSN5SimTK11TiXmlCursorE", !14, i64 0, !14, i64 4}
!14 = !{!"int", !7, i64 0}
!15 = !{!"_ZTSN5SimTK9TiXmlNode8NodeTypeE", !7, i64 0}
!16 = !{!"_ZTSN5SimTK6StringE", !17, i64 0}
!17 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !18, i64 0, !19, i64 8, !7, i64 16}
!18 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!19 = !{!"long", !7, i64 0}
!20 = !{!"bool", !7, i64 0}
!21 = !{i8 0, i8 2}
!22 = !{}
!23 = !{!10, !14, i64 108}
!24 = !{!10, !14, i64 144}
!25 = !{i64 0, i64 4, !26, i64 4, i64 4, !26}
!26 = !{!14, !14, i64 0}
!27 = !{!10, !20, i64 156}
!28 = !{!11, !6, i64 40}
!29 = !{!30, !30, i64 0}
!30 = !{!"vtable pointer", !8, i64 0}
!31 = distinct !{!31, !32}
!32 = !{!"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 uwtable
declare dso_local void @_ZNK5SimTK9TiXmlNode6CopyToEPS0_(ptr noundef nonnull align 8 dereferenceable(104), ptr noundef) local_unnamed_addr #0 align 2

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK5SimTK13TiXmlDocument6CopyToEPS0_(ptr noundef nonnull align 8 dereferenceable(192) %0, ptr noundef %1) local_unnamed_addr #0 align 2 {
  tail call void @_ZNK5SimTK9TiXmlNode6CopyToEPS0_(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef %1)
  %3 = getelementptr inbounds i8, ptr %0, i64 104
  %4 = load i8, ptr %3, align 8, !tbaa !5, !range !20, !noundef !21
  %5 = getelementptr inbounds i8, ptr %1, i64 104
  store i8 %4, ptr %5, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 108
  %7 = load i32, ptr %6, align 4, !tbaa !22
  %8 = getelementptr inbounds i8, ptr %1, i64 108
  store i32 %7, ptr %8, align 4, !tbaa !22
  %9 = getelementptr inbounds i8, ptr %0, i64 112
  %10 = getelementptr inbounds i8, ptr %1, i64 112
  %11 = tail call noundef nonnull align 8 dereferenceable(32) ptr @_ZN5SimTK6StringaSERKS0_(ptr noundef nonnull align 8 dereferenceable(32) %10, ptr noundef nonnull align 8 dereferenceable(32) %9)
  %12 = getelementptr inbounds i8, ptr %0, i64 144
  %13 = load i32, ptr %12, align 8, !tbaa !23
  %14 = getelementptr inbounds i8, ptr %1, i64 144
  store i32 %13, ptr %14, align 8, !tbaa !23
  %15 = getelementptr inbounds i8, ptr %0, i64 148
  %16 = getelementptr inbounds i8, ptr %1, i64 148
  %17 = load i64, ptr %15, align 4
  store i64 %17, ptr %16, align 4
  %18 = getelementptr inbounds i8, ptr %0, i64 156
  %19 = load i8, ptr %18, align 4, !tbaa !24, !range !20, !noundef !21
  %20 = getelementptr inbounds i8, ptr %1, i64 156
  store i8 %19, ptr %20, align 4, !tbaa !24
  %21 = getelementptr inbounds i8, ptr %0, i64 160
  %22 = getelementptr inbounds i8, ptr %1, i64 160
  %23 = tail call noundef nonnull align 8 dereferenceable(32) ptr @_ZN5SimTK6StringaSERKS0_(ptr noundef nonnull align 8 dereferenceable(32) %22, ptr noundef nonnull align 8 dereferenceable(32) %21)
  %24 = getelementptr inbounds i8, ptr %0, i64 40
  %25 = load ptr, ptr %24, align 8, !tbaa !25
  %.not13 = icmp eq ptr %25, null
  br i1 %.not13, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.014 = phi ptr [ %31, %.lr.ph ], [ %25, %2 ]
  %26 = load ptr, ptr %.014, align 8, !tbaa !26
  %27 = getelementptr inbounds i8, ptr %26, i64 128
  %28 = load ptr, ptr %27, align 8
  %29 = tail call noundef ptr %28(ptr noundef nonnull align 8 dereferenceable(104) %.014)
  %30 = tail call noundef ptr @_ZN5SimTK9TiXmlNode12LinkEndChildEPS0_(ptr noundef nonnull align 8 dereferenceable(104) %1, ptr noundef %29)
  %31 = tail call noundef ptr @_ZN5SimTK9TiXmlNode11NextSiblingEv(ptr noundef nonnull align 8 dereferenceable(104) %.014)
  %.not = icmp eq ptr %31, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !28

._crit_edge:                                      ; preds = %.lr.ph, %2
  ret void
}

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 = { 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 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" }

!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, !19, i64 104}
!6 = !{!"_ZTSN5SimTK13TiXmlDocumentE", !7, i64 0, !19, i64 104, !10, i64 108, !15, i64 112, !10, i64 144, !9, i64 148, !19, i64 156, !15, i64 160}
!7 = !{!"_ZTSN5SimTK9TiXmlNodeE", !8, i64 0, !13, i64 24, !14, i64 32, !13, i64 40, !13, i64 48, !15, i64 56, !13, i64 88, !13, i64 96}
!8 = !{!"_ZTSN5SimTK9TiXmlBaseE", !9, i64 8, !13, i64 16}
!9 = !{!"_ZTSN5SimTK11TiXmlCursorE", !10, i64 0, !10, i64 4}
!10 = !{!"int", !11, i64 0}
!11 = !{!"omnipotent char", !12, i64 0}
!12 = !{!"Simple C++ TBAA"}
!13 = !{!"any pointer", !11, i64 0}
!14 = !{!"_ZTSN5SimTK9TiXmlNode8NodeTypeE", !11, i64 0}
!15 = !{!"_ZTSN5SimTK6StringE", !16, i64 0}
!16 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !17, i64 0, !18, i64 8, !11, i64 16}
!17 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !13, i64 0}
!18 = !{!"long", !11, i64 0}
!19 = !{!"bool", !11, i64 0}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = !{!6, !10, i64 108}
!23 = !{!6, !10, i64 144}
!24 = !{!6, !19, i64 156}
!25 = !{!7, !13, i64 40}
!26 = !{!27, !27, i64 0}
!27 = !{!"vtable pointer", !12, i64 0}
!28 = distinct !{!28, !29}
!29 = !{!"llvm.loop.mustprogress"}


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