; LLVM IR from div-bargali/Data-Structures-and-Algorithms :: C++/Data-Structures/Tree/AVL_Tree.ll (Z6insertP4Nodei)

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

%class.Node = type { i32, ptr, ptr, i32 }

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

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

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

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #3

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

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

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

12:                                               ; preds = %2
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = call noundef ptr @_Z7newNodei(i32 noundef %13)
  store ptr %14, ptr %3, align 8
  br label %132

15:                                               ; preds = %2
  %16 = load i32, ptr %5, align 4, !tbaa !9
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %class.Node, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 8, !tbaa !11
  %20 = icmp slt i32 %16, %19
  br i1 %20, label %21, label %29

21:                                               ; preds = %15
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %class.Node, ptr %22, i32 0, i32 1
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = call noundef ptr @_Z6insertP4Nodei(ptr noundef %24, i32 noundef %25)
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %class.Node, ptr %27, i32 0, i32 1
  store ptr %26, ptr %28, align 8, !tbaa !13
  br label %46

29:                                               ; preds = %15
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %class.Node, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !11
  %34 = icmp sgt i32 %30, %33
  br i1 %34, label %35, label %43

35:                                               ; preds = %29
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %class.Node, ptr %36, i32 0, i32 2
  %38 = load ptr, ptr %37, align 8, !tbaa !14
  %39 = load i32, ptr %5, align 4, !tbaa !9
  %40 = call noundef ptr @_Z6insertP4Nodei(ptr noundef %38, i32 noundef %39)
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %class.Node, ptr %41, i32 0, i32 2
  store ptr %40, ptr %42, align 8, !tbaa !14
  br label %45

43:                                               ; preds = %29
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %44, ptr %3, align 8
  br label %132

45:                                               ; preds = %35
  br label %46

46:                                               ; preds = %45, %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %class.Node, ptr %47, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !13
  %50 = call noundef i32 @_Z6heightP4Node(ptr noundef %49)
  store i32 %50, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %class.Node, ptr %51, i32 0, i32 2
  %53 = load ptr, ptr %52, align 8, !tbaa !14
  %54 = call noundef i32 @_Z6heightP4Node(ptr noundef %53)
  store i32 %54, ptr %7, align 4, !tbaa !9
  %55 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef nonnull align 4 dereferenceable(4) %7)
  %56 = load i32, ptr %55, align 4, !tbaa !9
  %57 = add nsw i32 1, %56
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %class.Node, ptr %58, i32 0, i32 3
  store i32 %57, ptr %59, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = call noundef i32 @_Z10getBalanceP4Node(ptr noundef %60)
  store i32 %61, ptr %8, align 4, !tbaa !9
  %62 = load i32, ptr %8, align 4, !tbaa !9
  %63 = icmp sgt i32 %62, 1
  br i1 %63, label %64, label %75

64:                                               ; preds = %46
  %65 = load i32, ptr %5, align 4, !tbaa !9
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %class.Node, ptr %66, i32 0, i32 1
  %68 = load ptr, ptr %67, align 8, !tbaa !13
  %69 = getelementptr inbounds %class.Node, ptr %68, i32 0, i32 0
  %70 = load i32, ptr %69, align 8, !tbaa !11
  %71 = icmp slt i32 %65, %70
  br i1 %71, label %72, label %75

72:                                               ; preds = %64
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = call noundef ptr @_Z11rightRotateP4Node(ptr noundef %73)
  store ptr %74, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %131

75:                                               ; preds = %64, %46
  %76 = load i32, ptr %8, align 4, !tbaa !9
  %77 = icmp slt i32 %76, -1
  br i1 %77, label %78, label %89

78:                                               ; preds = %75
  %79 = load i32, ptr %5, align 4, !tbaa !9
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = getelementptr inbounds %class.Node, ptr %80, i32 0, i32 2
  %82 = load ptr, ptr %81, align 8, !tbaa !14
  %83 = getelementptr inbounds %class.Node, ptr %82, i32 0, i32 0
  %84 = load i32, ptr %83, align 8, !tbaa !11
  %85 = icmp sgt i32 %79, %84
  br i1 %85, label %86, label %89

86:                                               ; preds = %78
  %87 = load ptr, ptr %4, align 8, !tbaa !5
  %88 = call noundef ptr @_Z10leftRotateP4Node(ptr noundef %87)
  store ptr %88, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %131

89:                                               ; preds = %78, %75
  %90 = load i32, ptr %8, align 4, !tbaa !9
  %91 = icmp sgt i32 %90, 1
  br i1 %91, label %92, label %109

92:                                               ; preds = %89
  %93 = load i32, ptr %5, align 4, !tbaa !9
  %94 = load ptr, ptr %4, align 8, !tbaa !5
  %95 = getelementptr inbounds %class.Node, ptr %94, i32 0, i32 1
  %96 = load ptr, ptr %95, align 8, !tbaa !13
  %97 = getelementptr inbounds %class.Node, ptr %96, i32 0, i32 0
  %98 = load i32, ptr %97, align 8, !tbaa !11
  %99 = icmp sgt i32 %93, %98
  br i1 %99, label %100, label %109

100:                                              ; preds = %92
  %101 = load ptr, ptr %4, align 8, !tbaa !5
  %102 = getelementptr inbounds %class.Node, ptr %101, i32 0, i32 1
  %103 = load ptr, ptr %102, align 8, !tbaa !13
  %104 = call noundef ptr @_Z10leftRotateP4Node(ptr noundef %103)
  %105 = load ptr, ptr %4, align 8, !tbaa !5
  %106 = getelementptr inbounds %class.Node, ptr %105, i32 0, i32 1
  store ptr %104, ptr %106, align 8, !tbaa !13
  %107 = load ptr, ptr %4, align 8, !tbaa !5
  %108 = call noundef ptr @_Z11rightRotateP4Node(ptr noundef %107)
  store ptr %108, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %131

109:                                              ; preds = %92, %89
  %110 = load i32, ptr %8, align 4, !tbaa !9
  %111 = icmp slt i32 %110, -1
  br i1 %111, label %112, label %129

112:                                              ; preds = %109
  %113 = load i32, ptr %5, align 4, !tbaa !9
  %114 = load ptr, ptr %4, align 8, !tbaa !5
  %115 = getelementptr inbounds %class.Node, ptr %114, i32 0, i32 2
  %116 = load ptr, ptr %115, align 8, !tbaa !14
  %117 = getelementptr inbounds %class.Node, ptr %116, i32 0, i32 0
  %118 = load i32, ptr %117, align 8, !tbaa !11
  %119 = icmp slt i32 %113, %118
  br i1 %119, label %120, label %129

120:                                              ; preds = %112
  %121 = load ptr, ptr %4, align 8, !tbaa !5
  %122 = getelementptr inbounds %class.Node, ptr %121, i32 0, i32 2
  %123 = load ptr, ptr %122, align 8, !tbaa !14
  %124 = call noundef ptr @_Z11rightRotateP4Node(ptr noundef %123)
  %125 = load ptr, ptr %4, align 8, !tbaa !5
  %126 = getelementptr inbounds %class.Node, ptr %125, i32 0, i32 2
  store ptr %124, ptr %126, align 8, !tbaa !14
  %127 = load ptr, ptr %4, align 8, !tbaa !5
  %128 = call noundef ptr @_Z10leftRotateP4Node(ptr noundef %127)
  store ptr %128, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %131

129:                                              ; preds = %112, %109
  %130 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %130, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %131

131:                                              ; preds = %129, %120, %100, %86, %72
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %132

132:                                              ; preds = %131, %43, %12
  %133 = load ptr, ptr %3, align 8
  ret ptr %133
}

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" }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTS4Node", !10, i64 0, !6, i64 8, !6, i64 16, !10, i64 24}
!13 = !{!12, !6, i64 8}
!14 = !{!12, !6, i64 16}
!15 = !{!12, !10, i64 24}


; 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 @_Z6heightP4Node(ptr noundef) local_unnamed_addr #0

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

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

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #3

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

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

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

6:                                                ; preds = %2
  %7 = tail call noundef ptr @_Z7newNodei(i32 noundef %1)
  br label %.thread42

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

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = tail call noundef ptr @_Z6insertP4Nodei(ptr noundef %13, i32 noundef %1)
  store ptr %14, ptr %12, align 8, !tbaa !11
  br label %21

15:                                               ; preds = %8
  %16 = icmp slt i32 %9, %1
  br i1 %16, label %17, label %.thread42

17:                                               ; preds = %15
  %18 = getelementptr inbounds i8, ptr %0, i64 16
  %19 = load ptr, ptr %18, align 8, !tbaa !12
  %20 = tail call noundef ptr @_Z6insertP4Nodei(ptr noundef %19, i32 noundef %1)
  store ptr %20, ptr %18, align 8, !tbaa !12
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 8
  %.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !11
  br label %21

21:                                               ; preds = %17, %11
  %22 = phi ptr [ %.pre, %17 ], [ %14, %11 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  %23 = getelementptr inbounds i8, ptr %0, i64 8
  %24 = tail call noundef i32 @_Z6heightP4Node(ptr noundef %22)
  store i32 %24, ptr %3, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  %25 = getelementptr inbounds i8, ptr %0, i64 16
  %26 = load ptr, ptr %25, align 8, !tbaa !12
  %27 = tail call noundef i32 @_Z6heightP4Node(ptr noundef %26)
  store i32 %27, ptr %4, align 4, !tbaa !13
  %28 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %29 = load i32, ptr %28, align 4, !tbaa !13
  %30 = add nsw i32 %29, 1
  %31 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 %30, ptr %31, align 8, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  %32 = call noundef i32 @_Z10getBalanceP4Node(ptr noundef nonnull %0)
  %33 = icmp sgt i32 %32, 1
  br i1 %33, label %34, label %40

34:                                               ; preds = %21
  %35 = load ptr, ptr %23, align 8, !tbaa !11
  %36 = load i32, ptr %35, align 8, !tbaa !5
  %37 = icmp sgt i32 %36, %1
  br i1 %37, label %38, label %48

38:                                               ; preds = %34
  %39 = call noundef ptr @_Z11rightRotateP4Node(ptr noundef nonnull %0)
  br label %.thread42

40:                                               ; preds = %21
  %41 = icmp slt i32 %32, -1
  br i1 %41, label %42, label %.thread42

42:                                               ; preds = %40
  %43 = load ptr, ptr %25, align 8, !tbaa !12
  %44 = load i32, ptr %43, align 8, !tbaa !5
  %45 = icmp slt i32 %44, %1
  br i1 %45, label %46, label %.thread42.thread

46:                                               ; preds = %42
  %47 = call noundef ptr @_Z10leftRotateP4Node(ptr noundef nonnull %0)
  br label %.thread42

48:                                               ; preds = %34
  %49 = icmp slt i32 %36, %1
  br i1 %49, label %50, label %.thread42

50:                                               ; preds = %48
  %51 = call noundef ptr @_Z10leftRotateP4Node(ptr noundef nonnull %35)
  store ptr %51, ptr %23, align 8, !tbaa !11
  %52 = call noundef ptr @_Z11rightRotateP4Node(ptr noundef nonnull %0)
  br label %.thread42

.thread42.thread:                                 ; preds = %42
  %53 = icmp sgt i32 %44, %1
  br i1 %53, label %54, label %.thread42

54:                                               ; preds = %.thread42.thread
  %55 = call noundef ptr @_Z11rightRotateP4Node(ptr noundef nonnull %43)
  store ptr %55, ptr %25, align 8, !tbaa !12
  %56 = call noundef ptr @_Z10leftRotateP4Node(ptr noundef nonnull %0)
  br label %.thread42

.thread42:                                        ; preds = %48, %40, %38, %46, %50, %54, %.thread42.thread, %15, %6
  %.1 = phi ptr [ %7, %6 ], [ %0, %15 ], [ %39, %38 ], [ %47, %46 ], [ %52, %50 ], [ %56, %54 ], [ %0, %.thread42.thread ], [ %0, %40 ], [ %0, %48 ]
  ret ptr %.1
}

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


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