; LLVM IR from JayXon/Leanify :: lib/pugixml/pugixml.ll (ZNK4pugi8xml_node23find_child_by_attributeEPKcS2_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 }
%"struct.pugi::xml_attribute_struct" = type { i64, ptr, ptr, ptr, ptr }

@.str.4 = external hidden unnamed_addr constant [1 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 hidden noundef zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_18strequalEPKcS3_(ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local ptr @_ZNK4pugi8xml_node23find_child_by_attributeEPKcS2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #2 align 2 {
  %5 = alloca %"class.pugi::xml_node", align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  %16 = load ptr, ptr %6, align 8
  %17 = getelementptr inbounds %"class.pugi::xml_node", ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = icmp ne ptr %18, null
  br i1 %19, label %21, label %20

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

21:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %22 = getelementptr inbounds %"class.pugi::xml_node", ptr %16, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !9
  %24 = getelementptr inbounds %"struct.pugi::xml_node_struct", ptr %23, i32 0, i32 4
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  store ptr %25, ptr %10, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %92, %21
  %27 = load ptr, ptr %10, align 8, !tbaa !5
  %28 = icmp ne ptr %27, null
  br i1 %28, label %30, label %29

29:                                               ; preds = %26
  store i32 2, ptr %11, align 4
  br label %96

30:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  %32 = getelementptr inbounds %"struct.pugi::xml_node_struct", ptr %31, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !14
  store ptr %33, ptr %12, align 8, !tbaa !5
  %34 = load ptr, ptr %12, align 8, !tbaa !5
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %88

36:                                               ; preds = %30
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = load ptr, ptr %12, align 8, !tbaa !5
  %39 = call noundef zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_18strequalEPKcS3_(ptr noundef %37, ptr noundef %38)
  br i1 %39, label %40, label %88

40:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = getelementptr inbounds %"struct.pugi::xml_node_struct", ptr %41, i32 0, i32 7
  %43 = load ptr, ptr %42, align 8, !tbaa !15
  store ptr %43, ptr %13, align 8, !tbaa !5
  br label %44

44:                                               ; preds = %81, %40
  %45 = load ptr, ptr %13, align 8, !tbaa !5
  %46 = icmp ne ptr %45, null
  br i1 %46, label %48, label %47

47:                                               ; preds = %44
  store i32 5, ptr %11, align 4
  br label %85

48:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %49 = load ptr, ptr %13, align 8, !tbaa !5
  %50 = getelementptr inbounds %"struct.pugi::xml_attribute_struct", ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !16
  store ptr %51, ptr %14, align 8, !tbaa !5
  %52 = load ptr, ptr %14, align 8, !tbaa !5
  %53 = icmp ne ptr %52, null
  br i1 %53, label %54, label %77

54:                                               ; preds = %48
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = load ptr, ptr %14, align 8, !tbaa !5
  %57 = call noundef zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_18strequalEPKcS3_(ptr noundef %55, ptr noundef %56)
  br i1 %57, label %58, label %77

58:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %59 = load ptr, ptr %13, align 8, !tbaa !5
  %60 = getelementptr inbounds %"struct.pugi::xml_attribute_struct", ptr %59, i32 0, i32 2
  %61 = load ptr, ptr %60, align 8, !tbaa !18
  store ptr %61, ptr %15, align 8, !tbaa !5
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = load ptr, ptr %15, align 8, !tbaa !5
  %64 = icmp ne ptr %63, null
  br i1 %64, label %65, label %67

65:                                               ; preds = %58
  %66 = load ptr, ptr %15, align 8, !tbaa !5
  br label %68

67:                                               ; preds = %58
  br label %68

68:                                               ; preds = %67, %65
  %69 = phi ptr [ %66, %65 ], [ @.str.4, %67 ]
  %70 = call noundef zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_18strequalEPKcS3_(ptr noundef %62, ptr noundef %69)
  br i1 %70, label %71, label %73

71:                                               ; preds = %68
  %72 = load ptr, ptr %10, align 8, !tbaa !5
  call void @_ZN4pugi8xml_nodeC1EPNS_15xml_node_structE(ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef %72)
  store i32 1, ptr %11, align 4
  br label %74

73:                                               ; preds = %68
  store i32 0, ptr %11, align 4
  br label %74

74:                                               ; preds = %73, %71
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  %75 = load i32, ptr %11, align 4
  switch i32 %75, label %78 [
    i32 0, label %76
  ]

76:                                               ; preds = %74
  br label %77

77:                                               ; preds = %76, %54, %48
  store i32 0, ptr %11, align 4
  br label %78

78:                                               ; preds = %77, %74
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  %79 = load i32, ptr %11, align 4
  switch i32 %79, label %85 [
    i32 0, label %80
  ]

80:                                               ; preds = %78
  br label %81

81:                                               ; preds = %80
  %82 = load ptr, ptr %13, align 8, !tbaa !5
  %83 = getelementptr inbounds %"struct.pugi::xml_attribute_struct", ptr %82, i32 0, i32 4
  %84 = load ptr, ptr %83, align 8, !tbaa !19
  store ptr %84, ptr %13, align 8, !tbaa !5
  br label %44, !llvm.loop !20

85:                                               ; preds = %78, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  %86 = load i32, ptr %11, align 4
  switch i32 %86, label %89 [
    i32 5, label %87
  ]

87:                                               ; preds = %85
  br label %88

88:                                               ; preds = %87, %36, %30
  store i32 0, ptr %11, align 4
  br label %89

89:                                               ; preds = %88, %85
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %90 = load i32, ptr %11, align 4
  switch i32 %90, label %96 [
    i32 0, label %91
  ]

91:                                               ; preds = %89
  br label %92

92:                                               ; preds = %91
  %93 = load ptr, ptr %10, align 8, !tbaa !5
  %94 = getelementptr inbounds %"struct.pugi::xml_node_struct", ptr %93, i32 0, i32 6
  %95 = load ptr, ptr %94, align 8, !tbaa !22
  store ptr %95, ptr %10, align 8, !tbaa !5
  br label %26, !llvm.loop !23

96:                                               ; preds = %89, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %97 = load i32, ptr %11, align 4
  switch i32 %97, label %102 [
    i32 2, label %98
    i32 1, label %99
  ]

98:                                               ; preds = %96
  call void @_ZN4pugi8xml_nodeC1Ev(ptr noundef nonnull align 8 dereferenceable(8) %5)
  br label %99

99:                                               ; preds = %98, %96, %20
  %100 = getelementptr inbounds %"class.pugi::xml_node", ptr %5, i32 0, i32 0
  %101 = load ptr, ptr %100, align 8
  ret ptr %101

102:                                              ; preds = %96
  unreachable
}

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 = { 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 32}
!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 8}
!15 = !{!12, !6, i64 56}
!16 = !{!17, !6, i64 8}
!17 = !{!"_ZTSN4pugi20xml_attribute_structE", !13, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!18 = !{!17, !6, i64 16}
!19 = !{!17, !6, i64 32}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!12, !6, i64 48}
!23 = distinct !{!23, !21}


; 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.4 = external hidden unnamed_addr constant [1 x i8], align 1

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

; Function Attrs: mustprogress uwtable
define dso_local ptr @_ZNK4pugi8xml_node23find_child_by_attributeEPKcS2_S2_(ptr nocapture noundef nonnull readonly align 8 dereferenceable(8) %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #1 align 2 {
  %5 = alloca %"class.pugi::xml_node", align 8
  %6 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %7, label %8

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

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %6, i64 32
  %.050 = load ptr, ptr %9, align 8, !tbaa !10
  %.not3151 = icmp eq ptr %.050, null
  br i1 %.not3151, label %._crit_edge, label %.lr.ph54

.lr.ph54:                                         ; preds = %8, %.thread
  %.052 = phi ptr [ %.0, %.thread ], [ %.050, %8 ]
  %10 = getelementptr inbounds i8, ptr %.052, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %.not32 = icmp eq ptr %11, null
  br i1 %.not32, label %.thread, label %12

12:                                               ; preds = %.lr.ph54
  %13 = tail call noundef zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_18strequalEPKcS3_(ptr noundef %1, ptr noundef nonnull %11)
  br i1 %13, label %14, label %.thread

14:                                               ; preds = %12
  %15 = getelementptr inbounds i8, ptr %.052, i64 56
  %.02747 = load ptr, ptr %15, align 8, !tbaa !10
  %.not3348 = icmp eq ptr %.02747, null
  br i1 %.not3348, label %.thread, label %.lr.ph

.lr.ph:                                           ; preds = %14, %.critedge37
  %.02749 = phi ptr [ %.027, %.critedge37 ], [ %.02747, %14 ]
  %16 = getelementptr inbounds i8, ptr %.02749, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  %.not34 = icmp eq ptr %17, null
  br i1 %.not34, label %.critedge37, label %18

18:                                               ; preds = %.lr.ph
  %19 = tail call noundef zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_18strequalEPKcS3_(ptr noundef %2, ptr noundef nonnull %17)
  br i1 %19, label %20, label %.critedge37

20:                                               ; preds = %18
  %21 = getelementptr inbounds i8, ptr %.02749, i64 16
  %22 = load ptr, ptr %21, align 8, !tbaa !16
  %.not35 = icmp eq ptr %22, null
  %23 = select i1 %.not35, ptr @.str.4, ptr %22
  %24 = tail call noundef zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_18strequalEPKcS3_(ptr noundef %3, ptr noundef nonnull %23)
  br i1 %24, label %27, label %.critedge37

.critedge37:                                      ; preds = %20, %18, %.lr.ph
  %25 = getelementptr inbounds i8, ptr %.02749, i64 32
  %.027 = load ptr, ptr %25, align 8, !tbaa !10
  %.not33 = icmp eq ptr %.027, null
  br i1 %.not33, label %.thread, label %.lr.ph, !llvm.loop !17

.thread:                                          ; preds = %.critedge37, %14, %12, %.lr.ph54
  %26 = getelementptr inbounds i8, ptr %.052, i64 48
  %.0 = load ptr, ptr %26, align 8, !tbaa !10
  %.not31 = icmp eq ptr %.0, null
  br i1 %.not31, label %._crit_edge, label %.lr.ph54, !llvm.loop !19

27:                                               ; preds = %20
  call void @_ZN4pugi8xml_nodeC1EPNS_15xml_node_structE(ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef nonnull %.052)
  br label %28

._crit_edge:                                      ; preds = %.thread, %8
  call void @_ZN4pugi8xml_nodeC1Ev(ptr noundef nonnull align 8 dereferenceable(8) %5)
  br label %28

28:                                               ; preds = %27, %._crit_edge, %7
  %29 = load ptr, ptr %5, align 8
  ret ptr %29
}

declare void @_ZN4pugi8xml_nodeC1Ev(ptr) local_unnamed_addr

declare void @_ZN4pugi8xml_nodeC1EPNS_15xml_node_structE(ptr, ptr) local_unnamed_addr

attributes #0 = { 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 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_nodeE", !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!7, !7, i64 0}
!11 = !{!12, !7, i64 8}
!12 = !{!"_ZTSN4pugi15xml_node_structE", !13, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56}
!13 = !{!"long", !8, i64 0}
!14 = !{!15, !7, i64 8}
!15 = !{!"_ZTSN4pugi20xml_attribute_structE", !13, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32}
!16 = !{!15, !7, i64 16}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


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