; LLVM IR from FSmallenburg/EDMD :: Grow (mdgrow)

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

@particles = external dso_local global [100000 x %struct.sparticle], 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 double @findneighborlistupdate(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local double @findcollision(ptr noundef, ptr noundef, double noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @createevent(double noundef, ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @findallcollisions() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca double, 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
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %71, %0
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = icmp slt i32 %11, 100000
  br i1 %12, label %13, label %74

13:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %14 = load i32, ptr %1, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds %struct.sparticle, ptr @particles, i64 %15
  store ptr %16, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %17 = load ptr, ptr %3, align 8, !tbaa !9
  store ptr %17, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %18 = load ptr, ptr %3, align 8, !tbaa !9
  %19 = call double @findneighborlistupdate(ptr noundef %18)
  store double %19, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 8, ptr %6, align 4, !tbaa !5
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %50, %13
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = load ptr, ptr %3, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.sparticle, ptr %22, i32 0, i32 11
  %24 = load i8, ptr %23, align 8, !tbaa !13
  %25 = zext i8 %24 to i32
  %26 = icmp slt i32 %21, %25
  br i1 %26, label %27, label %53

27:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %28 = load ptr, ptr %3, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.sparticle, ptr %28, i32 0, i32 10
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [24 x ptr], ptr %29, i64 0, i64 %31
  %33 = load ptr, ptr %32, align 8, !tbaa !9
  store ptr %33, ptr %7, align 8, !tbaa !9
  %34 = load ptr, ptr %7, align 8, !tbaa !9
  %35 = load ptr, ptr %3, align 8, !tbaa !9
  %36 = icmp ugt ptr %34, %35
  br i1 %36, label %37, label %49

37:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %38 = load ptr, ptr %3, align 8, !tbaa !9
  %39 = load ptr, ptr %7, align 8, !tbaa !9
  %40 = load double, ptr %5, align 8, !tbaa !11
  %41 = call double @findcollision(ptr noundef %38, ptr noundef %39, double noundef %40)
  store double %41, ptr %8, align 8, !tbaa !11
  %42 = load double, ptr %8, align 8, !tbaa !11
  %43 = load double, ptr %5, align 8, !tbaa !11
  %44 = fcmp olt double %42, %43
  br i1 %44, label %45, label %48

45:                                               ; preds = %37
  %46 = load double, ptr %8, align 8, !tbaa !11
  store double %46, ptr %5, align 8, !tbaa !11
  %47 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %47, ptr %4, align 8, !tbaa !9
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %48

48:                                               ; preds = %45, %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %49

49:                                               ; preds = %48, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %50

50:                                               ; preds = %49
  %51 = load i32, ptr %2, align 4, !tbaa !5
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %2, align 4, !tbaa !5
  br label %20, !llvm.loop !15

53:                                               ; preds = %20
  %54 = load ptr, ptr %4, align 8, !tbaa !9
  %55 = icmp ne ptr %54, null
  br i1 %55, label %56, label %70

56:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %57 = load double, ptr %5, align 8, !tbaa !11
  %58 = load ptr, ptr %3, align 8, !tbaa !9
  %59 = load ptr, ptr %4, align 8, !tbaa !9
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = call ptr @createevent(double noundef %57, ptr noundef %58, ptr noundef %59, i32 noundef %60)
  store ptr %61, ptr %9, align 8, !tbaa !9
  %62 = load ptr, ptr %9, align 8, !tbaa !9
  %63 = load ptr, ptr %3, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.sparticle, ptr %63, i32 0, i32 23
  store ptr %62, ptr %64, align 8, !tbaa !17
  %65 = load ptr, ptr %4, align 8, !tbaa !9
  %66 = getelementptr inbounds %struct.sparticle, ptr %65, i32 0, i32 24
  %67 = load i32, ptr %66, align 8, !tbaa !18
  %68 = load ptr, ptr %9, align 8, !tbaa !9
  %69 = getelementptr inbounds %struct.sevent, ptr %68, i32 0, i32 10
  store i32 %67, ptr %69, align 8, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  br label %70

70:                                               ; preds = %56, %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  br label %71

71:                                               ; preds = %70
  %72 = load i32, ptr %1, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %1, align 4, !tbaa !5
  br label %10, !llvm.loop !21

74:                                               ; preds = %10
  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, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !7, i64 272}
!14 = !{!"sparticle", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !7, i64 80, !7, i64 272, !12, i64 280, !12, i64 288, !12, i64 296, !12, i64 304, !7, i64 312, !7, i64 313, !7, i64 314, !7, i64 315, !6, i64 316, !6, i64 320, !6, i64 324, !10, i64 328, !6, i64 336, !10, i64 344, !10, i64 352, !6, i64 360, !7, i64 364}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!14, !10, i64 328}
!18 = !{!14, !6, i64 336}
!19 = !{!20, !6, i64 72}
!20 = !{!"sevent", !12, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !7, i64 64, !6, i64 68, !6, i64 72}
!21 = distinct !{!21, !16}


; 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, double, [24 x ptr], i8, double, double, double, double, i8, i8, i8, i8, i32, i32, i32, ptr, i32, ptr, ptr, i32, i8 }

@particles = external dso_local global [100000 x %struct.sparticle], align 16

; Function Attrs: nounwind uwtable
declare dso_local double @findneighborlistupdate(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @createevent(double noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @findallcollisions() local_unnamed_addr #0 {
  br label %1

1:                                                ; preds = %0, %24
  %indvars.iv47 = phi i64 [ 0, %0 ], [ %indvars.iv.next48, %24 ]
  %2 = getelementptr inbounds %struct.sparticle, ptr @particles, i64 %indvars.iv47
  %3 = tail call double @findneighborlistupdate(ptr noundef nonnull %2)
  %4 = getelementptr inbounds i8, ptr %2, i64 272
  %5 = load i8, ptr %4, align 16, !tbaa !5
  %.not45 = icmp eq i8 %5, 0
  br i1 %.not45, label %._crit_edge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %6 = getelementptr inbounds i8, ptr %2, i64 80
  br label %7

7:                                                ; preds = %.lr.ph, %15
  %8 = phi i8 [ %5, %.lr.ph ], [ %16, %15 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %15 ]
  %.02840 = phi ptr [ %2, %.lr.ph ], [ %.2, %15 ]
  %.02939 = phi i32 [ 8, %.lr.ph ], [ %.231, %15 ]
  %.03238 = phi double [ %3, %.lr.ph ], [ %.234, %15 ]
  %9 = getelementptr inbounds [24 x ptr], ptr %6, i64 0, i64 %indvars.iv
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %11 = icmp ugt ptr %10, %2
  br i1 %11, label %12, label %15

12:                                               ; preds = %7
  %13 = tail call double @findcollision(ptr noundef nonnull %2, ptr noundef nonnull %10, double noundef %.03238)
  %14 = fcmp olt double %13, %.03238
  %.133 = select i1 %14, double %13, double %.03238
  %.130 = select i1 %14, i32 0, i32 %.02939
  %.1 = select i1 %14, ptr %10, ptr %.02840
  %.pre = load i8, ptr %4, align 16, !tbaa !5
  br label %15

15:                                               ; preds = %12, %7
  %16 = phi i8 [ %.pre, %12 ], [ %8, %7 ]
  %.234 = phi double [ %.133, %12 ], [ %.03238, %7 ]
  %.231 = phi i32 [ %.130, %12 ], [ %.02939, %7 ]
  %.2 = phi ptr [ %.1, %12 ], [ %.02840, %7 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %17 = zext i8 %16 to i64
  %18 = icmp ult i64 %indvars.iv.next, %17
  br i1 %18, label %7, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %15
  %.not = icmp eq ptr %.2, null
  br i1 %.not, label %24, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %1, %._crit_edge
  %.028.lcssa56 = phi ptr [ %.2, %._crit_edge ], [ %2, %1 ]
  %.029.lcssa55 = phi i32 [ %.231, %._crit_edge ], [ 8, %1 ]
  %.032.lcssa54 = phi double [ %.234, %._crit_edge ], [ %3, %1 ]
  %19 = tail call ptr @createevent(double noundef %.032.lcssa54, ptr noundef nonnull %2, ptr noundef nonnull %.028.lcssa56, i32 noundef %.029.lcssa55)
  %20 = getelementptr inbounds i8, ptr %2, i64 328
  store ptr %19, ptr %20, align 8, !tbaa !15
  %21 = getelementptr inbounds i8, ptr %.028.lcssa56, i64 336
  %22 = load i32, ptr %21, align 8, !tbaa !16
  %23 = getelementptr inbounds i8, ptr %19, i64 72
  store i32 %22, ptr %23, align 8, !tbaa !17
  br label %24

24:                                               ; preds = %._crit_edge.thread, %._crit_edge
  %indvars.iv.next48 = add nuw nsw i64 %indvars.iv47, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next48, 100000
  br i1 %exitcond.not, label %25, label %1, !llvm.loop !19

25:                                               ; preds = %24
  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, !8, i64 272}
!6 = !{!"sparticle", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !8, i64 80, !8, i64 272, !7, i64 280, !7, i64 288, !7, i64 296, !7, i64 304, !8, i64 312, !8, i64 313, !8, i64 314, !8, i64 315, !10, i64 316, !10, i64 320, !10, i64 324, !11, i64 328, !10, i64 336, !11, i64 344, !11, i64 352, !10, i64 360, !8, i64 364}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!11, !11, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!6, !11, i64 328}
!16 = !{!6, !10, i64 336}
!17 = !{!18, !10, i64 72}
!18 = !{!"sevent", !7, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !8, i64 64, !10, i64 68, !10, i64 72}
!19 = distinct !{!19, !14}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass