; LLVM IR from Dev-XYS/Algorithms :: K-Dimensional-Tree.ll (Z6insertRP4node5pointi)

; 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.point = type { [2 x i32] }
%struct.node = type { ptr, ptr, %struct.point, [2 x i32], [2 x i32] }

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4nodeC2E5point(ptr noundef nonnull align 8 dereferenceable(40), i64) unnamed_addr #2 align 2

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN5pointixEi(ptr noundef nonnull align 4 dereferenceable(8), i32 noundef) #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z6updateP4node(ptr noundef) #4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6insertRP4node5pointi(ptr noundef nonnull align 8 dereferenceable(8) %0, i64 %1, i32 noundef %2) #5 personality ptr @__gxx_personality_v0 {
  %4 = alloca %struct.point, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca %struct.point, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca %struct.point, align 4
  %11 = alloca %struct.point, align 4
  %12 = getelementptr inbounds %struct.point, ptr %4, i32 0, i32 0
  store i64 %1, ptr %12, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %46

16:                                               ; preds = %3
  %17 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 40) #6
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 4 %4, i64 8, i1 false), !tbaa.struct !11
  %18 = getelementptr inbounds %struct.point, ptr %7, i32 0, i32 0
  %19 = load i64, ptr %18, align 4
  invoke void @_ZN4nodeC2E5point(ptr noundef nonnull align 8 dereferenceable(40) %17, i64 %19)
          to label %20 unwind label %42

20:                                               ; preds = %16
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %17, ptr %21, align 8, !tbaa !5
  %22 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5pointixEi(ptr noundef nonnull align 4 dereferenceable(8) %4, i32 noundef 0)
  %23 = load i32, ptr %22, align 4, !tbaa !9
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.node, ptr %25, i32 0, i32 4
  %27 = getelementptr inbounds [2 x i32], ptr %26, i64 0, i64 0
  store i32 %23, ptr %27, align 8, !tbaa !9
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.node, ptr %29, i32 0, i32 3
  %31 = getelementptr inbounds [2 x i32], ptr %30, i64 0, i64 0
  store i32 %23, ptr %31, align 8, !tbaa !9
  %32 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5pointixEi(ptr noundef nonnull align 4 dereferenceable(8) %4, i32 noundef 1)
  %33 = load i32, ptr %32, align 4, !tbaa !9
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load ptr, ptr %34, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.node, ptr %35, i32 0, i32 4
  %37 = getelementptr inbounds [2 x i32], ptr %36, i64 0, i64 1
  store i32 %33, ptr %37, align 4, !tbaa !9
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.node, ptr %39, i32 0, i32 3
  %41 = getelementptr inbounds [2 x i32], ptr %40, i64 0, i64 1
  store i32 %33, ptr %41, align 4, !tbaa !9
  br label %76

42:                                               ; preds = %16
  %43 = landingpad { ptr, i32 }
          cleanup
  %44 = extractvalue { ptr, i32 } %43, 0
  store ptr %44, ptr %8, align 8
  %45 = extractvalue { ptr, i32 } %43, 1
  store i32 %45, ptr %9, align 4
  call void @_ZdlPvm(ptr noundef %17, i64 noundef 40) #7
  br label %77

46:                                               ; preds = %3
  %47 = load i32, ptr %6, align 4, !tbaa !9
  %48 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5pointixEi(ptr noundef nonnull align 4 dereferenceable(8) %4, i32 noundef %47)
  %49 = load i32, ptr %48, align 4, !tbaa !9
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = load ptr, ptr %50, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.node, ptr %51, i32 0, i32 2
  %53 = load i32, ptr %6, align 4, !tbaa !9
  %54 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5pointixEi(ptr noundef nonnull align 4 dereferenceable(8) %52, i32 noundef %53)
  %55 = load i32, ptr %54, align 4, !tbaa !9
  %56 = icmp sle i32 %49, %55
  br i1 %56, label %57, label %65

57:                                               ; preds = %46
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = load ptr, ptr %58, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.node, ptr %59, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 4 %4, i64 8, i1 false), !tbaa.struct !11
  %61 = load i32, ptr %6, align 4, !tbaa !9
  %62 = xor i32 %61, 1
  %63 = getelementptr inbounds %struct.point, ptr %10, i32 0, i32 0
  %64 = load i64, ptr %63, align 4
  call void @_Z6insertRP4node5pointi(ptr noundef nonnull align 8 dereferenceable(8) %60, i64 %64, i32 noundef %62)
  br label %73

65:                                               ; preds = %46
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = load ptr, ptr %66, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.node, ptr %67, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 4 %4, i64 8, i1 false), !tbaa.struct !11
  %69 = load i32, ptr %6, align 4, !tbaa !9
  %70 = xor i32 %69, 1
  %71 = getelementptr inbounds %struct.point, ptr %11, i32 0, i32 0
  %72 = load i64, ptr %71, align 4
  call void @_Z6insertRP4node5pointi(ptr noundef nonnull align 8 dereferenceable(8) %68, i64 %72, i32 noundef %70)
  br label %73

73:                                               ; preds = %65, %57
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = load ptr, ptr %74, align 8, !tbaa !5
  call void @_Z6updateP4node(ptr noundef %75)
  br label %76

76:                                               ; preds = %73, %20
  ret void

77:                                               ; preds = %42
  %78 = load ptr, ptr %8, align 8
  %79 = load i32, ptr %9, align 4
  %80 = insertvalue { ptr, i32 } poison, ptr %78, 0
  %81 = insertvalue { ptr, i32 } %80, i32 %79, 1
  resume { ptr, i32 } %81
}

attributes #0 = { 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 #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #4 = { inlinehint 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 #5 = { 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 #6 = { builtin allocsize(0) }
attributes #7 = { builtin 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 = !{i64 0, i64 8, !12}
!12 = !{!7, !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"

%struct.point = type { [2 x i32] }

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4nodeC2E5point(ptr noundef nonnull align 8 dereferenceable(40), i64) unnamed_addr #1 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN5pointixEi(ptr noundef nonnull align 4 dereferenceable(8), i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z6updateP4node(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6insertRP4node5pointi(ptr nocapture noundef nonnull align 8 dereferenceable(8) %0, i64 %1, i32 noundef %2) local_unnamed_addr #3 personality ptr @__gxx_personality_v0 {
  %4 = alloca %struct.point, align 8
  store i64 %1, ptr %4, align 8
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %7, label %19

7:                                                ; preds = %3
  %8 = tail call noalias noundef nonnull dereferenceable(40) ptr @_Znwm(i64 noundef 40) #4
  tail call void @_ZN4nodeC2E5point(ptr noundef nonnull align 8 dereferenceable(40) %8, i64 %1)
  store ptr %8, ptr %0, align 8, !tbaa !5
  %9 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5pointixEi(ptr noundef nonnull align 4 dereferenceable(8) %4, i32 noundef 0)
  %10 = load i32, ptr %9, align 4, !tbaa !9
  %11 = load ptr, ptr %0, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i64 32
  store i32 %10, ptr %12, align 8, !tbaa !9
  %13 = getelementptr inbounds i8, ptr %11, i64 24
  store i32 %10, ptr %13, align 8, !tbaa !9
  %14 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5pointixEi(ptr noundef nonnull align 4 dereferenceable(8) %4, i32 noundef 1)
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %16 = load ptr, ptr %0, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 36
  store i32 %15, ptr %17, align 4, !tbaa !9
  %18 = getelementptr inbounds i8, ptr %16, i64 28
  store i32 %15, ptr %18, align 4, !tbaa !9
  br label %34

19:                                               ; preds = %3
  %20 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5pointixEi(ptr noundef nonnull align 4 dereferenceable(8) %4, i32 noundef %2)
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = load ptr, ptr %0, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i64 16
  %24 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5pointixEi(ptr noundef nonnull align 4 dereferenceable(8) %23, i32 noundef %2)
  %25 = load i32, ptr %24, align 4, !tbaa !9
  %.not = icmp sgt i32 %21, %25
  %26 = load ptr, ptr %0, align 8, !tbaa !5
  br i1 %.not, label %29, label %27

27:                                               ; preds = %19
  %.sroa.01.0.copyload = load i64, ptr %4, align 8, !tbaa !11
  %28 = xor i32 %2, 1
  call void @_Z6insertRP4node5pointi(ptr noundef nonnull align 8 dereferenceable(8) %26, i64 %.sroa.01.0.copyload, i32 noundef %28)
  br label %32

29:                                               ; preds = %19
  %30 = getelementptr inbounds i8, ptr %26, i64 8
  %.sroa.0.0.copyload = load i64, ptr %4, align 8, !tbaa !11
  %31 = xor i32 %2, 1
  call void @_Z6insertRP4node5pointi(ptr noundef nonnull align 8 dereferenceable(8) %30, i64 %.sroa.0.0.copyload, i32 noundef %31)
  br label %32

32:                                               ; preds = %29, %27
  %33 = load ptr, ptr %0, align 8, !tbaa !5
  call void @_Z6updateP4node(ptr noundef %33)
  br label %34

34:                                               ; preds = %32, %7
  ret void
}

attributes #0 = { 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 #1 = { 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 #2 = { inlinehint 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 = { 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 #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 = !{!7, !7, i64 0}


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