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

; 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_named_node_iterator" = type { %"class.pugi::xml_node", %"class.pugi::xml_node", 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: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK4pugi8xml_node4nameEv(ptr noundef nonnull align 8 dereferenceable(8)) #1 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local ptr @_ZNK4pugi8xml_node16previous_siblingEPKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local ptr @_ZNK4pugi8xml_node10last_childEv(ptr noundef nonnull align 8 dereferenceable(8)) #2 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) #3

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZN4pugi23xml_named_node_iteratormmEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca %"class.pugi::xml_node", align 8
  %4 = alloca %"class.pugi::xml_node", align 8
  %5 = alloca %"class.pugi::xml_node", align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8
  %7 = getelementptr inbounds %"class.pugi::xml_named_node_iterator", ptr %6, i32 0, i32 0
  %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 %18

11:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %12 = getelementptr inbounds %"class.pugi::xml_named_node_iterator", ptr %6, i32 0, i32 0
  %13 = getelementptr inbounds %"class.pugi::xml_named_node_iterator", ptr %6, i32 0, i32 2
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  %15 = call ptr @_ZNK4pugi8xml_node16previous_siblingEPKc(ptr noundef nonnull align 8 dereferenceable(8) %12, ptr noundef %14)
  %16 = getelementptr inbounds %"class.pugi::xml_node", ptr %3, i32 0, i32 0
  store ptr %15, ptr %16, align 8
  %17 = getelementptr inbounds %"class.pugi::xml_named_node_iterator", ptr %6, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %17, ptr align 8 %3, i64 8, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  br label %36

18:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %19 = getelementptr inbounds %"class.pugi::xml_named_node_iterator", ptr %6, i32 0, i32 1
  %20 = call ptr @_ZNK4pugi8xml_node10last_childEv(ptr noundef nonnull align 8 dereferenceable(8) %19)
  %21 = getelementptr inbounds %"class.pugi::xml_node", ptr %4, i32 0, i32 0
  store ptr %20, ptr %21, align 8
  %22 = getelementptr inbounds %"class.pugi::xml_named_node_iterator", ptr %6, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %22, ptr align 8 %4, i64 8, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %23 = getelementptr inbounds %"class.pugi::xml_named_node_iterator", ptr %6, i32 0, i32 0
  %24 = call noundef ptr @_ZNK4pugi8xml_node4nameEv(ptr noundef nonnull align 8 dereferenceable(8) %23)
  %25 = getelementptr inbounds %"class.pugi::xml_named_node_iterator", ptr %6, i32 0, i32 2
  %26 = load ptr, ptr %25, align 8, !tbaa !12
  %27 = call noundef zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_18strequalEPKcS3_(ptr noundef %24, ptr noundef %26)
  br i1 %27, label %35, label %28

28:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %29 = getelementptr inbounds %"class.pugi::xml_named_node_iterator", ptr %6, i32 0, i32 0
  %30 = getelementptr inbounds %"class.pugi::xml_named_node_iterator", ptr %6, i32 0, i32 2
  %31 = load ptr, ptr %30, align 8, !tbaa !12
  %32 = call ptr @_ZNK4pugi8xml_node16previous_siblingEPKc(ptr noundef nonnull align 8 dereferenceable(8) %29, ptr noundef %31)
  %33 = getelementptr inbounds %"class.pugi::xml_node", ptr %5, i32 0, i32 0
  store ptr %32, ptr %33, align 8
  %34 = getelementptr inbounds %"class.pugi::xml_named_node_iterator", ptr %6, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %34, ptr align 8 %5, i64 8, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %35

35:                                               ; preds = %28, %18
  br label %36

36:                                               ; preds = %35, %11
  ret ptr %6
}

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"_ZTSN4pugi23xml_named_node_iteratorE", !11, i64 0, !11, i64 8, !6, i64 16}
!11 = !{!"_ZTSN4pugi8xml_nodeE", !6, i64 0}
!12 = !{!10, !6, i64 16}
!13 = !{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"

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK4pugi8xml_node4nameEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0 align 2

; 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
declare dso_local ptr @_ZNK4pugi8xml_node16previous_siblingEPKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local ptr @_ZNK4pugi8xml_node10last_childEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZN4pugi23xml_named_node_iteratormmEv(ptr noundef nonnull returned align 8 dereferenceable(24) %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 %5, label %3

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  br label %.sink.split

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = tail call ptr @_ZNK4pugi8xml_node10last_childEv(ptr noundef nonnull align 8 dereferenceable(8) %6)
  store ptr %7, ptr %0, align 8, !tbaa !11
  %8 = tail call noundef ptr @_ZNK4pugi8xml_node4nameEv(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %11 = tail call noundef zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_18strequalEPKcS3_(ptr noundef %8, ptr noundef %10)
  br i1 %11, label %14, label %.sink.split

.sink.split:                                      ; preds = %5, %3
  %.sink = phi ptr [ %4, %3 ], [ %9, %5 ]
  %12 = load ptr, ptr %.sink, align 8, !tbaa !12
  %13 = tail call ptr @_ZNK4pugi8xml_node16previous_siblingEPKc(ptr noundef nonnull align 8 dereferenceable(8) %0, ptr noundef %12)
  store ptr %13, ptr %0, align 8, !tbaa !11
  br label %14

14:                                               ; preds = %.sink.split, %5
  ret ptr %0
}

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, !8, i64 0}
!6 = !{!"_ZTSN4pugi23xml_named_node_iteratorE", !7, i64 0, !7, i64 8, !8, i64 16}
!7 = !{!"_ZTSN4pugi8xml_nodeE", !8, i64 0}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!8, !8, i64 0}
!12 = !{!6, !8, i64 16}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass