; LLVM IR from AlgoGenesis/C :: Mathematical Algorithms/Voronoi Diagram Construction (Program)

; 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 { double, double }
%struct.VoronoiCell = type { [200 x %struct.Point], i32 }

@site_count = external dso_local global i32, align 4
@sites = external dso_local global [100 x %struct.Point], align 16
@voronoi_cells = external dso_local global [100 x %struct.VoronoiCell], align 16

; Function Attrs: nounwind uwtable
declare dso_local double @distance(double, double, double, double) #0

; Function Attrs: nounwind uwtable
define dso_local void @compute_voronoi() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca %struct.VoronoiCell, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca %struct.Point, align 8
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  %10 = alloca double, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %84, %0
  %12 = load i32, ptr %1, align 4, !tbaa !5
  %13 = load i32, ptr @site_count, align 4, !tbaa !5
  %14 = icmp slt i32 %12, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %11
  store i32 2, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  br label %87

16:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 3208, ptr %3) #4
  call void @llvm.memset.p0.i64(ptr align 8 %3, i8 0, i64 3208, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %77, %16
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = icmp slt i32 %18, 100
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  store i32 5, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %80

21:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %73, %21
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = icmp slt i32 %23, 100
  br i1 %24, label %26, label %25

25:                                               ; preds = %22
  store i32 8, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %76

26:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #4
  %27 = getelementptr inbounds %struct.Point, ptr %6, i32 0, i32 0
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = sitofp i32 %28 to double
  store double %29, ptr %27, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct.Point, ptr %6, i32 0, i32 1
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = sitofp i32 %31 to double
  store double %32, ptr %30, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 -1, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store double 0x7FF0000000000000, ptr %8, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %58, %26
  %34 = load i32, ptr %9, align 4, !tbaa !5
  %35 = load i32, ptr @site_count, align 4, !tbaa !5
  %36 = icmp slt i32 %34, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  store i32 11, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %61

38:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %39 = load i32, ptr %9, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [100 x %struct.Point], ptr @sites, i64 0, i64 %40
  %42 = getelementptr inbounds { double, double }, ptr %6, i32 0, i32 0
  %43 = load double, ptr %42, align 8
  %44 = getelementptr inbounds { double, double }, ptr %6, i32 0, i32 1
  %45 = load double, ptr %44, align 8
  %46 = getelementptr inbounds { double, double }, ptr %41, i32 0, i32 0
  %47 = load double, ptr %46, align 16
  %48 = getelementptr inbounds { double, double }, ptr %41, i32 0, i32 1
  %49 = load double, ptr %48, align 8
  %50 = call double @distance(double %43, double %45, double %47, double %49)
  store double %50, ptr %10, align 8, !tbaa !13
  %51 = load double, ptr %10, align 8, !tbaa !13
  %52 = load double, ptr %8, align 8, !tbaa !13
  %53 = fcmp olt double %51, %52
  br i1 %53, label %54, label %57

54:                                               ; preds = %38
  %55 = load double, ptr %10, align 8, !tbaa !13
  store double %55, ptr %8, align 8, !tbaa !13
  %56 = load i32, ptr %9, align 4, !tbaa !5
  store i32 %56, ptr %7, align 4, !tbaa !5
  br label %57

57:                                               ; preds = %54, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %58

58:                                               ; preds = %57
  %59 = load i32, ptr %9, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %9, align 4, !tbaa !5
  br label %33, !llvm.loop !14

61:                                               ; preds = %37
  %62 = load i32, ptr %7, align 4, !tbaa !5
  %63 = load i32, ptr %1, align 4, !tbaa !5
  %64 = icmp eq i32 %62, %63
  br i1 %64, label %65, label %72

65:                                               ; preds = %61
  %66 = getelementptr inbounds %struct.VoronoiCell, ptr %3, i32 0, i32 0
  %67 = getelementptr inbounds %struct.VoronoiCell, ptr %3, i32 0, i32 1
  %68 = load i32, ptr %67, align 8, !tbaa !16
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %67, align 8, !tbaa !16
  %70 = sext i32 %68 to i64
  %71 = getelementptr inbounds [200 x %struct.Point], ptr %66, i64 0, i64 %70
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %71, ptr align 8 %6, i64 16, i1 false), !tbaa.struct !18
  br label %72

72:                                               ; preds = %65, %61
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #4
  br label %73

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

76:                                               ; preds = %25
  br label %77

77:                                               ; preds = %76
  %78 = load i32, ptr %4, align 4, !tbaa !5
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %4, align 4, !tbaa !5
  br label %17, !llvm.loop !20

80:                                               ; preds = %20
  %81 = load i32, ptr %1, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [100 x %struct.VoronoiCell], ptr @voronoi_cells, i64 0, i64 %82
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %83, ptr align 8 %3, i64 3208, i1 false), !tbaa.struct !21
  call void @llvm.lifetime.end.p0(i64 3208, ptr %3) #4
  br label %84

84:                                               ; preds = %80
  %85 = load i32, ptr %1, align 4, !tbaa !5
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %1, align 4, !tbaa !5
  br label %11, !llvm.loop !23

87:                                               ; preds = %15
  ret void
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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) #3

attributes #0 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !11, i64 0}
!10 = !{!"", !11, i64 0, !11, i64 8}
!11 = !{!"double", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!11, !11, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !6, i64 3200}
!17 = !{!"", !7, i64 0, !6, i64 3200}
!18 = !{i64 0, i64 8, !13, i64 8, i64 8, !13}
!19 = distinct !{!19, !15}
!20 = distinct !{!20, !15}
!21 = !{i64 0, i64 3200, !22, i64 3200, i64 4, !5}
!22 = !{!7, !7, i64 0}
!23 = distinct !{!23, !15}


; 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 { double, double }
%struct.VoronoiCell = type { [200 x %struct.Point], i32 }

@site_count = external dso_local local_unnamed_addr global i32, align 4
@sites = external dso_local local_unnamed_addr global [100 x %struct.Point], align 16
@voronoi_cells = external dso_local local_unnamed_addr global [100 x %struct.VoronoiCell], align 16

; Function Attrs: nounwind uwtable
declare dso_local double @distance(double, double, double, double) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @compute_voronoi() local_unnamed_addr #0 {
  %1 = alloca %struct.VoronoiCell, align 8
  %2 = load i32, ptr @site_count, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph38.split.preheader, label %._crit_edge39

.lr.ph38.split.preheader:                         ; preds = %0
  %4 = getelementptr inbounds i8, ptr %1, i64 3200
  br label %.lr.ph38.split

._crit_edge39:                                    ; preds = %.split34.us, %0
  ret void

.lr.ph38.split:                                   ; preds = %.lr.ph38.split.preheader, %.split34.us
  %5 = phi i32 [ %2, %.lr.ph38.split.preheader ], [ %12, %.split34.us ]
  %indvars.iv49 = phi i64 [ 0, %.lr.ph38.split.preheader ], [ %indvars.iv.next50, %.split34.us ]
  call void @llvm.lifetime.start.p0(i64 3208, ptr nonnull %1) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(3208) %1, i8 0, i64 3208, i1 false)
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.preheader, label %.split34.us

.preheader:                                       ; preds = %.lr.ph38.split, %.split.us
  %7 = phi i32 [ %16, %.split.us ], [ %5, %.lr.ph38.split ]
  %8 = phi i32 [ %17, %.split.us ], [ %5, %.lr.ph38.split ]
  %9 = phi i32 [ %18, %.split.us ], [ %5, %.lr.ph38.split ]
  %.02131 = phi i32 [ %19, %.split.us ], [ 0, %.lr.ph38.split ]
  %.us-phi2930 = phi i32 [ %.us-phi, %.split.us ], [ 0, %.lr.ph38.split ]
  %10 = uitofp nneg i32 %.02131 to double
  %11 = icmp sgt i32 %9, 0
  br i1 %11, label %.preheader.split, label %.split.us

.split34.us:                                      ; preds = %.split.us, %.lr.ph38.split
  %12 = phi i32 [ %5, %.lr.ph38.split ], [ %16, %.split.us ]
  %.us-phi35 = phi i32 [ 0, %.lr.ph38.split ], [ %.us-phi, %.split.us ]
  store i32 %.us-phi35, ptr %4, align 8, !tbaa !9
  %13 = getelementptr inbounds [100 x %struct.VoronoiCell], ptr @voronoi_cells, i64 0, i64 %indvars.iv49
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(3208) %13, ptr noundef nonnull align 8 dereferenceable(3208) %1, i64 3208, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 3208, ptr nonnull %1) #4
  %indvars.iv.next50 = add nuw nsw i64 %indvars.iv49, 1
  %14 = sext i32 %12 to i64
  %15 = icmp slt i64 %indvars.iv.next50, %14
  br i1 %15, label %.lr.ph38.split, label %._crit_edge39, !llvm.loop !13

.split.us:                                        ; preds = %43, %.preheader
  %16 = phi i32 [ %7, %.preheader ], [ %25, %43 ]
  %17 = phi i32 [ %8, %.preheader ], [ %26, %43 ]
  %18 = phi i32 [ %9, %.preheader ], [ %26, %43 ]
  %.us-phi = phi i32 [ %.us-phi2930, %.preheader ], [ %44, %43 ]
  %19 = add nuw nsw i32 %.02131, 1
  %exitcond48.not = icmp eq i32 %19, 100
  br i1 %exitcond48.not, label %.split34.us, label %.preheader, !llvm.loop !16

.preheader.split:                                 ; preds = %.preheader, %43
  %20 = phi i32 [ %25, %43 ], [ %7, %.preheader ]
  %21 = phi i32 [ %26, %43 ], [ %8, %.preheader ]
  %22 = phi i32 [ %44, %43 ], [ %.us-phi2930, %.preheader ]
  %.02227 = phi i32 [ %45, %43 ], [ 0, %.preheader ]
  %23 = uitofp nneg i32 %.02227 to double
  %24 = icmp sgt i32 %21, 0
  br i1 %24, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.preheader.split
  %25 = phi i32 [ %20, %.preheader.split ], [ %36, %.lr.ph ]
  %26 = phi i32 [ %21, %.preheader.split ], [ %36, %.lr.ph ]
  %.019.lcssa = phi i32 [ -1, %.preheader.split ], [ %.120, %.lr.ph ]
  %27 = zext i32 %.019.lcssa to i64
  %28 = icmp eq i64 %indvars.iv49, %27
  br i1 %28, label %39, label %43

.lr.ph:                                           ; preds = %.preheader.split, %.lr.ph
  %indvars.iv44 = phi i64 [ %indvars.iv.next45, %.lr.ph ], [ 0, %.preheader.split ]
  %.01825 = phi double [ %.1, %.lr.ph ], [ 0x7FF0000000000000, %.preheader.split ]
  %.01924 = phi i32 [ %.120, %.lr.ph ], [ -1, %.preheader.split ]
  %29 = getelementptr inbounds [100 x %struct.Point], ptr @sites, i64 0, i64 %indvars.iv44
  %30 = load double, ptr %29, align 16
  %31 = getelementptr inbounds i8, ptr %29, i64 8
  %32 = load double, ptr %31, align 8
  %33 = tail call double @distance(double %10, double %23, double %30, double %32)
  %34 = fcmp olt double %33, %.01825
  %35 = trunc nuw nsw i64 %indvars.iv44 to i32
  %.120 = select i1 %34, i32 %35, i32 %.01924
  %.1 = select i1 %34, double %33, double %.01825
  %indvars.iv.next45 = add nuw nsw i64 %indvars.iv44, 1
  %36 = load i32, ptr @site_count, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = icmp slt i64 %indvars.iv.next45, %37
  br i1 %38, label %.lr.ph, label %._crit_edge, !llvm.loop !17

39:                                               ; preds = %._crit_edge
  %40 = add nsw i32 %22, 1
  %41 = sext i32 %22 to i64
  %42 = getelementptr inbounds [200 x %struct.Point], ptr %1, i64 0, i64 %41
  store double %10, ptr %42, align 8, !tbaa !18
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %42, i64 8
  store double %23, ptr %.sroa.5.0..sroa_idx, align 8, !tbaa !18
  br label %43

43:                                               ; preds = %39, %._crit_edge
  %44 = phi i32 [ %40, %39 ], [ %22, %._crit_edge ]
  %45 = add nuw nsw i32 %.02227, 1
  %exitcond47.not = icmp eq i32 %45, 100
  br i1 %exitcond47.not, label %.split.us, label %.preheader.split, !llvm.loop !20
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

attributes #0 = { 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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 3200}
!10 = !{!"", !7, i64 0, !6, i64 3200}
!11 = !{i64 0, i64 3200, !12, i64 3200, i64 4, !5}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !14, !15}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!"llvm.loop.unswitch.partial.disable"}
!16 = distinct !{!16, !14, !15}
!17 = distinct !{!17, !14}
!18 = !{!19, !19, i64 0}
!19 = !{!"double", !7, i64 0}
!20 = distinct !{!20, !14, !15}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass,TailCallElimPass