; LLVM IR from ShahjalalShohag/code-library :: Data Structures/KD Tree.ll (Z10build_treeRP7kd_nodeiii)

; 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.cmp_points = type { i32 }
%struct.kd_node = type { i32, i32, %struct.point, ptr, ptr }

@arr = external dso_local global [100009 x %struct.point], align 16

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z10build_treeRP7kd_nodeiii(ptr noundef nonnull align 8 dereferenceable(8) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %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.cmp_points, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  %11 = load i32, ptr %6, align 4, !tbaa !9
  %12 = load i32, ptr %7, align 4, !tbaa !9
  %13 = icmp sgt i32 %11, %12
  br i1 %13, label %14, label %16

14:                                               ; preds = %4
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr null, ptr %15, align 8, !tbaa !5
  br label %85

16:                                               ; preds = %4
  %17 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 32) #7
  call void @llvm.memset.p0.i64(ptr align 16 %17, i8 0, i64 32, i1 false)
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %17, ptr %18, align 8, !tbaa !5
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = icmp eq i32 %19, %20
  br i1 %21, label %22, label %35

22:                                               ; preds = %16
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [100009 x %struct.point], ptr @arr, i64 0, i64 %24
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.kd_node, ptr %27, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %28, ptr align 8 %25, i64 8, i1 false), !tbaa.struct !11
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.kd_node, ptr %30, i32 0, i32 3
  store ptr null, ptr %31, align 8, !tbaa !13
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.kd_node, ptr %33, i32 0, i32 4
  store ptr null, ptr %34, align 8, !tbaa !16
  br label %85

35:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #8
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = load i32, ptr %7, align 4, !tbaa !9
  %38 = add nsw i32 %36, %37
  %39 = sdiv i32 %38, 2
  store i32 %39, ptr %9, align 4, !tbaa !9
  %40 = load i32, ptr %6, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds %struct.point, ptr @arr, i64 %41
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds %struct.point, ptr @arr, i64 %44
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds %struct.point, ptr @arr, i64 %47
  %49 = getelementptr inbounds %struct.point, ptr %48, i64 1
  %50 = load i32, ptr %8, align 4, !tbaa !9
  call void @_ZN10cmp_pointsC2Ei(ptr noundef nonnull align 4 dereferenceable(4) %10, i32 noundef %50)
  %51 = getelementptr inbounds %struct.cmp_points, ptr %10, i32 0, i32 0
  %52 = load i32, ptr %51, align 4
  call void @_ZSt11nth_elementIP5point10cmp_pointsEvT_S3_S3_T0_(ptr noundef %42, ptr noundef %45, ptr noundef %49, i32 %52)
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [100009 x %struct.point], ptr @arr, i64 0, i64 %54
  %56 = getelementptr inbounds %struct.point, ptr %55, i32 0, i32 0
  %57 = load i32, ptr %8, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [2 x i32], ptr %56, i64 0, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !9
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = load ptr, ptr %61, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.kd_node, ptr %62, i32 0, i32 1
  store i32 %60, ptr %63, align 4, !tbaa !17
  %64 = load i32, ptr %8, align 4, !tbaa !9
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = load ptr, ptr %65, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.kd_node, ptr %66, i32 0, i32 0
  store i32 %64, ptr %67, align 8, !tbaa !18
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = load ptr, ptr %68, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.kd_node, ptr %69, i32 0, i32 3
  %71 = load i32, ptr %6, align 4, !tbaa !9
  %72 = load i32, ptr %9, align 4, !tbaa !9
  %73 = load i32, ptr %8, align 4, !tbaa !9
  %74 = add nsw i32 %73, 1
  %75 = srem i32 %74, 2
  call void @_Z10build_treeRP7kd_nodeiii(ptr noundef nonnull align 8 dereferenceable(8) %70, i32 noundef %71, i32 noundef %72, i32 noundef %75)
  %76 = load ptr, ptr %5, align 8, !tbaa !5
  %77 = load ptr, ptr %76, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.kd_node, ptr %77, i32 0, i32 4
  %79 = load i32, ptr %9, align 4, !tbaa !9
  %80 = add nsw i32 %79, 1
  %81 = load i32, ptr %7, align 4, !tbaa !9
  %82 = load i32, ptr %8, align 4, !tbaa !9
  %83 = add nsw i32 %82, 1
  %84 = srem i32 %83, 2
  call void @_Z10build_treeRP7kd_nodeiii(ptr noundef nonnull align 8 dereferenceable(8) %78, i32 noundef %80, i32 noundef %81, i32 noundef %84)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #8
  br label %85

85:                                               ; preds = %35, %22, %14
  ret void
}

; 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

; 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) #4

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 #6 = { 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 #7 = { builtin allocsize(0) }
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}
!11 = !{i64 0, i64 8, !12}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !6, i64 16}
!14 = !{!"_ZTS7kd_node", !10, i64 0, !10, i64 4, !15, i64 8, !6, i64 16, !6, i64 24}
!15 = !{!"_ZTS5point", !7, i64 0}
!16 = !{!14, !6, i64 24}
!17 = !{!14, !10, i64 4}
!18 = !{!14, !10, 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] }
%struct.cmp_points = type { i32 }

@arr = external dso_local global [100009 x %struct.point], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z10build_treeRP7kd_nodeiii(ptr nocapture noundef nonnull align 8 dereferenceable(8) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = alloca %struct.cmp_points, align 4
  %6 = icmp sgt i32 %1, %2
  br i1 %6, label %7, label %8

7:                                                ; preds = %4
  store ptr null, ptr %0, align 8, !tbaa !5
  br label %39

8:                                                ; preds = %4
  %9 = tail call noalias noundef nonnull dereferenceable(32) ptr @_Znwm(i64 noundef 32) #5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %9, i8 0, i64 32, i1 false)
  store ptr %9, ptr %0, align 8, !tbaa !5
  %10 = icmp eq i32 %1, %2
  br i1 %10, label %11, label %17

11:                                               ; preds = %8
  %12 = sext i32 %1 to i64
  %13 = getelementptr inbounds [100009 x %struct.point], ptr @arr, i64 0, i64 %12
  %14 = getelementptr inbounds i8, ptr %9, i64 8
  %15 = load i64, ptr %13, align 8, !tbaa !9
  store i64 %15, ptr %14, align 8, !tbaa !9
  %16 = getelementptr inbounds i8, ptr %9, i64 16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %16, i8 0, i64 16, i1 false)
  br label %39

17:                                               ; preds = %8
  %18 = add nsw i32 %2, %1
  %19 = sdiv i32 %18, 2
  %20 = sext i32 %1 to i64
  %21 = getelementptr inbounds %struct.point, ptr @arr, i64 %20
  %22 = sext i32 %19 to i64
  %23 = getelementptr inbounds %struct.point, ptr @arr, i64 %22
  %24 = sext i32 %2 to i64
  %25 = getelementptr inbounds %struct.point, ptr @arr, i64 %24
  %26 = getelementptr inbounds i8, ptr %25, i64 8
  call void @_ZN10cmp_pointsC2Ei(ptr noundef nonnull align 4 dereferenceable(4) %5, i32 noundef %3)
  %27 = load i32, ptr %5, align 4
  call void @_ZSt11nth_elementIP5point10cmp_pointsEvT_S3_S3_T0_(ptr noundef nonnull %21, ptr noundef nonnull %23, ptr noundef nonnull %26, i32 %27)
  %28 = sext i32 %3 to i64
  %29 = getelementptr inbounds [2 x i32], ptr %23, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !10
  %31 = load ptr, ptr %0, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %31, i64 4
  store i32 %30, ptr %32, align 4, !tbaa !12
  store i32 %3, ptr %31, align 8, !tbaa !15
  %33 = getelementptr inbounds i8, ptr %31, i64 16
  %34 = add nsw i32 %3, 1
  %35 = srem i32 %34, 2
  call void @_Z10build_treeRP7kd_nodeiii(ptr noundef nonnull align 8 dereferenceable(8) %33, i32 noundef %1, i32 noundef %19, i32 noundef %35)
  %36 = load ptr, ptr %0, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %36, i64 24
  %38 = add nsw i32 %19, 1
  call void @_Z10build_treeRP7kd_nodeiii(ptr noundef nonnull align 8 dereferenceable(8) %37, i32 noundef %38, i32 noundef %2, i32 noundef %35)
  br label %39

39:                                               ; preds = %17, %11, %7
  ret void
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt11nth_elementIP5point10cmp_pointsEvT_S3_S3_T0_(ptr noundef, ptr noundef, ptr noundef, i32) local_unnamed_addr #3

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

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 = { 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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #4 = { 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 #5 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 4}
!13 = !{!"_ZTS7kd_node", !11, i64 0, !11, i64 4, !14, i64 8, !6, i64 16, !6, i64 24}
!14 = !{!"_ZTS5point", !7, i64 0}
!15 = !{!13, !11, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,TailCallElimPass