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

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

@.str.19 = external hidden unnamed_addr constant [77 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [2 x i8], align 1
@__PRETTY_FUNCTION__._ZN5SimTK9TiXmlNode15DisconnectChildEPS0_ = external hidden unnamed_addr constant [58 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN5SimTK9TiXmlNode15DisconnectChildEPS0_(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds %"class.SimTK::TiXmlNode", ptr %6, i32 0, i32 1
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = icmp ne ptr %8, %5
  br i1 %9, label %10, label %11

10:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str.32, ptr noundef @.str.19, i32 noundef 404, ptr noundef @__PRETTY_FUNCTION__._ZN5SimTK9TiXmlNode15DisconnectChildEPS0_) #2
  unreachable

11:                                               ; preds = %2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %"class.SimTK::TiXmlNode", ptr %12, i32 0, i32 7
  %14 = load ptr, ptr %13, align 8, !tbaa !19
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %24

16:                                               ; preds = %11
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %"class.SimTK::TiXmlNode", ptr %17, i32 0, i32 6
  %19 = load ptr, ptr %18, align 8, !tbaa !20
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %"class.SimTK::TiXmlNode", ptr %20, i32 0, i32 7
  %22 = load ptr, ptr %21, align 8, !tbaa !19
  %23 = getelementptr inbounds %"class.SimTK::TiXmlNode", ptr %22, i32 0, i32 6
  store ptr %19, ptr %23, align 8, !tbaa !20
  br label %29

24:                                               ; preds = %11
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %"class.SimTK::TiXmlNode", ptr %25, i32 0, i32 6
  %27 = load ptr, ptr %26, align 8, !tbaa !20
  %28 = getelementptr inbounds %"class.SimTK::TiXmlNode", ptr %5, i32 0, i32 4
  store ptr %27, ptr %28, align 8, !tbaa !21
  br label %29

29:                                               ; preds = %24, %16
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %"class.SimTK::TiXmlNode", ptr %30, i32 0, i32 6
  %32 = load ptr, ptr %31, align 8, !tbaa !20
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %42

34:                                               ; preds = %29
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %"class.SimTK::TiXmlNode", ptr %35, i32 0, i32 7
  %37 = load ptr, ptr %36, align 8, !tbaa !19
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %"class.SimTK::TiXmlNode", ptr %38, i32 0, i32 6
  %40 = load ptr, ptr %39, align 8, !tbaa !20
  %41 = getelementptr inbounds %"class.SimTK::TiXmlNode", ptr %40, i32 0, i32 7
  store ptr %37, ptr %41, align 8, !tbaa !19
  br label %47

42:                                               ; preds = %29
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %"class.SimTK::TiXmlNode", ptr %43, i32 0, i32 7
  %45 = load ptr, ptr %44, align 8, !tbaa !19
  %46 = getelementptr inbounds %"class.SimTK::TiXmlNode", ptr %5, i32 0, i32 3
  store ptr %45, ptr %46, align 8, !tbaa !22
  br label %47

47:                                               ; preds = %42, %34
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %"class.SimTK::TiXmlNode", ptr %48, i32 0, i32 7
  store ptr null, ptr %49, align 8, !tbaa !19
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %"class.SimTK::TiXmlNode", ptr %50, i32 0, i32 6
  store ptr null, ptr %51, align 8, !tbaa !20
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %"class.SimTK::TiXmlNode", ptr %52, i32 0, i32 1
  store ptr null, ptr %53, align 8, !tbaa !9
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  ret ptr %54
}

attributes #0 = { noreturn nounwind "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" }
attributes #2 = { noreturn 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 = !{!"_ZTSN5SimTK9TiXmlNodeE", !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 = !{!"_ZTSN5SimTK9TiXmlBaseE", !12, i64 8, !6, i64 16}
!12 = !{!"_ZTSN5SimTK11TiXmlCursorE", !13, i64 0, !13, i64 4}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_ZTSN5SimTK9TiXmlNode8NodeTypeE", !7, i64 0}
!15 = !{!"_ZTSN5SimTK6StringE", !16, i64 0}
!16 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !17, i64 0, !18, i64 8, !7, i64 16}
!17 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!18 = !{!"long", !7, i64 0}
!19 = !{!10, !6, i64 96}
!20 = !{!10, !6, i64 88}
!21 = !{!10, !6, i64 48}
!22 = !{!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"

@.str.19 = external hidden unnamed_addr constant [77 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [2 x i8], align 1
@__PRETTY_FUNCTION__._ZN5SimTK9TiXmlNode15DisconnectChildEPS0_ = external hidden unnamed_addr constant [58 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN5SimTK9TiXmlNode15DisconnectChildEPS0_(ptr noundef nonnull writeonly align 8 dereferenceable(104) %0, ptr noundef returned %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %1, i64 24
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.not = icmp eq ptr %4, %0
  br i1 %.not, label %6, label %5

5:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.32, ptr noundef nonnull @.str.19, i32 noundef 404, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN5SimTK9TiXmlNode15DisconnectChildEPS0_) #3
  unreachable

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %1, i64 96
  %8 = load ptr, ptr %7, align 8, !tbaa !18
  %.not16 = icmp eq ptr %8, null
  %9 = getelementptr inbounds i8, ptr %1, i64 88
  %10 = load ptr, ptr %9, align 8, !tbaa !19
  %11 = getelementptr inbounds i8, ptr %0, i64 48
  %12 = getelementptr inbounds i8, ptr %8, i64 88
  %.sink = select i1 %.not16, ptr %11, ptr %12
  store ptr %10, ptr %.sink, align 8, !tbaa !20
  %.not17 = icmp eq ptr %10, null
  %13 = getelementptr inbounds i8, ptr %0, i64 40
  %14 = getelementptr inbounds i8, ptr %10, i64 96
  %.sink18 = select i1 %.not17, ptr %13, ptr %14
  store ptr %8, ptr %.sink18, align 8, !tbaa !20
  %15 = getelementptr inbounds i8, ptr %1, i64 88
  store ptr null, ptr %3, align 8, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %15, i8 0, i64 16, i1 false)
  ret ptr %1
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #0 = { noreturn nounwind "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" }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { noreturn 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 = !{!"_ZTSN5SimTK9TiXmlNodeE", !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 = !{!"_ZTSN5SimTK9TiXmlBaseE", !8, i64 8, !12, i64 16}
!8 = !{!"_ZTSN5SimTK11TiXmlCursorE", !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 = !{!"_ZTSN5SimTK9TiXmlNode8NodeTypeE", !10, i64 0}
!14 = !{!"_ZTSN5SimTK6StringE", !15, i64 0}
!15 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !16, i64 0, !17, i64 8, !10, i64 16}
!16 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !12, i64 0}
!17 = !{!"long", !10, i64 0}
!18 = !{!6, !12, i64 96}
!19 = !{!6, !12, i64 88}
!20 = !{!12, !12, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass