; LLVM IR from FSmallenburg/EDMD :: Multi (mdMulti)

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

@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, i32 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.sevent, ptr %2, i32 0, i32 2
  %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.sevent, ptr %9, i32 0, i32 2
  %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.sevent, ptr %14, i32 0, i32 1
  %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.sevent, ptr %19, i32 0, i32 1
  %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.sevent, ptr %23, i32 0, i32 0
  %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
  %27 = getelementptr inbounds %struct.sevent, ptr %26, i32 0, i32 10
  %28 = load i8, ptr %27, align 8, !tbaa !19
  %29 = zext i8 %28 to i32
  switch i32 %29, label %40 [
    i32 0, label %30
    i32 8, label %32
    i32 100, label %36
    i32 101, label %38
  ]

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

32:                                               ; preds = %22
  %33 = load ptr, ptr %1, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.sevent, ptr %33, i32 0, i32 4
  %35 = load ptr, ptr %34, align 8, !tbaa !20
  call void @makeneighborlist(ptr noundef %35, i32 noundef 0)
  br label %40

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

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

40:                                               ; preds = %38, %36, %32, %30, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #2
  ret void
}

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @addnexteventlist() #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @thermostat() #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 16}
!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, !6, i64 64, !6, i64 72, !7, i64 80, !12, i64 84}
!11 = !{!"double", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!10, !6, i64 8}
!16 = distinct !{!16, !14}
!17 = !{!10, !11, i64 0}
!18 = !{!11, !11, i64 0}
!19 = !{!10, !7, i64 80}
!20 = !{!10, !6, i64 32}


; 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, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @step() local_unnamed_addr #0 {
  %.pn10 = load ptr, ptr @root, align 8, !tbaa !5
  %.0.in11 = getelementptr inbounds i8, ptr %.pn10, i64 16
  %.012 = load ptr, ptr %.0.in11, align 8, !tbaa !9
  %1 = icmp eq ptr %.012, 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 16
  %.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 [ %.012, %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 8
  %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 = load double, ptr %.1, align 8, !tbaa !17
  store double %6, ptr @simtime, align 8, !tbaa !18
  %7 = getelementptr inbounds i8, ptr %.1, i64 80
  %8 = load i8, ptr %7, align 8, !tbaa !19
  switch i8 %8, label %15 [
    i8 0, label %9
    i8 8, label %10
    i8 100, label %13
    i8 101, label %14
  ]

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

10:                                               ; preds = %5
  %11 = getelementptr inbounds i8, ptr %.1, i64 32
  %12 = load ptr, ptr %11, align 8, !tbaa !20
  tail call void @makeneighborlist(ptr noundef %12, i32 noundef 0)
  br label %15

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

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

15:                                               ; preds = %14, %13, %10, %9, %5
  ret void
}

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @thermostat() 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 16}
!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, !6, i64 64, !6, i64 72, !7, i64 80, !12, i64 84}
!11 = !{!"double", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!10, !6, i64 8}
!16 = distinct !{!16, !14}
!17 = !{!10, !11, i64 0}
!18 = !{!11, !11, i64 0}
!19 = !{!10, !7, i64 80}
!20 = !{!10, !6, i64 32}


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