; LLVM IR from JayXon/Leanify :: lib/pugixml/pugixml.ll (ZN4pugi8xml_node17insert_move_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: inlinehint mustprogress nounwind uwtable
declare hidden noundef nonnull align 8 dereferenceable(96) ptr @_ZN4pugi4impl12_GLOBAL__N_112get_documentINS_15xml_node_structEEERNS1_19xml_document_structEPKT_(ptr noundef) #1

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_113xml_allocator7reserveEv(ptr noundef nonnull align 8 dereferenceable(16)) #2 align 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: inlinehint mustprogress nounwind uwtable
declare hidden void @_ZN4pugi4impl12_GLOBAL__N_117insert_node_afterEPNS_15xml_node_structES3_(ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
declare hidden noundef zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_110allow_moveENS_8xml_nodeES2_(ptr, ptr) #4

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden void @_ZN4pugi4impl12_GLOBAL__N_111remove_nodeEPNS_15xml_node_structE(ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local ptr @_ZN4pugi8xml_node17insert_move_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) #4 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 %"class.pugi::xml_node", align 8
  %9 = alloca %"class.pugi::xml_node", align 8
  %10 = alloca ptr, align 8
  %11 = 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
  %12 = load ptr, ptr %5, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 8 %12, i64 8, i1 false), !tbaa.struct !9
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %9, ptr align 8 %13, i64 8, i1 false), !tbaa.struct !9
  %14 = getelementptr inbounds %"class.pugi::xml_node", ptr %8, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8
  %16 = getelementptr inbounds %"class.pugi::xml_node", ptr %9, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8
  %18 = call noundef zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_110allow_moveENS_8xml_nodeES2_(ptr %15, ptr %17)
  br i1 %18, label %20, label %19

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

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

25:                                               ; preds = %20
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds %"class.pugi::xml_node", ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !10
  %29 = getelementptr inbounds %"struct.pugi::xml_node_struct", ptr %28, i32 0, i32 3
  %30 = load ptr, ptr %29, align 8, !tbaa !12
  %31 = getelementptr inbounds %"class.pugi::xml_node", ptr %12, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !10
  %33 = icmp ne ptr %30, %32
  br i1 %33, label %34, label %35

34:                                               ; preds = %25, %20
  call void @_ZN4pugi8xml_nodeC1Ev(ptr noundef nonnull align 8 dereferenceable(8) %4)
  br label %69

35:                                               ; preds = %25
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %"class.pugi::xml_node", ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !10
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds %"class.pugi::xml_node", ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !10
  %42 = icmp eq ptr %38, %41
  br i1 %42, label %43, label %44

43:                                               ; preds = %35
  call void @_ZN4pugi8xml_nodeC1Ev(ptr noundef nonnull align 8 dereferenceable(8) %4)
  br label %69

44:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %45 = getelementptr inbounds %"class.pugi::xml_node", ptr %12, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !10
  %47 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN4pugi4impl12_GLOBAL__N_113get_allocatorINS_15xml_node_structEEERNS1_13xml_allocatorEPKT_(ptr noundef %46)
  store ptr %47, ptr %10, align 8, !tbaa !5
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = call noundef zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_113xml_allocator7reserveEv(ptr noundef nonnull align 8 dereferenceable(16) %48)
  br i1 %49, label %51, label %50

50:                                               ; preds = %44
  call void @_ZN4pugi8xml_nodeC1Ev(ptr noundef nonnull align 8 dereferenceable(8) %4)
  store i32 1, ptr %11, align 4
  br label %68

51:                                               ; preds = %44
  %52 = getelementptr inbounds %"class.pugi::xml_node", ptr %12, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !10
  %54 = call noundef nonnull align 8 dereferenceable(96) ptr @_ZN4pugi4impl12_GLOBAL__N_112get_documentINS_15xml_node_structEEERNS1_19xml_document_structEPKT_(ptr noundef %53)
  %55 = getelementptr inbounds %"struct.pugi::xml_node_struct", ptr %54, i32 0, i32 0
  %56 = load i64, ptr %55, align 8, !tbaa !15
  %57 = or i64 %56, 64
  store i64 %57, ptr %55, align 8, !tbaa !15
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds %"class.pugi::xml_node", ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !10
  call void @_ZN4pugi4impl12_GLOBAL__N_111remove_nodeEPNS_15xml_node_structE(ptr noundef %60)
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = getelementptr inbounds %"class.pugi::xml_node", ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !10
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = getelementptr inbounds %"class.pugi::xml_node", ptr %64, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8, !tbaa !10
  call void @_ZN4pugi4impl12_GLOBAL__N_117insert_node_afterEPNS_15xml_node_structES3_(ptr noundef %63, ptr noundef %66)
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 %67, i64 8, i1 false), !tbaa.struct !9
  store i32 1, ptr %11, align 4
  br label %68

68:                                               ; preds = %51, %50
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %69

69:                                               ; preds = %68, %43, %34, %19
  %70 = getelementptr inbounds %"class.pugi::xml_node", ptr %4, i32 0, i32 0
  %71 = load ptr, ptr %70, align 8
  ret ptr %71
}

declare void @_ZN4pugi8xml_nodeC1Ev(ptr)

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i64 0, i64 8, !5}
!10 = !{!11, !6, i64 0}
!11 = !{!"_ZTSN4pugi8xml_nodeE", !6, i64 0}
!12 = !{!13, !6, i64 24}
!13 = !{!"_ZTSN4pugi15xml_node_structE", !14, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!14 = !{!"long", !7, i64 0}
!15 = !{!13, !14, i64 0}


; 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: inlinehint mustprogress nounwind uwtable
declare hidden noundef nonnull align 8 dereferenceable(96) ptr @_ZN4pugi4impl12_GLOBAL__N_112get_documentINS_15xml_node_structEEERNS1_19xml_document_structEPKT_(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_113xml_allocator7reserveEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1 align 2

; 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 #0

; Function Attrs: mustprogress uwtable
declare hidden noundef zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_110allow_moveENS_8xml_nodeES2_(ptr, ptr) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden void @_ZN4pugi4impl12_GLOBAL__N_111remove_nodeEPNS_15xml_node_structE(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local ptr @_ZN4pugi8xml_node17insert_move_afterERKS0_S2_(ptr nocapture noundef nonnull readonly align 8 dereferenceable(8) %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(8) %1, ptr nocapture noundef nonnull readonly align 8 dereferenceable(8) %2) local_unnamed_addr #2 align 2 {
  %4 = alloca %"class.pugi::xml_node", align 8
  %.sroa.01.0.copyload = load ptr, ptr %0, align 8, !tbaa !5
  %.sroa.0.0.copyload = load ptr, ptr %1, align 8, !tbaa !5
  %5 = tail call noundef zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_110allow_moveENS_8xml_nodeES2_(ptr %.sroa.01.0.copyload, ptr %.sroa.0.0.copyload)
  br i1 %5, label %7, label %6

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

7:                                                ; preds = %3
  %8 = load ptr, ptr %2, align 8, !tbaa !9
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %13, label %9

9:                                                ; preds = %7
  %10 = getelementptr inbounds i8, ptr %8, i64 24
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %12 = load ptr, ptr %0, align 8, !tbaa !9
  %.not13 = icmp eq ptr %11, %12
  br i1 %.not13, label %14, label %13

13:                                               ; preds = %9, %7
  call void @_ZN4pugi8xml_nodeC1Ev(ptr noundef nonnull align 8 dereferenceable(8) %4)
  br label %31

14:                                               ; preds = %9
  %15 = load ptr, ptr %1, align 8, !tbaa !9
  %16 = icmp eq ptr %15, %8
  br i1 %16, label %17, label %18

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

18:                                               ; preds = %14
  %19 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZN4pugi4impl12_GLOBAL__N_113get_allocatorINS_15xml_node_structEEERNS1_13xml_allocatorEPKT_(ptr noundef %12)
  %20 = tail call noundef zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_113xml_allocator7reserveEv(ptr noundef nonnull align 8 dereferenceable(16) %19)
  br i1 %20, label %22, label %21

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

22:                                               ; preds = %18
  %23 = load ptr, ptr %0, align 8, !tbaa !9
  %24 = tail call noundef nonnull align 8 dereferenceable(96) ptr @_ZN4pugi4impl12_GLOBAL__N_112get_documentINS_15xml_node_structEEERNS1_19xml_document_structEPKT_(ptr noundef %23)
  %25 = load i64, ptr %24, align 8, !tbaa !14
  %26 = or i64 %25, 64
  store i64 %26, ptr %24, align 8, !tbaa !14
  %27 = load ptr, ptr %1, align 8, !tbaa !9
  tail call void @_ZN4pugi4impl12_GLOBAL__N_111remove_nodeEPNS_15xml_node_structE(ptr noundef %27)
  %28 = load ptr, ptr %1, align 8, !tbaa !9
  %29 = load ptr, ptr %2, align 8, !tbaa !9
  tail call void @_ZN4pugi4impl12_GLOBAL__N_117insert_node_afterEPNS_15xml_node_structES3_(ptr noundef %28, ptr noundef %29)
  %30 = load i64, ptr %1, align 8, !tbaa !5
  store i64 %30, ptr %4, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %21, %22, %17, %13, %6
  %32 = load ptr, ptr %4, align 8
  ret ptr %32
}

declare void @_ZN4pugi8xml_nodeC1Ev(ptr) local_unnamed_addr

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

!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 0}
!10 = !{!"_ZTSN4pugi8xml_nodeE", !6, i64 0}
!11 = !{!12, !6, i64 24}
!12 = !{!"_ZTSN4pugi15xml_node_structE", !13, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 0}


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