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

; 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.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] }

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

declare void @_ZN13TiXmlDocument8SetErrorEiPKcP16TiXmlParsingData13TiXmlEncoding(ptr noundef nonnull align 8 dereferenceable(157), i32 noundef, ptr noundef, ptr noundef, i32 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN9TiXmlNode12ReplaceChildEPS_RKS_(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef %1, ptr noundef nonnull align 8 dereferenceable(104) %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %15, label %14

14:                                               ; preds = %3
  store ptr null, ptr %4, align 8
  br label %94

15:                                               ; preds = %3
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %class.TiXmlNode, ptr %16, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = icmp ne ptr %18, %11
  br i1 %19, label %20, label %21

20:                                               ; preds = %15
  store ptr null, ptr %4, align 8
  br label %94

21:                                               ; preds = %15
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = load ptr, ptr %22, align 8, !tbaa !18
  %24 = getelementptr inbounds ptr, ptr %23, i64 4
  %25 = load ptr, ptr %24, align 8
  %26 = call noundef ptr %25(ptr noundef nonnull align 8 dereferenceable(104) %22)
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %35

28:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %29 = call noundef ptr @_ZN9TiXmlNode11GetDocumentEv(ptr noundef nonnull align 8 dereferenceable(104) %11)
  store ptr %29, ptr %8, align 8, !tbaa !5
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %34

32:                                               ; preds = %28
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZN13TiXmlDocument8SetErrorEiPKcP16TiXmlParsingData13TiXmlEncoding(ptr noundef nonnull align 8 dereferenceable(157) %33, i32 noundef 15, ptr noundef null, ptr noundef null, i32 noundef 0)
  br label %34

34:                                               ; preds = %32, %28
  store ptr null, ptr %4, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %94

35:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = load ptr, ptr %36, align 8, !tbaa !18
  %38 = getelementptr inbounds ptr, ptr %37, i64 16
  %39 = load ptr, ptr %38, align 8
  %40 = call noundef ptr %39(ptr noundef nonnull align 8 dereferenceable(104) %36)
  store ptr %40, ptr %9, align 8, !tbaa !5
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = icmp ne ptr %41, null
  br i1 %42, label %44, label %43

43:                                               ; preds = %35
  store ptr null, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %93

44:                                               ; preds = %35
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds %class.TiXmlNode, ptr %45, i32 0, i32 7
  %47 = load ptr, ptr %46, align 8, !tbaa !20
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = getelementptr inbounds %class.TiXmlNode, ptr %48, i32 0, i32 7
  store ptr %47, ptr %49, align 8, !tbaa !20
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %class.TiXmlNode, ptr %50, i32 0, i32 6
  %52 = load ptr, ptr %51, align 8, !tbaa !21
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = getelementptr inbounds %class.TiXmlNode, ptr %53, i32 0, i32 6
  store ptr %52, ptr %54, align 8, !tbaa !21
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = getelementptr inbounds %class.TiXmlNode, ptr %55, i32 0, i32 7
  %57 = load ptr, ptr %56, align 8, !tbaa !20
  %58 = icmp ne ptr %57, null
  br i1 %58, label %59, label %65

59:                                               ; preds = %44
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = getelementptr inbounds %class.TiXmlNode, ptr %61, i32 0, i32 7
  %63 = load ptr, ptr %62, align 8, !tbaa !20
  %64 = getelementptr inbounds %class.TiXmlNode, ptr %63, i32 0, i32 6
  store ptr %60, ptr %64, align 8, !tbaa !21
  br label %68

65:                                               ; preds = %44
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  %67 = getelementptr inbounds %class.TiXmlNode, ptr %11, i32 0, i32 4
  store ptr %66, ptr %67, align 8, !tbaa !22
  br label %68

68:                                               ; preds = %65, %59
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %class.TiXmlNode, ptr %69, i32 0, i32 6
  %71 = load ptr, ptr %70, align 8, !tbaa !21
  %72 = icmp ne ptr %71, null
  br i1 %72, label %73, label %79

73:                                               ; preds = %68
  %74 = load ptr, ptr %9, align 8, !tbaa !5
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = getelementptr inbounds %class.TiXmlNode, ptr %75, i32 0, i32 6
  %77 = load ptr, ptr %76, align 8, !tbaa !21
  %78 = getelementptr inbounds %class.TiXmlNode, ptr %77, i32 0, i32 7
  store ptr %74, ptr %78, align 8, !tbaa !20
  br label %82

79:                                               ; preds = %68
  %80 = load ptr, ptr %9, align 8, !tbaa !5
  %81 = getelementptr inbounds %class.TiXmlNode, ptr %11, i32 0, i32 3
  store ptr %80, ptr %81, align 8, !tbaa !23
  br label %82

82:                                               ; preds = %79, %73
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  %84 = icmp eq ptr %83, null
  br i1 %84, label %89, label %85

85:                                               ; preds = %82
  %86 = load ptr, ptr %83, align 8, !tbaa !18
  %87 = getelementptr inbounds ptr, ptr %86, i64 1
  %88 = load ptr, ptr %87, align 8
  call void %88(ptr noundef nonnull align 8 dereferenceable(104) %83) #3
  br label %89

89:                                               ; preds = %85, %82
  %90 = load ptr, ptr %9, align 8, !tbaa !5
  %91 = getelementptr inbounds %class.TiXmlNode, ptr %90, i32 0, i32 1
  store ptr %11, ptr %91, align 8, !tbaa !9
  %92 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %92, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %93

93:                                               ; preds = %89, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %94

94:                                               ; preds = %93, %34, %20, %14
  %95 = load ptr, ptr %4, align 8
  ret ptr %95
}

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 = { "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, !6, i64 24}
!10 = !{!"_ZTS9TiXmlNode", !11, i64 0, !6, i64 24, !14, i64 32, !6, i64 40, !6, i64 48, !15, i64 56, !6, i64 88, !6, i64 96}
!11 = !{!"_ZTS9TiXmlBase", !12, i64 8, !6, i64 16}
!12 = !{!"_ZTS11TiXmlCursor", !13, i64 0, !13, i64 4}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_ZTSN9TiXmlNode8NodeTypeE", !7, i64 0}
!15 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !16, i64 0, !17, i64 8, !7, i64 16}
!16 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!19, !19, i64 0}
!19 = !{!"vtable pointer", !8, i64 0}
!20 = !{!10, !6, i64 96}
!21 = !{!10, !6, i64 88}
!22 = !{!10, !6, i64 48}
!23 = !{!10, !6, i64 40}


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

declare void @_ZN13TiXmlDocument8SetErrorEiPKcP16TiXmlParsingData13TiXmlEncoding(ptr noundef nonnull align 8 dereferenceable(157), i32 noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN9TiXmlNode12ReplaceChildEPS_RKS_(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef %1, ptr noundef nonnull align 8 dereferenceable(104) %2) local_unnamed_addr #0 align 2 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %39, label %4

4:                                                ; preds = %3
  %5 = getelementptr inbounds i8, ptr %1, i64 24
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %.not30 = icmp eq ptr %6, %0
  br i1 %.not30, label %7, label %39

7:                                                ; preds = %4
  %8 = load ptr, ptr %2, align 8, !tbaa !17
  %9 = getelementptr inbounds i8, ptr %8, i64 32
  %10 = load ptr, ptr %9, align 8
  %11 = tail call noundef ptr %10(ptr noundef nonnull align 8 dereferenceable(104) %2)
  %.not31 = icmp eq ptr %11, null
  br i1 %.not31, label %15, label %12

12:                                               ; preds = %7
  %13 = tail call noundef ptr @_ZN9TiXmlNode11GetDocumentEv(ptr noundef nonnull align 8 dereferenceable(104) %0)
  %.not35 = icmp eq ptr %13, null
  br i1 %.not35, label %39, label %14

14:                                               ; preds = %12
  tail call void @_ZN13TiXmlDocument8SetErrorEiPKcP16TiXmlParsingData13TiXmlEncoding(ptr noundef nonnull align 8 dereferenceable(157) %13, i32 noundef 15, ptr noundef null, ptr noundef null, i32 noundef 0)
  br label %39

15:                                               ; preds = %7
  %16 = load ptr, ptr %2, align 8, !tbaa !17
  %17 = getelementptr inbounds i8, ptr %16, i64 128
  %18 = load ptr, ptr %17, align 8
  %19 = tail call noundef ptr %18(ptr noundef nonnull align 8 dereferenceable(104) %2)
  %.not32 = icmp eq ptr %19, null
  br i1 %.not32, label %39, label %20

20:                                               ; preds = %15
  %21 = getelementptr inbounds i8, ptr %1, i64 96
  %22 = load ptr, ptr %21, align 8, !tbaa !19
  %23 = getelementptr inbounds i8, ptr %19, i64 96
  store ptr %22, ptr %23, align 8, !tbaa !19
  %24 = getelementptr inbounds i8, ptr %1, i64 88
  %25 = load ptr, ptr %24, align 8, !tbaa !20
  %26 = getelementptr inbounds i8, ptr %19, i64 88
  store ptr %25, ptr %26, align 8, !tbaa !20
  %.not33 = icmp eq ptr %22, null
  br i1 %.not33, label %29, label %27

27:                                               ; preds = %20
  %28 = getelementptr inbounds i8, ptr %22, i64 88
  store ptr %19, ptr %28, align 8, !tbaa !20
  %.pre = load ptr, ptr %24, align 8, !tbaa !20
  br label %31

29:                                               ; preds = %20
  %30 = getelementptr inbounds i8, ptr %0, i64 48
  store ptr %19, ptr %30, align 8, !tbaa !21
  br label %31

31:                                               ; preds = %29, %27
  %32 = phi ptr [ %25, %29 ], [ %.pre, %27 ]
  %.not34 = icmp eq ptr %32, null
  %33 = getelementptr inbounds i8, ptr %32, i64 96
  %34 = getelementptr inbounds i8, ptr %0, i64 40
  %.sink = select i1 %.not34, ptr %34, ptr %33
  store ptr %19, ptr %.sink, align 8, !tbaa !22
  %35 = load ptr, ptr %1, align 8, !tbaa !17
  %36 = getelementptr inbounds i8, ptr %35, i64 8
  %37 = load ptr, ptr %36, align 8
  tail call void %37(ptr noundef nonnull align 8 dereferenceable(104) %1) #2
  %38 = getelementptr inbounds i8, ptr %19, i64 24
  store ptr %0, ptr %38, align 8, !tbaa !5
  br label %39

39:                                               ; preds = %31, %15, %12, %14, %4, %3
  %.1 = phi ptr [ null, %3 ], [ null, %4 ], [ null, %14 ], [ null, %12 ], [ %19, %31 ], [ null, %15 ]
  ret ptr %.1
}

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass