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

@reftime = external dso_local global double, align 8
@currentlist = external dso_local global i32, align 4
@listcounter1 = external dso_local global i32, align 4
@listcounter2 = external dso_local global i32, align 4
@mergecounter = external dso_local global i32, align 4
@eventlists = external dso_local global ptr, align 8
@eventlisttime = external dso_local global double, align 8
@numeventlists = external dso_local global i32, align 4

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

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

; Function Attrs: nounwind uwtable
define dso_local void @addnexteventlist() #1 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = load i32, ptr @currentlist, align 4, !tbaa !5
  %6 = add nsw i32 %5, 1
  store i32 %6, ptr @currentlist, align 4, !tbaa !5
  %7 = load double, ptr @eventlisttime, align 8, !tbaa !9
  %8 = load double, ptr @reftime, align 8, !tbaa !9
  %9 = fadd double %8, %7
  store double %9, ptr @reftime, align 8, !tbaa !9
  %10 = load i32, ptr @currentlist, align 4, !tbaa !5
  %11 = load i32, ptr @numeventlists, align 4, !tbaa !5
  %12 = icmp eq i32 %10, %11
  br i1 %12, label %13, label %35

13:                                               ; preds = %0
  store i32 0, ptr @currentlist, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #2
  %14 = load ptr, ptr @eventlists, align 8, !tbaa !11
  %15 = load i32, ptr @numeventlists, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds ptr, ptr %14, i64 %16
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  store ptr %18, ptr %1, align 8, !tbaa !11
  %19 = load ptr, ptr @eventlists, align 8, !tbaa !11
  %20 = load i32, ptr @numeventlists, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds ptr, ptr %19, i64 %21
  store ptr null, ptr %22, align 8, !tbaa !11
  store i32 0, ptr @listcounter2, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %26, %13
  %24 = load ptr, ptr %1, align 8, !tbaa !11
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %34

26:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #2
  %27 = load ptr, ptr %1, align 8, !tbaa !11
  %28 = getelementptr inbounds %struct.sevent, ptr %27, i32 0, i32 2
  %29 = load ptr, ptr %28, align 8, !tbaa !13
  store ptr %29, ptr %2, align 8, !tbaa !11
  %30 = load ptr, ptr %1, align 8, !tbaa !11
  call void @addevent(ptr noundef %30)
  %31 = load ptr, ptr %2, align 8, !tbaa !11
  store ptr %31, ptr %1, align 8, !tbaa !11
  %32 = load i32, ptr @listcounter2, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr @listcounter2, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #2
  br label %23, !llvm.loop !15

34:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #2
  br label %35

35:                                               ; preds = %34, %0
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %36 = load ptr, ptr @eventlists, align 8, !tbaa !11
  %37 = load i32, ptr @currentlist, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds ptr, ptr %36, i64 %38
  %40 = load ptr, ptr %39, align 8, !tbaa !11
  store ptr %40, ptr %3, align 8, !tbaa !11
  br label %41

41:                                               ; preds = %44, %35
  %42 = load ptr, ptr %3, align 8, !tbaa !11
  %43 = icmp ne ptr %42, null
  br i1 %43, label %44, label %52

44:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %45 = load ptr, ptr %3, align 8, !tbaa !11
  %46 = getelementptr inbounds %struct.sevent, ptr %45, i32 0, i32 2
  %47 = load ptr, ptr %46, align 8, !tbaa !13
  store ptr %47, ptr %4, align 8, !tbaa !11
  %48 = load ptr, ptr %3, align 8, !tbaa !11
  call void @addeventtotree(ptr noundef %48)
  %49 = load ptr, ptr %4, align 8, !tbaa !11
  store ptr %49, ptr %3, align 8, !tbaa !11
  %50 = load i32, ptr @listcounter1, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr @listcounter1, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  br label %41, !llvm.loop !17

52:                                               ; preds = %41
  %53 = load ptr, ptr @eventlists, align 8, !tbaa !11
  %54 = load i32, ptr @currentlist, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds ptr, ptr %53, i64 %55
  store ptr null, ptr %56, align 8, !tbaa !11
  %57 = load i32, ptr @mergecounter, align 4, !tbaa !5
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr @mergecounter, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret void
}

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !12, i64 16}
!14 = !{!"sevent", !10, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !6, i64 80, !6, i64 84}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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

@reftime = external dso_local local_unnamed_addr global double, align 8
@currentlist = external dso_local local_unnamed_addr global i32, align 4
@listcounter1 = external dso_local local_unnamed_addr global i32, align 4
@listcounter2 = external dso_local local_unnamed_addr global i32, align 4
@mergecounter = external dso_local local_unnamed_addr global i32, align 4
@eventlists = external dso_local local_unnamed_addr global ptr, align 8
@eventlisttime = external dso_local local_unnamed_addr global double, align 8
@numeventlists = external dso_local local_unnamed_addr global i32, align 4

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

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

; Function Attrs: nounwind uwtable
define dso_local void @addnexteventlist() local_unnamed_addr #0 {
  %1 = load i32, ptr @currentlist, align 4, !tbaa !5
  %2 = add nsw i32 %1, 1
  store i32 %2, ptr @currentlist, align 4, !tbaa !5
  %3 = load double, ptr @eventlisttime, align 8, !tbaa !9
  %4 = load double, ptr @reftime, align 8, !tbaa !9
  %5 = fadd double %3, %4
  store double %5, ptr @reftime, align 8, !tbaa !9
  %6 = load i32, ptr @numeventlists, align 4, !tbaa !5
  %7 = icmp eq i32 %2, %6
  br i1 %7, label %8, label %.loopexit

8:                                                ; preds = %0
  store i32 0, ptr @currentlist, align 4, !tbaa !5
  %9 = load ptr, ptr @eventlists, align 8, !tbaa !11
  %10 = sext i32 %2 to i64
  %11 = getelementptr inbounds ptr, ptr %9, i64 %10
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  store ptr null, ptr %11, align 8, !tbaa !11
  store i32 0, ptr @listcounter2, align 4, !tbaa !5
  %.not10 = icmp eq ptr %12, null
  br i1 %.not10, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %8, %.lr.ph
  %.011 = phi ptr [ %14, %.lr.ph ], [ %12, %8 ]
  %13 = getelementptr inbounds i8, ptr %.011, i64 16
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  tail call void @addevent(ptr noundef nonnull %.011)
  %15 = load i32, ptr @listcounter2, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr @listcounter2, align 4, !tbaa !5
  %.not = icmp eq ptr %14, null
  br i1 %.not, label %.loopexit.loopexit, label %.lr.ph, !llvm.loop !15

.loopexit.loopexit:                               ; preds = %.lr.ph
  %.pre = load i32, ptr @currentlist, align 4, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %8, %0
  %17 = phi i32 [ %.pre, %.loopexit.loopexit ], [ 0, %8 ], [ %2, %0 ]
  %18 = load ptr, ptr @eventlists, align 8, !tbaa !11
  %19 = sext i32 %17 to i64
  %20 = getelementptr inbounds ptr, ptr %18, i64 %19
  %21 = load ptr, ptr %20, align 8, !tbaa !11
  %.not912 = icmp eq ptr %21, null
  br i1 %.not912, label %._crit_edge, label %.lr.ph14

.lr.ph14:                                         ; preds = %.loopexit, %.lr.ph14
  %.0813 = phi ptr [ %23, %.lr.ph14 ], [ %21, %.loopexit ]
  %22 = getelementptr inbounds i8, ptr %.0813, i64 16
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  tail call void @addeventtotree(ptr noundef nonnull %.0813)
  %24 = load i32, ptr @listcounter1, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr @listcounter1, align 4, !tbaa !5
  %.not9 = icmp eq ptr %23, null
  br i1 %.not9, label %._crit_edge.loopexit, label %.lr.ph14, !llvm.loop !17

._crit_edge.loopexit:                             ; preds = %.lr.ph14
  %.pre15 = load ptr, ptr @eventlists, align 8, !tbaa !11
  %.pre16 = load i32, ptr @currentlist, align 4, !tbaa !5
  %.pre17 = sext i32 %.pre16 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.loopexit
  %.pre-phi = phi i64 [ %.pre17, %._crit_edge.loopexit ], [ %19, %.loopexit ]
  %26 = phi ptr [ %.pre15, %._crit_edge.loopexit ], [ %18, %.loopexit ]
  %27 = getelementptr inbounds ptr, ptr %26, i64 %.pre-phi
  store ptr null, ptr %27, align 8, !tbaa !11
  %28 = load i32, ptr @mergecounter, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr @mergecounter, align 4, !tbaa !5
  ret void
}

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !12, i64 16}
!14 = !{!"sevent", !10, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !6, i64 80, !6, i64 84}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass