; LLVM IR from FSmallenburg/EDMD :: Cell (mdCell)

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

@N = external dso_local global i32, align 4
@particles = external dso_local global ptr, align 8
@cx = external dso_local global i32, align 4
@cy = external dso_local global i32, align 4
@cz = external dso_local global i32, align 4
@celllist = external dso_local global [75 x [75 x [75 x ptr]]], 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: nounwind uwtable
declare dso_local void @findcollision(ptr noundef, ptr noundef) #1

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

10:                                               ; preds = %110, %0
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = load i32, ptr @N, align 4, !tbaa !5
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %14, label %113

14:                                               ; preds = %10
  %15 = load ptr, ptr @particles, align 8, !tbaa !9
  %16 = load i32, ptr %1, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds %struct.sparticle, ptr %15, i64 %17
  %19 = getelementptr inbounds %struct.sparticle, ptr %18, i32 0, i32 10
  %20 = load i32, ptr %19, align 4, !tbaa !11
  %21 = load i32, ptr @cx, align 4, !tbaa !5
  %22 = add nsw i32 %20, %21
  store i32 %22, ptr %5, align 4, !tbaa !5
  %23 = load ptr, ptr @particles, align 8, !tbaa !9
  %24 = load i32, ptr %1, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds %struct.sparticle, ptr %23, i64 %25
  %27 = getelementptr inbounds %struct.sparticle, ptr %26, i32 0, i32 11
  %28 = load i32, ptr %27, align 8, !tbaa !14
  %29 = load i32, ptr @cy, align 4, !tbaa !5
  %30 = add nsw i32 %28, %29
  store i32 %30, ptr %6, align 4, !tbaa !5
  %31 = load ptr, ptr @particles, align 8, !tbaa !9
  %32 = load i32, ptr %1, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds %struct.sparticle, ptr %31, i64 %33
  %35 = getelementptr inbounds %struct.sparticle, ptr %34, i32 0, i32 12
  %36 = load i32, ptr %35, align 4, !tbaa !15
  %37 = load i32, ptr @cz, align 4, !tbaa !5
  %38 = add nsw i32 %36, %37
  store i32 %38, ptr %7, align 4, !tbaa !5
  %39 = load ptr, ptr @particles, align 8, !tbaa !9
  %40 = load i32, ptr %1, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds %struct.sparticle, ptr %39, i64 %41
  store ptr %42, ptr %8, align 8, !tbaa !9
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = sub nsw i32 %43, 1
  store i32 %44, ptr %2, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %106, %14
  %46 = load i32, ptr %2, align 4, !tbaa !5
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = add nsw i32 %47, 2
  %49 = icmp slt i32 %46, %48
  br i1 %49, label %50, label %109

50:                                               ; preds = %45
  %51 = load i32, ptr %6, align 4, !tbaa !5
  %52 = sub nsw i32 %51, 1
  store i32 %52, ptr %3, align 4, !tbaa !5
  br label %53

53:                                               ; preds = %102, %50
  %54 = load i32, ptr %3, align 4, !tbaa !5
  %55 = load i32, ptr %6, align 4, !tbaa !5
  %56 = add nsw i32 %55, 2
  %57 = icmp slt i32 %54, %56
  br i1 %57, label %58, label %105

58:                                               ; preds = %53
  %59 = load i32, ptr %7, align 4, !tbaa !5
  %60 = sub nsw i32 %59, 1
  store i32 %60, ptr %4, align 4, !tbaa !5
  br label %61

61:                                               ; preds = %98, %58
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = load i32, ptr %7, align 4, !tbaa !5
  %64 = add nsw i32 %63, 2
  %65 = icmp slt i32 %62, %64
  br i1 %65, label %66, label %101

66:                                               ; preds = %61
  %67 = load i32, ptr %2, align 4, !tbaa !5
  %68 = load i32, ptr @cx, align 4, !tbaa !5
  %69 = srem i32 %67, %68
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [75 x [75 x [75 x ptr]]], ptr @celllist, i64 0, i64 %70
  %72 = load i32, ptr %3, align 4, !tbaa !5
  %73 = load i32, ptr @cy, align 4, !tbaa !5
  %74 = srem i32 %72, %73
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [75 x [75 x ptr]], ptr %71, i64 0, i64 %75
  %77 = load i32, ptr %4, align 4, !tbaa !5
  %78 = load i32, ptr @cz, align 4, !tbaa !5
  %79 = srem i32 %77, %78
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [75 x ptr], ptr %76, i64 0, i64 %80
  %82 = load ptr, ptr %81, align 8, !tbaa !9
  store ptr %82, ptr %9, align 8, !tbaa !9
  br label %83

83:                                               ; preds = %93, %66
  %84 = load ptr, ptr %9, align 8, !tbaa !9
  %85 = icmp ne ptr %84, null
  br i1 %85, label %86, label %97

86:                                               ; preds = %83
  %87 = load ptr, ptr %9, align 8, !tbaa !9
  %88 = load ptr, ptr %8, align 8, !tbaa !9
  %89 = icmp ugt ptr %87, %88
  br i1 %89, label %90, label %93

90:                                               ; preds = %86
  %91 = load ptr, ptr %8, align 8, !tbaa !9
  %92 = load ptr, ptr %9, align 8, !tbaa !9
  call void @findcollision(ptr noundef %91, ptr noundef %92)
  br label %93

93:                                               ; preds = %90, %86
  %94 = load ptr, ptr %9, align 8, !tbaa !9
  %95 = getelementptr inbounds %struct.sparticle, ptr %94, i32 0, i32 18
  %96 = load ptr, ptr %95, align 8, !tbaa !16
  store ptr %96, ptr %9, align 8, !tbaa !9
  br label %83, !llvm.loop !17

97:                                               ; preds = %83
  br label %98

98:                                               ; preds = %97
  %99 = load i32, ptr %4, align 4, !tbaa !5
  %100 = add nsw i32 %99, 1
  store i32 %100, ptr %4, align 4, !tbaa !5
  br label %61, !llvm.loop !19

101:                                              ; preds = %61
  br label %102

102:                                              ; preds = %101
  %103 = load i32, ptr %3, align 4, !tbaa !5
  %104 = add nsw i32 %103, 1
  store i32 %104, ptr %3, align 4, !tbaa !5
  br label %53, !llvm.loop !20

105:                                              ; preds = %53
  br label %106

106:                                              ; preds = %105
  %107 = load i32, ptr %2, align 4, !tbaa !5
  %108 = add nsw i32 %107, 1
  store i32 %108, ptr %2, align 4, !tbaa !5
  br label %45, !llvm.loop !21

109:                                              ; preds = %45
  br label %110

110:                                              ; preds = %109
  %111 = load i32, ptr %1, align 4, !tbaa !5
  %112 = add nsw i32 %111, 1
  store i32 %112, ptr %1, align 4, !tbaa !5
  br label %10, !llvm.loop !22

113:                                              ; preds = %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !6, i64 76}
!12 = !{!"sparticle", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !13, i64 56, !13, i64 64, !7, i64 72, !6, i64 76, !6, i64 80, !6, i64 84, !6, i64 88, !6, i64 92, !6, i64 96, !10, i64 104, !10, i64 112, !10, i64 120, !7, i64 128}
!13 = !{!"double", !7, i64 0}
!14 = !{!12, !6, i64 80}
!15 = !{!12, !6, i64 84}
!16 = !{!12, !10, i64 120}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}
!20 = distinct !{!20, !18}
!21 = distinct !{!21, !18}
!22 = distinct !{!22, !18}


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

@N = external dso_local local_unnamed_addr global i32, align 4
@particles = external dso_local local_unnamed_addr global ptr, align 8
@cx = external dso_local local_unnamed_addr global i32, align 4
@cy = external dso_local local_unnamed_addr global i32, align 4
@cz = external dso_local local_unnamed_addr global i32, align 4
@celllist = external dso_local local_unnamed_addr global [75 x [75 x [75 x ptr]]], align 16

; Function Attrs: nounwind uwtable
declare dso_local void @findcollision(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @findallcollisions() local_unnamed_addr #0 {
  %1 = load i32, ptr @N, align 4, !tbaa !5
  %2 = icmp sgt i32 %1, 0
  br i1 %2, label %.lr.ph39, label %._crit_edge40

.lr.ph39:                                         ; preds = %0, %42
  %indvars.iv = phi i64 [ %indvars.iv.next, %42 ], [ 0, %0 ]
  %3 = load ptr, ptr @particles, align 8, !tbaa !9
  %4 = getelementptr inbounds %struct.sparticle, ptr %3, i64 %indvars.iv
  %5 = getelementptr inbounds i8, ptr %4, i64 76
  %6 = load i32, ptr %5, align 4, !tbaa !11
  %7 = load i32, ptr @cx, align 4, !tbaa !5
  %8 = add nsw i32 %7, %6
  %9 = getelementptr inbounds i8, ptr %4, i64 80
  %10 = load i32, ptr %9, align 8, !tbaa !14
  %11 = load i32, ptr @cy, align 4, !tbaa !5
  %12 = add nsw i32 %11, %10
  %13 = getelementptr inbounds i8, ptr %4, i64 84
  %14 = load i32, ptr %13, align 4, !tbaa !15
  %15 = load i32, ptr @cz, align 4, !tbaa !5
  %16 = add nsw i32 %15, %14
  %17 = add nsw i32 %8, -1
  %18 = add nsw i32 %12, -1
  %19 = add nsw i32 %16, -1
  br label %20

20:                                               ; preds = %.lr.ph39, %40
  %.02736 = phi i32 [ %17, %.lr.ph39 ], [ %41, %40 ]
  br label %21

21:                                               ; preds = %20, %38
  %.02835 = phi i32 [ %18, %20 ], [ %39, %38 ]
  br label %22

22:                                               ; preds = %21, %._crit_edge
  %.02934 = phi i32 [ %19, %21 ], [ %37, %._crit_edge ]
  %23 = load i32, ptr @cx, align 4, !tbaa !5
  %24 = srem i32 %.02736, %23
  %25 = sext i32 %24 to i64
  %26 = load i32, ptr @cy, align 4, !tbaa !5
  %27 = srem i32 %.02835, %26
  %28 = sext i32 %27 to i64
  %29 = load i32, ptr @cz, align 4, !tbaa !5
  %30 = srem i32 %.02934, %29
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [75 x [75 x [75 x ptr]]], ptr @celllist, i64 0, i64 %25, i64 %28, i64 %31
  %.031 = load ptr, ptr %32, align 8, !tbaa !9
  %.not32 = icmp eq ptr %.031, null
  br i1 %.not32, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %22, %35
  %.033 = phi ptr [ %.0, %35 ], [ %.031, %22 ]
  %33 = icmp ugt ptr %.033, %4
  br i1 %33, label %34, label %35

34:                                               ; preds = %.lr.ph
  tail call void @findcollision(ptr noundef %4, ptr noundef nonnull %.033)
  br label %35

35:                                               ; preds = %34, %.lr.ph
  %36 = getelementptr inbounds i8, ptr %.033, i64 120
  %.0 = load ptr, ptr %36, align 8, !tbaa !9
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !16

._crit_edge:                                      ; preds = %35, %22
  %37 = add nsw i32 %.02934, 1
  %.not41 = icmp sgt i32 %.02934, %16
  br i1 %.not41, label %38, label %22, !llvm.loop !18

38:                                               ; preds = %._crit_edge
  %39 = add nsw i32 %.02835, 1
  %.not42 = icmp sgt i32 %.02835, %12
  br i1 %.not42, label %40, label %21, !llvm.loop !19

40:                                               ; preds = %38
  %41 = add nsw i32 %.02736, 1
  %.not43 = icmp sgt i32 %.02736, %8
  br i1 %.not43, label %42, label %20, !llvm.loop !20

42:                                               ; preds = %40
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %43 = load i32, ptr @N, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = icmp slt i64 %indvars.iv.next, %44
  br i1 %45, label %.lr.ph39, label %._crit_edge40, !llvm.loop !21

._crit_edge40:                                    ; preds = %42, %0
  ret void
}

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

!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, !6, i64 76}
!12 = !{!"sparticle", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !13, i64 56, !13, i64 64, !7, i64 72, !6, i64 76, !6, i64 80, !6, i64 84, !6, i64 88, !6, i64 92, !6, i64 96, !10, i64 104, !10, i64 112, !10, i64 120, !7, i64 128}
!13 = !{!"double", !7, i64 0}
!14 = !{!12, !6, i64 80}
!15 = !{!12, !6, i64 84}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}
!19 = distinct !{!19, !17}
!20 = distinct !{!20, !17}
!21 = distinct !{!21, !17}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass