; LLVM IR from MostafaTwfiq/C-DataStructures-And-Algorithms :: DataStructure/Trees/Sources (SplayTree)

; 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.SplayTree = type { ptr, i32, ptr, ptr }
%struct.SplayNode = type { ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
declare dso_local i32 @splayTreeGetRotationType(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @splayTreePerformRotation(ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local ptr @splayNode(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  %10 = load ptr, ptr %8, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %4
  store ptr null, ptr %5, align 8
  br label %79

13:                                               ; preds = %4
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.SplayTree, ptr %14, i32 0, i32 3
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %17 = load ptr, ptr %9, align 8, !tbaa !5
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.SplayNode, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !12
  %21 = call i32 %16(ptr noundef %17, ptr noundef %20)
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %25

23:                                               ; preds = %13
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %24, ptr %5, align 8
  br label %79

25:                                               ; preds = %13
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.SplayTree, ptr %26, i32 0, i32 3
  %28 = load ptr, ptr %27, align 8, !tbaa !9
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.SplayNode, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !12
  %33 = call i32 %28(ptr noundef %29, ptr noundef %32)
  %34 = icmp sgt i32 %33, 0
  br i1 %34, label %35, label %57

35:                                               ; preds = %25
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.SplayNode, ptr %38, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !14
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = call ptr @splayNode(ptr noundef %36, ptr noundef %37, ptr noundef %40, ptr noundef %41)
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.SplayNode, ptr %43, i32 0, i32 1
  store ptr %42, ptr %44, align 8, !tbaa !14
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.SplayNode, ptr %48, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !14
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.SplayTree, ptr %52, i32 0, i32 3
  %54 = load ptr, ptr %53, align 8, !tbaa !9
  %55 = call i32 @splayTreeGetRotationType(ptr noundef %46, ptr noundef %47, ptr noundef %50, ptr noundef %51, ptr noundef %54)
  %56 = call ptr @splayTreePerformRotation(ptr noundef %45, i32 noundef %55)
  store ptr %56, ptr %5, align 8
  br label %79

57:                                               ; preds = %25
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.SplayNode, ptr %60, i32 0, i32 2
  %62 = load ptr, ptr %61, align 8, !tbaa !15
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = call ptr @splayNode(ptr noundef %58, ptr noundef %59, ptr noundef %62, ptr noundef %63)
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.SplayNode, ptr %65, i32 0, i32 2
  store ptr %64, ptr %66, align 8, !tbaa !15
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.SplayNode, ptr %70, i32 0, i32 2
  %72 = load ptr, ptr %71, align 8, !tbaa !15
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.SplayTree, ptr %74, i32 0, i32 3
  %76 = load ptr, ptr %75, align 8, !tbaa !9
  %77 = call i32 @splayTreeGetRotationType(ptr noundef %68, ptr noundef %69, ptr noundef %72, ptr noundef %73, ptr noundef %76)
  %78 = call ptr @splayTreePerformRotation(ptr noundef %67, i32 noundef %77)
  store ptr %78, ptr %5, align 8
  br label %79

79:                                               ; preds = %57, %35, %23, %12
  %80 = load ptr, ptr %5, align 8
  ret ptr %80
}

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


; 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: nounwind uwtable
declare dso_local i32 @splayTreeGetRotationType(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @splayTreePerformRotation(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @splayNode(ptr nocapture noundef readonly %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = icmp eq ptr %2, null
  br i1 %5, label %common.ret37, label %6

6:                                                ; preds = %4
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = load ptr, ptr %2, align 8, !tbaa !11
  %10 = tail call i32 %8(ptr noundef %3, ptr noundef %9) #1
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %common.ret37, label %common.ret.sink.split

common.ret37:                                     ; preds = %6, %4, %common.ret.sink.split
  %common.ret37.op = phi ptr [ %21, %common.ret.sink.split ], [ null, %4 ], [ %2, %6 ]
  ret ptr %common.ret37.op

common.ret.sink.split:                            ; preds = %6
  %12 = load ptr, ptr %7, align 8, !tbaa !5
  %13 = load ptr, ptr %2, align 8, !tbaa !11
  %14 = tail call i32 %12(ptr noundef %3, ptr noundef %13) #1
  %15 = icmp sgt i32 %14, 0
  %spec.select = select i1 %15, i64 8, i64 16
  %16 = getelementptr inbounds i8, ptr %2, i64 %spec.select
  %17 = load ptr, ptr %16, align 8, !tbaa !13
  %18 = tail call ptr @splayNode(ptr noundef nonnull %0, ptr noundef nonnull %2, ptr noundef %17, ptr noundef %3)
  store ptr %18, ptr %16, align 8, !tbaa !13
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = tail call i32 @splayTreeGetRotationType(ptr noundef %1, ptr noundef nonnull %2, ptr noundef %18, ptr noundef %3, ptr noundef %19)
  %21 = tail call ptr @splayTreePerformRotation(ptr noundef nonnull %2, i32 noundef %20)
  br label %common.ret37
}

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


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