; LLVM IR from mackorone/mms :: old/v2/src/lib/pugixml/pugixml.ll (ZN4pugi8xml_node17insert_copy_afterERKS0_S2_)

; 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.pugi::xml_node" = type { ptr }
%"struct.pugi::xml_node_struct" = type { i64, ptr, ptr, ptr, ptr, ptr, 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 nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK4pugi8xml_nodentEv(ptr noundef nonnull align 8 dereferenceable(8)) #1 align 2

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef nonnull align 8 dereferenceable(16) ptr @_ZN4pugi4impl12_GLOBAL__N_113get_allocatorEPKNS_15xml_node_structE(ptr noundef) #2

; 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) #3

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

; Function Attrs: inlinehint mustprogress uwtable
declare hidden noundef ptr @_ZN4pugi4impl12_GLOBAL__N_113allocate_nodeERNS1_13xml_allocatorENS_13xml_node_typeE(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #4

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden void @_ZN4pugi4impl12_GLOBAL__N_117insert_node_afterEPNS_15xml_node_structES3_(ptr noundef, ptr noundef) #2

; Function Attrs: mustprogress uwtable
declare hidden void @_ZN4pugi4impl12_GLOBAL__N_114node_copy_treeEPNS_15xml_node_structES3_(ptr noundef, ptr noundef) #5

; Function Attrs: mustprogress uwtable
define dso_local ptr @_ZN4pugi8xml_node17insert_copy_afterERKS0_S2_(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull align 8 dereferenceable(8) %2) #5 align 2 {
  %4 = alloca %"class.pugi::xml_node", align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %"class.pugi::xml_node", align 8
  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
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = call noundef i32 @_ZNK4pugi8xml_node4typeEv(ptr noundef nonnull align 8 dereferenceable(8) %12)
  store i32 %13, ptr %8, align 4, !tbaa !9
  %14 = call noundef i32 @_ZNK4pugi8xml_node4typeEv(ptr noundef nonnull align 8 dereferenceable(8) %11)
  %15 = load i32, ptr %8, align 4, !tbaa !9
  %16 = call noundef zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_118allow_insert_childENS_13xml_node_typeES2_(i32 noundef %14, i32 noundef %15)
  br i1 %16, label %18, label %17

17:                                               ; preds = %3
  call void @_ZN4pugi8xml_nodeC1Ev(ptr noundef nonnull align 8 dereferenceable(8) %4)
  store i32 1, ptr %9, align 4
  br label %53

18:                                               ; preds = %3
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds %"class.pugi::xml_node", ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !11
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %32

23:                                               ; preds = %18
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = getelementptr inbounds %"class.pugi::xml_node", ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  %27 = getelementptr inbounds %"struct.pugi::xml_node_struct", ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  %29 = getelementptr inbounds %"class.pugi::xml_node", ptr %11, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !11
  %31 = icmp ne ptr %28, %30
  br i1 %31, label %32, label %33

32:                                               ; preds = %23, %18
  call void @_ZN4pugi8xml_nodeC1Ev(ptr noundef nonnull align 8 dereferenceable(8) %4)
  store i32 1, ptr %9, align 4
  br label %53

33:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %34 = getelementptr inbounds %"class.pugi::xml_node", ptr %11, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !11
  %36 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN4pugi4impl12_GLOBAL__N_113get_allocatorEPKNS_15xml_node_structE(ptr noundef %35)
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = call noundef ptr @_ZN4pugi4impl12_GLOBAL__N_113allocate_nodeERNS1_13xml_allocatorENS_13xml_node_typeE(ptr noundef nonnull align 8 dereferenceable(16) %36, i32 noundef %37)
  call void @_ZN4pugi8xml_nodeC1EPNS_15xml_node_structE(ptr noundef nonnull align 8 dereferenceable(8) %10, ptr noundef %38)
  %39 = call noundef zeroext i1 @_ZNK4pugi8xml_nodentEv(ptr noundef nonnull align 8 dereferenceable(8) %10)
  br i1 %39, label %40, label %41

40:                                               ; preds = %33
  call void @_ZN4pugi8xml_nodeC1Ev(ptr noundef nonnull align 8 dereferenceable(8) %4)
  store i32 1, ptr %9, align 4
  br label %52

41:                                               ; preds = %33
  %42 = getelementptr inbounds %"class.pugi::xml_node", ptr %10, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !11
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = getelementptr inbounds %"class.pugi::xml_node", ptr %44, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !11
  call void @_ZN4pugi4impl12_GLOBAL__N_117insert_node_afterEPNS_15xml_node_structES3_(ptr noundef %43, ptr noundef %46)
  %47 = getelementptr inbounds %"class.pugi::xml_node", ptr %10, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !11
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %"class.pugi::xml_node", ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !11
  call void @_ZN4pugi4impl12_GLOBAL__N_114node_copy_treeEPNS_15xml_node_structES3_(ptr noundef %48, ptr noundef %51)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 %10, i64 8, i1 false), !tbaa.struct !16
  store i32 1, ptr %9, align 4
  br label %52

52:                                               ; preds = %41, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  br label %53

53:                                               ; preds = %52, %32, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  %54 = getelementptr inbounds %"class.pugi::xml_node", ptr %4, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8
  ret ptr %55
}

declare void @_ZN4pugi8xml_nodeC1Ev(ptr)

declare void @_ZN4pugi8xml_nodeC1EPNS_15xml_node_structE(ptr, ptr)

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 = { inlinehint 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { 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 #6 = { 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, !10, i64 0}
!10 = !{!"_ZTSN4pugi13xml_node_typeE", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTSN4pugi8xml_nodeE", !6, i64 0}
!13 = !{!14, !6, i64 8}
!14 = !{!"_ZTSN4pugi15xml_node_structE", !15, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!15 = !{!"long", !7, i64 0}
!16 = !{i64 0, i64 8, !5}


; 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.pugi::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

; 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 noundef zeroext i1 @_ZNK4pugi8xml_nodentEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1 align 2

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef nonnull align 8 dereferenceable(16) ptr @_ZN4pugi4impl12_GLOBAL__N_113get_allocatorEPKNS_15xml_node_structE(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: inlinehint mustprogress uwtable
declare hidden noundef ptr @_ZN4pugi4impl12_GLOBAL__N_113allocate_nodeERNS1_13xml_allocatorENS_13xml_node_typeE(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden void @_ZN4pugi4impl12_GLOBAL__N_117insert_node_afterEPNS_15xml_node_structES3_(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare hidden void @_ZN4pugi4impl12_GLOBAL__N_114node_copy_treeEPNS_15xml_node_structES3_(ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: mustprogress uwtable
define dso_local ptr @_ZN4pugi8xml_node17insert_copy_afterERKS0_S2_(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef nonnull align 8 dereferenceable(8) %1, ptr nocapture noundef nonnull readonly align 8 dereferenceable(8) %2) local_unnamed_addr #4 align 2 {
  %4 = alloca %"class.pugi::xml_node", align 8
  %5 = alloca %"class.pugi::xml_node", align 8
  %6 = tail call noundef i32 @_ZNK4pugi8xml_node4typeEv(ptr noundef nonnull align 8 dereferenceable(8) %1)
  %7 = tail call noundef i32 @_ZNK4pugi8xml_node4typeEv(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %8 = tail call noundef zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_118allow_insert_childENS_13xml_node_typeES2_(i32 noundef %7, i32 noundef %6)
  br i1 %8, label %10, label %9

9:                                                ; preds = %3
  call void @_ZN4pugi8xml_nodeC1Ev(ptr noundef nonnull align 8 dereferenceable(8) %4)
  br label %29

10:                                               ; preds = %3
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %.not = icmp eq ptr %11, null
  br i1 %.not, label %16, label %12

12:                                               ; preds = %10
  %13 = getelementptr inbounds i8, ptr %11, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !10
  %15 = load ptr, ptr %0, align 8, !tbaa !5
  %.not7 = icmp eq ptr %14, %15
  br i1 %.not7, label %17, label %16

16:                                               ; preds = %12, %10
  call void @_ZN4pugi8xml_nodeC1Ev(ptr noundef nonnull align 8 dereferenceable(8) %4)
  br label %29

17:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #5
  %18 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZN4pugi4impl12_GLOBAL__N_113get_allocatorEPKNS_15xml_node_structE(ptr noundef %15)
  %19 = tail call noundef ptr @_ZN4pugi4impl12_GLOBAL__N_113allocate_nodeERNS1_13xml_allocatorENS_13xml_node_typeE(ptr noundef nonnull align 8 dereferenceable(16) %18, i32 noundef %6)
  call void @_ZN4pugi8xml_nodeC1EPNS_15xml_node_structE(ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef %19)
  %20 = call noundef zeroext i1 @_ZNK4pugi8xml_nodentEv(ptr noundef nonnull align 8 dereferenceable(8) %5)
  br i1 %20, label %21, label %22

21:                                               ; preds = %17
  call void @_ZN4pugi8xml_nodeC1Ev(ptr noundef nonnull align 8 dereferenceable(8) %4)
  br label %28

22:                                               ; preds = %17
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  call void @_ZN4pugi4impl12_GLOBAL__N_117insert_node_afterEPNS_15xml_node_structES3_(ptr noundef %23, ptr noundef %24)
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load ptr, ptr %1, align 8, !tbaa !5
  call void @_ZN4pugi4impl12_GLOBAL__N_114node_copy_treeEPNS_15xml_node_structES3_(ptr noundef %25, ptr noundef %26)
  %27 = load i64, ptr %5, align 8, !tbaa !13
  store i64 %27, ptr %4, align 8, !tbaa !13
  br label %28

28:                                               ; preds = %22, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #5
  br label %29

29:                                               ; preds = %28, %16, %9
  %30 = load ptr, ptr %4, align 8
  ret ptr %30
}

declare void @_ZN4pugi8xml_nodeC1Ev(ptr) local_unnamed_addr

declare void @_ZN4pugi8xml_nodeC1EPNS_15xml_node_structE(ptr, ptr) local_unnamed_addr

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 = { inlinehint 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 = { 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 #4 = { 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 #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, !7, i64 0}
!6 = !{!"_ZTSN4pugi8xml_nodeE", !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !7, i64 8}
!11 = !{!"_ZTSN4pugi15xml_node_structE", !12, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56}
!12 = !{!"long", !8, i64 0}
!13 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass