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

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

@mindis = external dso_local global i32, align 4

; 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) #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
declare dso_local noundef i32 @_Z7get_dis5pointP4node(i64, ptr noundef) #2

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

19:                                               ; preds = %3
  br label %108

20:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.node, ptr %21, i32 0, i32 2
  %23 = call noundef i32 @_Z4distR5pointS0_(ptr noundef nonnull align 4 dereferenceable(8) %4, ptr noundef nonnull align 4 dereferenceable(8) %22)
  store i32 %23, ptr %7, align 4, !tbaa !9
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = load i32, ptr @mindis, align 4, !tbaa !9
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %27, label %29

27:                                               ; preds = %20
  %28 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %28, ptr @mindis, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %27, %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 1000000000, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 1000000000, ptr %9, align 4, !tbaa !9
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.node, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !11
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %41

34:                                               ; preds = %29
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 4 %4, i64 8, i1 false), !tbaa.struct !14
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.node, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !11
  %38 = getelementptr inbounds %struct.point, ptr %10, i32 0, i32 0
  %39 = load i64, ptr %38, align 4
  %40 = call noundef i32 @_Z7get_dis5pointP4node(i64 %39, ptr noundef %37)
  store i32 %40, ptr %8, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %34, %29
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.node, ptr %42, i32 0, i32 1
  %44 = load ptr, ptr %43, align 8, !tbaa !16
  %45 = icmp ne ptr %44, null
  br i1 %45, label %46, label %53

46:                                               ; preds = %41
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 4 %4, i64 8, i1 false), !tbaa.struct !14
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.node, ptr %47, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !16
  %50 = getelementptr inbounds %struct.point, ptr %11, i32 0, i32 0
  %51 = load i64, ptr %50, align 4
  %52 = call noundef i32 @_Z7get_dis5pointP4node(i64 %51, ptr noundef %49)
  store i32 %52, ptr %9, align 4, !tbaa !9
  br label %53

53:                                               ; preds = %46, %41
  %54 = load i32, ptr %8, align 4, !tbaa !9
  %55 = load i32, ptr %9, align 4, !tbaa !9
  %56 = icmp slt i32 %54, %55
  br i1 %56, label %57, label %82

57:                                               ; preds = %53
  %58 = load i32, ptr %8, align 4, !tbaa !9
  %59 = load i32, ptr @mindis, align 4, !tbaa !9
  %60 = icmp slt i32 %58, %59
  br i1 %60, label %61, label %69

61:                                               ; preds = %57
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.node, ptr %62, i32 0, i32 0
  %64 = load ptr, ptr %63, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %12, ptr align 4 %4, i64 8, i1 false), !tbaa.struct !14
  %65 = load i32, ptr %6, align 4, !tbaa !9
  %66 = xor i32 %65, 1
  %67 = getelementptr inbounds %struct.point, ptr %12, i32 0, i32 0
  %68 = load i64, ptr %67, align 4
  call void @_Z4findP4node5pointi(ptr noundef %64, i64 %68, i32 noundef %66)
  br label %69

69:                                               ; preds = %61, %57
  %70 = load i32, ptr %9, align 4, !tbaa !9
  %71 = load i32, ptr @mindis, align 4, !tbaa !9
  %72 = icmp slt i32 %70, %71
  br i1 %72, label %73, label %81

73:                                               ; preds = %69
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.node, ptr %74, i32 0, i32 1
  %76 = load ptr, ptr %75, align 8, !tbaa !16
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %13, ptr align 4 %4, i64 8, i1 false), !tbaa.struct !14
  %77 = load i32, ptr %6, align 4, !tbaa !9
  %78 = xor i32 %77, 1
  %79 = getelementptr inbounds %struct.point, ptr %13, i32 0, i32 0
  %80 = load i64, ptr %79, align 4
  call void @_Z4findP4node5pointi(ptr noundef %76, i64 %80, i32 noundef %78)
  br label %81

81:                                               ; preds = %73, %69
  br label %107

82:                                               ; preds = %53
  %83 = load i32, ptr %9, align 4, !tbaa !9
  %84 = load i32, ptr @mindis, align 4, !tbaa !9
  %85 = icmp slt i32 %83, %84
  br i1 %85, label %86, label %94

86:                                               ; preds = %82
  %87 = load ptr, ptr %5, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.node, ptr %87, i32 0, i32 1
  %89 = load ptr, ptr %88, align 8, !tbaa !16
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %14, ptr align 4 %4, i64 8, i1 false), !tbaa.struct !14
  %90 = load i32, ptr %6, align 4, !tbaa !9
  %91 = xor i32 %90, 1
  %92 = getelementptr inbounds %struct.point, ptr %14, i32 0, i32 0
  %93 = load i64, ptr %92, align 4
  call void @_Z4findP4node5pointi(ptr noundef %89, i64 %93, i32 noundef %91)
  br label %94

94:                                               ; preds = %86, %82
  %95 = load i32, ptr %8, align 4, !tbaa !9
  %96 = load i32, ptr @mindis, align 4, !tbaa !9
  %97 = icmp slt i32 %95, %96
  br i1 %97, label %98, label %106

98:                                               ; preds = %94
  %99 = load ptr, ptr %5, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.node, ptr %99, i32 0, i32 0
  %101 = load ptr, ptr %100, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %15, ptr align 4 %4, i64 8, i1 false), !tbaa.struct !14
  %102 = load i32, ptr %6, align 4, !tbaa !9
  %103 = xor i32 %102, 1
  %104 = getelementptr inbounds %struct.point, ptr %15, i32 0, i32 0
  %105 = load i64, ptr %104, align 4
  call void @_Z4findP4node5pointi(ptr noundef %101, i64 %105, i32 noundef %103)
  br label %106

106:                                              ; preds = %98, %94
  br label %107

107:                                              ; preds = %106, %81
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %108

108:                                              ; preds = %107, %19
  ret void
}

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

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 = !{!12, !6, i64 0}
!12 = !{!"_ZTS4node", !6, i64 0, !6, i64 8, !13, i64 16, !7, i64 24, !7, i64 32}
!13 = !{!"_ZTS5point", !7, i64 0}
!14 = !{i64 0, i64 8, !15}
!15 = !{!7, !7, i64 0}
!16 = !{!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"

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

@mindis = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z7get_dis5pointP4node(i64, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4findP4node5pointi(ptr noundef %0, i64 %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = alloca %struct.point, align 8
  store i64 %1, ptr %4, align 8
  %5 = icmp eq ptr %0, null
  br i1 %5, label %46, label %6

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = call noundef i32 @_Z4distR5pointS0_(ptr noundef nonnull align 4 dereferenceable(8) %4, ptr noundef nonnull align 4 dereferenceable(8) %7)
  %9 = load i32, ptr @mindis, align 4, !tbaa !5
  %10 = icmp slt i32 %8, %9
  br i1 %10, label %11, label %12

11:                                               ; preds = %6
  store i32 %8, ptr @mindis, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %11, %6
  %13 = load ptr, ptr %0, align 8, !tbaa !9
  %.not = icmp eq ptr %13, null
  br i1 %.not, label %16, label %14

14:                                               ; preds = %12
  %.sroa.05.0.copyload = load i64, ptr %4, align 8, !tbaa !13
  %15 = call noundef i32 @_Z7get_dis5pointP4node(i64 %.sroa.05.0.copyload, ptr noundef nonnull %13)
  br label %16

16:                                               ; preds = %14, %12
  %.0 = phi i32 [ %15, %14 ], [ 1000000000, %12 ]
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  %.not31 = icmp eq ptr %18, null
  br i1 %.not31, label %21, label %19

19:                                               ; preds = %16
  %.sroa.04.0.copyload = load i64, ptr %4, align 8, !tbaa !13
  %20 = call noundef i32 @_Z7get_dis5pointP4node(i64 %.sroa.04.0.copyload, ptr noundef nonnull %18)
  br label %21

21:                                               ; preds = %19, %16
  %.026 = phi i32 [ %20, %19 ], [ 1000000000, %16 ]
  %22 = icmp slt i32 %.0, %.026
  %23 = load i32, ptr @mindis, align 4, !tbaa !5
  br i1 %22, label %24, label %35

24:                                               ; preds = %21
  %25 = icmp slt i32 %.0, %23
  br i1 %25, label %26, label %29

26:                                               ; preds = %24
  %27 = load ptr, ptr %0, align 8, !tbaa !9
  %.sroa.03.0.copyload = load i64, ptr %4, align 8, !tbaa !13
  %28 = xor i32 %2, 1
  call void @_Z4findP4node5pointi(ptr noundef %27, i64 %.sroa.03.0.copyload, i32 noundef %28)
  %.pre32 = load i32, ptr @mindis, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %26, %24
  %30 = phi i32 [ %.pre32, %26 ], [ %23, %24 ]
  %31 = icmp slt i32 %.026, %30
  br i1 %31, label %32, label %46

32:                                               ; preds = %29
  %33 = load ptr, ptr %17, align 8, !tbaa !14
  %.sroa.02.0.copyload = load i64, ptr %4, align 8, !tbaa !13
  %34 = xor i32 %2, 1
  call void @_Z4findP4node5pointi(ptr noundef %33, i64 %.sroa.02.0.copyload, i32 noundef %34)
  br label %46

35:                                               ; preds = %21
  %36 = icmp slt i32 %.026, %23
  br i1 %36, label %37, label %40

37:                                               ; preds = %35
  %38 = load ptr, ptr %17, align 8, !tbaa !14
  %.sroa.01.0.copyload = load i64, ptr %4, align 8, !tbaa !13
  %39 = xor i32 %2, 1
  call void @_Z4findP4node5pointi(ptr noundef %38, i64 %.sroa.01.0.copyload, i32 noundef %39)
  %.pre = load i32, ptr @mindis, align 4, !tbaa !5
  br label %40

40:                                               ; preds = %37, %35
  %41 = phi i32 [ %.pre, %37 ], [ %23, %35 ]
  %42 = icmp slt i32 %.0, %41
  br i1 %42, label %43, label %46

43:                                               ; preds = %40
  %44 = load ptr, ptr %0, align 8, !tbaa !9
  %.sroa.0.0.copyload = load i64, ptr %4, align 8, !tbaa !13
  %45 = xor i32 %2, 1
  call void @_Z4findP4node5pointi(ptr noundef %44, i64 %.sroa.0.0.copyload, i32 noundef %45)
  br label %46

46:                                               ; preds = %32, %29, %43, %40, %3
  ret void
}

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

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 = { 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" }

!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, !11, i64 0}
!10 = !{!"_ZTS4node", !11, i64 0, !11, i64 8, !12, i64 16, !7, i64 24, !7, i64 32}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"_ZTS5point", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!10, !11, i64 8}


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