; LLVM IR from Thre4dripper/DSA-Programs :: 15. AVL Tree/Insertion.ll (Z6InsertiP4Node)

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

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

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

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

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

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z6InsertiP4Node(i32 noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store ptr null, ptr %6, align 8, !tbaa !9
  %8 = load ptr, ptr %5, align 8, !tbaa !9
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %22

10:                                               ; preds = %2
  %11 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 24) #4
  store ptr %11, ptr %6, align 8, !tbaa !9
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = load ptr, ptr %6, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.Node, ptr %13, i32 0, i32 0
  store i32 %12, ptr %14, align 8, !tbaa !11
  %15 = load ptr, ptr %6, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.Node, ptr %15, i32 0, i32 3
  store ptr null, ptr %16, align 8, !tbaa !13
  %17 = load ptr, ptr %6, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.Node, ptr %17, i32 0, i32 2
  store ptr null, ptr %18, align 8, !tbaa !14
  %19 = load ptr, ptr %6, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.Node, ptr %19, i32 0, i32 1
  store i32 0, ptr %20, align 4, !tbaa !15
  %21 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %21, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %120

22:                                               ; preds = %2
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = load ptr, ptr %5, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.Node, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 8, !tbaa !11
  %27 = icmp slt i32 %23, %26
  br i1 %27, label %28, label %36

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

36:                                               ; preds = %22
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = load ptr, ptr %5, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.Node, ptr %38, i32 0, i32 0
  %40 = load i32, ptr %39, align 8, !tbaa !11
  %41 = icmp sgt i32 %37, %40
  br i1 %41, label %42, label %50

42:                                               ; preds = %36
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = load ptr, ptr %5, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.Node, ptr %44, i32 0, i32 3
  %46 = load ptr, ptr %45, align 8, !tbaa !13
  %47 = call noundef ptr @_Z6InsertiP4Node(i32 noundef %43, ptr noundef %46)
  %48 = load ptr, ptr %5, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.Node, ptr %48, i32 0, i32 3
  store ptr %47, ptr %49, align 8, !tbaa !13
  br label %50

50:                                               ; preds = %42, %36
  br label %51

51:                                               ; preds = %50, %28
  %52 = load ptr, ptr %5, align 8, !tbaa !9
  %53 = call noundef i32 @_Z13BalanceFactorP4Node(ptr noundef %52)
  %54 = load ptr, ptr %5, align 8, !tbaa !9
  %55 = getelementptr inbounds %struct.Node, ptr %54, i32 0, i32 1
  store i32 %53, ptr %55, align 4, !tbaa !15
  %56 = load ptr, ptr %5, align 8, !tbaa !9
  %57 = getelementptr inbounds %struct.Node, ptr %56, i32 0, i32 1
  %58 = load i32, ptr %57, align 4, !tbaa !15
  %59 = icmp eq i32 %58, 2
  br i1 %59, label %60, label %70

60:                                               ; preds = %51
  %61 = load ptr, ptr %5, align 8, !tbaa !9
  %62 = getelementptr inbounds %struct.Node, ptr %61, i32 0, i32 2
  %63 = load ptr, ptr %62, align 8, !tbaa !14
  %64 = getelementptr inbounds %struct.Node, ptr %63, i32 0, i32 1
  %65 = load i32, ptr %64, align 4, !tbaa !15
  %66 = icmp eq i32 %65, 1
  br i1 %66, label %67, label %70

67:                                               ; preds = %60
  %68 = load ptr, ptr %5, align 8, !tbaa !9
  %69 = call noundef ptr @_Z10RRrotationP4Node(ptr noundef %68)
  store ptr %69, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %120

70:                                               ; preds = %60, %51
  %71 = load ptr, ptr %5, align 8, !tbaa !9
  %72 = getelementptr inbounds %struct.Node, ptr %71, i32 0, i32 1
  %73 = load i32, ptr %72, align 4, !tbaa !15
  %74 = icmp eq i32 %73, 2
  br i1 %74, label %75, label %85

75:                                               ; preds = %70
  %76 = load ptr, ptr %5, align 8, !tbaa !9
  %77 = getelementptr inbounds %struct.Node, ptr %76, i32 0, i32 2
  %78 = load ptr, ptr %77, align 8, !tbaa !14
  %79 = getelementptr inbounds %struct.Node, ptr %78, i32 0, i32 1
  %80 = load i32, ptr %79, align 4, !tbaa !15
  %81 = icmp eq i32 %80, -1
  br i1 %81, label %82, label %85

82:                                               ; preds = %75
  %83 = load ptr, ptr %5, align 8, !tbaa !9
  %84 = call noundef ptr @_Z10LRrotationP4Node(ptr noundef %83)
  store ptr %84, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %120

85:                                               ; preds = %75, %70
  %86 = load ptr, ptr %5, align 8, !tbaa !9
  %87 = getelementptr inbounds %struct.Node, ptr %86, i32 0, i32 1
  %88 = load i32, ptr %87, align 4, !tbaa !15
  %89 = icmp eq i32 %88, -2
  br i1 %89, label %90, label %100

90:                                               ; preds = %85
  %91 = load ptr, ptr %5, align 8, !tbaa !9
  %92 = getelementptr inbounds %struct.Node, ptr %91, i32 0, i32 3
  %93 = load ptr, ptr %92, align 8, !tbaa !13
  %94 = getelementptr inbounds %struct.Node, ptr %93, i32 0, i32 1
  %95 = load i32, ptr %94, align 4, !tbaa !15
  %96 = icmp eq i32 %95, 1
  br i1 %96, label %97, label %100

97:                                               ; preds = %90
  %98 = load ptr, ptr %5, align 8, !tbaa !9
  %99 = call noundef ptr @_Z10RLrotationP4Node(ptr noundef %98)
  store ptr %99, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %120

100:                                              ; preds = %90, %85
  %101 = load ptr, ptr %5, align 8, !tbaa !9
  %102 = getelementptr inbounds %struct.Node, ptr %101, i32 0, i32 1
  %103 = load i32, ptr %102, align 4, !tbaa !15
  %104 = icmp eq i32 %103, -2
  br i1 %104, label %105, label %115

105:                                              ; preds = %100
  %106 = load ptr, ptr %5, align 8, !tbaa !9
  %107 = getelementptr inbounds %struct.Node, ptr %106, i32 0, i32 3
  %108 = load ptr, ptr %107, align 8, !tbaa !13
  %109 = getelementptr inbounds %struct.Node, ptr %108, i32 0, i32 1
  %110 = load i32, ptr %109, align 4, !tbaa !15
  %111 = icmp eq i32 %110, -1
  br i1 %111, label %112, label %115

112:                                              ; preds = %105
  %113 = load ptr, ptr %5, align 8, !tbaa !9
  %114 = call noundef ptr @_Z10LLrotationP4Node(ptr noundef %113)
  store ptr %114, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %120

115:                                              ; preds = %105, %100
  br label %116

116:                                              ; preds = %115
  br label %117

117:                                              ; preds = %116
  br label %118

118:                                              ; preds = %117
  %119 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr %119, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %120

120:                                              ; preds = %118, %112, %97, %82, %67, %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %121 = load ptr, ptr %3, align 8
  ret ptr %121
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nobuiltin 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 }
attributes #4 = { builtin 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS4Node", !6, i64 0, !6, i64 4, !10, i64 8, !10, i64 16}
!13 = !{!12, !10, i64 16}
!14 = !{!12, !10, i64 8}
!15 = !{!12, !6, 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 uwtable
declare dso_local noundef i32 @_Z13BalanceFactorP4Node(ptr noundef) local_unnamed_addr #0

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

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

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

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

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

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

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

10:                                               ; preds = %7
  %11 = icmp slt i32 %8, %0
  br i1 %11, label %.sink.split, label %15

.sink.split:                                      ; preds = %10, %7
  %.sink40 = phi i64 [ 8, %7 ], [ 16, %10 ]
  %12 = getelementptr inbounds i8, ptr %1, i64 %.sink40
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = tail call noundef ptr @_Z6InsertiP4Node(i32 noundef %0, ptr noundef %13)
  store ptr %14, ptr %12, align 8, !tbaa !11
  br label %15

15:                                               ; preds = %.sink.split, %10
  %16 = tail call noundef i32 @_Z13BalanceFactorP4Node(ptr noundef nonnull %1)
  %17 = getelementptr inbounds i8, ptr %1, i64 4
  store i32 %16, ptr %17, align 4, !tbaa !12
  switch i32 %16, label %.thread37 [
    i32 2, label %18
    i32 -2, label %27
  ]

18:                                               ; preds = %15
  %19 = getelementptr inbounds i8, ptr %1, i64 8
  %20 = load ptr, ptr %19, align 8, !tbaa !13
  %21 = getelementptr inbounds i8, ptr %20, i64 4
  %22 = load i32, ptr %21, align 4, !tbaa !12
  switch i32 %22, label %.thread37 [
    i32 1, label %23
    i32 -1, label %25
  ]

23:                                               ; preds = %18
  %24 = tail call noundef ptr @_Z10RRrotationP4Node(ptr noundef nonnull %1)
  br label %.thread37

25:                                               ; preds = %18
  %26 = tail call noundef ptr @_Z10LRrotationP4Node(ptr noundef nonnull %1)
  br label %.thread37

27:                                               ; preds = %15
  %28 = getelementptr inbounds i8, ptr %1, i64 16
  %29 = load ptr, ptr %28, align 8, !tbaa !14
  %30 = getelementptr inbounds i8, ptr %29, i64 4
  %31 = load i32, ptr %30, align 4, !tbaa !12
  switch i32 %31, label %.thread37 [
    i32 1, label %32
    i32 -1, label %34
  ]

32:                                               ; preds = %27
  %33 = tail call noundef ptr @_Z10RLrotationP4Node(ptr noundef nonnull %1)
  br label %.thread37

34:                                               ; preds = %27
  %35 = tail call noundef ptr @_Z10LLrotationP4Node(ptr noundef nonnull %1)
  br label %.thread37

.thread37:                                        ; preds = %27, %18, %15, %34, %32, %25, %23, %4
  %.0 = phi ptr [ %5, %4 ], [ %24, %23 ], [ %26, %25 ], [ %33, %32 ], [ %35, %34 ], [ %1, %15 ], [ %1, %18 ], [ %1, %27 ]
  ret ptr %.0
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(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 = { 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 #1 = { nobuiltin 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { builtin 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, !7, i64 0}
!6 = !{!"_ZTS4Node", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!6, !7, i64 4}
!13 = !{!6, !10, i64 8}
!14 = !{!6, !10, i64 16}


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