; LLVM IR from upupming/algorithm :: AdvancedLevel_C++/1066. Root of AVL Tree (25).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, ptr, ptr }

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

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

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

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

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

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

7:                                                ; preds = %2
  %8 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 24) #4
  call void @llvm.memset.p0.i64(ptr align 16 %8, i8 0, i64 24, i1 false)
  store ptr %8, ptr %3, align 8, !tbaa !5
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.node, ptr %10, i32 0, i32 0
  store i32 %9, ptr %11, align 8, !tbaa !11
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.node, ptr %12, i32 0, i32 2
  store ptr null, ptr %13, align 8, !tbaa !13
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.node, ptr %14, i32 0, i32 1
  store ptr null, ptr %15, align 8, !tbaa !14
  br label %93

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

22:                                               ; preds = %16
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.node, ptr %23, i32 0, i32 1
  %25 = load ptr, ptr %24, align 8, !tbaa !14
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = call noundef ptr @_Z6insertP4nodei(ptr noundef %25, i32 noundef %26)
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.node, ptr %28, i32 0, i32 1
  store ptr %27, ptr %29, align 8, !tbaa !14
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.node, ptr %30, i32 0, i32 1
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  %33 = call noundef i32 @_Z9getHeightP4node(ptr noundef %32)
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.node, ptr %34, i32 0, i32 2
  %36 = load ptr, ptr %35, align 8, !tbaa !13
  %37 = call noundef i32 @_Z9getHeightP4node(ptr noundef %36)
  %38 = sub nsw i32 %33, %37
  %39 = icmp eq i32 %38, 2
  br i1 %39, label %40, label %56

40:                                               ; preds = %22
  %41 = load i32, ptr %4, align 4, !tbaa !9
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.node, ptr %42, i32 0, i32 1
  %44 = load ptr, ptr %43, align 8, !tbaa !14
  %45 = getelementptr inbounds %struct.node, ptr %44, i32 0, i32 0
  %46 = load i32, ptr %45, align 8, !tbaa !11
  %47 = icmp slt i32 %41, %46
  br i1 %47, label %48, label %51

48:                                               ; preds = %40
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = call noundef ptr @_Z11rotateRightP4node(ptr noundef %49)
  br label %54

51:                                               ; preds = %40
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = call noundef ptr @_Z15rotateLeftRightP4node(ptr noundef %52)
  br label %54

54:                                               ; preds = %51, %48
  %55 = phi ptr [ %50, %48 ], [ %53, %51 ]
  store ptr %55, ptr %3, align 8, !tbaa !5
  br label %56

56:                                               ; preds = %54, %22
  br label %92

57:                                               ; preds = %16
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.node, ptr %58, i32 0, i32 2
  %60 = load ptr, ptr %59, align 8, !tbaa !13
  %61 = load i32, ptr %4, align 4, !tbaa !9
  %62 = call noundef ptr @_Z6insertP4nodei(ptr noundef %60, i32 noundef %61)
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.node, ptr %63, i32 0, i32 2
  store ptr %62, ptr %64, align 8, !tbaa !13
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.node, ptr %65, i32 0, i32 1
  %67 = load ptr, ptr %66, align 8, !tbaa !14
  %68 = call noundef i32 @_Z9getHeightP4node(ptr noundef %67)
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.node, ptr %69, i32 0, i32 2
  %71 = load ptr, ptr %70, align 8, !tbaa !13
  %72 = call noundef i32 @_Z9getHeightP4node(ptr noundef %71)
  %73 = sub nsw i32 %68, %72
  %74 = icmp eq i32 %73, -2
  br i1 %74, label %75, label %91

75:                                               ; preds = %57
  %76 = load i32, ptr %4, align 4, !tbaa !9
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.node, ptr %77, i32 0, i32 2
  %79 = load ptr, ptr %78, align 8, !tbaa !13
  %80 = getelementptr inbounds %struct.node, ptr %79, i32 0, i32 0
  %81 = load i32, ptr %80, align 8, !tbaa !11
  %82 = icmp sgt i32 %76, %81
  br i1 %82, label %83, label %86

83:                                               ; preds = %75
  %84 = load ptr, ptr %3, align 8, !tbaa !5
  %85 = call noundef ptr @_Z10rotateLeftP4node(ptr noundef %84)
  br label %89

86:                                               ; preds = %75
  %87 = load ptr, ptr %3, align 8, !tbaa !5
  %88 = call noundef ptr @_Z15rotateRightLeftP4node(ptr noundef %87)
  br label %89

89:                                               ; preds = %86, %83
  %90 = phi ptr [ %85, %83 ], [ %88, %86 ]
  store ptr %90, ptr %3, align 8, !tbaa !5
  br label %91

91:                                               ; preds = %89, %57
  br label %92

92:                                               ; preds = %91, %56
  br label %93

93:                                               ; preds = %92, %7
  %94 = load ptr, ptr %3, align 8, !tbaa !5
  ret ptr %94
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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"}
!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}
!13 = !{!12, !6, i64 16}
!14 = !{!12, !6, i64 8}


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

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

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

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

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

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

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

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

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = tail call noundef ptr @_Z6insertP4nodei(ptr noundef %12, i32 noundef %1)
  store ptr %13, ptr %11, align 8, !tbaa !11
  %14 = tail call noundef i32 @_Z9getHeightP4node(ptr noundef %13)
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  %16 = load ptr, ptr %15, align 8, !tbaa !12
  %17 = tail call noundef i32 @_Z9getHeightP4node(ptr noundef %16)
  %18 = sub nsw i32 %14, %17
  %19 = icmp eq i32 %18, 2
  br i1 %19, label %20, label %47

20:                                               ; preds = %10
  %21 = load ptr, ptr %11, align 8, !tbaa !11
  %22 = load i32, ptr %21, align 8, !tbaa !5
  %23 = icmp sgt i32 %22, %1
  br i1 %23, label %24, label %26

24:                                               ; preds = %20
  %25 = tail call noundef ptr @_Z11rotateRightP4node(ptr noundef nonnull %0)
  br label %47

26:                                               ; preds = %20
  %27 = tail call noundef ptr @_Z15rotateLeftRightP4node(ptr noundef nonnull %0)
  br label %47

28:                                               ; preds = %7
  %29 = getelementptr inbounds i8, ptr %0, i64 16
  %30 = load ptr, ptr %29, align 8, !tbaa !12
  %31 = tail call noundef ptr @_Z6insertP4nodei(ptr noundef %30, i32 noundef %1)
  store ptr %31, ptr %29, align 8, !tbaa !12
  %32 = getelementptr inbounds i8, ptr %0, i64 8
  %33 = load ptr, ptr %32, align 8, !tbaa !11
  %34 = tail call noundef i32 @_Z9getHeightP4node(ptr noundef %33)
  %35 = load ptr, ptr %29, align 8, !tbaa !12
  %36 = tail call noundef i32 @_Z9getHeightP4node(ptr noundef %35)
  %37 = sub nsw i32 %34, %36
  %38 = icmp eq i32 %37, -2
  br i1 %38, label %39, label %47

39:                                               ; preds = %28
  %40 = load ptr, ptr %29, align 8, !tbaa !12
  %41 = load i32, ptr %40, align 8, !tbaa !5
  %42 = icmp slt i32 %41, %1
  br i1 %42, label %43, label %45

43:                                               ; preds = %39
  %44 = tail call noundef ptr @_Z10rotateLeftP4node(ptr noundef nonnull %0)
  br label %47

45:                                               ; preds = %39
  %46 = tail call noundef ptr @_Z15rotateRightLeftP4node(ptr noundef nonnull %0)
  br label %47

47:                                               ; preds = %43, %45, %24, %26, %10, %28, %4
  %.0 = phi ptr [ %5, %4 ], [ %0, %10 ], [ %0, %28 ], [ %25, %24 ], [ %27, %26 ], [ %44, %43 ], [ %46, %45 ]
  ret ptr %.0
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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, !7, i64 0}
!6 = !{!"_ZTS4node", !7, i64 0, !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 = !{!6, !10, i64 8}
!12 = !{!6, !10, i64 16}


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