; LLVM IR from JayXon/Leanify :: lib/pugixml/pugixml.ll (ZN4pugi8xml_node18insert_child_afterENS_13xml_node_typeERKS0_)

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

@.str.6 = external hidden unnamed_addr constant [4 x i8], align 1

; 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: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN4pugi8xml_node8set_nameEPKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #2 align 2

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local ptr @_ZN4pugi8xml_node18insert_child_afterENS_13xml_node_typeERKS0_(ptr noundef nonnull align 8 dereferenceable(8) %0, i32 noundef %1, ptr noundef nonnull align 8 dereferenceable(8) %2) #2 align 2 {
  %4 = alloca %"class.pugi::xml_node", align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca %"class.pugi::xml_node", align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8
  %12 = call noundef i32 @_ZNK4pugi8xml_node4typeEv(ptr noundef nonnull align 8 dereferenceable(8) %11)
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = call noundef zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_118allow_insert_childENS_13xml_node_typeES2_(i32 noundef %12, i32 noundef %13)
  br i1 %14, label %16, label %15

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

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

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

30:                                               ; preds = %21, %16
  call void @_ZN4pugi8xml_nodeC1Ev(ptr noundef nonnull align 8 dereferenceable(8) %4)
  br label %57

31:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %32 = getelementptr inbounds %"class.pugi::xml_node", ptr %11, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !11
  %34 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZN4pugi4impl12_GLOBAL__N_113get_allocatorINS_15xml_node_structEEERNS1_13xml_allocatorEPKT_(ptr noundef %33)
  store ptr %34, ptr %8, align 8, !tbaa !5
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = call noundef zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_113xml_allocator7reserveEv(ptr noundef nonnull align 8 dereferenceable(16) %35)
  br i1 %36, label %38, label %37

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

38:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = load i32, ptr %6, align 4, !tbaa !9
  %41 = call noundef ptr @_ZN4pugi4impl12_GLOBAL__N_113allocate_nodeERNS1_13xml_allocatorENS_13xml_node_typeE(ptr noundef nonnull align 8 dereferenceable(16) %39, i32 noundef %40)
  call void @_ZN4pugi8xml_nodeC1EPNS_15xml_node_structE(ptr noundef nonnull align 8 dereferenceable(8) %10, ptr noundef %41)
  %42 = call noundef zeroext i1 @_ZNK4pugi8xml_nodentEv(ptr noundef nonnull align 8 dereferenceable(8) %10)
  br i1 %42, label %43, label %44

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

44:                                               ; preds = %38
  %45 = getelementptr inbounds %"class.pugi::xml_node", ptr %10, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !11
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %"class.pugi::xml_node", ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !11
  call void @_ZN4pugi4impl12_GLOBAL__N_117insert_node_afterEPNS_15xml_node_structES3_(ptr noundef %46, ptr noundef %49)
  %50 = load i32, ptr %6, align 4, !tbaa !9
  %51 = icmp eq i32 %50, 7
  br i1 %51, label %52, label %54

52:                                               ; preds = %44
  %53 = call noundef zeroext i1 @_ZN4pugi8xml_node8set_nameEPKc(ptr noundef nonnull align 8 dereferenceable(8) %10, ptr noundef @.str.6)
  br label %54

54:                                               ; preds = %52, %44
  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 %55

55:                                               ; preds = %54, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  br label %56

56:                                               ; preds = %55, %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  br label %57

57:                                               ; preds = %56, %30, %15
  %58 = getelementptr inbounds %"class.pugi::xml_node", ptr %4, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8
  ret ptr %59
}

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

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 = { 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 #3 = { 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 #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 24}
!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 }

@.str.6 = external hidden unnamed_addr constant [4 x i8], align 1

; 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: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN4pugi8xml_node8set_nameEPKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #2 align 2

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

; 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: 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 #4

; Function Attrs: mustprogress uwtable
define dso_local ptr @_ZN4pugi8xml_node18insert_child_afterENS_13xml_node_typeERKS0_(ptr noundef nonnull align 8 dereferenceable(8) %0, i32 noundef %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
  %5 = alloca %"class.pugi::xml_node", align 8
  %6 = tail call noundef i32 @_ZNK4pugi8xml_node4typeEv(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %7 = tail call noundef zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_118allow_insert_childENS_13xml_node_typeES2_(i32 noundef %6, i32 noundef %1)
  br i1 %7, label %9, label %8

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

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

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

15:                                               ; preds = %11, %9
  call void @_ZN4pugi8xml_nodeC1Ev(ptr noundef nonnull align 8 dereferenceable(8) %4)
  br label %33

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

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

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

23:                                               ; preds = %20
  call void @_ZN4pugi8xml_nodeC1Ev(ptr noundef nonnull align 8 dereferenceable(8) %4)
  br label %32

24:                                               ; preds = %20
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  call void @_ZN4pugi4impl12_GLOBAL__N_117insert_node_afterEPNS_15xml_node_structES3_(ptr noundef %25, ptr noundef %26)
  %27 = icmp eq i32 %1, 7
  br i1 %27, label %28, label %30

28:                                               ; preds = %24
  %29 = call noundef zeroext i1 @_ZN4pugi8xml_node8set_nameEPKc(ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef nonnull @.str.6)
  br label %30

30:                                               ; preds = %28, %24
  %31 = load i64, ptr %5, align 8, !tbaa !13
  store i64 %31, ptr %4, align 8, !tbaa !13
  br label %32

32:                                               ; preds = %30, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #5
  br label %33

33:                                               ; preds = %19, %32, %15, %8
  %34 = load ptr, ptr %4, align 8
  ret ptr %34
}

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

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 = { 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 #3 = { 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 #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 = { 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 24}
!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,SimplifyCFGPass,TailCallElimPass