; LLVM IR from FSmallenburg/EDMD :: Single (mdSingle)

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

@N = external dso_local global i32, align 4
@particles = external dso_local global ptr, 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
declare dso_local double @findneighborlistupdate(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @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
  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 %8

8:                                                ; preds = %59, %0
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = load i32, ptr @N, align 4, !tbaa !5
  %11 = icmp slt i32 %9, %10
  br i1 %11, label %12, label %62

12:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %13 = load ptr, ptr @particles, align 8, !tbaa !9
  %14 = load i32, ptr %1, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds %struct.sparticle, ptr %13, 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 = %46, %12
  %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 10
  %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 %49

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 9
  %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 %45

37:                                               ; preds = %27
  %38 = load ptr, ptr %3, align 8, !tbaa !9
  %39 = load ptr, ptr %7, align 8, !tbaa !9
  %40 = call i32 @findcollision(ptr noundef %38, ptr noundef %39, ptr noundef %5)
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %44

42:                                               ; preds = %37
  %43 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %43, ptr %4, align 8, !tbaa !9
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %42, %37
  br label %45

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

46:                                               ; preds = %45
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %2, align 4, !tbaa !5
  br label %20, !llvm.loop !15

49:                                               ; preds = %20
  %50 = load double, ptr %5, align 8, !tbaa !11
  %51 = load ptr, ptr %3, align 8, !tbaa !9
  %52 = load ptr, ptr %4, align 8, !tbaa !9
  %53 = load i32, ptr %6, align 4, !tbaa !5
  call void @createevent(double noundef %50, ptr noundef %51, ptr noundef %52, i32 noundef %53)
  %54 = load ptr, ptr %4, align 8, !tbaa !9
  %55 = getelementptr inbounds %struct.sparticle, ptr %54, i32 0, i32 19
  %56 = load i32, ptr %55, align 4, !tbaa !17
  %57 = load ptr, ptr %3, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct.sparticle, ptr %57, i32 0, i32 20
  store i32 %56, ptr %58, align 8, !tbaa !18
  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 %59

59:                                               ; preds = %49
  %60 = load i32, ptr %1, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %1, align 4, !tbaa !5
  br label %8, !llvm.loop !19

62:                                               ; preds = %8
  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 264}
!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, !7, i64 72, !7, i64 264, !12, i64 272, !12, i64 280, !12, i64 288, !7, i64 296, !6, i64 300, !6, i64 304, !6, i64 308, !6, i64 312, !6, i64 316, !6, i64 320, !10, i64 328, !10, i64 336, !7, i64 344, !12, i64 352, !10, i64 360, !10, i64 368, !10, i64 376, !10, i64 384, !6, i64 392, !7, i64 396}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!14, !6, i64 316}
!18 = !{!14, !6, i64 320}
!19 = distinct !{!19, !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, [24 x ptr], i8, double, double, double, i8, i32, i32, i32, i32, i32, i32, ptr, ptr, i8, double, ptr, ptr, ptr, ptr, i32, i8 }

@N = external dso_local local_unnamed_addr global i32, align 4
@particles = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress 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) local_unnamed_addr #1

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

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

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

.lr.ph32:                                         ; preds = %0, %._crit_edge
  %indvars.iv36 = phi i64 [ %indvars.iv.next37, %._crit_edge ], [ 0, %0 ]
  %4 = load ptr, ptr @particles, align 8, !tbaa !9
  %5 = getelementptr inbounds %struct.sparticle, ptr %4, i64 %indvars.iv36
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #2
  %6 = call double @findneighborlistupdate(ptr noundef %5)
  store double %6, ptr %1, align 8, !tbaa !11
  %7 = getelementptr inbounds i8, ptr %5, i64 264
  %8 = load i8, ptr %7, align 8, !tbaa !13
  %.not34 = icmp eq i8 %8, 0
  br i1 %.not34, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph32
  %9 = getelementptr inbounds i8, ptr %5, i64 72
  br label %10

10:                                               ; preds = %.lr.ph, %17
  %11 = phi i8 [ %8, %.lr.ph ], [ %18, %17 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %17 ]
  %.01928 = phi i32 [ 8, %.lr.ph ], [ %.1, %17 ]
  %.02027 = phi ptr [ %5, %.lr.ph ], [ %.121, %17 ]
  %12 = getelementptr inbounds [24 x ptr], ptr %9, i64 0, i64 %indvars.iv
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %14 = icmp ugt ptr %13, %5
  br i1 %14, label %15, label %17

15:                                               ; preds = %10
  %16 = call i32 @findcollision(ptr noundef nonnull %5, ptr noundef nonnull %13, ptr noundef nonnull %1)
  %.not = icmp eq i32 %16, 0
  %spec.select = select i1 %.not, ptr %.02027, ptr %13
  %spec.select25 = select i1 %.not, i32 %.01928, i32 0
  %.pre = load i8, ptr %7, align 8, !tbaa !13
  br label %17

17:                                               ; preds = %15, %10
  %18 = phi i8 [ %11, %10 ], [ %.pre, %15 ]
  %.121 = phi ptr [ %.02027, %10 ], [ %spec.select, %15 ]
  %.1 = phi i32 [ %.01928, %10 ], [ %spec.select25, %15 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %19 = zext i8 %18 to i64
  %20 = icmp ult i64 %indvars.iv.next, %19
  br i1 %20, label %10, label %._crit_edge.loopexit, !llvm.loop !15

._crit_edge.loopexit:                             ; preds = %17
  %.pre39 = load double, ptr %1, align 8, !tbaa !11
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.lr.ph32
  %21 = phi double [ %6, %.lr.ph32 ], [ %.pre39, %._crit_edge.loopexit ]
  %.020.lcssa = phi ptr [ %5, %.lr.ph32 ], [ %.121, %._crit_edge.loopexit ]
  %.019.lcssa = phi i32 [ 8, %.lr.ph32 ], [ %.1, %._crit_edge.loopexit ]
  call void @createevent(double noundef %21, ptr noundef nonnull %5, ptr noundef %.020.lcssa, i32 noundef %.019.lcssa)
  %22 = getelementptr inbounds i8, ptr %.020.lcssa, i64 316
  %23 = load i32, ptr %22, align 4, !tbaa !17
  %24 = getelementptr inbounds i8, ptr %5, i64 320
  store i32 %23, ptr %24, align 8, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #2
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %25 = load i32, ptr @N, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = icmp slt i64 %indvars.iv.next37, %26
  br i1 %27, label %.lr.ph32, label %._crit_edge33, !llvm.loop !19

._crit_edge33:                                    ; preds = %._crit_edge, %0
  ret void
}

attributes #0 = { mustprogress 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 264}
!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, !7, i64 72, !7, i64 264, !12, i64 272, !12, i64 280, !12, i64 288, !7, i64 296, !6, i64 300, !6, i64 304, !6, i64 308, !6, i64 312, !6, i64 316, !6, i64 320, !10, i64 328, !10, i64 336, !7, i64 344, !12, i64 352, !10, i64 360, !10, i64 368, !10, i64 376, !10, i64 384, !6, i64 392, !7, i64 396}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!14, !6, i64 316}
!18 = !{!14, !6, i64 320}
!19 = distinct !{!19, !16}


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