; LLVM IR from TyrantLucifer/DataStructure :: Tree (AVLBinaryTree)

; 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.TreeNode = type { i32, i32, ptr, ptr }

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

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

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

12:                                               ; preds = %2
  %13 = call noalias ptr @malloc(i64 noundef 24) #3
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %13, ptr %14, align 8, !tbaa !5
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.TreeNode, ptr %17, i32 0, i32 0
  store i32 %15, ptr %18, align 8, !tbaa !11
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.TreeNode, ptr %20, i32 0, i32 1
  store i32 0, ptr %21, align 4, !tbaa !13
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.TreeNode, ptr %23, i32 0, i32 2
  store ptr null, ptr %24, align 8, !tbaa !14
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.TreeNode, ptr %26, i32 0, i32 3
  store ptr null, ptr %27, align 8, !tbaa !15
  br label %134

28:                                               ; preds = %2
  %29 = load i32, ptr %4, align 4, !tbaa !9
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.TreeNode, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !11
  %34 = icmp slt i32 %29, %33
  br i1 %34, label %35, label %80

35:                                               ; preds = %28
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.TreeNode, ptr %37, i32 0, i32 2
  %39 = load i32, ptr %4, align 4, !tbaa !9
  call void @avlInsert(ptr noundef %38, i32 noundef %39)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = load ptr, ptr %40, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.TreeNode, ptr %41, i32 0, i32 2
  %43 = load ptr, ptr %42, align 8, !tbaa !14
  %44 = call i32 @getHeight(ptr noundef %43)
  store i32 %44, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = load ptr, ptr %45, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.TreeNode, ptr %46, i32 0, i32 3
  %48 = load ptr, ptr %47, align 8, !tbaa !15
  %49 = call i32 @getHeight(ptr noundef %48)
  store i32 %49, ptr %6, align 4, !tbaa !9
  %50 = load i32, ptr %5, align 4, !tbaa !9
  %51 = load i32, ptr %6, align 4, !tbaa !9
  %52 = sub nsw i32 %50, %51
  %53 = icmp eq i32 %52, 2
  br i1 %53, label %54, label %79

54:                                               ; preds = %35
  %55 = load i32, ptr %4, align 4, !tbaa !9
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = load ptr, ptr %56, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.TreeNode, ptr %57, i32 0, i32 2
  %59 = load ptr, ptr %58, align 8, !tbaa !14
  %60 = getelementptr inbounds %struct.TreeNode, ptr %59, i32 0, i32 0
  %61 = load i32, ptr %60, align 8, !tbaa !11
  %62 = icmp slt i32 %55, %61
  br i1 %62, label %63, label %67

63:                                               ; preds = %54
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = load ptr, ptr %64, align 8, !tbaa !5
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llRotation(ptr noundef %65, ptr noundef %66)
  br label %78

67:                                               ; preds = %54
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = load ptr, ptr %68, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.TreeNode, ptr %69, i32 0, i32 2
  %71 = load ptr, ptr %70, align 8, !tbaa !14
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = load ptr, ptr %72, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.TreeNode, ptr %73, i32 0, i32 2
  call void @rrRotation(ptr noundef %71, ptr noundef %74)
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = load ptr, ptr %75, align 8, !tbaa !5
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llRotation(ptr noundef %76, ptr noundef %77)
  br label %78

78:                                               ; preds = %67, %63
  br label %79

79:                                               ; preds = %78, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %133

80:                                               ; preds = %28
  %81 = load i32, ptr %4, align 4, !tbaa !9
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = load ptr, ptr %82, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.TreeNode, ptr %83, i32 0, i32 0
  %85 = load i32, ptr %84, align 8, !tbaa !11
  %86 = icmp sgt i32 %81, %85
  br i1 %86, label %87, label %132

87:                                               ; preds = %80
  %88 = load ptr, ptr %3, align 8, !tbaa !5
  %89 = load ptr, ptr %88, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.TreeNode, ptr %89, i32 0, i32 3
  %91 = load i32, ptr %4, align 4, !tbaa !9
  call void @avlInsert(ptr noundef %90, i32 noundef %91)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %92 = load ptr, ptr %3, align 8, !tbaa !5
  %93 = load ptr, ptr %92, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.TreeNode, ptr %93, i32 0, i32 2
  %95 = load ptr, ptr %94, align 8, !tbaa !14
  %96 = call i32 @getHeight(ptr noundef %95)
  store i32 %96, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %97 = load ptr, ptr %3, align 8, !tbaa !5
  %98 = load ptr, ptr %97, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.TreeNode, ptr %98, i32 0, i32 3
  %100 = load ptr, ptr %99, align 8, !tbaa !15
  %101 = call i32 @getHeight(ptr noundef %100)
  store i32 %101, ptr %8, align 4, !tbaa !9
  %102 = load i32, ptr %8, align 4, !tbaa !9
  %103 = load i32, ptr %7, align 4, !tbaa !9
  %104 = sub nsw i32 %102, %103
  %105 = icmp eq i32 %104, 2
  br i1 %105, label %106, label %131

106:                                              ; preds = %87
  %107 = load i32, ptr %4, align 4, !tbaa !9
  %108 = load ptr, ptr %3, align 8, !tbaa !5
  %109 = load ptr, ptr %108, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.TreeNode, ptr %109, i32 0, i32 3
  %111 = load ptr, ptr %110, align 8, !tbaa !15
  %112 = getelementptr inbounds %struct.TreeNode, ptr %111, i32 0, i32 0
  %113 = load i32, ptr %112, align 8, !tbaa !11
  %114 = icmp sgt i32 %107, %113
  br i1 %114, label %115, label %119

115:                                              ; preds = %106
  %116 = load ptr, ptr %3, align 8, !tbaa !5
  %117 = load ptr, ptr %116, align 8, !tbaa !5
  %118 = load ptr, ptr %3, align 8, !tbaa !5
  call void @rrRotation(ptr noundef %117, ptr noundef %118)
  br label %130

119:                                              ; preds = %106
  %120 = load ptr, ptr %3, align 8, !tbaa !5
  %121 = load ptr, ptr %120, align 8, !tbaa !5
  %122 = getelementptr inbounds %struct.TreeNode, ptr %121, i32 0, i32 3
  %123 = load ptr, ptr %122, align 8, !tbaa !15
  %124 = load ptr, ptr %3, align 8, !tbaa !5
  %125 = load ptr, ptr %124, align 8, !tbaa !5
  %126 = getelementptr inbounds %struct.TreeNode, ptr %125, i32 0, i32 3
  call void @llRotation(ptr noundef %123, ptr noundef %126)
  %127 = load ptr, ptr %3, align 8, !tbaa !5
  %128 = load ptr, ptr %127, align 8, !tbaa !5
  %129 = load ptr, ptr %3, align 8, !tbaa !5
  call void @rrRotation(ptr noundef %128, ptr noundef %129)
  br label %130

130:                                              ; preds = %119, %115
  br label %131

131:                                              ; preds = %130, %87
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %132

132:                                              ; preds = %131, %80
  br label %133

133:                                              ; preds = %132, %79
  br label %134

134:                                              ; preds = %133, %12
  %135 = load ptr, ptr %3, align 8, !tbaa !5
  %136 = load ptr, ptr %135, align 8, !tbaa !5
  %137 = getelementptr inbounds %struct.TreeNode, ptr %136, i32 0, i32 2
  %138 = load ptr, ptr %137, align 8, !tbaa !14
  %139 = call i32 @getHeight(ptr noundef %138)
  %140 = load ptr, ptr %3, align 8, !tbaa !5
  %141 = load ptr, ptr %140, align 8, !tbaa !5
  %142 = getelementptr inbounds %struct.TreeNode, ptr %141, i32 0, i32 3
  %143 = load ptr, ptr %142, align 8, !tbaa !15
  %144 = call i32 @getHeight(ptr noundef %143)
  %145 = call i32 @max(i32 noundef %139, i32 noundef %144)
  %146 = add nsw i32 %145, 1
  %147 = load ptr, ptr %3, align 8, !tbaa !5
  %148 = load ptr, ptr %147, align 8, !tbaa !5
  %149 = getelementptr inbounds %struct.TreeNode, ptr %148, i32 0, i32 1
  store i32 %146, ptr %149, align 4, !tbaa !13
  ret void
}

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind allocsize(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 allocsize(0) }
attributes #4 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"TreeNode", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16}
!13 = !{!12, !10, i64 4}
!14 = !{!12, !6, i64 8}
!15 = !{!12, !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 @getHeight(ptr noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @avlInsert(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %5, label %8

5:                                                ; preds = %2
  %6 = tail call noalias dereferenceable_or_null(24) ptr @malloc(i64 noundef 24) #3
  store ptr %6, ptr %0, align 8, !tbaa !5
  store i32 %1, ptr %6, align 8, !tbaa !9
  %7 = getelementptr inbounds i8, ptr %6, i64 4
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(20) %7, i8 0, i64 20, i1 false)
  br label %55

8:                                                ; preds = %2
  %9 = load i32, ptr %3, align 8, !tbaa !9
  %10 = icmp sgt i32 %9, %1
  br i1 %10, label %11, label %32

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %3, i64 8
  tail call void @avlInsert(ptr noundef nonnull %12, i32 noundef %1)
  %13 = load ptr, ptr %0, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 8
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  %16 = tail call i32 @getHeight(ptr noundef %15)
  %17 = load ptr, ptr %0, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 16
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  %20 = tail call i32 @getHeight(ptr noundef %19)
  %21 = sub nsw i32 %16, %20
  %22 = icmp eq i32 %21, 2
  br i1 %22, label %23, label %55

23:                                               ; preds = %11
  %24 = load ptr, ptr %0, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i64 8
  %26 = load ptr, ptr %25, align 8, !tbaa !12
  %27 = load i32, ptr %26, align 8, !tbaa !9
  %28 = icmp sgt i32 %27, %1
  br i1 %28, label %29, label %30

29:                                               ; preds = %23
  tail call void @llRotation(ptr noundef nonnull %24, ptr noundef nonnull %0)
  br label %55

30:                                               ; preds = %23
  tail call void @rrRotation(ptr noundef nonnull %26, ptr noundef nonnull %25)
  %31 = load ptr, ptr %0, align 8, !tbaa !5
  tail call void @llRotation(ptr noundef %31, ptr noundef nonnull %0)
  br label %55

32:                                               ; preds = %8
  %33 = icmp slt i32 %9, %1
  br i1 %33, label %34, label %55

34:                                               ; preds = %32
  %35 = getelementptr inbounds i8, ptr %3, i64 16
  tail call void @avlInsert(ptr noundef nonnull %35, i32 noundef %1)
  %36 = load ptr, ptr %0, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %36, i64 8
  %38 = load ptr, ptr %37, align 8, !tbaa !12
  %39 = tail call i32 @getHeight(ptr noundef %38)
  %40 = load ptr, ptr %0, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %40, i64 16
  %42 = load ptr, ptr %41, align 8, !tbaa !13
  %43 = tail call i32 @getHeight(ptr noundef %42)
  %44 = sub nsw i32 %43, %39
  %45 = icmp eq i32 %44, 2
  br i1 %45, label %46, label %55

46:                                               ; preds = %34
  %47 = load ptr, ptr %0, align 8, !tbaa !5
  %48 = getelementptr inbounds i8, ptr %47, i64 16
  %49 = load ptr, ptr %48, align 8, !tbaa !13
  %50 = load i32, ptr %49, align 8, !tbaa !9
  %51 = icmp slt i32 %50, %1
  br i1 %51, label %52, label %53

52:                                               ; preds = %46
  tail call void @rrRotation(ptr noundef nonnull %47, ptr noundef nonnull %0)
  br label %55

53:                                               ; preds = %46
  tail call void @llRotation(ptr noundef nonnull %49, ptr noundef nonnull %48)
  %54 = load ptr, ptr %0, align 8, !tbaa !5
  tail call void @rrRotation(ptr noundef %54, ptr noundef nonnull %0)
  br label %55

55:                                               ; preds = %34, %53, %52, %11, %30, %29, %32, %5
  %56 = load ptr, ptr %0, align 8, !tbaa !5
  %57 = getelementptr inbounds i8, ptr %56, i64 8
  %58 = load ptr, ptr %57, align 8, !tbaa !12
  %59 = tail call i32 @getHeight(ptr noundef %58)
  %60 = load ptr, ptr %0, align 8, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %60, i64 16
  %62 = load ptr, ptr %61, align 8, !tbaa !13
  %63 = tail call i32 @getHeight(ptr noundef %62)
  %64 = tail call i32 @max(i32 noundef %59, i32 noundef %63)
  %65 = add nsw i32 %64, 1
  %66 = load ptr, ptr %0, align 8, !tbaa !5
  %67 = getelementptr inbounds i8, ptr %66, i64 4
  store i32 %65, ptr %67, align 4, !tbaa !14
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nounwind allocsize(0) }

!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 0}
!10 = !{!"TreeNode", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = !{!10, !6, i64 16}
!14 = !{!10, !11, i64 4}


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