; LLVM IR from Dev-XYS/Algorithms :: Splay.ll (Z6insertRP4nodeii)

; 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, [2 x ptr] }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z6rotateRP4nodei(ptr noundef nonnull align 8 dereferenceable(8), 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 uwtable
define dso_local void @_Z6insertRP4nodeii(ptr noundef nonnull align 8 dereferenceable(8) %0, i32 noundef %1, i32 noundef %2) #2 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = load ptr, ptr %12, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %25

15:                                               ; preds = %3
  %16 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 24) #6
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = load i32, ptr %6, align 4, !tbaa !9
  invoke void @_ZN4nodeC2Eii(ptr noundef nonnull align 8 dereferenceable(24) %16, i32 noundef %17, i32 noundef %18)
          to label %19 unwind label %21

19:                                               ; preds = %15
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %16, ptr %20, align 8, !tbaa !5
  br label %107

21:                                               ; preds = %15
  %22 = landingpad { ptr, i32 }
          cleanup
  %23 = extractvalue { ptr, i32 } %22, 0
  store ptr %23, ptr %7, align 8
  %24 = extractvalue { ptr, i32 } %22, 1
  store i32 %24, ptr %8, align 4
  call void @_ZdlPvm(ptr noundef %16, i64 noundef 24) #7
  br label %108

25:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #8
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = call noundef i32 @_Z7compareP4nodei(ptr noundef %27, i32 noundef %28)
  store i32 %29, ptr %9, align 4, !tbaa !9
  %30 = load i32, ptr %9, align 4, !tbaa !9
  %31 = icmp eq i32 %30, -1
  br i1 %31, label %32, label %33

32:                                               ; preds = %25
  store i32 1, ptr %10, align 4
  br label %105

33:                                               ; preds = %25
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = load ptr, ptr %34, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.node, ptr %35, i32 0, i32 2
  %37 = load i32, ptr %9, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [2 x ptr], ptr %36, i64 0, i64 %38
  %40 = load ptr, ptr %39, align 8, !tbaa !5
  %41 = icmp eq ptr %40, null
  br i1 %41, label %42, label %57

42:                                               ; preds = %33
  %43 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 24) #6
  %44 = load i32, ptr %5, align 4, !tbaa !9
  %45 = load i32, ptr %6, align 4, !tbaa !9
  invoke void @_ZN4nodeC2Eii(ptr noundef nonnull align 8 dereferenceable(24) %43, i32 noundef %44, i32 noundef %45)
          to label %46 unwind label %53

46:                                               ; preds = %42
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = load ptr, ptr %47, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.node, ptr %48, i32 0, i32 2
  %50 = load i32, ptr %9, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [2 x ptr], ptr %49, i64 0, i64 %51
  store ptr %43, ptr %52, align 8, !tbaa !5
  br label %102

53:                                               ; preds = %42
  %54 = landingpad { ptr, i32 }
          cleanup
  %55 = extractvalue { ptr, i32 } %54, 0
  store ptr %55, ptr %7, align 8
  %56 = extractvalue { ptr, i32 } %54, 1
  store i32 %56, ptr %8, align 4
  call void @_ZdlPvm(ptr noundef %43, i64 noundef 24) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #8
  br label %108

57:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #8
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = load ptr, ptr %58, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.node, ptr %59, i32 0, i32 2
  %61 = load i32, ptr %9, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [2 x ptr], ptr %60, i64 0, i64 %62
  %64 = load ptr, ptr %63, align 8, !tbaa !5
  %65 = load i32, ptr %5, align 4, !tbaa !9
  %66 = call noundef i32 @_Z7compareP4nodei(ptr noundef %64, i32 noundef %65)
  store i32 %66, ptr %11, align 4, !tbaa !9
  %67 = load i32, ptr %11, align 4, !tbaa !9
  %68 = icmp eq i32 %67, -1
  br i1 %68, label %69, label %70

69:                                               ; preds = %57
  store i32 1, ptr %10, align 4
  br label %99

70:                                               ; preds = %57
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = load ptr, ptr %71, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.node, ptr %72, i32 0, i32 2
  %74 = load i32, ptr %9, align 4, !tbaa !9
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [2 x ptr], ptr %73, i64 0, i64 %75
  %77 = load ptr, ptr %76, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.node, ptr %77, i32 0, i32 2
  %79 = load i32, ptr %11, align 4, !tbaa !9
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [2 x ptr], ptr %78, i64 0, i64 %80
  %82 = load i32, ptr %5, align 4, !tbaa !9
  %83 = load i32, ptr %6, align 4, !tbaa !9
  call void @_Z6insertRP4nodeii(ptr noundef nonnull align 8 dereferenceable(8) %81, i32 noundef %82, i32 noundef %83)
  %84 = load i32, ptr %9, align 4, !tbaa !9
  %85 = load i32, ptr %11, align 4, !tbaa !9
  %86 = icmp eq i32 %84, %85
  br i1 %86, label %87, label %90

87:                                               ; preds = %70
  %88 = load ptr, ptr %4, align 8, !tbaa !5
  %89 = load i32, ptr %9, align 4, !tbaa !9
  call void @_Z6rotateRP4nodei(ptr noundef nonnull align 8 dereferenceable(8) %88, i32 noundef %89)
  br label %98

90:                                               ; preds = %70
  %91 = load ptr, ptr %4, align 8, !tbaa !5
  %92 = load ptr, ptr %91, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.node, ptr %92, i32 0, i32 2
  %94 = load i32, ptr %9, align 4, !tbaa !9
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [2 x ptr], ptr %93, i64 0, i64 %95
  %97 = load i32, ptr %11, align 4, !tbaa !9
  call void @_Z6rotateRP4nodei(ptr noundef nonnull align 8 dereferenceable(8) %96, i32 noundef %97)
  br label %98

98:                                               ; preds = %90, %87
  store i32 0, ptr %10, align 4
  br label %99

99:                                               ; preds = %98, %69
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #8
  %100 = load i32, ptr %10, align 4
  switch i32 %100, label %105 [
    i32 0, label %101
  ]

101:                                              ; preds = %99
  br label %102

102:                                              ; preds = %101, %46
  %103 = load ptr, ptr %4, align 8, !tbaa !5
  %104 = load i32, ptr %9, align 4, !tbaa !9
  call void @_Z6rotateRP4nodei(ptr noundef nonnull align 8 dereferenceable(8) %103, i32 noundef %104)
  store i32 0, ptr %10, align 4
  br label %105

105:                                              ; preds = %102, %99, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #8
  %106 = load i32, ptr %10, align 4
  switch i32 %106, label %113 [
    i32 0, label %107
    i32 1, label %107
  ]

107:                                              ; preds = %105, %105, %19
  ret void

108:                                              ; preds = %53, %21
  %109 = load ptr, ptr %7, align 8
  %110 = load i32, ptr %8, align 4
  %111 = insertvalue { ptr, i32 } poison, ptr %109, 0
  %112 = insertvalue { ptr, i32 } %111, i32 %110, 1
  resume { ptr, i32 } %112

113:                                              ; preds = %105
  unreachable
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4nodeC2Eii(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef, i32 noundef) unnamed_addr #0 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #4

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7compareP4nodei(ptr noundef, i32 noundef) #5

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 = { 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 #4 = { nobuiltin nounwind "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 #5 = { 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 #6 = { builtin allocsize(0) }
attributes #7 = { builtin nounwind }
attributes #8 = { 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}


; 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 void @_Z6rotateRP4nodei(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6insertRP4nodeii(ptr noundef nonnull align 8 dereferenceable(8) %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 personality ptr @__gxx_personality_v0 {
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %6, label %8

6:                                                ; preds = %3
  %7 = tail call noalias noundef nonnull dereferenceable(24) ptr @_Znwm(i64 noundef 24) #4
  tail call void @_ZN4nodeC2Eii(ptr noundef nonnull align 8 dereferenceable(24) %7, i32 noundef %1, i32 noundef %2)
  store ptr %7, ptr %0, align 8, !tbaa !5
  br label %.critedge

8:                                                ; preds = %3
  %9 = tail call noundef i32 @_Z7compareP4nodei(ptr noundef nonnull %4, i32 noundef %1)
  %10 = icmp eq i32 %9, -1
  br i1 %10, label %.critedge, label %11

11:                                               ; preds = %8
  %12 = load ptr, ptr %0, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %12, i64 8
  %14 = sext i32 %9 to i64
  %15 = getelementptr inbounds [2 x ptr], ptr %13, i64 0, i64 %14
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %23

18:                                               ; preds = %11
  %19 = tail call noalias noundef nonnull dereferenceable(24) ptr @_Znwm(i64 noundef 24) #4
  tail call void @_ZN4nodeC2Eii(ptr noundef nonnull align 8 dereferenceable(24) %19, i32 noundef %1, i32 noundef %2)
  %20 = load ptr, ptr %0, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %20, i64 8
  %22 = getelementptr inbounds [2 x ptr], ptr %21, i64 0, i64 %14
  store ptr %19, ptr %22, align 8, !tbaa !5
  br label %39

23:                                               ; preds = %11
  %24 = tail call noundef i32 @_Z7compareP4nodei(ptr noundef nonnull %16, i32 noundef %1)
  %.not = icmp eq i32 %24, -1
  br i1 %.not, label %.critedge, label %25

25:                                               ; preds = %23
  %26 = load ptr, ptr %0, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %26, i64 8
  %28 = getelementptr inbounds [2 x ptr], ptr %27, i64 0, i64 %14
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %29, i64 8
  %31 = sext i32 %24 to i64
  %32 = getelementptr inbounds [2 x ptr], ptr %30, i64 0, i64 %31
  tail call void @_Z6insertRP4nodeii(ptr noundef nonnull align 8 dereferenceable(8) %32, i32 noundef %1, i32 noundef %2)
  %33 = icmp eq i32 %9, %24
  br i1 %33, label %34, label %35

34:                                               ; preds = %25
  tail call void @_Z6rotateRP4nodei(ptr noundef nonnull align 8 dereferenceable(8) %0, i32 noundef %9)
  br label %39

35:                                               ; preds = %25
  %36 = load ptr, ptr %0, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %36, i64 8
  %38 = getelementptr inbounds [2 x ptr], ptr %37, i64 0, i64 %14
  tail call void @_Z6rotateRP4nodei(ptr noundef nonnull align 8 dereferenceable(8) %38, i32 noundef %24)
  br label %39

39:                                               ; preds = %35, %34, %18
  tail call void @_Z6rotateRP4nodei(ptr noundef nonnull align 8 dereferenceable(8) %0, i32 noundef %9)
  br label %.critedge

.critedge:                                        ; preds = %39, %8, %23, %6
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4nodeC2Eii(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef, i32 noundef) unnamed_addr #0 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7compareP4nodei(ptr noundef, i32 noundef) 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 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 = { 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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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