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

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

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

13:                                               ; preds = %2
  call void @_ZN4pugi8xml_nodeC1Ev(ptr noundef nonnull align 8 dereferenceable(8) %3)
  br label %48

14:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %15 = getelementptr inbounds %"class.pugi::xml_node", ptr %9, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %17 = getelementptr inbounds %"struct.pugi::xml_node_struct", ptr %16, i32 0, i32 5
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  store ptr %18, ptr %6, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %41, %14
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %"struct.pugi::xml_node_struct", ptr %20, i32 0, i32 6
  %22 = load ptr, ptr %21, align 8, !tbaa !14
  %23 = icmp ne ptr %22, null
  br i1 %23, label %25, label %24

24:                                               ; preds = %19
  store i32 2, ptr %7, align 4
  br label %45

25:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %"struct.pugi::xml_node_struct", ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !15
  store ptr %28, ptr %8, align 8, !tbaa !5
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %37

31:                                               ; preds = %25
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = call noundef zeroext i1 @_ZN4pugi4impl12_GLOBAL__N_18strequalEPKcS3_(ptr noundef %32, ptr noundef %33)
  br i1 %34, label %35, label %37

35:                                               ; preds = %31
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN4pugi8xml_nodeC1EPNS_15xml_node_structE(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef %36)
  store i32 1, ptr %7, align 4
  br label %38

37:                                               ; preds = %31, %25
  store i32 0, ptr %7, align 4
  br label %38

38:                                               ; preds = %37, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %39 = load i32, ptr %7, align 4
  switch i32 %39, label %45 [
    i32 0, label %40
  ]

40:                                               ; preds = %38
  br label %41

41:                                               ; preds = %40
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %"struct.pugi::xml_node_struct", ptr %42, i32 0, i32 5
  %44 = load ptr, ptr %43, align 8, !tbaa !11
  store ptr %44, ptr %6, align 8, !tbaa !5
  br label %19, !llvm.loop !16

45:                                               ; preds = %38, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %46 = load i32, ptr %7, align 4
  switch i32 %46, label %51 [
    i32 2, label %47
    i32 1, label %48
  ]

47:                                               ; preds = %45
  call void @_ZN4pugi8xml_nodeC1Ev(ptr noundef nonnull align 8 dereferenceable(8) %3)
  br label %48

48:                                               ; preds = %47, %45, %13
  %49 = getelementptr inbounds %"class.pugi::xml_node", ptr %3, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8
  ret ptr %50

51:                                               ; preds = %45
  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 40}
!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 48}
!15 = !{!12, !6, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"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"

%"class.pugi::xml_node" = type { ptr }

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

.preheader:                                       ; preds = %2
  %.0.in18 = getelementptr inbounds i8, ptr %4, i64 40
  %.019 = load ptr, ptr %.0.in18, align 8, !tbaa !10
  %5 = getelementptr inbounds i8, ptr %.019, i64 48
  %6 = load ptr, ptr %5, align 8, !tbaa !13
  %.not1220 = icmp eq ptr %6, null
  br i1 %.not1220, label %._crit_edge, label %.lr.ph

7:                                                ; preds = %2
  call void @_ZN4pugi8xml_nodeC1Ev(ptr noundef nonnull align 8 dereferenceable(8) %3)
  br label %16

.lr.ph:                                           ; preds = %.preheader, %12
  %.021 = phi ptr [ %.0, %12 ], [ %.019, %.preheader ]
  %8 = getelementptr inbounds i8, ptr %.021, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !14
  %.not13 = icmp eq ptr %9, null
  br i1 %.not13, label %12, label %10

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

12:                                               ; preds = %10, %.lr.ph
  %.0.in = getelementptr inbounds i8, ptr %.021, i64 40
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !10
  %13 = getelementptr inbounds i8, ptr %.0, i64 48
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  %.not12 = icmp eq ptr %14, null
  br i1 %.not12, label %._crit_edge, label %.lr.ph, !llvm.loop !15

15:                                               ; preds = %10
  call void @_ZN4pugi8xml_nodeC1EPNS_15xml_node_structE(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull %.021)
  br label %16

._crit_edge:                                      ; preds = %12, %.preheader
  call void @_ZN4pugi8xml_nodeC1Ev(ptr noundef nonnull align 8 dereferenceable(8) %3)
  br label %16

16:                                               ; preds = %15, %._crit_edge, %7
  %17 = load ptr, ptr %3, align 8
  ret ptr %17
}

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 = !{!11, !7, i64 40}
!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 48}
!14 = !{!11, !7, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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