; 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
declare dso_local ptr @createSplayTreeNode(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local ptr @splayTreeInsertR(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 %19

12:                                               ; preds = %4
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.SplayTree, ptr %13, i32 0, i32 1
  %15 = load i32, ptr %14, align 8, !tbaa !9
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr %14, align 8, !tbaa !9
  %17 = load ptr, ptr %9, align 8, !tbaa !5
  %18 = call ptr @createSplayTreeNode(ptr noundef %17)
  store ptr %18, ptr %5, align 8
  br label %83

19:                                               ; preds = %4
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.SplayTree, ptr %20, i32 0, i32 3
  %22 = load ptr, ptr %21, align 8, !tbaa !12
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.SplayNode, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = call i32 %22(ptr noundef %23, ptr noundef %26)
  %28 = icmp sgt i32 %27, 0
  br i1 %28, label %39, label %29

29:                                               ; preds = %19
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.SplayTree, ptr %30, i32 0, i32 3
  %32 = load ptr, ptr %31, align 8, !tbaa !12
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.SplayNode, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !13
  %37 = call i32 %32(ptr noundef %33, ptr noundef %36)
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %39, label %61

39:                                               ; preds = %29, %19
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.SplayNode, ptr %42, i32 0, i32 1
  %44 = load ptr, ptr %43, align 8, !tbaa !15
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = call ptr @splayTreeInsertR(ptr noundef %40, ptr noundef %41, ptr noundef %44, ptr noundef %45)
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.SplayNode, ptr %47, i32 0, i32 1
  store ptr %46, ptr %48, align 8, !tbaa !15
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.SplayNode, ptr %52, i32 0, i32 1
  %54 = load ptr, ptr %53, align 8, !tbaa !15
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.SplayTree, ptr %56, i32 0, i32 3
  %58 = load ptr, ptr %57, align 8, !tbaa !12
  %59 = call i32 @splayTreeGetRotationType(ptr noundef %50, ptr noundef %51, ptr noundef %54, ptr noundef %55, ptr noundef %58)
  %60 = call ptr @splayTreePerformRotation(ptr noundef %49, i32 noundef %59)
  store ptr %60, ptr %5, align 8
  br label %83

61:                                               ; preds = %29
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.SplayNode, ptr %64, i32 0, i32 2
  %66 = load ptr, ptr %65, align 8, !tbaa !16
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  %68 = call ptr @splayTreeInsertR(ptr noundef %62, ptr noundef %63, ptr noundef %66, ptr noundef %67)
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.SplayNode, ptr %69, i32 0, i32 2
  store ptr %68, ptr %70, align 8, !tbaa !16
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.SplayNode, ptr %74, i32 0, i32 2
  %76 = load ptr, ptr %75, align 8, !tbaa !16
  %77 = load ptr, ptr %9, align 8, !tbaa !5
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.SplayTree, ptr %78, i32 0, i32 3
  %80 = load ptr, ptr %79, align 8, !tbaa !12
  %81 = call i32 @splayTreeGetRotationType(ptr noundef %72, ptr noundef %73, ptr noundef %76, ptr noundef %77, ptr noundef %80)
  %82 = call ptr @splayTreePerformRotation(ptr noundef %71, i32 noundef %81)
  store ptr %82, ptr %5, align 8
  br label %83

83:                                               ; preds = %61, %39, %12
  %84 = load ptr, ptr %5, align 8
  ret ptr %84
}

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, !11, i64 8}
!10 = !{!"SplayTree", !6, i64 0, !11, i64 8, !6, i64 16, !6, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 24}
!13 = !{!14, !6, i64 0}
!14 = !{!"SplayNode", !6, i64 0, !6, i64 8, !6, i64 16}
!15 = !{!14, !6, i64 8}
!16 = !{!14, !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
declare dso_local ptr @createSplayTreeNode(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @splayTreeInsertR(ptr noundef %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.ret, label %10

common.ret:                                       ; preds = %4
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = add nsw i32 %7, 1
  store i32 %8, ptr %6, align 8, !tbaa !5
  %9 = tail call ptr @createSplayTreeNode(ptr noundef %3)
  br label %common.ret33

10:                                               ; preds = %4
  %11 = getelementptr inbounds i8, ptr %0, i64 24
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = load ptr, ptr %2, align 8, !tbaa !12
  %14 = tail call i32 %12(ptr noundef %3, ptr noundef %13) #1
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %21, label %16

16:                                               ; preds = %10
  %17 = load ptr, ptr %11, align 8, !tbaa !11
  %18 = load ptr, ptr %2, align 8, !tbaa !12
  %19 = tail call i32 %17(ptr noundef %3, ptr noundef %18) #1
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %21, label %28

common.ret33:                                     ; preds = %28, %21, %common.ret
  %common.ret33.op = phi ptr [ %9, %common.ret ], [ %27, %21 ], [ %34, %28 ]
  ret ptr %common.ret33.op

21:                                               ; preds = %16, %10
  %22 = getelementptr inbounds i8, ptr %2, i64 8
  %23 = load ptr, ptr %22, align 8, !tbaa !14
  %24 = tail call ptr @splayTreeInsertR(ptr noundef nonnull %0, ptr noundef nonnull %2, ptr noundef %23, ptr noundef %3)
  store ptr %24, ptr %22, align 8, !tbaa !14
  %25 = load ptr, ptr %11, align 8, !tbaa !11
  %26 = tail call i32 @splayTreeGetRotationType(ptr noundef %1, ptr noundef nonnull %2, ptr noundef %24, ptr noundef %3, ptr noundef %25)
  %27 = tail call ptr @splayTreePerformRotation(ptr noundef nonnull %2, i32 noundef %26)
  br label %common.ret33

28:                                               ; preds = %16
  %29 = getelementptr inbounds i8, ptr %2, i64 16
  %30 = load ptr, ptr %29, align 8, !tbaa !15
  %31 = tail call ptr @splayTreeInsertR(ptr noundef nonnull %0, ptr noundef nonnull %2, ptr noundef %30, ptr noundef %3)
  store ptr %31, ptr %29, align 8, !tbaa !15
  %32 = load ptr, ptr %11, align 8, !tbaa !11
  %33 = tail call i32 @splayTreeGetRotationType(ptr noundef %1, ptr noundef nonnull %2, ptr noundef %31, ptr noundef %3, ptr noundef %32)
  %34 = tail call ptr @splayTreePerformRotation(ptr noundef nonnull %2, i32 noundef %33)
  br label %common.ret33
}

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, !10, i64 8}
!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 = !{!6, !7, i64 24}
!12 = !{!13, !7, i64 0}
!13 = !{!"SplayNode", !7, i64 0, !7, i64 8, !7, i64 16}
!14 = !{!13, !7, i64 8}
!15 = !{!13, !7, i64 16}


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