; LLVM IR from Dev-XYS/Algorithms :: K-Dimensional-Tree (main)

; 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] }

@d = external dso_local global [500010 x %struct.point], align 16
@root = external dso_local global ptr, align 8
@mindis = external dso_local global i32, align 4
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [5 x i8], align 1

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5buildRP4nodeiii(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef, i32 noundef, i32 noundef) #1

; 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) #0 align 2

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6insertRP4node5pointi(ptr noundef nonnull align 8 dereferenceable(8), i64, i32 noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4findP4node5pointi(ptr noundef, i64, i32 noundef) #1

declare i32 @printf(ptr noundef, ...) #3

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #4 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca %struct.point, align 4
  %9 = alloca %struct.point, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %2, ptr noundef %3)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %26, %0
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = icmp slt i32 %12, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %29

16:                                               ; preds = %11
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [500010 x %struct.point], ptr @d, i64 0, i64 %18
  %20 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5pointixEi(ptr noundef nonnull align 4 dereferenceable(8) %19, i32 noundef 0)
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [500010 x %struct.point], ptr @d, i64 0, i64 %22
  %24 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5pointixEi(ptr noundef nonnull align 4 dereferenceable(8) %23, i32 noundef 1)
  %25 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %20, ptr noundef %24)
  br label %26

26:                                               ; preds = %16
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %4, align 4, !tbaa !5
  br label %11, !llvm.loop !9

29:                                               ; preds = %15
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = sub nsw i32 %30, 1
  call void @_Z5buildRP4nodeiii(ptr noundef nonnull align 8 dereferenceable(8) @root, i32 noundef 0, i32 noundef %31, i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  br label %32

32:                                               ; preds = %59, %29
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = add nsw i32 %33, -1
  store i32 %34, ptr %3, align 4, !tbaa !5
  %35 = icmp ne i32 %33, 0
  br i1 %35, label %36, label %60

36:                                               ; preds = %32
  %37 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef %5, ptr noundef %6, ptr noundef %7)
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = icmp eq i32 %38, 1
  br i1 %39, label %40, label %45

40:                                               ; preds = %36
  %41 = load i32, ptr %6, align 4, !tbaa !5
  %42 = load i32, ptr %7, align 4, !tbaa !5
  call void @_ZN5pointC2Eii(ptr noundef nonnull align 4 dereferenceable(8) %8, i32 noundef %41, i32 noundef %42)
  %43 = getelementptr inbounds %struct.point, ptr %8, i32 0, i32 0
  %44 = load i64, ptr %43, align 4
  call void @_Z6insertRP4node5pointi(ptr noundef nonnull align 8 dereferenceable(8) @root, i64 %44, i32 noundef 0)
  br label %59

45:                                               ; preds = %36
  store i32 1000000000, ptr @mindis, align 4, !tbaa !5
  %46 = load ptr, ptr @root, align 8, !tbaa !11
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = load i32, ptr %7, align 4, !tbaa !5
  call void @_ZN5pointC2Eii(ptr noundef nonnull align 4 dereferenceable(8) %9, i32 noundef %47, i32 noundef %48)
  %49 = getelementptr inbounds %struct.point, ptr %9, i32 0, i32 0
  %50 = load i64, ptr %49, align 4
  call void @_Z4findP4node5pointi(ptr noundef %46, i64 %50, i32 noundef 0)
  %51 = load i32, ptr @mindis, align 4, !tbaa !5
  %52 = icmp slt i32 %51, 1000000000
  br i1 %52, label %53, label %56

53:                                               ; preds = %45
  %54 = load i32, ptr @mindis, align 4, !tbaa !5
  %55 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %54)
  br label %58

56:                                               ; preds = %45
  %57 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  br label %58

58:                                               ; preds = %56, %53
  br label %59

59:                                               ; preds = %58, %40
  br label %32, !llvm.loop !13

60:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 = { mustprogress norecurse 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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = distinct !{!13, !10}


; 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] }

@d = external dso_local global [500010 x %struct.point], align 16
@root = external dso_local global ptr, align 8
@mindis = external dso_local local_unnamed_addr global i32, align 4
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [5 x i8], align 1

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5buildRP4nodeiii(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; 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 #0 align 2

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6insertRP4node5pointi(ptr noundef nonnull align 8 dereferenceable(8), i64, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4findP4node5pointi(ptr noundef, i64, i32 noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #4 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca %struct.point, align 8
  %7 = alloca %struct.point, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %0
  %.lcssa = phi i32 [ %9, %0 ], [ %18, %.lr.ph ]
  %11 = add nsw i32 %.lcssa, -1
  call void @_Z5buildRP4nodeiii(ptr noundef nonnull align 8 dereferenceable(8) @root, i32 noundef 0, i32 noundef %11, i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #5
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = add nsw i32 %12, -1
  store i32 %13, ptr %2, align 4, !tbaa !5
  %.not7 = icmp eq i32 %12, 0
  br i1 %.not7, label %._crit_edge10, label %.lr.ph9

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %14 = getelementptr inbounds [500010 x %struct.point], ptr @d, i64 0, i64 %indvars.iv
  %15 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5pointixEi(ptr noundef nonnull align 4 dereferenceable(8) %14, i32 noundef 0)
  %16 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5pointixEi(ptr noundef nonnull align 4 dereferenceable(8) %14, i32 noundef 1)
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %15, ptr noundef nonnull %16)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %18 = load i32, ptr %1, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = icmp slt i64 %indvars.iv.next, %19
  br i1 %20, label %.lr.ph, label %._crit_edge, !llvm.loop !9

.lr.ph9:                                          ; preds = %._crit_edge, %39
  %21 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull %3, ptr noundef nonnull %4, ptr noundef nonnull %5)
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = icmp eq i32 %22, 1
  br i1 %23, label %24, label %28

24:                                               ; preds = %.lr.ph9
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = load i32, ptr %5, align 4, !tbaa !5
  call void @_ZN5pointC2Eii(ptr noundef nonnull align 4 dereferenceable(8) %6, i32 noundef %25, i32 noundef %26)
  %27 = load i64, ptr %6, align 8
  call void @_Z6insertRP4node5pointi(ptr noundef nonnull align 8 dereferenceable(8) @root, i64 %27, i32 noundef 0)
  br label %39

28:                                               ; preds = %.lr.ph9
  store i32 1000000000, ptr @mindis, align 4, !tbaa !5
  %29 = load ptr, ptr @root, align 8, !tbaa !11
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = load i32, ptr %5, align 4, !tbaa !5
  call void @_ZN5pointC2Eii(ptr noundef nonnull align 4 dereferenceable(8) %7, i32 noundef %30, i32 noundef %31)
  %32 = load i64, ptr %7, align 8
  call void @_Z4findP4node5pointi(ptr noundef %29, i64 %32, i32 noundef 0)
  %33 = load i32, ptr @mindis, align 4, !tbaa !5
  %34 = icmp slt i32 %33, 1000000000
  br i1 %34, label %35, label %37

35:                                               ; preds = %28
  %36 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %33)
  br label %39

37:                                               ; preds = %28
  %38 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  br label %39

39:                                               ; preds = %35, %37, %24
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = add nsw i32 %40, -1
  store i32 %41, ptr %2, align 4, !tbaa !5
  %.not = icmp eq i32 %40, 0
  br i1 %.not, label %._crit_edge10, label %.lr.ph9, !llvm.loop !13

._crit_edge10:                                    ; preds = %39, %._crit_edge
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nofree 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 = { mustprogress norecurse 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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = distinct !{!13, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass