; 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
@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
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
define dso_local void @thermostat(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca double, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %8 = load i32, ptr @N, align 4, !tbaa !9
  %9 = sdiv i32 %8, 100
  store i32 %9, ptr %6, align 4, !tbaa !9
  %10 = load i32, ptr %6, align 4, !tbaa !9
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %13

12:                                               ; preds = %1
  store i32 1, ptr %6, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %12, %1
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %55, %13
  %15 = load i32, ptr %3, align 4, !tbaa !9
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %18, label %58

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

55:                                               ; preds = %18
  %56 = load i32, ptr %3, align 4, !tbaa !9
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %3, align 4, !tbaa !9
  br label %14, !llvm.loop !19

58:                                               ; preds = %14
  %59 = load double, ptr @simtime, align 8, !tbaa !14
  %60 = load double, ptr @thermostatinterval, align 8, !tbaa !14
  %61 = fadd double %59, %60
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.sparticle, ptr %62, i32 0, i32 24
  store double %61, ptr %63, align 8, !tbaa !21
  %64 = load ptr, ptr %2, align 8, !tbaa !5
  call void @addevent(ptr noundef %64)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

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

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

; 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 = !{!"any pointer", !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, !13, i64 288}
!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, !7, i64 264, !13, i64 272, !13, i64 280, !13, i64 288, !7, i64 296, !10, i64 300, !10, i64 304, !10, i64 308, !10, i64 312, !10, i64 316, !10, i64 320, !6, i64 328, !6, i64 336, !7, i64 344, !13, i64 352, !6, i64 360, !6, i64 368, !6, i64 376, !6, i64 384, !10, i64 392, !7, i64 396}
!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 316}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!12, !13, i64 352}


; 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
@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: 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
define dso_local void @thermostat(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @N, align 4, !tbaa !5
  %3 = sdiv i32 %2, 100
  %.off = add i32 %2, 99
  %4 = icmp ult i32 %.off, 199
  %spec.store.select = select i1 %4, i32 1, i32 %3
  %5 = icmp sgt i32 %spec.store.select, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.017 = phi i32 [ %30, %.lr.ph ], [ 0, %1 ]
  %6 = tail call double @genrand_real2()
  %7 = load i32, ptr @N, align 4, !tbaa !5
  %8 = sitofp i32 %7 to double
  %9 = fmul double %6, %8
  %10 = fptosi double %9 to i32
  %11 = load ptr, ptr @particles, align 8, !tbaa !9
  %12 = sext i32 %10 to i64
  %13 = getelementptr inbounds %struct.sparticle, ptr %11, i64 %12
  %14 = getelementptr inbounds i8, ptr %13, i64 288
  %15 = load double, ptr %14, align 8, !tbaa !11
  %16 = tail call double @sqrt(double noundef %15) #2
  %17 = fdiv double 1.000000e+00, %16
  tail call void @update(ptr noundef %13)
  %18 = tail call double @random_gaussian()
  %19 = fmul double %17, %18
  %20 = getelementptr inbounds i8, ptr %13, i64 24
  store double %19, ptr %20, align 8, !tbaa !14
  %21 = tail call double @random_gaussian()
  %22 = fmul double %17, %21
  %23 = getelementptr inbounds i8, ptr %13, i64 32
  store double %22, ptr %23, align 8, !tbaa !15
  %24 = tail call double @random_gaussian()
  %25 = fmul double %17, %24
  %26 = getelementptr inbounds i8, ptr %13, i64 40
  store double %25, ptr %26, align 8, !tbaa !16
  %27 = getelementptr inbounds i8, ptr %13, i64 316
  %28 = load i32, ptr %27, align 4, !tbaa !17
  %29 = add i32 %28, 1
  store i32 %29, ptr %27, align 4, !tbaa !17
  tail call void @removeevent(ptr noundef %13)
  tail call void @findcollisions(ptr noundef %13)
  %30 = add nuw nsw i32 %.017, 1
  %exitcond.not = icmp eq i32 %30, %spec.store.select
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !18

._crit_edge:                                      ; preds = %.lr.ph, %1
  %31 = load double, ptr @simtime, align 8, !tbaa !20
  %32 = load double, ptr @thermostatinterval, align 8, !tbaa !20
  %33 = fadd double %31, %32
  %34 = getelementptr inbounds i8, ptr %0, i64 352
  store double %33, ptr %34, align 8, !tbaa !21
  tail call void @addevent(ptr noundef %0)
  ret void
}

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

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

; 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 288}
!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, !7, i64 264, !13, i64 272, !13, i64 280, !13, 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, !13, i64 352, !10, i64 360, !10, i64 368, !10, i64 376, !10, i64 384, !6, i64 392, !7, i64 396}
!13 = !{!"double", !7, i64 0}
!14 = !{!12, !13, i64 24}
!15 = !{!12, !13, i64 32}
!16 = !{!12, !13, i64 40}
!17 = !{!12, !6, i64 316}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!13, !13, i64 0}
!21 = !{!12, !13, i64 352}


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