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

@maxtime = external dso_local global double, align 8
@simtime = external dso_local global double, align 8
@.str = external hidden unnamed_addr constant [10 x i8], align 1
@celllist = external dso_local global ptr, align 8
@particles = external dso_local global ptr, align 8
@eventlists = external dso_local global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @init()
  %2 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  br label %3

3:                                                ; preds = %7, %0
  %4 = load double, ptr @simtime, align 8, !tbaa !5
  %5 = load double, ptr @maxtime, align 8, !tbaa !5
  %6 = fcmp ole double %4, %5
  br i1 %6, label %7, label %8

7:                                                ; preds = %3
  call void @step()
  br label %3, !llvm.loop !9

8:                                                ; preds = %3
  %9 = load double, ptr @maxtime, align 8, !tbaa !5
  store double %9, ptr @simtime, align 8, !tbaa !5
  call void @printstuff()
  call void @outputsnapshot()
  %10 = load ptr, ptr @celllist, align 8, !tbaa !11
  call void @free(ptr noundef %10) #3
  %11 = load ptr, ptr @particles, align 8, !tbaa !11
  call void @free(ptr noundef %11) #3
  %12 = load ptr, ptr @eventlists, align 8, !tbaa !11
  call void @free(ptr noundef %12) #3
  ret i32 0
}

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @outputsnapshot() #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 = { "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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}


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

@maxtime = external dso_local local_unnamed_addr global double, align 8
@simtime = external dso_local local_unnamed_addr global double, align 8
@.str = external hidden unnamed_addr constant [10 x i8], align 1
@celllist = external dso_local local_unnamed_addr global ptr, align 8
@particles = external dso_local local_unnamed_addr global ptr, align 8
@eventlists = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  tail call void @init()
  %1 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %2 = load double, ptr @simtime, align 8, !tbaa !5
  %3 = load double, ptr @maxtime, align 8, !tbaa !5
  %4 = fcmp ugt double %2, %3
  br i1 %4, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %.lr.ph
  tail call void @step()
  %5 = load double, ptr @simtime, align 8, !tbaa !5
  %6 = load double, ptr @maxtime, align 8, !tbaa !5
  %7 = fcmp ugt double %5, %6
  br i1 %7, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %0
  %.lcssa = phi double [ %3, %0 ], [ %6, %.lr.ph ]
  store double %.lcssa, ptr @simtime, align 8, !tbaa !5
  tail call void @printstuff()
  tail call void @outputsnapshot()
  %8 = load ptr, ptr @celllist, align 8, !tbaa !11
  tail call void @free(ptr noundef %8) #3
  %9 = load ptr, ptr @particles, align 8, !tbaa !11
  tail call void @free(ptr noundef %9) #3
  %10 = load ptr, ptr @eventlists, align 8, !tbaa !11
  tail call void @free(ptr noundef %10) #3
  ret i32 0
}

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @outputsnapshot() 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" }
attributes #2 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass