; LLVM IR from FSmallenburg/EDMD :: Grow (mdgrow)

; 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, i8, i32, i32 }

@eventlisttime = external dso_local global double, align 8
@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
@numeventlists = external dso_local global i32, align 4
@eventlists = external dso_local global [500001 x ptr], align 16

; 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
  br label %3

3:                                                ; preds = %14, %0
  %4 = load i32, ptr @currentlist, align 4, !tbaa !5
  %5 = add nsw i32 %4, 1
  store i32 %5, ptr @currentlist, align 4, !tbaa !5
  %6 = load i32, ptr @currentlist, align 4, !tbaa !5
  %7 = load i32, ptr @numeventlists, align 4, !tbaa !5
  %8 = icmp eq i32 %6, %7
  br i1 %8, label %9, label %10

9:                                                ; preds = %3
  store i32 0, ptr @currentlist, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %9, %3
  %11 = load double, ptr @eventlisttime, align 8, !tbaa !9
  %12 = load double, ptr @reftime, align 8, !tbaa !9
  %13 = fadd double %12, %11
  store double %13, ptr @reftime, align 8, !tbaa !9
  br label %14

14:                                               ; preds = %10
  %15 = load i32, ptr @currentlist, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [500001 x ptr], ptr @eventlists, i64 0, i64 %16
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = icmp eq ptr %18, null
  br i1 %19, label %3, label %20, !llvm.loop !13

20:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #2
  %21 = load i32, ptr @currentlist, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [500001 x ptr], ptr @eventlists, i64 0, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  store ptr %24, ptr %1, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #2
  br label %25

25:                                               ; preds = %28, %20
  %26 = load ptr, ptr %1, align 8, !tbaa !11
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %36

28:                                               ; preds = %25
  %29 = load ptr, ptr %1, align 8, !tbaa !11
  %30 = getelementptr inbounds %struct.sevent, ptr %29, i32 0, i32 7
  %31 = load ptr, ptr %30, align 8, !tbaa !15
  store ptr %31, ptr %2, align 8, !tbaa !11
  %32 = load ptr, ptr %1, align 8, !tbaa !11
  call void @addeventtotree(ptr noundef %32)
  %33 = load ptr, ptr %2, align 8, !tbaa !11
  store ptr %33, ptr %1, align 8, !tbaa !11
  %34 = load i32, ptr @listcounter1, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr @listcounter1, align 4, !tbaa !5
  br label %25, !llvm.loop !17

36:                                               ; preds = %25
  %37 = load i32, ptr @currentlist, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [500001 x ptr], ptr @eventlists, i64 0, i64 %38
  store ptr null, ptr %39, align 8, !tbaa !11
  %40 = load i32, ptr @numeventlists, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [500001 x ptr], ptr @eventlists, i64 0, i64 %41
  %43 = load ptr, ptr %42, align 8, !tbaa !11
  store ptr %43, ptr %1, align 8, !tbaa !11
  %44 = load i32, ptr @numeventlists, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [500001 x ptr], ptr @eventlists, i64 0, i64 %45
  store ptr null, ptr %46, align 8, !tbaa !11
  br label %47

47:                                               ; preds = %50, %36
  %48 = load ptr, ptr %1, align 8, !tbaa !11
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %58

50:                                               ; preds = %47
  %51 = load ptr, ptr %1, align 8, !tbaa !11
  %52 = getelementptr inbounds %struct.sevent, ptr %51, i32 0, i32 7
  %53 = load ptr, ptr %52, align 8, !tbaa !15
  store ptr %53, ptr %2, align 8, !tbaa !11
  %54 = load ptr, ptr %1, align 8, !tbaa !11
  call void @addevent(ptr noundef %54)
  %55 = load ptr, ptr %2, align 8, !tbaa !11
  store ptr %55, ptr %1, align 8, !tbaa !11
  %56 = load i32, ptr @listcounter2, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr @listcounter2, align 4, !tbaa !5
  br label %47, !llvm.loop !18

58:                                               ; preds = %47
  %59 = load i32, ptr @mergecounter, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr @mergecounter, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #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 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !12, i64 56}
!16 = !{!"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, !7, i64 64, !6, i64 68, !6, i64 72}
!17 = distinct !{!17, !14}
!18 = distinct !{!18, !14}


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

@eventlisttime = external dso_local local_unnamed_addr global double, align 8
@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
@numeventlists = external dso_local local_unnamed_addr global i32, align 4
@eventlists = external dso_local local_unnamed_addr global [500001 x ptr], align 16

; 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 @numeventlists, align 4, !tbaa !5
  %2 = load double, ptr @eventlisttime, align 8, !tbaa !9
  %currentlist.promoted = load i32, ptr @currentlist, align 4
  %reftime.promoted = load double, ptr @reftime, align 8, !tbaa !9
  br label %3

3:                                                ; preds = %3, %0
  %4 = phi double [ %7, %3 ], [ %reftime.promoted, %0 ]
  %spec.store.select10 = phi i32 [ %spec.store.select, %3 ], [ %currentlist.promoted, %0 ]
  %5 = add nsw i32 %spec.store.select10, 1
  %6 = icmp eq i32 %5, %1
  %spec.store.select = select i1 %6, i32 0, i32 %5
  %7 = fadd double %2, %4
  %8 = sext i32 %spec.store.select to i64
  %9 = getelementptr inbounds [500001 x ptr], ptr @eventlists, i64 0, i64 %8
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = icmp eq ptr %10, null
  br i1 %11, label %3, label %.preheader, !llvm.loop !13

.preheader:                                       ; preds = %3
  store i32 %spec.store.select, ptr @currentlist, align 4
  store double %7, ptr @reftime, align 8, !tbaa !9
  br label %12

12:                                               ; preds = %.preheader, %12
  %.012 = phi ptr [ %10, %.preheader ], [ %14, %12 ]
  %13 = getelementptr inbounds i8, ptr %.012, i64 56
  %14 = load ptr, ptr %13, align 8, !tbaa !15
  tail call void @addeventtotree(ptr noundef nonnull %.012)
  %15 = load i32, ptr @listcounter1, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr @listcounter1, align 4, !tbaa !5
  %.not = icmp eq ptr %14, null
  br i1 %.not, label %17, label %12, !llvm.loop !17

17:                                               ; preds = %12
  %18 = load i32, ptr @currentlist, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [500001 x ptr], ptr @eventlists, i64 0, i64 %19
  store ptr null, ptr %20, align 8, !tbaa !11
  %21 = load i32, ptr @numeventlists, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [500001 x ptr], ptr @eventlists, i64 0, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  store ptr null, ptr %23, align 8, !tbaa !11
  %.not913 = icmp eq ptr %24, null
  br i1 %.not913, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %17, %.lr.ph
  %.114 = phi ptr [ %26, %.lr.ph ], [ %24, %17 ]
  %25 = getelementptr inbounds i8, ptr %.114, i64 56
  %26 = load ptr, ptr %25, align 8, !tbaa !15
  tail call void @addevent(ptr noundef nonnull %.114)
  %27 = load i32, ptr @listcounter2, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr @listcounter2, align 4, !tbaa !5
  %.not9 = icmp eq ptr %26, null
  br i1 %.not9, label %._crit_edge, label %.lr.ph, !llvm.loop !18

._crit_edge:                                      ; preds = %.lr.ph, %17
  %29 = load i32, ptr @mergecounter, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, 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 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !12, i64 56}
!16 = !{!"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, !7, i64 64, !6, i64 68, !6, i64 72}
!17 = distinct !{!17, !14}
!18 = distinct !{!18, !14}


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