; LLVM IR from Algo-Phantoms/Algo-Tree :: Code/C++/avl_tree.ll (Z12AVLinsertionP4nodei)

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

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

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

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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z6createi(i32 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z12AVLinsertionP4nodei(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 %14

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

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

20:                                               ; preds = %14
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.node, ptr %21, i32 0, i32 1
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = call noundef ptr @_Z12AVLinsertionP4nodei(ptr noundef %23, i32 noundef %24)
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.node, ptr %26, i32 0, i32 1
  store ptr %25, ptr %27, align 8, !tbaa !13
  br label %36

28:                                               ; preds = %14
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.node, ptr %29, i32 0, i32 2
  %31 = load ptr, ptr %30, align 8, !tbaa !14
  %32 = load i32, ptr %5, align 4, !tbaa !9
  %33 = call noundef ptr @_Z12AVLinsertionP4nodei(ptr noundef %31, i32 noundef %32)
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.node, ptr %34, i32 0, i32 2
  store ptr %33, ptr %35, align 8, !tbaa !14
  br label %36

36:                                               ; preds = %28, %20
  br label %37

37:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.node, ptr %38, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !13
  %41 = call noundef i32 @_Z6heightP4node(ptr noundef %40)
  store i32 %41, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.node, ptr %42, i32 0, i32 2
  %44 = load ptr, ptr %43, align 8, !tbaa !14
  %45 = call noundef i32 @_Z6heightP4node(ptr noundef %44)
  store i32 %45, ptr %7, align 4, !tbaa !9
  %46 = 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)
  %47 = load i32, ptr %46, align 4, !tbaa !9
  %48 = add nsw i32 %47, 1
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.node, ptr %49, i32 0, i32 3
  store i32 %48, ptr %50, 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
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = call noundef i32 @_Z13BalanceFactorP4node(ptr noundef %51)
  %53 = icmp eq i32 %52, 2
  br i1 %53, label %54, label %63

54:                                               ; preds = %37
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.node, ptr %55, i32 0, i32 1
  %57 = load ptr, ptr %56, align 8, !tbaa !13
  %58 = call noundef i32 @_Z13BalanceFactorP4node(ptr noundef %57)
  %59 = icmp eq i32 %58, 1
  br i1 %59, label %60, label %63

60:                                               ; preds = %54
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = call noundef ptr @_Z10LLrotationP4node(ptr noundef %61)
  store ptr %62, ptr %3, align 8
  br label %104

63:                                               ; preds = %54, %37
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = call noundef i32 @_Z13BalanceFactorP4node(ptr noundef %64)
  %66 = icmp eq i32 %65, 2
  br i1 %66, label %67, label %76

67:                                               ; preds = %63
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.node, ptr %68, i32 0, i32 1
  %70 = load ptr, ptr %69, align 8, !tbaa !13
  %71 = call noundef i32 @_Z13BalanceFactorP4node(ptr noundef %70)
  %72 = icmp eq i32 %71, -1
  br i1 %72, label %73, label %76

73:                                               ; preds = %67
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = call noundef ptr @_Z10LRrotationP4node(ptr noundef %74)
  store ptr %75, ptr %3, align 8
  br label %104

76:                                               ; preds = %67, %63
  %77 = load ptr, ptr %4, align 8, !tbaa !5
  %78 = call noundef i32 @_Z13BalanceFactorP4node(ptr noundef %77)
  %79 = icmp eq i32 %78, -2
  br i1 %79, label %80, label %89

80:                                               ; preds = %76
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.node, ptr %81, i32 0, i32 2
  %83 = load ptr, ptr %82, align 8, !tbaa !14
  %84 = call noundef i32 @_Z13BalanceFactorP4node(ptr noundef %83)
  %85 = icmp eq i32 %84, -1
  br i1 %85, label %86, label %89

86:                                               ; preds = %80
  %87 = load ptr, ptr %4, align 8, !tbaa !5
  %88 = call noundef ptr @_Z10RRrotationP4node(ptr noundef %87)
  store ptr %88, ptr %3, align 8
  br label %104

89:                                               ; preds = %80, %76
  %90 = load ptr, ptr %4, align 8, !tbaa !5
  %91 = call noundef i32 @_Z13BalanceFactorP4node(ptr noundef %90)
  %92 = icmp eq i32 %91, -2
  br i1 %92, label %93, label %102

93:                                               ; preds = %89
  %94 = load ptr, ptr %4, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.node, ptr %94, i32 0, i32 2
  %96 = load ptr, ptr %95, align 8, !tbaa !14
  %97 = call noundef i32 @_Z13BalanceFactorP4node(ptr noundef %96)
  %98 = icmp eq i32 %97, 1
  br i1 %98, label %99, label %102

99:                                               ; preds = %93
  %100 = load ptr, ptr %4, align 8, !tbaa !5
  %101 = call noundef ptr @_Z10RLrotationP4node(ptr noundef %100)
  store ptr %101, ptr %3, align 8
  br label %104

102:                                              ; preds = %93, %89
  %103 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %103, ptr %3, align 8
  br label %104

104:                                              ; preds = %102, %99, %86, %73, %60, %10
  %105 = load ptr, ptr %3, align 8
  ret ptr %105
}

; 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

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 = { 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 nounwind uwtable
declare dso_local noundef ptr @_Z10LLrotationP4node(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress 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 @_Z10RRrotationP4node(ptr noundef) local_unnamed_addr #0

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

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z12AVLinsertionP4nodei(ptr noundef %0, i32 noundef %1) local_unnamed_addr #2 {
  %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 @_Z6createi(i32 noundef %1)
  br label %65

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 @_Z12AVLinsertionP4nodei(ptr noundef %13, i32 noundef %1)
  store ptr %14, ptr %12, align 8, !tbaa !11
  br label %19

15:                                               ; preds = %8
  %16 = getelementptr inbounds i8, ptr %0, i64 16
  %17 = load ptr, ptr %16, align 8, !tbaa !12
  %18 = tail call noundef ptr @_Z12AVLinsertionP4nodei(ptr noundef %17, i32 noundef %1)
  store ptr %18, ptr %16, 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 %19

19:                                               ; preds = %11, %15
  %20 = phi ptr [ %14, %11 ], [ %.pre, %15 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  %21 = getelementptr inbounds i8, ptr %0, i64 8
  %22 = tail call noundef i32 @_Z6heightP4node(ptr noundef %20)
  store i32 %22, ptr %3, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  %23 = getelementptr inbounds i8, ptr %0, i64 16
  %24 = load ptr, ptr %23, align 8, !tbaa !12
  %25 = tail call noundef i32 @_Z6heightP4node(ptr noundef %24)
  store i32 %25, ptr %4, align 4, !tbaa !13
  %26 = 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)
  %27 = load i32, ptr %26, align 4, !tbaa !13
  %28 = add nsw i32 %27, 1
  %29 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 %28, ptr %29, 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
  %30 = call noundef i32 @_Z13BalanceFactorP4node(ptr noundef nonnull %0)
  %31 = icmp eq i32 %30, 2
  br i1 %31, label %32, label %38

32:                                               ; preds = %19
  %33 = load ptr, ptr %21, align 8, !tbaa !11
  %34 = call noundef i32 @_Z13BalanceFactorP4node(ptr noundef %33)
  %35 = icmp eq i32 %34, 1
  br i1 %35, label %36, label %38

36:                                               ; preds = %32
  %37 = call noundef ptr @_Z10LLrotationP4node(ptr noundef nonnull %0)
  br label %65

38:                                               ; preds = %32, %19
  %39 = call noundef i32 @_Z13BalanceFactorP4node(ptr noundef nonnull %0)
  %40 = icmp eq i32 %39, 2
  br i1 %40, label %41, label %47

41:                                               ; preds = %38
  %42 = load ptr, ptr %21, align 8, !tbaa !11
  %43 = call noundef i32 @_Z13BalanceFactorP4node(ptr noundef %42)
  %44 = icmp eq i32 %43, -1
  br i1 %44, label %45, label %47

45:                                               ; preds = %41
  %46 = call noundef ptr @_Z10LRrotationP4node(ptr noundef nonnull %0)
  br label %65

47:                                               ; preds = %41, %38
  %48 = call noundef i32 @_Z13BalanceFactorP4node(ptr noundef nonnull %0)
  %49 = icmp eq i32 %48, -2
  br i1 %49, label %50, label %56

50:                                               ; preds = %47
  %51 = load ptr, ptr %23, align 8, !tbaa !12
  %52 = call noundef i32 @_Z13BalanceFactorP4node(ptr noundef %51)
  %53 = icmp eq i32 %52, -1
  br i1 %53, label %54, label %56

54:                                               ; preds = %50
  %55 = call noundef ptr @_Z10RRrotationP4node(ptr noundef nonnull %0)
  br label %65

56:                                               ; preds = %50, %47
  %57 = call noundef i32 @_Z13BalanceFactorP4node(ptr noundef nonnull %0)
  %58 = icmp eq i32 %57, -2
  br i1 %58, label %59, label %65

59:                                               ; preds = %56
  %60 = load ptr, ptr %23, align 8, !tbaa !12
  %61 = call noundef i32 @_Z13BalanceFactorP4node(ptr noundef %60)
  %62 = icmp eq i32 %61, 1
  br i1 %62, label %63, label %65

63:                                               ; preds = %59
  %64 = call noundef ptr @_Z10RLrotationP4node(ptr noundef nonnull %0)
  br label %65

65:                                               ; preds = %56, %59, %63, %54, %45, %36, %6
  %.0 = phi ptr [ %7, %6 ], [ %37, %36 ], [ %46, %45 ], [ %55, %54 ], [ %64, %63 ], [ %0, %59 ], [ %0, %56 ]
  ret ptr %.0
}

; 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

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 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 = { 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: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass