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

; 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_text" = 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 zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_112is_text_nodeEPNS_15xml_node_structE(ptr noundef) #1

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

10:                                               ; preds = %1
  %11 = getelementptr inbounds %"class.pugi::xml_text", ptr %6, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = call noundef zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_112is_text_nodeEPNS_15xml_node_structE(ptr noundef %12)
  br i1 %13, label %14, label %17

14:                                               ; preds = %10, %1
  %15 = getelementptr inbounds %"class.pugi::xml_text", ptr %6, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  store ptr %16, ptr %2, align 8
  br label %56

17:                                               ; preds = %10
  %18 = getelementptr inbounds %"class.pugi::xml_text", ptr %6, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %20 = getelementptr inbounds %"struct.pugi::xml_node_struct", ptr %19, i32 0, i32 0
  %21 = load i64, ptr %20, align 8, !tbaa !11
  %22 = and i64 %21, 15
  %23 = trunc i64 %22 to i32
  %24 = icmp eq i32 %23, 2
  br i1 %24, label %25, label %34

25:                                               ; preds = %17
  %26 = getelementptr inbounds %"class.pugi::xml_text", ptr %6, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  %28 = getelementptr inbounds %"struct.pugi::xml_node_struct", ptr %27, i32 0, i32 2
  %29 = load ptr, ptr %28, align 8, !tbaa !14
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %34

31:                                               ; preds = %25
  %32 = getelementptr inbounds %"class.pugi::xml_text", ptr %6, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !9
  store ptr %33, ptr %2, align 8
  br label %56

34:                                               ; preds = %25, %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %35 = getelementptr inbounds %"class.pugi::xml_text", ptr %6, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !9
  %37 = getelementptr inbounds %"struct.pugi::xml_node_struct", ptr %36, i32 0, i32 4
  %38 = load ptr, ptr %37, align 8, !tbaa !15
  store ptr %38, ptr %4, align 8, !tbaa !5
  br label %39

39:                                               ; preds = %49, %34
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = icmp ne ptr %40, null
  br i1 %41, label %43, label %42

42:                                               ; preds = %39
  store i32 2, ptr %5, align 4
  br label %53

43:                                               ; preds = %39
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = call noundef zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_112is_text_nodeEPNS_15xml_node_structE(ptr noundef %44)
  br i1 %45, label %46, label %48

46:                                               ; preds = %43
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %47, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %53

48:                                               ; preds = %43
  br label %49

49:                                               ; preds = %48
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %"struct.pugi::xml_node_struct", ptr %50, i32 0, i32 6
  %52 = load ptr, ptr %51, align 8, !tbaa !16
  store ptr %52, ptr %4, align 8, !tbaa !5
  br label %39, !llvm.loop !17

53:                                               ; preds = %46, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %54 = load i32, ptr %5, align 4
  switch i32 %54, label %58 [
    i32 2, label %55
    i32 1, label %56
  ]

55:                                               ; preds = %53
  store ptr null, ptr %2, align 8
  br label %56

56:                                               ; preds = %55, %53, %31, %14
  %57 = load ptr, ptr %2, align 8
  ret ptr %57

58:                                               ; preds = %53
  unreachable
}

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 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 = { 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_textE", !6, i64 0}
!11 = !{!12, !13, i64 0}
!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, !6, i64 16}
!15 = !{!12, !6, i64 32}
!16 = !{!12, !6, i64 48}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_112is_text_nodeEPNS_15xml_node_structE(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZNK4pugi8xml_text5_dataEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(8) %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 %.loopexit, label %3

3:                                                ; preds = %1
  %4 = tail call noundef zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_112is_text_nodeEPNS_15xml_node_structE(ptr noundef nonnull %2)
  %.pre = load ptr, ptr %0, align 8, !tbaa !5
  br i1 %4, label %.loopexit, label %5

5:                                                ; preds = %3
  %6 = load i64, ptr %.pre, align 8, !tbaa !10
  %7 = and i64 %6, 15
  %8 = icmp eq i64 %7, 2
  br i1 %8, label %9, label %12

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

12:                                               ; preds = %9, %5
  %13 = getelementptr inbounds i8, ptr %.pre, i64 32
  %.0611 = load ptr, ptr %13, align 8, !tbaa !14
  %.not1012 = icmp eq ptr %.0611, null
  br i1 %.not1012, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %12, %15
  %.0613 = phi ptr [ %.06, %15 ], [ %.0611, %12 ]
  %14 = tail call noundef zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_112is_text_nodeEPNS_15xml_node_structE(ptr noundef nonnull %.0613)
  br i1 %14, label %.loopexit, label %15

15:                                               ; preds = %.lr.ph
  %16 = getelementptr inbounds i8, ptr %.0613, i64 48
  %.06 = load ptr, ptr %16, align 8, !tbaa !14
  %.not10 = icmp eq ptr %.06, null
  br i1 %.not10, label %.loopexit, label %.lr.ph, !llvm.loop !15

.loopexit:                                        ; preds = %.lr.ph, %15, %1, %3, %12, %9
  %.1 = phi ptr [ %.pre, %9 ], [ null, %12 ], [ %.pre, %3 ], [ null, %1 ], [ %.0613, %.lr.ph ], [ null, %15 ]
  ret ptr %.1
}

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

!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_textE", !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !12, i64 0}
!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 = !{!11, !7, i64 16}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass