; LLVM IR from robinrodricks/InspiritImage :: Inspirit.Assurf/clib (utils)

; 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._IPointMatch = type { ptr, ptr, ptr, double, double, i32, i32, i32 }
%struct._IPoint = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, double, double, i32, i32, i32, double, ptr, i32, [256 x i8] }

; 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: inlinehint nounwind uwtable
declare i32 @iSquare(i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @get2ClosestPointsIdx(i32 noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4, ptr noundef %5) #2 {
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !9
  store ptr %5, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  store i32 2147483647, ptr %14, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  store i32 2147483647, ptr %15, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  store i32 0, ptr %16, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  store i32 0, ptr %17, align 4, !tbaa !5
  store i32 0, ptr %13, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %72, %6
  %20 = load i32, ptr %13, align 4, !tbaa !5
  %21 = load i32, ptr %10, align 4, !tbaa !5
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %23, label %75

23:                                               ; preds = %19
  %24 = load ptr, ptr %12, align 8, !tbaa !9
  %25 = load i32, ptr %13, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds i32, ptr %24, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = icmp eq i32 %28, 1
  br i1 %29, label %30, label %31

30:                                               ; preds = %23
  br label %72

31:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  %32 = load i32, ptr %7, align 4, !tbaa !5
  %33 = load ptr, ptr %9, align 8, !tbaa !9
  %34 = load i32, ptr %13, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds %struct._IPointMatch, ptr %33, i64 %35
  %37 = getelementptr inbounds %struct._IPointMatch, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !11
  %39 = getelementptr inbounds %struct._IPoint, ptr %38, i32 0, i32 4
  %40 = load i32, ptr %39, align 8, !tbaa !14
  %41 = sub nsw i32 %32, %40
  %42 = call i32 @iSquare(i32 noundef %41)
  %43 = load i32, ptr %8, align 4, !tbaa !5
  %44 = load ptr, ptr %9, align 8, !tbaa !9
  %45 = load i32, ptr %13, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds %struct._IPointMatch, ptr %44, i64 %46
  %48 = getelementptr inbounds %struct._IPointMatch, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !11
  %50 = getelementptr inbounds %struct._IPoint, ptr %49, i32 0, i32 5
  %51 = load i32, ptr %50, align 4, !tbaa !16
  %52 = sub nsw i32 %43, %51
  %53 = call i32 @iSquare(i32 noundef %52)
  %54 = add nsw i32 %42, %53
  store i32 %54, ptr %18, align 4, !tbaa !5
  %55 = load i32, ptr %18, align 4, !tbaa !5
  %56 = load i32, ptr %14, align 4, !tbaa !5
  %57 = icmp slt i32 %55, %56
  br i1 %57, label %58, label %63

58:                                               ; preds = %31
  %59 = load i32, ptr %14, align 4, !tbaa !5
  store i32 %59, ptr %15, align 4, !tbaa !5
  %60 = load i32, ptr %18, align 4, !tbaa !5
  store i32 %60, ptr %14, align 4, !tbaa !5
  %61 = load i32, ptr %16, align 4, !tbaa !5
  store i32 %61, ptr %17, align 4, !tbaa !5
  %62 = load i32, ptr %13, align 4, !tbaa !5
  store i32 %62, ptr %16, align 4, !tbaa !5
  br label %71

63:                                               ; preds = %31
  %64 = load i32, ptr %18, align 4, !tbaa !5
  %65 = load i32, ptr %15, align 4, !tbaa !5
  %66 = icmp slt i32 %64, %65
  br i1 %66, label %67, label %70

67:                                               ; preds = %63
  %68 = load i32, ptr %18, align 4, !tbaa !5
  store i32 %68, ptr %15, align 4, !tbaa !5
  %69 = load i32, ptr %13, align 4, !tbaa !5
  store i32 %69, ptr %17, align 4, !tbaa !5
  br label %70

70:                                               ; preds = %67, %63
  br label %71

71:                                               ; preds = %70, %58
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  br label %72

72:                                               ; preds = %71, %30
  %73 = load i32, ptr %13, align 4, !tbaa !5
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %13, align 4, !tbaa !5
  br label %19, !llvm.loop !17

75:                                               ; preds = %19
  %76 = load i32, ptr %16, align 4, !tbaa !5
  %77 = load ptr, ptr %11, align 8, !tbaa !9
  %78 = getelementptr inbounds i32, ptr %77, i64 0
  store i32 %76, ptr %78, align 4, !tbaa !5
  %79 = load i32, ptr %17, align 4, !tbaa !5
  %80 = load ptr, ptr %11, align 8, !tbaa !9
  %81 = getelementptr inbounds i32, ptr %80, i64 1
  store i32 %79, ptr %81, align 4, !tbaa !5
  %82 = load ptr, ptr %12, align 8, !tbaa !9
  %83 = load i32, ptr %16, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds i32, ptr %82, i64 %84
  store i32 1, ptr %85, align 4, !tbaa !5
  %86 = load ptr, ptr %12, align 8, !tbaa !9
  %87 = load i32, ptr %17, align 4, !tbaa !5
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds i32, ptr %86, i64 %88
  store i32 1, ptr %89, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 = { 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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_IPointMatch", !10, i64 0, !10, i64 8, !10, i64 16, !13, i64 24, !13, i64 32, !6, i64 40, !6, i64 44, !6, i64 48}
!13 = !{!"double", !7, i64 0}
!14 = !{!15, !6, i64 16}
!15 = !{!"_IPoint", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !13, i64 40, !13, i64 48, !6, i64 56, !6, i64 60, !6, i64 64, !13, i64 72, !10, i64 80, !6, i64 88, !7, i64 92}
!16 = !{!15, !6, i64 20}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; 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._IPointMatch = type { ptr, ptr, ptr, double, double, i32, i32, i32 }

; Function Attrs: inlinehint nounwind uwtable
declare i32 @iSquare(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @get2ClosestPointsIdx(i32 noundef %0, i32 noundef %1, ptr nocapture noundef readonly %2, i32 noundef %3, ptr nocapture noundef writeonly %4, ptr nocapture noundef %5) local_unnamed_addr #1 {
  %7 = icmp sgt i32 %3, 0
  br i1 %7, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %6
  %wide.trip.count = zext nneg i32 %3 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %28
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %28 ]
  %.02844 = phi i32 [ 0, %.lr.ph.preheader ], [ %.2, %28 ]
  %.02943 = phi i32 [ 0, %.lr.ph.preheader ], [ %.231, %28 ]
  %.03242 = phi i32 [ 2147483647, %.lr.ph.preheader ], [ %.234, %28 ]
  %.03541 = phi i32 [ 2147483647, %.lr.ph.preheader ], [ %.237, %28 ]
  %8 = getelementptr inbounds i32, ptr %5, i64 %indvars.iv
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = icmp eq i32 %9, 1
  br i1 %10, label %28, label %11

11:                                               ; preds = %.lr.ph
  %12 = getelementptr inbounds %struct._IPointMatch, ptr %2, i64 %indvars.iv
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %14 = getelementptr inbounds i8, ptr %13, i64 16
  %15 = load i32, ptr %14, align 8, !tbaa !13
  %16 = sub nsw i32 %0, %15
  %17 = tail call i32 @iSquare(i32 noundef %16)
  %18 = load ptr, ptr %12, align 8, !tbaa !9
  %19 = getelementptr inbounds i8, ptr %18, i64 20
  %20 = load i32, ptr %19, align 4, !tbaa !15
  %21 = sub nsw i32 %1, %20
  %22 = tail call i32 @iSquare(i32 noundef %21)
  %23 = add nsw i32 %22, %17
  %24 = icmp slt i32 %23, %.03541
  %25 = trunc nuw nsw i64 %indvars.iv to i32
  br i1 %24, label %28, label %26

26:                                               ; preds = %11
  %27 = icmp slt i32 %23, %.03242
  %spec.select = tail call i32 @llvm.smin.i32(i32 %23, i32 %.03242)
  %spec.select40 = select i1 %27, i32 %25, i32 %.02844
  br label %28

28:                                               ; preds = %26, %11, %.lr.ph
  %.237 = phi i32 [ %.03541, %.lr.ph ], [ %23, %11 ], [ %.03541, %26 ]
  %.234 = phi i32 [ %.03242, %.lr.ph ], [ %.03541, %11 ], [ %spec.select, %26 ]
  %.231 = phi i32 [ %.02943, %.lr.ph ], [ %25, %11 ], [ %.02943, %26 ]
  %.2 = phi i32 [ %.02844, %.lr.ph ], [ %.02943, %11 ], [ %spec.select40, %26 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !16

._crit_edge:                                      ; preds = %28, %6
  %.029.lcssa = phi i32 [ 0, %6 ], [ %.231, %28 ]
  %.028.lcssa = phi i32 [ 0, %6 ], [ %.2, %28 ]
  store i32 %.029.lcssa, ptr %4, align 4, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %4, i64 4
  store i32 %.028.lcssa, ptr %29, align 4, !tbaa !5
  %30 = sext i32 %.029.lcssa to i64
  %31 = getelementptr inbounds i32, ptr %5, i64 %30
  store i32 1, ptr %31, align 4, !tbaa !5
  %32 = sext i32 %.028.lcssa to i64
  %33 = getelementptr inbounds i32, ptr %5, i64 %32
  store i32 1, ptr %33, align 4, !tbaa !5
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #2

attributes #0 = { inlinehint 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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_IPointMatch", !11, i64 0, !11, i64 8, !11, i64 16, !12, i64 24, !12, i64 32, !6, i64 40, !6, i64 44, !6, i64 48}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !6, i64 16}
!14 = !{!"_IPoint", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !12, i64 40, !12, i64 48, !6, i64 56, !6, i64 60, !6, i64 64, !12, i64 72, !11, i64 80, !6, i64 88, !7, i64 92}
!15 = !{!14, !6, i64 20}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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