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

; 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_(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %1, ptr noundef %2) #2 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 ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  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
  %13 = load ptr, ptr %5, align 8
  %14 = getelementptr inbounds %"class.pugi::xml_node", ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = icmp ne ptr %15, null
  br i1 %16, label %18, label %17

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

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

23:                                               ; preds = %75, %18
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %27, label %26

26:                                               ; preds = %23
  store i32 2, ptr %9, align 4
  br label %79

27:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = getelementptr inbounds %"struct.pugi::xml_node_struct", ptr %28, i32 0, i32 7
  %30 = load ptr, ptr %29, align 8, !tbaa !14
  store ptr %30, ptr %10, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %68, %27
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = icmp ne ptr %32, null
  br i1 %33, label %35, label %34

34:                                               ; preds = %31
  store i32 5, ptr %9, align 4
  br label %72

35:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = getelementptr inbounds %"struct.pugi::xml_attribute_struct", ptr %36, i32 0, i32 1
  %38 = load ptr, ptr %37, align 8, !tbaa !15
  store ptr %38, ptr %11, align 8, !tbaa !5
  %39 = load ptr, ptr %11, align 8, !tbaa !5
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %64

41:                                               ; preds = %35
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = load ptr, ptr %11, align 8, !tbaa !5
  %44 = call noundef zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_18strequalEPKcS3_(ptr noundef %42, ptr noundef %43)
  br i1 %44, label %45, label %64

45:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %46 = load ptr, ptr %10, align 8, !tbaa !5
  %47 = getelementptr inbounds %"struct.pugi::xml_attribute_struct", ptr %46, i32 0, i32 2
  %48 = load ptr, ptr %47, align 8, !tbaa !17
  store ptr %48, ptr %12, align 8, !tbaa !5
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = load ptr, ptr %12, align 8, !tbaa !5
  %51 = icmp ne ptr %50, null
  br i1 %51, label %52, label %54

52:                                               ; preds = %45
  %53 = load ptr, ptr %12, align 8, !tbaa !5
  br label %55

54:                                               ; preds = %45
  br label %55

55:                                               ; preds = %54, %52
  %56 = phi ptr [ %53, %52 ], [ @.str.4, %54 ]
  %57 = call noundef zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_18strequalEPKcS3_(ptr noundef %49, ptr noundef %56)
  br i1 %57, label %58, label %60

58:                                               ; preds = %55
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZN4pugi8xml_nodeC1EPNS_15xml_node_structE(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef %59)
  store i32 1, ptr %9, align 4
  br label %61

60:                                               ; preds = %55
  store i32 0, ptr %9, align 4
  br label %61

61:                                               ; preds = %60, %58
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %62 = load i32, ptr %9, align 4
  switch i32 %62, label %65 [
    i32 0, label %63
  ]

63:                                               ; preds = %61
  br label %64

64:                                               ; preds = %63, %41, %35
  store i32 0, ptr %9, align 4
  br label %65

65:                                               ; preds = %64, %61
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  %66 = load i32, ptr %9, align 4
  switch i32 %66, label %72 [
    i32 0, label %67
  ]

67:                                               ; preds = %65
  br label %68

68:                                               ; preds = %67
  %69 = load ptr, ptr %10, align 8, !tbaa !5
  %70 = getelementptr inbounds %"struct.pugi::xml_attribute_struct", ptr %69, i32 0, i32 4
  %71 = load ptr, ptr %70, align 8, !tbaa !18
  store ptr %71, ptr %10, align 8, !tbaa !5
  br label %31, !llvm.loop !19

72:                                               ; preds = %65, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %73 = load i32, ptr %9, align 4
  switch i32 %73, label %79 [
    i32 5, label %74
  ]

74:                                               ; preds = %72
  br label %75

75:                                               ; preds = %74
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  %77 = getelementptr inbounds %"struct.pugi::xml_node_struct", ptr %76, i32 0, i32 6
  %78 = load ptr, ptr %77, align 8, !tbaa !21
  store ptr %78, ptr %8, align 8, !tbaa !5
  br label %23, !llvm.loop !22

79:                                               ; preds = %72, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %80 = load i32, ptr %9, align 4
  switch i32 %80, label %85 [
    i32 2, label %81
    i32 1, label %82
  ]

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

82:                                               ; preds = %81, %79, %17
  %83 = getelementptr inbounds %"class.pugi::xml_node", ptr %4, i32 0, i32 0
  %84 = load ptr, ptr %83, align 8
  ret ptr %84

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


; 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_(ptr nocapture noundef nonnull readonly align 8 dereferenceable(8) %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 align 2 {
  %4 = alloca %"class.pugi::xml_node", align 8
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %6, label %7

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

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %5, i64 32
  %.039 = load ptr, ptr %8, align 8, !tbaa !10
  %.not2440 = icmp eq ptr %.039, null
  br i1 %.not2440, label %._crit_edge44, label %.lr.ph43

.lr.ph43:                                         ; preds = %7, %._crit_edge
  %.041 = phi ptr [ %.0, %._crit_edge ], [ %.039, %7 ]
  %9 = getelementptr inbounds i8, ptr %.041, i64 56
  %.02136 = load ptr, ptr %9, align 8, !tbaa !10
  %.not2537 = icmp eq ptr %.02136, null
  br i1 %.not2537, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph43, %.critedge29
  %.02138 = phi ptr [ %.021, %.critedge29 ], [ %.02136, %.lr.ph43 ]
  %10 = getelementptr inbounds i8, ptr %.02138, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %.not26 = icmp eq ptr %11, null
  br i1 %.not26, label %.critedge29, label %12

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

14:                                               ; preds = %12
  %15 = getelementptr inbounds i8, ptr %.02138, i64 16
  %16 = load ptr, ptr %15, align 8, !tbaa !14
  %.not27 = icmp eq ptr %16, null
  %17 = select i1 %.not27, ptr @.str.4, ptr %16
  %18 = tail call noundef zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_18strequalEPKcS3_(ptr noundef %2, ptr noundef nonnull %17)
  br i1 %18, label %21, label %.critedge29

.critedge29:                                      ; preds = %14, %12, %.lr.ph
  %19 = getelementptr inbounds i8, ptr %.02138, i64 32
  %.021 = load ptr, ptr %19, align 8, !tbaa !10
  %.not25 = icmp eq ptr %.021, null
  br i1 %.not25, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %.critedge29, %.lr.ph43
  %20 = getelementptr inbounds i8, ptr %.041, i64 48
  %.0 = load ptr, ptr %20, align 8, !tbaa !10
  %.not24 = icmp eq ptr %.0, null
  br i1 %.not24, label %._crit_edge44, label %.lr.ph43, !llvm.loop !17

21:                                               ; preds = %14
  call void @_ZN4pugi8xml_nodeC1EPNS_15xml_node_structE(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull %.041)
  br label %22

._crit_edge44:                                    ; preds = %._crit_edge, %7
  call void @_ZN4pugi8xml_nodeC1Ev(ptr noundef nonnull align 8 dereferenceable(8) %4)
  br label %22

22:                                               ; preds = %21, %._crit_edge44, %6
  %23 = load ptr, ptr %4, align 8
  ret ptr %23
}

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 = !{!"_ZTSN4pugi20xml_attribute_structE", !13, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32}
!13 = !{!"long", !8, i64 0}
!14 = !{!12, !7, i64 16}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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