; LLVM IR from FSmallenburg/EDMD :: Cell (mdCell)

; 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, i32, 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
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 i32, ptr %27, align 8, !tbaa !19
  switch i32 %28, label %35 [
    i32 0, label %29
    i32 100, label %31
    i32 101, label %33
  ]

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

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

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

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

37:                                               ; preds = %35, %33, %31, %29
  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 @cellcross(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, !12, 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, !12, i64 80}


; 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
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 i32, ptr %7, align 8, !tbaa !19
  switch i32 %8, label %12 [
    i32 0, label %9
    i32 100, label %10
    i32 101, label %11
  ]

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

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

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

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

13:                                               ; preds = %12, %11, %10, %9
  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 @cellcross(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, !12, 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, !12, i64 80}


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