; LLVM IR from UtkarshPathrabe/Competitive-Coding :: Model Algorithms/Advanced Data Structure/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"

%struct.node = type { i32, i32, i32, ptr, ptr }

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_Z7newNodei(i32 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: mustprogress nounwind uwtable
declare dso_local noundef ptr @_Z11rightRotateP4node(ptr noundef) #0

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

; 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) #2 {
  %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
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %13

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

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

19:                                               ; preds = %13
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.node, ptr %20, i32 0, i32 2
  %22 = load i32, ptr %21, align 8, !tbaa !13
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %21, align 8, !tbaa !13
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %24, ptr %3, align 8
  br label %132

25:                                               ; preds = %13
  %26 = load i32, ptr %5, align 4, !tbaa !9
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.node, ptr %27, i32 0, i32 0
  %29 = load i32, ptr %28, align 8, !tbaa !11
  %30 = icmp slt i32 %26, %29
  br i1 %30, label %31, label %39

31:                                               ; preds = %25
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.node, ptr %32, i32 0, i32 3
  %34 = load ptr, ptr %33, align 8, !tbaa !14
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = call noundef ptr @_Z6insertP4nodei(ptr noundef %34, i32 noundef %35)
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.node, ptr %37, i32 0, i32 3
  store ptr %36, ptr %38, align 8, !tbaa !14
  br label %47

39:                                               ; preds = %25
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.node, ptr %40, i32 0, i32 4
  %42 = load ptr, ptr %41, align 8, !tbaa !15
  %43 = load i32, ptr %5, align 4, !tbaa !9
  %44 = call noundef ptr @_Z6insertP4nodei(ptr noundef %42, i32 noundef %43)
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.node, ptr %45, i32 0, i32 4
  store ptr %44, ptr %46, align 8, !tbaa !15
  br label %47

47:                                               ; preds = %39, %31
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.node, ptr %48, i32 0, i32 3
  %50 = load ptr, ptr %49, align 8, !tbaa !14
  %51 = call noundef i32 @_Z6heightP4node(ptr noundef %50)
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.node, ptr %52, i32 0, i32 4
  %54 = load ptr, ptr %53, align 8, !tbaa !15
  %55 = call noundef i32 @_Z6heightP4node(ptr noundef %54)
  %56 = call noundef i32 @_Z3maxii(i32 noundef %51, i32 noundef %55)
  %57 = add nsw i32 %56, 1
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.node, ptr %58, i32 0, i32 1
  store i32 %57, ptr %59, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = call noundef i32 @_Z10getBalanceP4node(ptr noundef %60)
  store i32 %61, ptr %6, align 4, !tbaa !9
  %62 = load i32, ptr %6, align 4, !tbaa !9
  %63 = icmp sgt i32 %62, 1
  br i1 %63, label %64, label %75

64:                                               ; preds = %47
  %65 = load i32, ptr %5, align 4, !tbaa !9
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.node, ptr %66, i32 0, i32 3
  %68 = load ptr, ptr %67, align 8, !tbaa !14
  %69 = getelementptr inbounds %struct.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 %7, align 4
  br label %131

75:                                               ; preds = %64, %47
  %76 = load i32, ptr %6, 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 %struct.node, ptr %80, i32 0, i32 4
  %82 = load ptr, ptr %81, align 8, !tbaa !15
  %83 = getelementptr inbounds %struct.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 %7, align 4
  br label %131

89:                                               ; preds = %78, %75
  %90 = load i32, ptr %6, 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 %struct.node, ptr %94, i32 0, i32 3
  %96 = load ptr, ptr %95, align 8, !tbaa !14
  %97 = getelementptr inbounds %struct.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 %struct.node, ptr %101, i32 0, i32 3
  %103 = load ptr, ptr %102, align 8, !tbaa !14
  %104 = call noundef ptr @_Z10leftRotateP4node(ptr noundef %103)
  %105 = load ptr, ptr %4, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.node, ptr %105, i32 0, i32 3
  store ptr %104, ptr %106, align 8, !tbaa !14
  %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 %7, align 4
  br label %131

109:                                              ; preds = %92, %89
  %110 = load i32, ptr %6, 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 %struct.node, ptr %114, i32 0, i32 4
  %116 = load ptr, ptr %115, align 8, !tbaa !15
  %117 = getelementptr inbounds %struct.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 %struct.node, ptr %121, i32 0, i32 4
  %123 = load ptr, ptr %122, align 8, !tbaa !15
  %124 = call noundef ptr @_Z11rightRotateP4node(ptr noundef %123)
  %125 = load ptr, ptr %4, align 8, !tbaa !5
  %126 = getelementptr inbounds %struct.node, ptr %125, i32 0, i32 4
  store ptr %124, ptr %126, align 8, !tbaa !15
  %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 %7, 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 %7, align 4
  br label %131

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

132:                                              ; preds = %131, %19, %10
  %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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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, !10, i64 4, !10, i64 8, !6, i64 16, !6, i64 24}
!13 = !{!12, !10, i64 8}
!14 = !{!12, !6, i64 16}
!15 = !{!12, !6, i64 24}
!16 = !{!12, !10, i64 4}


; 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 @_Z3maxii(i32 noundef, i32 noundef) local_unnamed_addr #0

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

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

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

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

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

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

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

6:                                                ; preds = %2
  %7 = load i32, ptr %0, align 8, !tbaa !5
  %8 = icmp eq i32 %7, %1
  br i1 %8, label %9, label %13

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load i32, ptr %10, align 8, !tbaa !11
  %12 = add nsw i32 %11, 1
  store i32 %12, ptr %10, align 8, !tbaa !11
  br label %.thread42

13:                                               ; preds = %6
  %14 = icmp sgt i32 %7, %1
  br i1 %14, label %15, label %19

15:                                               ; preds = %13
  %16 = getelementptr inbounds i8, ptr %0, i64 16
  %17 = load ptr, ptr %16, align 8, !tbaa !12
  %18 = tail call noundef ptr @_Z6insertP4nodei(ptr noundef %17, i32 noundef %1)
  store ptr %18, ptr %16, align 8, !tbaa !12
  br label %23

19:                                               ; preds = %13
  %20 = getelementptr inbounds i8, ptr %0, i64 24
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = tail call noundef ptr @_Z6insertP4nodei(ptr noundef %21, i32 noundef %1)
  store ptr %22, ptr %20, align 8, !tbaa !13
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 16
  %.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !12
  br label %23

23:                                               ; preds = %19, %15
  %24 = phi ptr [ %.pre, %19 ], [ %18, %15 ]
  %25 = getelementptr inbounds i8, ptr %0, i64 16
  %26 = tail call noundef i32 @_Z6heightP4node(ptr noundef %24)
  %27 = getelementptr inbounds i8, ptr %0, i64 24
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  %29 = tail call noundef i32 @_Z6heightP4node(ptr noundef %28)
  %30 = tail call noundef i32 @_Z3maxii(i32 noundef %26, i32 noundef %29)
  %31 = add nsw i32 %30, 1
  %32 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %31, ptr %32, align 4, !tbaa !14
  %33 = tail call noundef i32 @_Z10getBalanceP4node(ptr noundef nonnull %0)
  %34 = icmp sgt i32 %33, 1
  br i1 %34, label %35, label %41

35:                                               ; preds = %23
  %36 = load ptr, ptr %25, align 8, !tbaa !12
  %37 = load i32, ptr %36, align 8, !tbaa !5
  %38 = icmp sgt i32 %37, %1
  br i1 %38, label %39, label %49

39:                                               ; preds = %35
  %40 = tail call noundef ptr @_Z11rightRotateP4node(ptr noundef nonnull %0)
  br label %.thread42

41:                                               ; preds = %23
  %42 = icmp slt i32 %33, -1
  br i1 %42, label %43, label %.thread42

43:                                               ; preds = %41
  %44 = load ptr, ptr %27, align 8, !tbaa !13
  %45 = load i32, ptr %44, align 8, !tbaa !5
  %46 = icmp slt i32 %45, %1
  br i1 %46, label %47, label %.thread42.thread

47:                                               ; preds = %43
  %48 = tail call noundef ptr @_Z10leftRotateP4node(ptr noundef nonnull %0)
  br label %.thread42

49:                                               ; preds = %35
  %50 = icmp slt i32 %37, %1
  br i1 %50, label %51, label %.thread42

51:                                               ; preds = %49
  %52 = tail call noundef ptr @_Z10leftRotateP4node(ptr noundef nonnull %36)
  store ptr %52, ptr %25, align 8, !tbaa !12
  %53 = tail call noundef ptr @_Z11rightRotateP4node(ptr noundef nonnull %0)
  br label %.thread42

.thread42.thread:                                 ; preds = %43
  %54 = icmp sgt i32 %45, %1
  br i1 %54, label %55, label %.thread42

55:                                               ; preds = %.thread42.thread
  %56 = tail call noundef ptr @_Z11rightRotateP4node(ptr noundef nonnull %44)
  store ptr %56, ptr %27, align 8, !tbaa !13
  %57 = tail call noundef ptr @_Z10leftRotateP4node(ptr noundef nonnull %0)
  br label %.thread42

.thread42:                                        ; preds = %49, %41, %39, %47, %51, %55, %.thread42.thread, %9, %4
  %.1 = phi ptr [ %5, %4 ], [ %0, %9 ], [ %40, %39 ], [ %48, %47 ], [ %53, %51 ], [ %57, %55 ], [ %0, %.thread42.thread ], [ %0, %41 ], [ %0, %49 ]
  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" }

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


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