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

; 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: 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) #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
define dso_local noundef i32 @_Z7get_dis5pointP4node(i64 %0, ptr noundef %1) #2 {
  %3 = alloca %struct.point, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = getelementptr inbounds %struct.point, ptr %3, i32 0, i32 0
  store i64 %0, ptr %6, align 4
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  %7 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5pointixEi(ptr noundef nonnull align 4 dereferenceable(8) %3, i32 noundef 0)
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.node, ptr %9, i32 0, i32 3
  %11 = getelementptr inbounds [2 x i32], ptr %10, i64 0, i64 0
  %12 = load i32, ptr %11, align 8, !tbaa !9
  %13 = icmp slt i32 %8, %12
  br i1 %13, label %14, label %24

14:                                               ; preds = %2
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.node, ptr %15, i32 0, i32 3
  %17 = getelementptr inbounds [2 x i32], ptr %16, i64 0, i64 0
  %18 = load i32, ptr %17, align 8, !tbaa !9
  %19 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5pointixEi(ptr noundef nonnull align 4 dereferenceable(8) %3, i32 noundef 0)
  %20 = load i32, ptr %19, align 4, !tbaa !9
  %21 = sub nsw i32 %18, %20
  %22 = load i32, ptr %5, align 4, !tbaa !9
  %23 = add nsw i32 %22, %21
  store i32 %23, ptr %5, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %14, %2
  %25 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5pointixEi(ptr noundef nonnull align 4 dereferenceable(8) %3, i32 noundef 0)
  %26 = load i32, ptr %25, align 4, !tbaa !9
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.node, ptr %27, i32 0, i32 4
  %29 = getelementptr inbounds [2 x i32], ptr %28, i64 0, i64 0
  %30 = load i32, ptr %29, align 8, !tbaa !9
  %31 = icmp sgt i32 %26, %30
  br i1 %31, label %32, label %42

32:                                               ; preds = %24
  %33 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5pointixEi(ptr noundef nonnull align 4 dereferenceable(8) %3, i32 noundef 0)
  %34 = load i32, ptr %33, align 4, !tbaa !9
  %35 = load ptr, ptr %4, 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 0
  %38 = load i32, ptr %37, align 8, !tbaa !9
  %39 = sub nsw i32 %34, %38
  %40 = load i32, ptr %5, align 4, !tbaa !9
  %41 = add nsw i32 %40, %39
  store i32 %41, ptr %5, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %32, %24
  %43 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5pointixEi(ptr noundef nonnull align 4 dereferenceable(8) %3, i32 noundef 1)
  %44 = load i32, ptr %43, align 4, !tbaa !9
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.node, ptr %45, i32 0, i32 3
  %47 = getelementptr inbounds [2 x i32], ptr %46, i64 0, i64 1
  %48 = load i32, ptr %47, align 4, !tbaa !9
  %49 = icmp slt i32 %44, %48
  br i1 %49, label %50, label %60

50:                                               ; preds = %42
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.node, ptr %51, i32 0, i32 3
  %53 = getelementptr inbounds [2 x i32], ptr %52, i64 0, i64 1
  %54 = load i32, ptr %53, align 4, !tbaa !9
  %55 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5pointixEi(ptr noundef nonnull align 4 dereferenceable(8) %3, i32 noundef 1)
  %56 = load i32, ptr %55, align 4, !tbaa !9
  %57 = sub nsw i32 %54, %56
  %58 = load i32, ptr %5, align 4, !tbaa !9
  %59 = add nsw i32 %58, %57
  store i32 %59, ptr %5, align 4, !tbaa !9
  br label %60

60:                                               ; preds = %50, %42
  %61 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5pointixEi(ptr noundef nonnull align 4 dereferenceable(8) %3, i32 noundef 1)
  %62 = load i32, ptr %61, align 4, !tbaa !9
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.node, ptr %63, i32 0, i32 4
  %65 = getelementptr inbounds [2 x i32], ptr %64, i64 0, i64 1
  %66 = load i32, ptr %65, align 4, !tbaa !9
  %67 = icmp sgt i32 %62, %66
  br i1 %67, label %68, label %78

68:                                               ; preds = %60
  %69 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5pointixEi(ptr noundef nonnull align 4 dereferenceable(8) %3, i32 noundef 1)
  %70 = load i32, ptr %69, align 4, !tbaa !9
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.node, ptr %71, i32 0, i32 4
  %73 = getelementptr inbounds [2 x i32], ptr %72, i64 0, i64 1
  %74 = load i32, ptr %73, align 4, !tbaa !9
  %75 = sub nsw i32 %70, %74
  %76 = load i32, ptr %5, align 4, !tbaa !9
  %77 = add nsw i32 %76, %75
  store i32 %77, ptr %5, align 4, !tbaa !9
  br label %78

78:                                               ; preds = %68, %60
  %79 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i32 %79
}

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


; 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: 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 nounwind uwtable
define dso_local noundef i32 @_Z7get_dis5pointP4node(i64 %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = alloca %struct.point, align 8
  store i64 %0, ptr %3, align 8
  %4 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5pointixEi(ptr noundef nonnull align 4 dereferenceable(8) %3, i32 noundef 0)
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %1, i64 24
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = icmp slt i32 %5, %7
  br i1 %8, label %9, label %13

9:                                                ; preds = %2
  %10 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5pointixEi(ptr noundef nonnull align 4 dereferenceable(8) %3, i32 noundef 0)
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = sub nsw i32 %7, %11
  br label %13

13:                                               ; preds = %9, %2
  %.0 = phi i32 [ %12, %9 ], [ 0, %2 ]
  %14 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5pointixEi(ptr noundef nonnull align 4 dereferenceable(8) %3, i32 noundef 0)
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %1, i64 32
  %17 = load i32, ptr %16, align 8, !tbaa !5
  %18 = icmp sgt i32 %15, %17
  br i1 %18, label %19, label %25

19:                                               ; preds = %13
  %20 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5pointixEi(ptr noundef nonnull align 4 dereferenceable(8) %3, i32 noundef 0)
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = load i32, ptr %16, align 8, !tbaa !5
  %23 = add i32 %21, %.0
  %24 = sub i32 %23, %22
  br label %25

25:                                               ; preds = %19, %13
  %.1 = phi i32 [ %24, %19 ], [ %.0, %13 ]
  %26 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5pointixEi(ptr noundef nonnull align 4 dereferenceable(8) %3, i32 noundef 1)
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %1, i64 28
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = icmp slt i32 %27, %29
  br i1 %30, label %31, label %36

31:                                               ; preds = %25
  %32 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5pointixEi(ptr noundef nonnull align 4 dereferenceable(8) %3, i32 noundef 1)
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = add i32 %29, %.1
  %35 = sub i32 %34, %33
  br label %36

36:                                               ; preds = %31, %25
  %.2 = phi i32 [ %35, %31 ], [ %.1, %25 ]
  %37 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5pointixEi(ptr noundef nonnull align 4 dereferenceable(8) %3, i32 noundef 1)
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %1, i64 36
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = icmp sgt i32 %38, %40
  br i1 %41, label %42, label %48

42:                                               ; preds = %36
  %43 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5pointixEi(ptr noundef nonnull align 4 dereferenceable(8) %3, i32 noundef 1)
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = load i32, ptr %39, align 4, !tbaa !5
  %46 = add i32 %44, %.2
  %47 = sub i32 %46, %45
  br label %48

48:                                               ; preds = %42, %36
  %.3 = phi i32 [ %47, %42 ], [ %.2, %36 ]
  ret i32 %.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" }

!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"}


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