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

; Function Attrs: nounwind uwtable
define dso_local void @get2ClosestPoints(i32 noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4, ptr noundef %5) #3 {
  %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) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  store i32 2147483647, ptr %14, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  store i32 2147483647, ptr %15, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  store i32 0, ptr %16, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  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) #4
  %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) #4
  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 ptr, ptr %11, align 8, !tbaa !9
  %77 = getelementptr inbounds %struct._IPointMatch, ptr %76, i64 0
  %78 = load ptr, ptr %9, align 8, !tbaa !9
  %79 = load i32, ptr %16, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds %struct._IPointMatch, ptr %78, i64 %80
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %77, ptr align 8 %81, i64 56, i1 false), !tbaa.struct !19
  %82 = load ptr, ptr %11, align 8, !tbaa !9
  %83 = getelementptr inbounds %struct._IPointMatch, ptr %82, i64 1
  %84 = load ptr, ptr %9, align 8, !tbaa !9
  %85 = load i32, ptr %17, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds %struct._IPointMatch, ptr %84, i64 %86
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %83, ptr align 8 %87, i64 56, i1 false), !tbaa.struct !19
  %88 = load ptr, ptr %12, align 8, !tbaa !9
  %89 = load i32, ptr %16, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds i32, ptr %88, i64 %90
  store i32 1, ptr %91, align 4, !tbaa !5
  %92 = load ptr, ptr %12, align 8, !tbaa !9
  %93 = load i32, ptr %17, align 4, !tbaa !5
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds i32, ptr %92, i64 %94
  store i32 1, ptr %95, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = !{!"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"}
!19 = !{i64 0, i64 8, !9, i64 8, i64 8, !9, i64 16, i64 8, !9, i64 24, i64 8, !20, i64 32, i64 8, !20, i64 40, i64 4, !5, i64 44, i64 4, !5, i64 48, i64 4, !5}
!20 = !{!13, !13, 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._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: mustprogress 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) #1

; Function Attrs: nounwind uwtable
define dso_local void @get2ClosestPoints(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 #2 {
  %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 ]
  %.03046 = phi i32 [ 0, %.lr.ph.preheader ], [ %.2, %28 ]
  %.03145 = phi i32 [ 0, %.lr.ph.preheader ], [ %.233, %28 ]
  %.03444 = phi i32 [ 2147483647, %.lr.ph.preheader ], [ %.236, %28 ]
  %.03743 = phi i32 [ 2147483647, %.lr.ph.preheader ], [ %.239, %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, %.03743
  %25 = trunc nuw nsw i64 %indvars.iv to i32
  br i1 %24, label %28, label %26

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

28:                                               ; preds = %26, %11, %.lr.ph
  %.239 = phi i32 [ %.03743, %.lr.ph ], [ %23, %11 ], [ %.03743, %26 ]
  %.236 = phi i32 [ %.03444, %.lr.ph ], [ %.03743, %11 ], [ %spec.select, %26 ]
  %.233 = phi i32 [ %.03145, %.lr.ph ], [ %25, %11 ], [ %.03145, %26 ]
  %.2 = phi i32 [ %.03046, %.lr.ph ], [ %.03145, %11 ], [ %spec.select42, %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.loopexit, label %.lr.ph, !llvm.loop !16

._crit_edge.loopexit:                             ; preds = %28
  %29 = sext i32 %.233 to i64
  %30 = sext i32 %.2 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %6
  %.031.lcssa = phi i64 [ 0, %6 ], [ %29, %._crit_edge.loopexit ]
  %.030.lcssa = phi i64 [ 0, %6 ], [ %30, %._crit_edge.loopexit ]
  %31 = getelementptr inbounds %struct._IPointMatch, ptr %2, i64 %.031.lcssa
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(56) %4, ptr noundef nonnull align 8 dereferenceable(56) %31, i64 56, i1 false), !tbaa.struct !18
  %32 = getelementptr inbounds i8, ptr %4, i64 56
  %33 = getelementptr inbounds %struct._IPointMatch, ptr %2, i64 %.030.lcssa
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(56) %32, ptr noundef nonnull align 8 dereferenceable(56) %33, i64 56, i1 false), !tbaa.struct !18
  %34 = getelementptr inbounds i32, ptr %5, i64 %.031.lcssa
  store i32 1, ptr %34, align 4, !tbaa !5
  %35 = getelementptr inbounds i32, ptr %5, i64 %.030.lcssa
  store i32 1, ptr %35, align 4, !tbaa !5
  ret void
}

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

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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"}
!18 = !{i64 0, i64 8, !19, i64 8, i64 8, !19, i64 16, i64 8, !19, i64 24, i64 8, !20, i64 32, i64 8, !20, i64 40, i64 4, !5, i64 44, i64 4, !5, i64 48, i64 4, !5}
!19 = !{!11, !11, i64 0}
!20 = !{!12, !12, i64 0}


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