; LLVM IR from priyankchheda/algorithms :: _other_languages/cpp/RedBlackTree/insert.ll (ZN12RedBlackTree11insertCase4EP4Node)

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

%struct.Node = type { i32, i32, 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

declare noundef ptr @_ZN12RedBlackTree11grandparentEP4Node(ptr noundef nonnull align 8 dereferenceable(12), ptr noundef) #1

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

16:                                               ; preds = %2
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.Node, ptr %17, i32 0, i32 4
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.Node, ptr %20, i32 0, i32 2
  %22 = load ptr, ptr %21, align 8, !tbaa !13
  %23 = icmp eq ptr %19, %22
  br i1 %23, label %24, label %31

24:                                               ; preds = %16
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.Node, ptr %25, i32 0, i32 4
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  call void @_ZN12RedBlackTree10leftRotateEP4Node(ptr noundef nonnull align 8 dereferenceable(12) %6, ptr noundef %27)
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.Node, ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !13
  store ptr %30, ptr %4, align 8, !tbaa !5
  br label %55

31:                                               ; preds = %16, %2
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.Node, ptr %33, i32 0, i32 4
  %35 = load ptr, ptr %34, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.Node, ptr %35, i32 0, i32 2
  %37 = load ptr, ptr %36, align 8, !tbaa !13
  %38 = icmp eq ptr %32, %37
  br i1 %38, label %39, label %54

39:                                               ; preds = %31
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.Node, ptr %40, i32 0, i32 4
  %42 = load ptr, ptr %41, align 8, !tbaa !9
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.Node, ptr %43, i32 0, i32 3
  %45 = load ptr, ptr %44, align 8, !tbaa !12
  %46 = icmp eq ptr %42, %45
  br i1 %46, label %47, label %54

47:                                               ; preds = %39
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.Node, ptr %48, i32 0, i32 4
  %50 = load ptr, ptr %49, align 8, !tbaa !9
  call void @_ZN12RedBlackTree11rightRotateEP4Node(ptr noundef nonnull align 8 dereferenceable(12) %6, ptr noundef %50)
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.Node, ptr %51, i32 0, i32 3
  %53 = load ptr, ptr %52, align 8, !tbaa !12
  store ptr %53, ptr %4, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %47, %39, %31
  br label %55

55:                                               ; preds = %54, %24
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN12RedBlackTree11insertCase5EP4Node(ptr noundef nonnull align 8 dereferenceable(12) %6, ptr noundef %56)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

declare void @_ZN12RedBlackTree10leftRotateEP4Node(ptr noundef nonnull align 8 dereferenceable(12), ptr noundef) #1

declare void @_ZN12RedBlackTree11rightRotateEP4Node(ptr noundef nonnull align 8 dereferenceable(12), ptr noundef) #1

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 24}
!10 = !{!"_ZTS4Node", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16, !6, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 16}
!13 = !{!10, !6, i64 8}


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

declare noundef ptr @_ZN12RedBlackTree11grandparentEP4Node(ptr noundef nonnull align 8 dereferenceable(12), ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN12RedBlackTree11insertCase4EP4Node(ptr noundef nonnull align 8 dereferenceable(12) %0, ptr noundef %1) local_unnamed_addr #1 align 2 {
  %3 = tail call noundef ptr @_ZN12RedBlackTree11grandparentEP4Node(ptr noundef nonnull align 8 dereferenceable(12) %0, ptr noundef %1)
  %4 = getelementptr inbounds i8, ptr %1, i64 24
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  %8 = icmp eq ptr %7, %1
  br i1 %8, label %9, label %14

9:                                                ; preds = %2
  %10 = getelementptr inbounds i8, ptr %3, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %12 = icmp eq ptr %5, %11
  br i1 %12, label %13, label %14

13:                                               ; preds = %9
  tail call void @_ZN12RedBlackTree10leftRotateEP4Node(ptr noundef nonnull align 8 dereferenceable(12) %0, ptr noundef nonnull %5)
  br label %.sink.split

14:                                               ; preds = %9, %2
  %15 = getelementptr inbounds i8, ptr %5, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !12
  %17 = icmp eq ptr %16, %1
  br i1 %17, label %18, label %25

18:                                               ; preds = %14
  %19 = getelementptr inbounds i8, ptr %3, i64 16
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = icmp eq ptr %5, %20
  br i1 %21, label %22, label %25

22:                                               ; preds = %18
  tail call void @_ZN12RedBlackTree11rightRotateEP4Node(ptr noundef nonnull align 8 dereferenceable(12) %0, ptr noundef nonnull %5)
  br label %.sink.split

.sink.split:                                      ; preds = %13, %22
  %.sink18 = phi i64 [ 16, %22 ], [ 8, %13 ]
  %23 = getelementptr inbounds i8, ptr %1, i64 %.sink18
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  br label %25

25:                                               ; preds = %.sink.split, %14, %18
  %.0 = phi ptr [ %1, %18 ], [ %1, %14 ], [ %24, %.sink.split ]
  tail call void @_ZN12RedBlackTree11insertCase5EP4Node(ptr noundef nonnull align 8 dereferenceable(12) %0, ptr noundef %.0)
  ret void
}

declare void @_ZN12RedBlackTree10leftRotateEP4Node(ptr noundef nonnull align 8 dereferenceable(12), ptr noundef) local_unnamed_addr #0

declare void @_ZN12RedBlackTree11rightRotateEP4Node(ptr noundef nonnull align 8 dereferenceable(12), ptr noundef) local_unnamed_addr #0

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

attributes #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, !10, i64 24}
!6 = !{!"_ZTS4Node", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16, !10, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = !{!6, !10, i64 8}
!13 = !{!10, !10, i64 0}


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