; LLVM IR from TheAlgorithms/C-Plus-Plus :: operations_on_datastructures (inorder_successor_of_bst)

; 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.operations_on_datastructures::inorder_traversal_of_bst::Node" = type { i64, 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 uwtable
declare dso_local noundef ptr @_ZN28operations_on_datastructures24inorder_traversal_of_bst7getNodeEPNS0_4NodeEl(ptr noundef, i64 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN28operations_on_datastructures24inorder_traversal_of_bst11findMinNodeEPNS0_4NodeE(ptr noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN28operations_on_datastructures24inorder_traversal_of_bst19getInorderSuccessorEPNS0_4NodeEl(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = load i64, ptr %5, align 8, !tbaa !9
  %12 = call noundef ptr @_ZN28operations_on_datastructures24inorder_traversal_of_bst7getNodeEPNS0_4NodeEl(ptr noundef %10, i64 noundef %11)
  store ptr %12, ptr %6, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %16

15:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %57

16:                                               ; preds = %2
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %"class.operations_on_datastructures::inorder_traversal_of_bst::Node", ptr %17, i32 0, i32 2
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %26

21:                                               ; preds = %16
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %"class.operations_on_datastructures::inorder_traversal_of_bst::Node", ptr %22, i32 0, i32 2
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  %25 = call noundef ptr @_ZN28operations_on_datastructures24inorder_traversal_of_bst11findMinNodeEPNS0_4NodeE(ptr noundef %24)
  store ptr %25, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %57

26:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store ptr null, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %27, ptr %9, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %54, %26
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = icmp ne ptr %29, %30
  br i1 %31, label %32, label %35

32:                                               ; preds = %28
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br label %35

35:                                               ; preds = %32, %28
  %36 = phi i1 [ false, %28 ], [ %34, %32 ]
  br i1 %36, label %37, label %55

37:                                               ; preds = %35
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %"class.operations_on_datastructures::inorder_traversal_of_bst::Node", ptr %38, i32 0, i32 0
  %40 = load i64, ptr %39, align 8, !tbaa !13
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = getelementptr inbounds %"class.operations_on_datastructures::inorder_traversal_of_bst::Node", ptr %41, i32 0, i32 0
  %43 = load i64, ptr %42, align 8, !tbaa !13
  %44 = icmp slt i64 %40, %43
  br i1 %44, label %45, label %50

45:                                               ; preds = %37
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %46, ptr %8, align 8, !tbaa !5
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = getelementptr inbounds %"class.operations_on_datastructures::inorder_traversal_of_bst::Node", ptr %47, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !14
  store ptr %49, ptr %9, align 8, !tbaa !5
  br label %54

50:                                               ; preds = %37
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = getelementptr inbounds %"class.operations_on_datastructures::inorder_traversal_of_bst::Node", ptr %51, i32 0, i32 2
  %53 = load ptr, ptr %52, align 8, !tbaa !11
  store ptr %53, ptr %9, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %50, %45
  br label %28, !llvm.loop !15

55:                                               ; preds = %35
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %56, ptr %3, align 8
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %57

57:                                               ; preds = %55, %21, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %58 = load ptr, ptr %3, align 8
  ret ptr %58
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { 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 #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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 16}
!12 = !{!"_ZTSN28operations_on_datastructures24inorder_traversal_of_bst4NodeE", !10, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!12, !10, i64 0}
!14 = !{!12, !6, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"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: mustprogress uwtable
declare dso_local noundef ptr @_ZN28operations_on_datastructures24inorder_traversal_of_bst7getNodeEPNS0_4NodeEl(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN28operations_on_datastructures24inorder_traversal_of_bst11findMinNodeEPNS0_4NodeE(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN28operations_on_datastructures24inorder_traversal_of_bst19getInorderSuccessorEPNS0_4NodeEl(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = tail call noundef ptr @_ZN28operations_on_datastructures24inorder_traversal_of_bst7getNodeEPNS0_4NodeEl(ptr noundef %0, i64 noundef %1)
  %4 = icmp eq ptr %3, null
  br i1 %4, label %.loopexit, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %3, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %.preheader, label %12

.preheader:                                       ; preds = %5
  %8 = icmp ne ptr %3, %0
  %9 = icmp ne ptr %0, null
  %10 = and i1 %8, %9
  br i1 %10, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %11 = load i64, ptr %3, align 8, !tbaa !11
  br label %14

12:                                               ; preds = %5
  %13 = tail call noundef ptr @_ZN28operations_on_datastructures24inorder_traversal_of_bst11findMinNodeEPNS0_4NodeE(ptr noundef nonnull %7)
  br label %.loopexit

14:                                               ; preds = %.lr.ph, %14
  %.021 = phi ptr [ %0, %.lr.ph ], [ %.1, %14 ]
  %.01520 = phi ptr [ null, %.lr.ph ], [ %.116, %14 ]
  %15 = load i64, ptr %.021, align 8, !tbaa !11
  %16 = icmp slt i64 %11, %15
  %.116 = select i1 %16, ptr %.021, ptr %.01520
  %.1.in.v = select i1 %16, i64 8, i64 16
  %.1.in = getelementptr inbounds i8, ptr %.021, i64 %.1.in.v
  %.1 = load ptr, ptr %.1.in, align 8, !tbaa !12
  %17 = icmp ne ptr %.1, %3
  %18 = icmp ne ptr %.1, null
  %19 = and i1 %17, %18
  br i1 %19, label %14, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %14, %.preheader, %2, %12
  %.017 = phi ptr [ %13, %12 ], [ null, %2 ], [ null, %.preheader ], [ %.116, %14 ]
  ret ptr %.017
}

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


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