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

@initialconfig = external dso_local global i32, align 4
@N = external dso_local global i32, align 4
@nempty = external dso_local global i32, align 4
@particles = external dso_local global ptr, align 8
@eventpool = external dso_local global ptr, align 8
@xsize = external dso_local global double, align 8
@ysize = external dso_local global double, align 8
@zsize = external dso_local global double, align 8
@.str.5 = external hidden unnamed_addr constant [10 x i8], align 1
@hx = external dso_local global double, align 8
@hy = external dso_local global double, align 8
@hz = external dso_local global double, align 8
@.str.6 = external hidden unnamed_addr constant [39 x i8], align 1
@totalevents = external dso_local global i32, align 4
@.str.7 = external hidden unnamed_addr constant [35 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @init_genrand(i64 noundef) #0

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

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
define dso_local void @init() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  store i64 1, ptr %2, align 8, !tbaa !5
  %5 = load i64, ptr %2, align 8, !tbaa !5
  %6 = trunc i64 %5 to i32
  %7 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i32 noundef %6)
  %8 = load i64, ptr %2, align 8, !tbaa !5
  call void @init_genrand(i64 noundef %8)
  %9 = load i32, ptr @initialconfig, align 4, !tbaa !9
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %11, label %12

11:                                               ; preds = %0
  call void @loadparticles()
  br label %13

12:                                               ; preds = %0
  call void @fcc()
  br label %13

13:                                               ; preds = %12, %11
  call void @randommovement()
  %14 = load double, ptr @xsize, align 8, !tbaa !11
  %15 = fmul double 5.000000e-01, %14
  store double %15, ptr @hx, align 8, !tbaa !11
  %16 = load double, ptr @ysize, align 8, !tbaa !11
  %17 = fmul double 5.000000e-01, %16
  store double %17, ptr @hy, align 8, !tbaa !11
  %18 = load double, ptr @zsize, align 8, !tbaa !11
  %19 = fmul double 5.000000e-01, %18
  store double %19, ptr @hz, align 8, !tbaa !11
  call void @initeventpool()
  store i32 0, ptr %1, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %37, %13
  %21 = load i32, ptr %1, align 4, !tbaa !9
  %22 = load i32, ptr @N, align 4, !tbaa !9
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %24, label %40

24:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %25 = load ptr, ptr @particles, align 8, !tbaa !13
  %26 = load i32, ptr %1, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds %struct.sparticle, ptr %25, i64 %27
  store ptr %28, ptr %3, align 8, !tbaa !13
  %29 = load ptr, ptr %3, align 8, !tbaa !13
  %30 = getelementptr inbounds %struct.sparticle, ptr %29, i32 0, i32 13
  store i32 0, ptr %30, align 8, !tbaa !15
  %31 = load ptr, ptr %3, align 8, !tbaa !13
  %32 = getelementptr inbounds %struct.sparticle, ptr %31, i32 0, i32 14
  store i32 0, ptr %32, align 4, !tbaa !17
  %33 = load ptr, ptr %3, align 8, !tbaa !13
  %34 = getelementptr inbounds %struct.sparticle, ptr %33, i32 0, i32 15
  store i32 0, ptr %34, align 8, !tbaa !18
  %35 = load ptr, ptr %3, align 8, !tbaa !13
  %36 = getelementptr inbounds %struct.sparticle, ptr %35, i32 0, i32 6
  store double 0.000000e+00, ptr %36, align 8, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  br label %37

37:                                               ; preds = %24
  %38 = load i32, ptr %1, align 4, !tbaa !9
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %1, align 4, !tbaa !9
  br label %20, !llvm.loop !20

40:                                               ; preds = %20
  call void @initcelllist()
  store i32 0, ptr %1, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %59, %40
  %42 = load i32, ptr %1, align 4, !tbaa !9
  %43 = load i32, ptr @N, align 4, !tbaa !9
  %44 = icmp slt i32 %42, %43
  br i1 %44, label %45, label %62

45:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %46 = load ptr, ptr @particles, align 8, !tbaa !13
  %47 = load i32, ptr %1, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds %struct.sparticle, ptr %46, i64 %48
  store ptr %49, ptr %4, align 8, !tbaa !13
  %50 = load ptr, ptr @eventpool, align 8, !tbaa !13
  %51 = load i32, ptr @nempty, align 4, !tbaa !9
  %52 = sub nsw i32 %51, 1
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds ptr, ptr %50, i64 %53
  %55 = load ptr, ptr %54, align 8, !tbaa !13
  %56 = load ptr, ptr %4, align 8, !tbaa !13
  %57 = getelementptr inbounds %struct.sparticle, ptr %56, i32 0, i32 16
  store ptr %55, ptr %57, align 8, !tbaa !22
  %58 = load ptr, ptr %4, align 8, !tbaa !13
  call void @findcrossing(ptr noundef %58)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %59

59:                                               ; preds = %45
  %60 = load i32, ptr %1, align 4, !tbaa !9
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %1, align 4, !tbaa !9
  br label %41, !llvm.loop !23

62:                                               ; preds = %41
  %63 = load i32, ptr @totalevents, align 4, !tbaa !9
  %64 = load i32, ptr @nempty, align 4, !tbaa !9
  %65 = sub nsw i32 %63, %64
  %66 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, i32 noundef %65)
  call void @findallcollisions()
  %67 = load i32, ptr @totalevents, align 4, !tbaa !9
  %68 = load i32, ptr @nempty, align 4, !tbaa !9
  %69 = sub nsw i32 %67, %68
  %70 = call i32 (ptr, ...) @printf(ptr noundef @.str.7, i32 noundef %69)
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  ret void
}

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

; Function Attrs: nounwind uwtable
declare dso_local void @fcc() #0

; Function Attrs: nounwind uwtable
declare dso_local void @loadparticles() #0

; Function Attrs: nounwind uwtable
declare dso_local void @randommovement() #0

; Function Attrs: nounwind uwtable
declare dso_local void @initcelllist() #0

; Function Attrs: nounwind uwtable
declare dso_local void @findallcollisions() #0

; Function Attrs: nounwind uwtable
declare dso_local void @initeventpool() #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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 #3 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !7, i64 0}
!15 = !{!16, !10, i64 88}
!16 = !{!"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, !10, i64 76, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92, !10, i64 96, !14, i64 104, !14, i64 112, !14, i64 120, !7, i64 128}
!17 = !{!16, !10, i64 92}
!18 = !{!16, !10, i64 96}
!19 = !{!16, !12, i64 48}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!16, !14, i64 104}
!23 = distinct !{!23, !21}


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

@initialconfig = external dso_local local_unnamed_addr global i32, align 4
@N = external dso_local local_unnamed_addr global i32, align 4
@nempty = external dso_local local_unnamed_addr global i32, align 4
@particles = external dso_local local_unnamed_addr global ptr, align 8
@eventpool = external dso_local local_unnamed_addr global ptr, align 8
@xsize = external dso_local local_unnamed_addr global double, align 8
@ysize = external dso_local local_unnamed_addr global double, align 8
@zsize = external dso_local local_unnamed_addr global double, align 8
@.str.5 = external hidden unnamed_addr constant [10 x i8], align 1
@hx = external dso_local local_unnamed_addr global double, align 8
@hy = external dso_local local_unnamed_addr global double, align 8
@hz = external dso_local local_unnamed_addr global double, align 8
@.str.6 = external hidden unnamed_addr constant [39 x i8], align 1
@totalevents = external dso_local local_unnamed_addr global i32, align 4
@.str.7 = external hidden unnamed_addr constant [35 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @init_genrand(i64 noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @init() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i32 noundef 1)
  tail call void @init_genrand(i64 noundef 1)
  %2 = load i32, ptr @initialconfig, align 4, !tbaa !5
  %3 = icmp eq i32 %2, 0
  br i1 %3, label %4, label %5

4:                                                ; preds = %0
  tail call void @loadparticles()
  br label %6

5:                                                ; preds = %0
  tail call void @fcc()
  br label %6

6:                                                ; preds = %5, %4
  tail call void @randommovement()
  %7 = load double, ptr @xsize, align 8, !tbaa !9
  %8 = fmul double %7, 5.000000e-01
  store double %8, ptr @hx, align 8, !tbaa !9
  %9 = load double, ptr @ysize, align 8, !tbaa !9
  %10 = fmul double %9, 5.000000e-01
  store double %10, ptr @hy, align 8, !tbaa !9
  %11 = load double, ptr @zsize, align 8, !tbaa !9
  %12 = fmul double %11, 5.000000e-01
  store double %12, ptr @hz, align 8, !tbaa !9
  tail call void @initeventpool()
  %13 = load i32, ptr @N, align 4, !tbaa !5
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %6
  %15 = load ptr, ptr @particles, align 8, !tbaa !11
  br label %16

16:                                               ; preds = %.lr.ph, %16
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %16 ]
  %17 = getelementptr inbounds %struct.sparticle, ptr %15, i64 %indvars.iv
  %18 = getelementptr inbounds i8, ptr %17, i64 88
  store i32 0, ptr %18, align 8, !tbaa !13
  %19 = getelementptr inbounds i8, ptr %17, i64 92
  store i32 0, ptr %19, align 4, !tbaa !15
  %20 = getelementptr inbounds i8, ptr %17, i64 96
  store i32 0, ptr %20, align 8, !tbaa !16
  %21 = getelementptr inbounds i8, ptr %17, i64 48
  store double 0.000000e+00, ptr %21, align 8, !tbaa !17
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %22 = load i32, ptr @N, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = icmp slt i64 %indvars.iv.next, %23
  br i1 %24, label %16, label %._crit_edge, !llvm.loop !18

._crit_edge:                                      ; preds = %16, %6
  tail call void @initcelllist()
  %25 = load i32, ptr @N, align 4, !tbaa !5
  %26 = icmp sgt i32 %25, 0
  br i1 %26, label %.lr.ph16, label %._crit_edge17

.lr.ph16:                                         ; preds = %._crit_edge, %.lr.ph16
  %indvars.iv19 = phi i64 [ %indvars.iv.next20, %.lr.ph16 ], [ 0, %._crit_edge ]
  %27 = load ptr, ptr @particles, align 8, !tbaa !11
  %28 = getelementptr inbounds %struct.sparticle, ptr %27, i64 %indvars.iv19
  %29 = load ptr, ptr @eventpool, align 8, !tbaa !11
  %30 = load i32, ptr @nempty, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr ptr, ptr %29, i64 %31
  %33 = getelementptr i8, ptr %32, i64 -8
  %34 = load ptr, ptr %33, align 8, !tbaa !11
  %35 = getelementptr inbounds i8, ptr %28, i64 104
  store ptr %34, ptr %35, align 8, !tbaa !20
  tail call void @findcrossing(ptr noundef %28)
  %indvars.iv.next20 = add nuw nsw i64 %indvars.iv19, 1
  %36 = load i32, ptr @N, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = icmp slt i64 %indvars.iv.next20, %37
  br i1 %38, label %.lr.ph16, label %._crit_edge17, !llvm.loop !21

._crit_edge17:                                    ; preds = %.lr.ph16, %._crit_edge
  %39 = load i32, ptr @totalevents, align 4, !tbaa !5
  %40 = load i32, ptr @nempty, align 4, !tbaa !5
  %41 = sub nsw i32 %39, %40
  %42 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, i32 noundef %41)
  tail call void @findallcollisions()
  %43 = load i32, ptr @totalevents, align 4, !tbaa !5
  %44 = load i32, ptr @nempty, align 4, !tbaa !5
  %45 = sub nsw i32 %43, %44
  %46 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, i32 noundef %45)
  ret void
}

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

; Function Attrs: nounwind uwtable
declare dso_local void @fcc() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @loadparticles() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @randommovement() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @initcelllist() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @findallcollisions() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @initeventpool() 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" }
attributes #1 = { nofree nounwind "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 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !6, i64 88}
!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, !7, i64 72, !6, i64 76, !6, i64 80, !6, i64 84, !6, i64 88, !6, i64 92, !6, i64 96, !12, i64 104, !12, i64 112, !12, i64 120, !7, i64 128}
!15 = !{!14, !6, i64 92}
!16 = !{!14, !6, i64 96}
!17 = !{!14, !10, i64 48}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!14, !12, i64 104}
!21 = distinct !{!21, !19}


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