; LLVM IR from HiroIshida/tinyfk :: urdf_parser/tinyxml/tinyxml.ll (ZNK12TiXmlElement6CopyToEPS_)

; 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.TiXmlElement = type { %class.TiXmlNode, %class.TiXmlAttributeSet }
%class.TiXmlNode = type { %class.TiXmlBase, ptr, i32, ptr, ptr, %"class.std::__cxx11::basic_string", ptr, ptr }
%class.TiXmlBase = type { ptr, %struct.TiXmlCursor, ptr }
%struct.TiXmlCursor = type { i32, i32 }
%"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] }
%class.TiXmlAttributeSet = type { %class.TiXmlAttribute }
%class.TiXmlAttribute = type { %class.TiXmlBase, ptr, %"class.std::__cxx11::basic_string", %"class.std::__cxx11::basic_string", ptr, ptr }

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK12TiXmlElement6CopyToEPS_(ptr noundef nonnull align 8 dereferenceable(216) %0, ptr noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZNK9TiXmlNode6CopyToEPS_(ptr noundef nonnull align 8 dereferenceable(104) %7, ptr noundef %8)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store ptr null, ptr %5, align 8, !tbaa !5
  %9 = getelementptr inbounds %class.TiXmlElement, ptr %7, i32 0, i32 1
  %10 = call noundef ptr @_ZNK17TiXmlAttributeSet5FirstEv(ptr noundef nonnull align 8 dereferenceable(112) %9)
  store ptr %10, ptr %5, align 8, !tbaa !5
  br label %11

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

14:                                               ; preds = %11
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = call noundef ptr @_ZNK14TiXmlAttribute4NameEv(ptr noundef nonnull align 8 dereferenceable(112) %16)
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = call noundef ptr @_ZNK14TiXmlAttribute5ValueEv(ptr noundef nonnull align 8 dereferenceable(112) %18)
  call void @_ZN12TiXmlElement12SetAttributeEPKcS1_(ptr noundef nonnull align 8 dereferenceable(216) %15, ptr noundef %17, ptr noundef %19)
  br label %20

20:                                               ; preds = %14
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = call noundef ptr @_ZNK14TiXmlAttribute4NextEv(ptr noundef nonnull align 8 dereferenceable(112) %21)
  store ptr %22, ptr %5, align 8, !tbaa !5
  br label %11, !llvm.loop !9

23:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store ptr null, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %class.TiXmlNode, ptr %7, i32 0, i32 3
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  store ptr %25, ptr %6, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %37, %23
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = icmp ne ptr %27, null
  br i1 %28, label %29, label %40

29:                                               ; preds = %26
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load ptr, ptr %31, align 8, !tbaa !20
  %33 = getelementptr inbounds ptr, ptr %32, i64 16
  %34 = load ptr, ptr %33, align 8
  %35 = call noundef ptr %34(ptr noundef nonnull align 8 dereferenceable(104) %31)
  %36 = call noundef ptr @_ZN9TiXmlNode12LinkEndChildEPS_(ptr noundef nonnull align 8 dereferenceable(104) %30, ptr noundef %35)
  br label %37

37:                                               ; preds = %29
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = call noundef ptr @_ZN9TiXmlNode11NextSiblingEv(ptr noundef nonnull align 8 dereferenceable(104) %38)
  store ptr %39, ptr %6, align 8, !tbaa !5
  br label %26, !llvm.loop !22

40:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

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

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

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK14TiXmlAttribute4NameEv(ptr noundef nonnull align 8 dereferenceable(112)) #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 = { 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"}
!11 = !{!12, !6, i64 40}
!12 = !{!"_ZTS9TiXmlNode", !13, i64 0, !6, i64 24, !16, i64 32, !6, i64 40, !6, i64 48, !17, i64 56, !6, i64 88, !6, i64 96}
!13 = !{!"_ZTS9TiXmlBase", !14, i64 8, !6, i64 16}
!14 = !{!"_ZTS11TiXmlCursor", !15, i64 0, !15, i64 4}
!15 = !{!"int", !7, i64 0}
!16 = !{!"_ZTSN9TiXmlNode8NodeTypeE", !7, 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 = !{!21, !21, i64 0}
!21 = !{!"vtable pointer", !8, i64 0}
!22 = distinct !{!22, !10}


; 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 @_ZNK9TiXmlNode6CopyToEPS_(ptr noundef nonnull align 8 dereferenceable(104), ptr noundef) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK12TiXmlElement6CopyToEPS_(ptr noundef nonnull align 8 dereferenceable(216) %0, ptr noundef %1) local_unnamed_addr #0 align 2 {
  tail call void @_ZNK9TiXmlNode6CopyToEPS_(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef %1)
  %3 = getelementptr inbounds i8, ptr %0, i64 104
  %4 = tail call noundef ptr @_ZNK17TiXmlAttributeSet5FirstEv(ptr noundef nonnull align 8 dereferenceable(112) %3)
  %.not13 = icmp eq ptr %4, null
  br i1 %.not13, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.01114 = phi ptr [ %7, %.lr.ph ], [ %4, %2 ]
  %5 = tail call noundef ptr @_ZNK14TiXmlAttribute4NameEv(ptr noundef nonnull align 8 dereferenceable(112) %.01114)
  %6 = tail call noundef ptr @_ZNK14TiXmlAttribute5ValueEv(ptr noundef nonnull align 8 dereferenceable(112) %.01114)
  tail call void @_ZN12TiXmlElement12SetAttributeEPKcS1_(ptr noundef nonnull align 8 dereferenceable(216) %1, ptr noundef %5, ptr noundef %6)
  %7 = tail call noundef ptr @_ZNK14TiXmlAttribute4NextEv(ptr noundef nonnull align 8 dereferenceable(112) %.01114)
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %2
  %8 = getelementptr inbounds i8, ptr %0, i64 40
  %9 = load ptr, ptr %8, align 8, !tbaa !7
  %.not1215 = icmp eq ptr %9, null
  br i1 %.not1215, label %._crit_edge19, label %.lr.ph18

.lr.ph18:                                         ; preds = %._crit_edge, %.lr.ph18
  %.016 = phi ptr [ %15, %.lr.ph18 ], [ %9, %._crit_edge ]
  %10 = load ptr, ptr %.016, align 8, !tbaa !19
  %11 = getelementptr inbounds i8, ptr %10, i64 128
  %12 = load ptr, ptr %11, align 8
  %13 = tail call noundef ptr %12(ptr noundef nonnull align 8 dereferenceable(104) %.016)
  %14 = tail call noundef ptr @_ZN9TiXmlNode12LinkEndChildEPS_(ptr noundef nonnull align 8 dereferenceable(104) %1, ptr noundef %13)
  %15 = tail call noundef ptr @_ZN9TiXmlNode11NextSiblingEv(ptr noundef nonnull align 8 dereferenceable(104) %.016)
  %.not12 = icmp eq ptr %15, null
  br i1 %.not12, label %._crit_edge19, label %.lr.ph18, !llvm.loop !21

._crit_edge19:                                    ; preds = %.lr.ph18, %._crit_edge
  ret void
}

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

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

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

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

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

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

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 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !14, i64 40}
!8 = !{!"_ZTS9TiXmlNode", !9, i64 0, !14, i64 24, !15, i64 32, !14, i64 40, !14, i64 48, !16, i64 56, !14, i64 88, !14, i64 96}
!9 = !{!"_ZTS9TiXmlBase", !10, i64 8, !14, i64 16}
!10 = !{!"_ZTS11TiXmlCursor", !11, i64 0, !11, i64 4}
!11 = !{!"int", !12, i64 0}
!12 = !{!"omnipotent char", !13, i64 0}
!13 = !{!"Simple C++ TBAA"}
!14 = !{!"any pointer", !12, i64 0}
!15 = !{!"_ZTSN9TiXmlNode8NodeTypeE", !12, i64 0}
!16 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !17, i64 0, !18, i64 8, !12, i64 16}
!17 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !14, i64 0}
!18 = !{!"long", !12, i64 0}
!19 = !{!20, !20, i64 0}
!20 = !{!"vtable pointer", !13, i64 0}
!21 = distinct !{!21, !6}


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