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

@N = external dso_local global i32, align 4
@simtime = external dso_local global double, align 8
@thermostatinterval = external dso_local global double, align 8
@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 @genrand_real2() #1

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

; Function Attrs: nounwind
declare double @sqrt(double noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @update(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @removeevent(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
declare dso_local void @findcollisions(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @thermostat() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca double, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %7 = load i32, ptr @N, align 4, !tbaa !5
  %8 = sdiv i32 %7, 100
  store i32 %8, ptr %5, align 4, !tbaa !5
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %11, label %12

11:                                               ; preds = %0
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %11, %0
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %76, %12
  %14 = load i32, ptr %1, align 4, !tbaa !5
  %15 = load i32, ptr %5, align 4, !tbaa !5
  %16 = icmp slt i32 %14, %15
  br i1 %16, label %17, label %79

17:                                               ; preds = %13
  %18 = call double @genrand_real2()
  %19 = load i32, ptr @N, align 4, !tbaa !5
  %20 = sitofp i32 %19 to double
  %21 = fmul double %18, %20
  %22 = fptosi double %21 to i32
  store i32 %22, ptr %2, align 4, !tbaa !5
  %23 = load ptr, ptr @particles, align 8, !tbaa !9
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds %struct.sparticle, ptr %23, i64 %25
  store ptr %26, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %27 = load ptr, ptr %3, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.sparticle, ptr %27, i32 0, i32 8
  %29 = load double, ptr %28, align 8, !tbaa !11
  %30 = call double @sqrt(double noundef %29) #3
  %31 = fdiv double 1.000000e+00, %30
  store double %31, ptr %6, align 8, !tbaa !14
  %32 = load ptr, ptr %3, align 8, !tbaa !9
  call void @update(ptr noundef %32)
  %33 = call double @random_gaussian()
  %34 = load double, ptr %6, align 8, !tbaa !14
  %35 = fmul double %33, %34
  %36 = load ptr, ptr %3, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.sparticle, ptr %36, i32 0, i32 3
  store double %35, ptr %37, align 8, !tbaa !15
  %38 = call double @random_gaussian()
  %39 = load double, ptr %6, align 8, !tbaa !14
  %40 = fmul double %38, %39
  %41 = load ptr, ptr %3, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct.sparticle, ptr %41, i32 0, i32 4
  store double %40, ptr %42, align 8, !tbaa !16
  %43 = call double @random_gaussian()
  %44 = load double, ptr %6, align 8, !tbaa !14
  %45 = fmul double %43, %44
  %46 = load ptr, ptr %3, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.sparticle, ptr %46, i32 0, i32 5
  store double %45, ptr %47, align 8, !tbaa !17
  %48 = load ptr, ptr %3, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.sparticle, ptr %48, i32 0, i32 16
  %50 = load ptr, ptr %49, align 8, !tbaa !18
  store ptr %50, ptr %4, align 8, !tbaa !9
  br label %51

51:                                               ; preds = %57, %17
  %52 = load ptr, ptr %4, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct.sevent, ptr %52, i32 0, i32 7
  %54 = load ptr, ptr %53, align 8, !tbaa !19
  %55 = load ptr, ptr %4, align 8, !tbaa !9
  %56 = icmp ne ptr %54, %55
  br i1 %56, label %57, label %61

57:                                               ; preds = %51
  %58 = load ptr, ptr %4, align 8, !tbaa !9
  %59 = getelementptr inbounds %struct.sevent, ptr %58, i32 0, i32 7
  %60 = load ptr, ptr %59, align 8, !tbaa !19
  call void @removeevent(ptr noundef %60)
  br label %51, !llvm.loop !21

61:                                               ; preds = %51
  br label %62

62:                                               ; preds = %68, %61
  %63 = load ptr, ptr %4, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.sevent, ptr %63, i32 0, i32 9
  %65 = load ptr, ptr %64, align 8, !tbaa !23
  %66 = load ptr, ptr %4, align 8, !tbaa !9
  %67 = icmp ne ptr %65, %66
  br i1 %67, label %68, label %72

68:                                               ; preds = %62
  %69 = load ptr, ptr %4, align 8, !tbaa !9
  %70 = getelementptr inbounds %struct.sevent, ptr %69, i32 0, i32 9
  %71 = load ptr, ptr %70, align 8, !tbaa !23
  call void @removeevent(ptr noundef %71)
  br label %62, !llvm.loop !24

72:                                               ; preds = %62
  %73 = load ptr, ptr %4, align 8, !tbaa !9
  call void @removeevent(ptr noundef %73)
  %74 = load ptr, ptr %3, align 8, !tbaa !9
  call void @findcrossing(ptr noundef %74)
  %75 = load ptr, ptr %3, align 8, !tbaa !9
  call void @findcollisions(ptr noundef %75, ptr noundef null)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %76

76:                                               ; preds = %72
  %77 = load i32, ptr %1, align 4, !tbaa !5
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %1, align 4, !tbaa !5
  br label %13, !llvm.loop !25

79:                                               ; preds = %13
  %80 = load double, ptr @simtime, align 8, !tbaa !14
  %81 = load double, ptr @thermostatinterval, align 8, !tbaa !14
  %82 = fadd double %80, %81
  call void @createevent(double noundef %82, ptr noundef null, ptr noundef null, i32 noundef 101)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local double @random_gaussian() #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 "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 = !{!"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, !13, i64 64}
!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 = !{!13, !13, i64 0}
!15 = !{!12, !13, i64 24}
!16 = !{!12, !13, i64 32}
!17 = !{!12, !13, i64 40}
!18 = !{!12, !10, i64 104}
!19 = !{!20, !10, i64 56}
!20 = !{!"sevent", !13, 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, !6, i64 80, !6, i64 84}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!20, !10, i64 72}
!24 = distinct !{!24, !22}
!25 = distinct !{!25, !22}


; 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
@simtime = external dso_local local_unnamed_addr global double, align 8
@thermostatinterval = external dso_local local_unnamed_addr global double, align 8
@particles = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
declare dso_local double @genrand_real2() local_unnamed_addr #0

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #1

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @thermostat() local_unnamed_addr #0 {
  %1 = load i32, ptr @N, align 4, !tbaa !5
  %2 = sdiv i32 %1, 100
  %.off = add i32 %1, 99
  %3 = icmp ult i32 %.off, 199
  %spec.store.select = select i1 %3, i32 1, i32 %2
  %4 = icmp sgt i32 %spec.store.select, 0
  br i1 %4, label %.lr.ph31, label %._crit_edge32

.lr.ph31:                                         ; preds = %0, %._crit_edge
  %.029 = phi i32 [ %36, %._crit_edge ], [ 0, %0 ]
  %5 = tail call double @genrand_real2()
  %6 = load i32, ptr @N, align 4, !tbaa !5
  %7 = sitofp i32 %6 to double
  %8 = fmul double %5, %7
  %9 = fptosi double %8 to i32
  %10 = load ptr, ptr @particles, align 8, !tbaa !9
  %11 = sext i32 %9 to i64
  %12 = getelementptr inbounds %struct.sparticle, ptr %10, i64 %11
  %13 = getelementptr inbounds i8, ptr %12, i64 64
  %14 = load double, ptr %13, align 8, !tbaa !11
  %15 = tail call double @sqrt(double noundef %14) #2
  %16 = fdiv double 1.000000e+00, %15
  tail call void @update(ptr noundef %12)
  %17 = tail call double @random_gaussian()
  %18 = fmul double %16, %17
  %19 = getelementptr inbounds i8, ptr %12, i64 24
  store double %18, ptr %19, align 8, !tbaa !14
  %20 = tail call double @random_gaussian()
  %21 = fmul double %16, %20
  %22 = getelementptr inbounds i8, ptr %12, i64 32
  store double %21, ptr %22, align 8, !tbaa !15
  %23 = tail call double @random_gaussian()
  %24 = fmul double %16, %23
  %25 = getelementptr inbounds i8, ptr %12, i64 40
  store double %24, ptr %25, align 8, !tbaa !16
  %26 = getelementptr inbounds i8, ptr %12, i64 104
  %27 = load ptr, ptr %26, align 8, !tbaa !17
  %28 = getelementptr inbounds i8, ptr %27, i64 56
  %29 = load ptr, ptr %28, align 8, !tbaa !18
  %.not26 = icmp eq ptr %29, %27
  br i1 %.not26, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph, %.lr.ph31
  %30 = getelementptr inbounds i8, ptr %27, i64 72
  %31 = load ptr, ptr %30, align 8, !tbaa !20
  %.not2527 = icmp eq ptr %31, %27
  br i1 %.not2527, label %._crit_edge, label %.lr.ph28

.lr.ph:                                           ; preds = %.lr.ph31, %.lr.ph
  %32 = phi ptr [ %33, %.lr.ph ], [ %29, %.lr.ph31 ]
  tail call void @removeevent(ptr noundef %32)
  %33 = load ptr, ptr %28, align 8, !tbaa !18
  %.not = icmp eq ptr %33, %27
  br i1 %.not, label %.preheader, label %.lr.ph, !llvm.loop !21

.lr.ph28:                                         ; preds = %.preheader, %.lr.ph28
  %34 = phi ptr [ %35, %.lr.ph28 ], [ %31, %.preheader ]
  tail call void @removeevent(ptr noundef %34)
  %35 = load ptr, ptr %30, align 8, !tbaa !20
  %.not25 = icmp eq ptr %35, %27
  br i1 %.not25, label %._crit_edge, label %.lr.ph28, !llvm.loop !23

._crit_edge:                                      ; preds = %.lr.ph28, %.preheader
  tail call void @removeevent(ptr noundef nonnull %27)
  tail call void @findcrossing(ptr noundef %12)
  tail call void @findcollisions(ptr noundef %12, ptr noundef null)
  %36 = add nuw nsw i32 %.029, 1
  %exitcond.not = icmp eq i32 %36, %spec.store.select
  br i1 %exitcond.not, label %._crit_edge32, label %.lr.ph31, !llvm.loop !24

._crit_edge32:                                    ; preds = %._crit_edge, %0
  %37 = load double, ptr @simtime, align 8, !tbaa !25
  %38 = load double, ptr @thermostatinterval, align 8, !tbaa !25
  %39 = fadd double %37, %38
  tail call void @createevent(double noundef %39, ptr noundef null, ptr noundef null, i32 noundef 101)
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local double @random_gaussian() 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 = { mustprogress nofree nounwind willreturn memory(write) "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, !13, i64 64}
!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, !13, i64 24}
!15 = !{!12, !13, i64 32}
!16 = !{!12, !13, i64 40}
!17 = !{!12, !10, i64 104}
!18 = !{!19, !10, i64 56}
!19 = !{!"sevent", !13, 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, !6, i64 80, !6, i64 84}
!20 = !{!19, !10, i64 72}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = distinct !{!23, !22}
!24 = distinct !{!24, !22}
!25 = !{!13, !13, i64 0}


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