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

@thermostatinterval = external dso_local global double, align 8
@time = external dso_local global double, align 8
@particles = external dso_local global [100000 x %struct.sparticle], align 16

; 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
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
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %63

10:                                               ; preds = %1
  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
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.sevent, ptr %11, i32 0, i32 0
  %13 = load double, ptr %12, align 8, !tbaa !9
  store double %13, ptr @time, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 1000, ptr %6, align 4, !tbaa !14
  %14 = load i32, ptr %6, align 4, !tbaa !14
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %10
  store i32 1, ptr %6, align 4, !tbaa !14
  br label %17

17:                                               ; preds = %16, %10
  store i32 0, ptr %3, align 4, !tbaa !14
  br label %18

18:                                               ; preds = %58, %17
  %19 = load i32, ptr %3, align 4, !tbaa !14
  %20 = load i32, ptr %6, align 4, !tbaa !14
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %22, label %61

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

58:                                               ; preds = %22
  %59 = load i32, ptr %3, align 4, !tbaa !14
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %3, align 4, !tbaa !14
  br label %18, !llvm.loop !22

61:                                               ; preds = %18
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  call void @removeevent(ptr noundef %62)
  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
  br label %63

63:                                               ; preds = %61, %1
  %64 = load double, ptr @time, align 8, !tbaa !13
  %65 = load double, ptr @thermostatinterval, align 8, !tbaa !13
  %66 = fadd double %64, %65
  %67 = call ptr @createevent(double noundef %66, ptr noundef null, ptr noundef null, i32 noundef 200)
  ret void
}

; 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 @findcollisions(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @createevent(double noundef, ptr noundef, ptr noundef, i32 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, !11, i64 0}
!10 = !{!"sevent", !11, 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}
!11 = !{!"double", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!12, !12, i64 0}
!15 = !{!16, !11, i64 304}
!16 = !{!"sparticle", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !7, i64 80, !7, i64 272, !11, i64 280, !11, i64 288, !11, i64 296, !11, 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}
!17 = !{!16, !11, i64 24}
!18 = !{!16, !11, i64 32}
!19 = !{!16, !11, i64 40}
!20 = !{!16, !12, i64 336}
!21 = !{!16, !6, i64 328}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


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

@thermostatinterval = external dso_local local_unnamed_addr global double, align 8
@time = external dso_local local_unnamed_addr global double, align 8
@particles = external dso_local global [100000 x %struct.sparticle], align 16

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

; Function Attrs: nounwind uwtable
define dso_local void @thermostat(ptr noundef %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %30, label %2

2:                                                ; preds = %1
  %3 = load double, ptr %0, align 8, !tbaa !5
  store double %3, ptr @time, align 8, !tbaa !12
  br label %4

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

29:                                               ; preds = %4
  tail call void @removeevent(ptr noundef nonnull %0)
  br label %30

30:                                               ; preds = %29, %1
  %31 = load double, ptr @time, align 8, !tbaa !12
  %32 = load double, ptr @thermostatinterval, align 8, !tbaa !12
  %33 = fadd double %31, %32
  %34 = tail call ptr @createevent(double noundef %33, ptr noundef null, ptr noundef null, i32 noundef 200)
  ret void
}

; 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 @findcollisions(ptr 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

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass