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

@maxdt = external dso_local global double, align 8
@time = external dso_local global double, align 8

; 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
define dso_local void @findcollisions(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = call double @findneighborlistupdate(ptr noundef %10)
  store double %11, ptr %5, align 8, !tbaa !9
  %12 = load double, ptr %5, align 8, !tbaa !9
  %13 = load double, ptr @maxdt, align 8, !tbaa !9
  %14 = fcmp ogt double %12, %13
  br i1 %14, label %15, label %17

15:                                               ; preds = %1
  %16 = load double, ptr @maxdt, align 8, !tbaa !9
  store double %16, ptr %5, align 8, !tbaa !9
  br label %17

17:                                               ; preds = %15, %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 8, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %18, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store i32 0, ptr %3, align 4, !tbaa !11
  br label %19

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

26:                                               ; preds = %19
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.sparticle, ptr %27, i32 0, i32 10
  %29 = load i32, ptr %3, align 4, !tbaa !11
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [24 x ptr], ptr %28, i64 0, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  store ptr %32, ptr %8, align 8, !tbaa !5
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = load double, ptr %5, align 8, !tbaa !9
  %36 = call double @findcollision(ptr noundef %33, ptr noundef %34, double noundef %35)
  store double %36, ptr %4, align 8, !tbaa !9
  %37 = load double, ptr %4, align 8, !tbaa !9
  %38 = load double, ptr %5, align 8, !tbaa !9
  %39 = fcmp olt double %37, %38
  br i1 %39, label %40, label %43

40:                                               ; preds = %26
  %41 = load double, ptr %4, align 8, !tbaa !9
  store double %41, ptr %5, align 8, !tbaa !9
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %42, ptr %7, align 8, !tbaa !5
  store i32 0, ptr %6, align 4, !tbaa !11
  br label %43

43:                                               ; preds = %40, %26
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr %3, align 4, !tbaa !11
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %3, align 4, !tbaa !11
  br label %19, !llvm.loop !15

47:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %48 = load double, ptr %5, align 8, !tbaa !9
  %49 = load double, ptr @time, align 8, !tbaa !9
  %50 = fadd double %48, %49
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = load i32, ptr %6, align 4, !tbaa !11
  %54 = call ptr @createevent(double noundef %50, ptr noundef %51, ptr noundef %52, i32 noundef %53)
  store ptr %54, ptr %9, align 8, !tbaa !5
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.sparticle, ptr %56, i32 0, i32 23
  store ptr %55, ptr %57, align 8, !tbaa !17
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.sparticle, ptr %58, i32 0, i32 24
  %60 = load i32, ptr %59, align 8, !tbaa !18
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.sevent, ptr %61, i32 0, i32 10
  store i32 %60, ptr %62, align 8, !tbaa !19
  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 8, ptr %7) #2
  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 4, ptr %3) #2
  ret void
}

; 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

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


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

@maxdt = external dso_local local_unnamed_addr global double, align 8
@time = external dso_local local_unnamed_addr global double, align 8

; Function Attrs: nounwind uwtable
define dso_local void @findcollisions(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call double @findneighborlistupdate(ptr noundef %0)
  %3 = load double, ptr @maxdt, align 8, !tbaa !5
  %4 = fcmp ogt double %2, %3
  %.022 = select i1 %4, double %3, double %2
  %5 = getelementptr inbounds i8, ptr %0, i64 272
  %6 = load i8, ptr %5, align 8, !tbaa !9
  %.not = icmp eq i8 %6, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

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

8:                                                ; preds = %.lr.ph, %8
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %8 ]
  %.132 = phi double [ %.022, %.lr.ph ], [ %.2, %8 ]
  %.02331 = phi ptr [ %0, %.lr.ph ], [ %.124, %8 ]
  %.02530 = phi i32 [ 8, %.lr.ph ], [ %.126, %8 ]
  %9 = getelementptr inbounds [24 x ptr], ptr %7, i64 0, i64 %indvars.iv
  %10 = load ptr, ptr %9, align 8, !tbaa !13
  %11 = tail call double @findcollision(ptr noundef nonnull %0, ptr noundef %10, double noundef %.132)
  %12 = fcmp olt double %11, %.132
  %.126 = select i1 %12, i32 0, i32 %.02530
  %.124 = select i1 %12, ptr %10, ptr %.02331
  %.2 = select i1 %12, double %11, double %.132
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %13 = load i8, ptr %5, align 8, !tbaa !9
  %14 = zext i8 %13 to i64
  %15 = icmp ult i64 %indvars.iv.next, %14
  br i1 %15, label %8, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %8, %1
  %.025.lcssa = phi i32 [ 8, %1 ], [ %.126, %8 ]
  %.023.lcssa = phi ptr [ %0, %1 ], [ %.124, %8 ]
  %.1.lcssa = phi double [ %.022, %1 ], [ %.2, %8 ]
  %16 = load double, ptr @time, align 8, !tbaa !5
  %17 = fadd double %.1.lcssa, %16
  %18 = tail call ptr @createevent(double noundef %17, ptr noundef nonnull %0, ptr noundef %.023.lcssa, i32 noundef %.025.lcssa)
  %19 = getelementptr inbounds i8, ptr %0, i64 328
  store ptr %18, ptr %19, align 8, !tbaa !16
  %20 = getelementptr inbounds i8, ptr %.023.lcssa, i64 336
  %21 = load i32, ptr %20, align 8, !tbaa !17
  %22 = getelementptr inbounds i8, ptr %18, i64 72
  store i32 %21, ptr %22, align 8, !tbaa !18
  ret void
}

; 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

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


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