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

@simtime = external dso_local global double, align 8
@root = 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 void @makeneighborlist(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @step() #1 {
  %1 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #2
  %2 = load ptr, ptr @root, align 8, !tbaa !5
  %3 = getelementptr inbounds %struct.sparticle, ptr %2, i32 0, i32 26
  %4 = load ptr, ptr %3, align 8, !tbaa !9
  store ptr %4, ptr %1, align 8, !tbaa !5
  br label %5

5:                                                ; preds = %8, %0
  %6 = load ptr, ptr %1, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %12

8:                                                ; preds = %5
  call void @addnexteventlist()
  %9 = load ptr, ptr @root, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.sparticle, ptr %9, i32 0, i32 26
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  store ptr %11, ptr %1, align 8, !tbaa !5
  br label %5, !llvm.loop !13

12:                                               ; preds = %5
  br label %13

13:                                               ; preds = %18, %12
  %14 = load ptr, ptr %1, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.sparticle, ptr %14, i32 0, i32 25
  %16 = load ptr, ptr %15, align 8, !tbaa !15
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %22

18:                                               ; preds = %13
  %19 = load ptr, ptr %1, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.sparticle, ptr %19, i32 0, i32 25
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  store ptr %21, ptr %1, align 8, !tbaa !5
  br label %13, !llvm.loop !16

22:                                               ; preds = %13
  %23 = load ptr, ptr %1, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.sparticle, ptr %23, i32 0, i32 24
  %25 = load double, ptr %24, align 8, !tbaa !17
  store double %25, ptr @simtime, align 8, !tbaa !18
  %26 = load ptr, ptr %1, align 8, !tbaa !5
  call void @removeevent(ptr noundef %26)
  %27 = load ptr, ptr %1, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.sparticle, ptr %27, i32 0, i32 30
  %29 = load i8, ptr %28, align 4, !tbaa !19
  %30 = zext i8 %29 to i32
  switch i32 %30, label %39 [
    i32 0, label %31
    i32 8, label %33
    i32 100, label %35
    i32 101, label %37
  ]

31:                                               ; preds = %22
  %32 = load ptr, ptr %1, align 8, !tbaa !5
  call void @collision(ptr noundef %32)
  br label %39

33:                                               ; preds = %22
  %34 = load ptr, ptr %1, align 8, !tbaa !5
  call void @makeneighborlist(ptr noundef %34)
  br label %39

35:                                               ; preds = %22
  %36 = load ptr, ptr %1, align 8, !tbaa !5
  call void @write(ptr noundef %36)
  br label %39

37:                                               ; preds = %22
  %38 = load ptr, ptr %1, align 8, !tbaa !5
  call void @thermostat(ptr noundef %38)
  br label %39

39:                                               ; preds = %37, %35, %33, %31, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #2
  ret void
}

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

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @addnexteventlist() #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 }

!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, !6, i64 368}
!10 = !{!"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, !7, i64 72, !7, i64 264, !11, i64 272, !11, i64 280, !11, i64 288, !7, i64 296, !12, i64 300, !12, i64 304, !12, i64 308, !12, i64 312, !12, i64 316, !12, i64 320, !6, i64 328, !6, i64 336, !7, i64 344, !11, i64 352, !6, i64 360, !6, i64 368, !6, i64 376, !6, i64 384, !12, i64 392, !7, i64 396}
!11 = !{!"double", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!10, !6, i64 360}
!16 = distinct !{!16, !14}
!17 = !{!10, !11, i64 352}
!18 = !{!11, !11, i64 0}
!19 = !{!10, !7, i64 396}


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

@simtime = external dso_local local_unnamed_addr global double, align 8
@root = external dso_local local_unnamed_addr global ptr, align 8

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

; Function Attrs: nounwind uwtable
define dso_local void @step() local_unnamed_addr #0 {
  %.pn11 = load ptr, ptr @root, align 8, !tbaa !5
  %.0.in12 = getelementptr inbounds i8, ptr %.pn11, i64 368
  %.013 = load ptr, ptr %.0.in12, align 8, !tbaa !9
  %1 = icmp eq ptr %.013, null
  br i1 %1, label %.lr.ph, label %.preheader.preheader

.lr.ph:                                           ; preds = %0, %.lr.ph
  tail call void @addnexteventlist()
  %.pn = load ptr, ptr @root, align 8, !tbaa !5
  %.0.in = getelementptr inbounds i8, ptr %.pn, i64 368
  %.0 = load ptr, ptr %.0.in, align 8, !tbaa !9
  %2 = icmp eq ptr %.0, null
  br i1 %2, label %.lr.ph, label %.preheader.preheader, !llvm.loop !13

.preheader.preheader:                             ; preds = %.lr.ph, %0
  %.1.ph = phi ptr [ %.013, %0 ], [ %.0, %.lr.ph ]
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.preheader
  %.1 = phi ptr [ %4, %.preheader ], [ %.1.ph, %.preheader.preheader ]
  %3 = getelementptr inbounds i8, ptr %.1, i64 360
  %4 = load ptr, ptr %3, align 8, !tbaa !15
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %5, label %.preheader, !llvm.loop !16

5:                                                ; preds = %.preheader
  %6 = getelementptr inbounds i8, ptr %.1, i64 352
  %7 = load double, ptr %6, align 8, !tbaa !17
  store double %7, ptr @simtime, align 8, !tbaa !18
  tail call void @removeevent(ptr noundef nonnull %.1)
  %8 = getelementptr inbounds i8, ptr %.1, i64 396
  %9 = load i8, ptr %8, align 4, !tbaa !19
  switch i8 %9, label %14 [
    i8 0, label %10
    i8 8, label %11
    i8 100, label %12
    i8 101, label %13
  ]

10:                                               ; preds = %5
  tail call void @collision(ptr noundef nonnull %.1)
  br label %14

11:                                               ; preds = %5
  tail call void @makeneighborlist(ptr noundef nonnull %.1)
  br label %14

12:                                               ; preds = %5
  tail call void @write(ptr noundef nonnull %.1)
  br label %14

13:                                               ; preds = %5
  tail call void @thermostat(ptr noundef nonnull %.1)
  br label %14

14:                                               ; preds = %13, %12, %11, %10, %5
  ret void
}

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

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @addnexteventlist() 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" }

!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, !6, i64 368}
!10 = !{!"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, !7, i64 72, !7, i64 264, !11, i64 272, !11, i64 280, !11, i64 288, !7, i64 296, !12, i64 300, !12, i64 304, !12, i64 308, !12, i64 312, !12, i64 316, !12, i64 320, !6, i64 328, !6, i64 336, !7, i64 344, !11, i64 352, !6, i64 360, !6, i64 368, !6, i64 376, !6, i64 384, !12, i64 392, !7, i64 396}
!11 = !{!"double", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!10, !6, i64 360}
!16 = distinct !{!16, !14}
!17 = !{!10, !11, i64 352}
!18 = !{!11, !11, i64 0}
!19 = !{!10, !7, i64 396}


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