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

; 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 }
%"class.pugi::xml_document" = type { %"class.pugi::xml_node", ptr, [192 x i8] }
%"struct.pugi::impl::(anonymous namespace)::xml_document_struct" = type { %"struct.pugi::xml_node_struct", %"struct.pugi::impl::(anonymous namespace)::xml_allocator", ptr, ptr }
%"struct.pugi::xml_node_struct" = type { i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%"struct.pugi::impl::(anonymous namespace)::xml_allocator" = type { ptr, i64 }
%"struct.pugi::impl::(anonymous namespace)::xml_extra_buffer" = type { ptr, ptr }
%"struct.pugi::impl::(anonymous namespace)::xml_memory_page" = type { ptr, ptr, ptr, i64, i64 }

@.str.1 = external hidden unnamed_addr constant [82 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [6 x i8], align 1
@__PRETTY_FUNCTION__._ZN4pugi12xml_document7destroyEv = external hidden unnamed_addr constant [35 x i8], align 1
@_ZN4pugi4impl12_GLOBAL__N_138xml_memory_management_function_storageIiE10deallocateE = external hidden global ptr, align 8
@.str.31 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [112 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4pugi12xml_document7destroyEv(ptr noundef nonnull align 8 dereferenceable(208) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8
  %8 = getelementptr inbounds %"class.pugi::xml_node", ptr %7, i32 0, i32 0
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %12

11:                                               ; preds = %1
  br label %14

12:                                               ; preds = %1
  call void @__assert_fail(ptr noundef @.str.30, ptr noundef @.str.1, i32 noundef 6042, ptr noundef @__PRETTY_FUNCTION__._ZN4pugi12xml_document7destroyEv) #3
  unreachable

13:                                               ; No predecessors!
  br label %14

14:                                               ; preds = %13, %11
  %15 = getelementptr inbounds %"class.pugi::xml_document", ptr %7, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %23

18:                                               ; preds = %14
  %19 = load ptr, ptr @_ZN4pugi4impl12_GLOBAL__N_138xml_memory_management_function_storageIiE10deallocateE, align 8, !tbaa !5
  %20 = getelementptr inbounds %"class.pugi::xml_document", ptr %7, i32 0, i32 1
  %21 = load ptr, ptr %20, align 8, !tbaa !11
  call void %19(ptr noundef %21)
  %22 = getelementptr inbounds %"class.pugi::xml_document", ptr %7, i32 0, i32 1
  store ptr null, ptr %22, align 8, !tbaa !11
  br label %23

23:                                               ; preds = %18, %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %24 = getelementptr inbounds %"class.pugi::xml_node", ptr %7, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !9
  %26 = getelementptr inbounds %"struct.pugi::impl::(anonymous namespace)::xml_document_struct", ptr %25, i32 0, i32 3
  %27 = load ptr, ptr %26, align 8, !tbaa !13
  store ptr %27, ptr %3, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %43, %23
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %32, label %31

31:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %47

32:                                               ; preds = %28
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %"struct.pugi::impl::(anonymous namespace)::xml_extra_buffer", ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !18
  %36 = icmp ne ptr %35, null
  br i1 %36, label %37, label %42

37:                                               ; preds = %32
  %38 = load ptr, ptr @_ZN4pugi4impl12_GLOBAL__N_138xml_memory_management_function_storageIiE10deallocateE, align 8, !tbaa !5
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %"struct.pugi::impl::(anonymous namespace)::xml_extra_buffer", ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !18
  call void %38(ptr noundef %41)
  br label %42

42:                                               ; preds = %37, %32
  br label %43

43:                                               ; preds = %42
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %"struct.pugi::impl::(anonymous namespace)::xml_extra_buffer", ptr %44, i32 0, i32 1
  %46 = load ptr, ptr %45, align 8, !tbaa !20
  store ptr %46, ptr %3, align 8, !tbaa !5
  br label %28, !llvm.loop !21

47:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %48 = getelementptr inbounds %"class.pugi::xml_node", ptr %7, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !9
  %50 = getelementptr inbounds %"struct.pugi::xml_node_struct", ptr %49, i32 0, i32 0
  %51 = load i64, ptr %50, align 8, !tbaa !23
  %52 = and i64 %51, -64
  %53 = inttoptr i64 %52 to ptr
  store ptr %53, ptr %4, align 8, !tbaa !5
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = icmp ne ptr %54, null
  br i1 %55, label %56, label %62

56:                                               ; preds = %47
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %"struct.pugi::impl::(anonymous namespace)::xml_memory_page", ptr %57, i32 0, i32 1
  %59 = load ptr, ptr %58, align 8, !tbaa !24
  %60 = icmp ne ptr %59, null
  %61 = xor i1 %60, true
  br label %62

62:                                               ; preds = %56, %47
  %63 = phi i1 [ false, %47 ], [ %61, %56 ]
  br i1 %63, label %64, label %65

64:                                               ; preds = %62
  br label %67

65:                                               ; preds = %62
  call void @__assert_fail(ptr noundef @.str.31, ptr noundef @.str.1, i32 noundef 6059, ptr noundef @__PRETTY_FUNCTION__._ZN4pugi12xml_document7destroyEv) #3
  unreachable

66:                                               ; No predecessors!
  br label %67

67:                                               ; preds = %66, %64
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %"class.pugi::xml_document", ptr %7, i32 0, i32 2
  %70 = getelementptr inbounds [192 x i8], ptr %69, i64 0, i64 0
  %71 = icmp uge ptr %68, %70
  br i1 %71, label %72, label %78

72:                                               ; preds = %67
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %"class.pugi::xml_document", ptr %7, i32 0, i32 2
  %75 = getelementptr inbounds [192 x i8], ptr %74, i64 0, i64 0
  %76 = getelementptr inbounds i8, ptr %75, i64 192
  %77 = icmp ult ptr %73, %76
  br label %78

78:                                               ; preds = %72, %67
  %79 = phi i1 [ false, %67 ], [ %77, %72 ]
  br i1 %79, label %80, label %81

80:                                               ; preds = %78
  br label %83

81:                                               ; preds = %78
  call void @__assert_fail(ptr noundef @.str.32, ptr noundef @.str.1, i32 noundef 6060, ptr noundef @__PRETTY_FUNCTION__._ZN4pugi12xml_document7destroyEv) #3
  unreachable

82:                                               ; No predecessors!
  br label %83

83:                                               ; preds = %82, %80
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %84 = load ptr, ptr %4, align 8, !tbaa !5
  %85 = getelementptr inbounds %"struct.pugi::impl::(anonymous namespace)::xml_memory_page", ptr %84, i32 0, i32 2
  %86 = load ptr, ptr %85, align 8, !tbaa !26
  store ptr %86, ptr %5, align 8, !tbaa !5
  br label %87

87:                                               ; preds = %91, %83
  %88 = load ptr, ptr %5, align 8, !tbaa !5
  %89 = icmp ne ptr %88, null
  br i1 %89, label %91, label %90

90:                                               ; preds = %87
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %97

91:                                               ; preds = %87
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = getelementptr inbounds %"struct.pugi::impl::(anonymous namespace)::xml_memory_page", ptr %92, i32 0, i32 2
  %94 = load ptr, ptr %93, align 8, !tbaa !26
  store ptr %94, ptr %6, align 8, !tbaa !5
  %95 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN4pugi4impl12_GLOBAL__N_113xml_allocator15deallocate_pageEPNS1_15xml_memory_pageE(ptr noundef %95)
  %96 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %96, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %87, !llvm.loop !27

97:                                               ; preds = %90
  %98 = getelementptr inbounds %"class.pugi::xml_node", ptr %7, i32 0, i32 0
  store ptr null, ptr %98, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  ret void
}

; Function Attrs: mustprogress uwtable
declare hidden void @_ZN4pugi4impl12_GLOBAL__N_113xml_allocator15deallocate_pageEPNS1_15xml_memory_pageE(ptr noundef) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { noreturn nounwind }
attributes #4 = { 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 0}
!10 = !{!"_ZTSN4pugi8xml_nodeE", !6, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"_ZTSN4pugi12xml_documentE", !10, i64 0, !6, i64 8, !7, i64 16}
!13 = !{!14, !6, i64 88}
!14 = !{!"_ZTSN4pugi4impl12_GLOBAL__N_119xml_document_structE", !15, i64 0, !17, i64 64, !6, i64 80, !6, i64 88}
!15 = !{!"_ZTSN4pugi15xml_node_structE", !16, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!16 = !{!"long", !7, i64 0}
!17 = !{!"_ZTSN4pugi4impl12_GLOBAL__N_113xml_allocatorE", !6, i64 0, !16, i64 8}
!18 = !{!19, !6, i64 0}
!19 = !{!"_ZTSN4pugi4impl12_GLOBAL__N_116xml_extra_bufferE", !6, i64 0, !6, i64 8}
!20 = !{!19, !6, i64 8}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!15, !16, i64 0}
!24 = !{!25, !6, i64 8}
!25 = !{!"_ZTSN4pugi4impl12_GLOBAL__N_115xml_memory_pageE", !6, i64 0, !6, i64 8, !6, i64 16, !16, i64 24, !16, i64 32}
!26 = !{!25, !6, i64 16}
!27 = distinct !{!27, !22}


; 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.1 = external hidden unnamed_addr constant [82 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [6 x i8], align 1
@__PRETTY_FUNCTION__._ZN4pugi12xml_document7destroyEv = external hidden unnamed_addr constant [35 x i8], align 1
@_ZN4pugi4impl12_GLOBAL__N_138xml_memory_management_function_storageIiE10deallocateE = external hidden local_unnamed_addr global ptr, align 8
@.str.31 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.32 = external hidden unnamed_addr constant [112 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 uwtable
define dso_local void @_ZN4pugi12xml_document7destroyEv(ptr noundef nonnull align 8 dereferenceable(208) %0) local_unnamed_addr #1 align 2 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %3, label %4

3:                                                ; preds = %1
  tail call void @__assert_fail(ptr noundef nonnull @.str.30, ptr noundef nonnull @.str.1, i32 noundef 6042, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4pugi12xml_document7destroyEv) #2
  unreachable

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !10
  %.not18 = icmp eq ptr %6, null
  br i1 %.not18, label %9, label %7

7:                                                ; preds = %4
  %8 = load ptr, ptr @_ZN4pugi4impl12_GLOBAL__N_138xml_memory_management_function_storageIiE10deallocateE, align 8, !tbaa !12
  tail call void %8(ptr noundef nonnull %6)
  store ptr null, ptr %5, align 8, !tbaa !10
  %.pre = load ptr, ptr %0, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %7, %4
  %10 = phi ptr [ %.pre, %7 ], [ %2, %4 ]
  %11 = getelementptr inbounds i8, ptr %10, i64 88
  %.024 = load ptr, ptr %11, align 8, !tbaa !12
  %.not1925 = icmp eq ptr %.024, null
  br i1 %.not1925, label %._crit_edge, label %.lr.ph

._crit_edge.loopexit:                             ; preds = %19
  %.pre32 = load ptr, ptr %0, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %9
  %12 = phi ptr [ %.pre32, %._crit_edge.loopexit ], [ %10, %9 ]
  %13 = load i64, ptr %12, align 8, !tbaa !13
  %14 = and i64 %13, -64
  %15 = inttoptr i64 %14 to ptr
  %.not20 = icmp eq i64 %14, 0
  br i1 %.not20, label %.critedge, label %21

.lr.ph:                                           ; preds = %9, %19
  %.026 = phi ptr [ %.0, %19 ], [ %.024, %9 ]
  %16 = load ptr, ptr %.026, align 8, !tbaa !16
  %.not23 = icmp eq ptr %16, null
  br i1 %.not23, label %19, label %17

17:                                               ; preds = %.lr.ph
  %18 = load ptr, ptr @_ZN4pugi4impl12_GLOBAL__N_138xml_memory_management_function_storageIiE10deallocateE, align 8, !tbaa !12
  tail call void %18(ptr noundef nonnull %16)
  br label %19

19:                                               ; preds = %.lr.ph, %17
  %20 = getelementptr inbounds i8, ptr %.026, i64 8
  %.0 = load ptr, ptr %20, align 8, !tbaa !12
  %.not19 = icmp eq ptr %.0, null
  br i1 %.not19, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !18

21:                                               ; preds = %._crit_edge
  %22 = getelementptr inbounds i8, ptr %15, i64 8
  %23 = load ptr, ptr %22, align 8, !tbaa !20
  %.not21 = icmp eq ptr %23, null
  br i1 %.not21, label %24, label %.critedge

.critedge:                                        ; preds = %._crit_edge, %21
  tail call void @__assert_fail(ptr noundef nonnull @.str.31, ptr noundef nonnull @.str.1, i32 noundef 6059, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4pugi12xml_document7destroyEv) #2
  unreachable

24:                                               ; preds = %21
  %25 = getelementptr inbounds i8, ptr %0, i64 16
  %26 = icmp ule ptr %25, %15
  %27 = getelementptr inbounds i8, ptr %0, i64 208
  %28 = icmp ugt ptr %27, %15
  %29 = select i1 %26, i1 %28, i1 false
  br i1 %29, label %31, label %30

30:                                               ; preds = %24
  tail call void @__assert_fail(ptr noundef nonnull @.str.32, ptr noundef nonnull @.str.1, i32 noundef 6060, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4pugi12xml_document7destroyEv) #2
  unreachable

31:                                               ; preds = %24
  %32 = getelementptr inbounds i8, ptr %15, i64 16
  %33 = load ptr, ptr %32, align 16, !tbaa !22
  %.not2227 = icmp eq ptr %33, null
  br i1 %.not2227, label %._crit_edge31, label %.lr.ph30

._crit_edge31:                                    ; preds = %.lr.ph30, %31
  store ptr null, ptr %0, align 8, !tbaa !5
  ret void

.lr.ph30:                                         ; preds = %31, %.lr.ph30
  %.01428 = phi ptr [ %35, %.lr.ph30 ], [ %33, %31 ]
  %34 = getelementptr inbounds i8, ptr %.01428, i64 16
  %35 = load ptr, ptr %34, align 8, !tbaa !22
  tail call void @_ZN4pugi4impl12_GLOBAL__N_113xml_allocator15deallocate_pageEPNS1_15xml_memory_pageE(ptr noundef nonnull %.01428)
  %.not22 = icmp eq ptr %35, null
  br i1 %.not22, label %._crit_edge31, label %.lr.ph30, !llvm.loop !23
}

; Function Attrs: mustprogress uwtable
declare hidden void @_ZN4pugi4impl12_GLOBAL__N_113xml_allocator15deallocate_pageEPNS1_15xml_memory_pageE(ptr noundef) local_unnamed_addr #1 align 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 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, !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 = !{!"_ZTSN4pugi12xml_documentE", !6, i64 0, !7, i64 8, !8, i64 16}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"_ZTSN4pugi15xml_node_structE", !15, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56}
!15 = !{!"long", !8, i64 0}
!16 = !{!17, !7, i64 0}
!17 = !{!"_ZTSN4pugi4impl12_GLOBAL__N_116xml_extra_bufferE", !7, i64 0, !7, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!21, !7, i64 8}
!21 = !{!"_ZTSN4pugi4impl12_GLOBAL__N_115xml_memory_pageE", !7, i64 0, !7, i64 8, !7, i64 16, !15, i64 24, !15, i64 32}
!22 = !{!21, !7, i64 16}
!23 = distinct !{!23, !19}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass