; LLVM IR from HarshCasper/NeoAlgo :: C-Plus-Plus/ds/avl_tree.ll (Z11insert_nodeP4Nodei)

; 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 { ptr, ptr, i32, i32, i32 }

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_Z12right_rotateP4Node(ptr noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_Z11left_rotateP4Node(ptr noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z11create_nodei(i32 noundef) #1

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

8:                                                ; preds = %2
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = call noundef ptr @_Z11create_nodei(i32 noundef %9)
  store ptr %10, ptr %4, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %11, ptr %3, align 8
  br label %128

12:                                               ; preds = %2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.Node, ptr %13, i32 0, i32 2
  %15 = load i32, ptr %14, align 8, !tbaa !11
  %16 = load i32, ptr %5, align 4, !tbaa !9
  %17 = icmp sgt i32 %15, %16
  br i1 %17, label %18, label %26

18:                                               ; preds = %12
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.Node, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = load i32, ptr %5, align 4, !tbaa !9
  %23 = call noundef ptr @_Z11insert_nodeP4Nodei(ptr noundef %21, i32 noundef %22)
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.Node, ptr %24, i32 0, i32 0
  store ptr %23, ptr %25, align 8, !tbaa !13
  br label %43

26:                                               ; preds = %12
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.Node, ptr %27, i32 0, i32 2
  %29 = load i32, ptr %28, align 8, !tbaa !11
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %32, label %40

32:                                               ; preds = %26
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.Node, ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = call noundef ptr @_Z11insert_nodeP4Nodei(ptr noundef %35, i32 noundef %36)
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.Node, ptr %38, i32 0, i32 1
  store ptr %37, ptr %39, align 8, !tbaa !14
  br label %42

40:                                               ; preds = %26
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %41, ptr %3, align 8
  br label %128

42:                                               ; preds = %32
  br label %43

43:                                               ; preds = %42, %18
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = call noundef i32 @_Z11find_heightP4Node(ptr noundef %44)
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.Node, ptr %46, i32 0, i32 4
  store i32 %45, ptr %47, align 8, !tbaa !15
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = call noundef i32 @_Z19find_balance_factorP4Node(ptr noundef %48)
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.Node, ptr %50, i32 0, i32 3
  store i32 %49, ptr %51, align 4, !tbaa !16
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.Node, ptr %52, i32 0, i32 3
  %54 = load i32, ptr %53, align 4, !tbaa !16
  %55 = icmp sgt i32 %54, 1
  br i1 %55, label %56, label %66

56:                                               ; preds = %43
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.Node, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !13
  %60 = getelementptr inbounds %struct.Node, ptr %59, i32 0, i32 3
  %61 = load i32, ptr %60, align 4, !tbaa !16
  %62 = icmp eq i32 %61, 1
  br i1 %62, label %63, label %66

63:                                               ; preds = %56
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = call noundef ptr @_Z12right_rotateP4Node(ptr noundef %64)
  store ptr %65, ptr %4, align 8, !tbaa !5
  br label %126

66:                                               ; preds = %56, %43
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.Node, ptr %67, i32 0, i32 3
  %69 = load i32, ptr %68, align 4, !tbaa !16
  %70 = icmp sgt i32 %69, 1
  br i1 %70, label %71, label %87

71:                                               ; preds = %66
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.Node, ptr %72, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !13
  %75 = getelementptr inbounds %struct.Node, ptr %74, i32 0, i32 3
  %76 = load i32, ptr %75, align 4, !tbaa !16
  %77 = icmp eq i32 %76, -1
  br i1 %77, label %78, label %87

78:                                               ; preds = %71
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.Node, ptr %79, i32 0, i32 0
  %81 = load ptr, ptr %80, align 8, !tbaa !13
  %82 = call noundef ptr @_Z11left_rotateP4Node(ptr noundef %81)
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.Node, ptr %83, i32 0, i32 0
  store ptr %82, ptr %84, align 8, !tbaa !13
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  %86 = call noundef ptr @_Z12right_rotateP4Node(ptr noundef %85)
  store ptr %86, ptr %4, align 8, !tbaa !5
  br label %125

87:                                               ; preds = %71, %66
  %88 = load ptr, ptr %4, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.Node, ptr %88, i32 0, i32 3
  %90 = load i32, ptr %89, align 4, !tbaa !16
  %91 = icmp slt i32 %90, -1
  br i1 %91, label %92, label %102

92:                                               ; preds = %87
  %93 = load ptr, ptr %4, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.Node, ptr %93, i32 0, i32 1
  %95 = load ptr, ptr %94, align 8, !tbaa !14
  %96 = getelementptr inbounds %struct.Node, ptr %95, i32 0, i32 3
  %97 = load i32, ptr %96, align 4, !tbaa !16
  %98 = icmp eq i32 %97, -1
  br i1 %98, label %99, label %102

99:                                               ; preds = %92
  %100 = load ptr, ptr %4, align 8, !tbaa !5
  %101 = call noundef ptr @_Z11left_rotateP4Node(ptr noundef %100)
  store ptr %101, ptr %4, align 8, !tbaa !5
  br label %124

102:                                              ; preds = %92, %87
  %103 = load ptr, ptr %4, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.Node, ptr %103, i32 0, i32 3
  %105 = load i32, ptr %104, align 4, !tbaa !16
  %106 = icmp slt i32 %105, -1
  br i1 %106, label %107, label %123

107:                                              ; preds = %102
  %108 = load ptr, ptr %4, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.Node, ptr %108, i32 0, i32 1
  %110 = load ptr, ptr %109, align 8, !tbaa !14
  %111 = getelementptr inbounds %struct.Node, ptr %110, i32 0, i32 3
  %112 = load i32, ptr %111, align 4, !tbaa !16
  %113 = icmp eq i32 %112, 1
  br i1 %113, label %114, label %123

114:                                              ; preds = %107
  %115 = load ptr, ptr %4, align 8, !tbaa !5
  %116 = getelementptr inbounds %struct.Node, ptr %115, i32 0, i32 1
  %117 = load ptr, ptr %116, align 8, !tbaa !14
  %118 = call noundef ptr @_Z12right_rotateP4Node(ptr noundef %117)
  %119 = load ptr, ptr %4, align 8, !tbaa !5
  %120 = getelementptr inbounds %struct.Node, ptr %119, i32 0, i32 1
  store ptr %118, ptr %120, align 8, !tbaa !14
  %121 = load ptr, ptr %4, align 8, !tbaa !5
  %122 = call noundef ptr @_Z11left_rotateP4Node(ptr noundef %121)
  store ptr %122, ptr %4, align 8, !tbaa !5
  br label %123

123:                                              ; preds = %114, %107, %102
  br label %124

124:                                              ; preds = %123, %99
  br label %125

125:                                              ; preds = %124, %78
  br label %126

126:                                              ; preds = %125, %63
  %127 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %127, ptr %3, align 8
  br label %128

128:                                              ; preds = %126, %40, %8
  %129 = load ptr, ptr %3, align 8
  ret ptr %129
}

attributes #0 = { 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 #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, !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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"_ZTS4Node", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !10, i64 24}
!13 = !{!12, !6, i64 0}
!14 = !{!12, !6, i64 8}
!15 = !{!12, !10, i64 24}
!16 = !{!12, !10, i64 20}


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

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

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z11insert_nodeP4Nodei(ptr noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %4, label %6

4:                                                ; preds = %2
  %5 = tail call noundef ptr @_Z11create_nodei(i32 noundef %1)
  br label %.thread41

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load i32, ptr %7, align 8, !tbaa !5
  %9 = icmp sgt i32 %8, %1
  br i1 %9, label %14, label %10

10:                                               ; preds = %6
  %11 = icmp slt i32 %8, %1
  br i1 %11, label %12, label %.thread41

12:                                               ; preds = %10
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  br label %14

14:                                               ; preds = %6, %12
  %.sink = phi ptr [ %13, %12 ], [ %0, %6 ]
  %15 = load ptr, ptr %.sink, align 8, !tbaa !11
  %16 = tail call noundef ptr @_Z11insert_nodeP4Nodei(ptr noundef %15, i32 noundef %1)
  store ptr %16, ptr %.sink, align 8, !tbaa !11
  %17 = tail call noundef i32 @_Z11find_heightP4Node(ptr noundef nonnull %0)
  %18 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 %17, ptr %18, align 8, !tbaa !12
  %19 = tail call noundef i32 @_Z19find_balance_factorP4Node(ptr noundef nonnull %0)
  %20 = getelementptr inbounds i8, ptr %0, i64 20
  store i32 %19, ptr %20, align 4, !tbaa !13
  %21 = icmp sgt i32 %19, 1
  br i1 %21, label %22, label %31

22:                                               ; preds = %14
  %23 = load ptr, ptr %0, align 8, !tbaa !14
  %24 = getelementptr inbounds i8, ptr %23, i64 20
  %25 = load i32, ptr %24, align 4, !tbaa !13
  switch i32 %25, label %.thread41 [
    i32 1, label %26
    i32 -1, label %28
  ]

26:                                               ; preds = %22
  %27 = tail call noundef ptr @_Z12right_rotateP4Node(ptr noundef nonnull %0)
  br label %.thread41

28:                                               ; preds = %22
  %29 = tail call noundef ptr @_Z11left_rotateP4Node(ptr noundef nonnull %23)
  store ptr %29, ptr %0, align 8, !tbaa !14
  %30 = tail call noundef ptr @_Z12right_rotateP4Node(ptr noundef nonnull %0)
  br label %.thread41

31:                                               ; preds = %14
  %32 = icmp slt i32 %19, -1
  br i1 %32, label %33, label %.thread41

33:                                               ; preds = %31
  %34 = getelementptr inbounds i8, ptr %0, i64 8
  %35 = load ptr, ptr %34, align 8, !tbaa !15
  %36 = getelementptr inbounds i8, ptr %35, i64 20
  %37 = load i32, ptr %36, align 4, !tbaa !13
  switch i32 %37, label %.thread41 [
    i32 -1, label %38
    i32 1, label %40
  ]

38:                                               ; preds = %33
  %39 = tail call noundef ptr @_Z11left_rotateP4Node(ptr noundef nonnull %0)
  br label %.thread41

40:                                               ; preds = %33
  %41 = tail call noundef ptr @_Z12right_rotateP4Node(ptr noundef nonnull %35)
  store ptr %41, ptr %34, align 8, !tbaa !15
  %42 = tail call noundef ptr @_Z11left_rotateP4Node(ptr noundef nonnull %0)
  br label %.thread41

.thread41:                                        ; preds = %33, %22, %31, %26, %38, %40, %28, %10, %4
  %.0 = phi ptr [ %5, %4 ], [ %0, %10 ], [ %27, %26 ], [ %30, %28 ], [ %39, %38 ], [ %42, %40 ], [ %0, %31 ], [ %0, %22 ], [ %0, %33 ]
  ret ptr %.0
}

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


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