; 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
@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
define dso_local void @addevent(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca double, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.sevent, ptr %5, i32 0, i32 0
  %7 = load double, ptr %6, align 8, !tbaa !9
  %8 = load double, ptr @reftime, align 8, !tbaa !13
  %9 = fsub double %7, %8
  store double %9, ptr %3, align 8, !tbaa !13
  %10 = load double, ptr %3, align 8, !tbaa !13
  %11 = load double, ptr @eventlisttime, align 8, !tbaa !13
  %12 = fcmp olt double %10, %11
  br i1 %12, label %13, label %18

13:                                               ; preds = %1
  %14 = load i32, ptr @currentlist, align 4, !tbaa !14
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.sevent, ptr %15, i32 0, i32 9
  store i32 %14, ptr %16, align 4, !tbaa !15
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  call void @addeventtotree(ptr noundef %17)
  br label %70

18:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %19 = load double, ptr %3, align 8, !tbaa !13
  %20 = load i32, ptr @numeventlists, align 4, !tbaa !14
  %21 = sitofp i32 %20 to double
  %22 = load double, ptr @eventlisttime, align 8, !tbaa !13
  %23 = fmul double %21, %22
  %24 = fcmp oge double %19, %23
  br i1 %24, label %25, label %27

25:                                               ; preds = %18
  %26 = load i32, ptr @numeventlists, align 4, !tbaa !14
  store i32 %26, ptr %4, align 4, !tbaa !14
  br label %43

27:                                               ; preds = %18
  %28 = load i32, ptr @currentlist, align 4, !tbaa !14
  %29 = sitofp i32 %28 to double
  %30 = load double, ptr %3, align 8, !tbaa !13
  %31 = load double, ptr @eventlisttime, align 8, !tbaa !13
  %32 = fdiv double %30, %31
  %33 = fadd double %29, %32
  %34 = fptosi double %33 to i32
  store i32 %34, ptr %4, align 4, !tbaa !14
  %35 = load i32, ptr %4, align 4, !tbaa !14
  %36 = load i32, ptr @numeventlists, align 4, !tbaa !14
  %37 = icmp sge i32 %35, %36
  br i1 %37, label %38, label %42

38:                                               ; preds = %27
  %39 = load i32, ptr @numeventlists, align 4, !tbaa !14
  %40 = load i32, ptr %4, align 4, !tbaa !14
  %41 = sub nsw i32 %40, %39
  store i32 %41, ptr %4, align 4, !tbaa !14
  br label %42

42:                                               ; preds = %38, %27
  br label %43

43:                                               ; preds = %42, %25
  %44 = load i32, ptr %4, align 4, !tbaa !14
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.sevent, ptr %45, i32 0, i32 9
  store i32 %44, ptr %46, align 4, !tbaa !15
  %47 = load i32, ptr %4, align 4, !tbaa !14
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [500001 x ptr], ptr @eventlists, i64 0, i64 %48
  %50 = load ptr, ptr %49, align 8, !tbaa !5
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.sevent, ptr %51, i32 0, i32 7
  store ptr %50, ptr %52, align 8, !tbaa !16
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.sevent, ptr %53, i32 0, i32 6
  store ptr null, ptr %54, align 8, !tbaa !17
  %55 = load ptr, ptr %2, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.sevent, ptr %55, i32 0, i32 7
  %57 = load ptr, ptr %56, align 8, !tbaa !16
  %58 = icmp ne ptr %57, null
  br i1 %58, label %59, label %65

59:                                               ; preds = %43
  %60 = load ptr, ptr %2, align 8, !tbaa !5
  %61 = load ptr, ptr %2, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.sevent, ptr %61, i32 0, i32 7
  %63 = load ptr, ptr %62, align 8, !tbaa !16
  %64 = getelementptr inbounds %struct.sevent, ptr %63, i32 0, i32 6
  store ptr %60, ptr %64, align 8, !tbaa !17
  br label %65

65:                                               ; preds = %59, %43
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  %67 = load i32, ptr %4, align 4, !tbaa !14
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [500001 x ptr], ptr @eventlists, i64 0, i64 %68
  store ptr %66, ptr %69, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %70

70:                                               ; preds = %65, %13
  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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!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, !7, i64 64, !12, i64 68, !12, i64 72}
!11 = !{!"double", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!12, !12, i64 0}
!15 = !{!10, !12, i64 68}
!16 = !{!10, !6, i64 56}
!17 = !{!10, !6, i64 48}


; 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
@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
define dso_local void @addevent(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load double, ptr %0, align 8, !tbaa !5
  %3 = load double, ptr @reftime, align 8, !tbaa !12
  %4 = fsub double %2, %3
  %5 = load double, ptr @eventlisttime, align 8, !tbaa !12
  %6 = fcmp olt double %4, %5
  br i1 %6, label %7, label %10

7:                                                ; preds = %1
  %8 = load i32, ptr @currentlist, align 4, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %0, i64 68
  store i32 %8, ptr %9, align 4, !tbaa !14
  tail call void @addeventtotree(ptr noundef nonnull %0)
  br label %32

10:                                               ; preds = %1
  %11 = load i32, ptr @numeventlists, align 4, !tbaa !13
  %12 = sitofp i32 %11 to double
  %13 = fmul double %5, %12
  %14 = fcmp ult double %4, %13
  br i1 %14, label %15, label %22

15:                                               ; preds = %10
  %16 = load i32, ptr @currentlist, align 4, !tbaa !13
  %17 = sitofp i32 %16 to double
  %18 = fdiv double %4, %5
  %19 = fadd double %18, %17
  %20 = fptosi double %19 to i32
  %.not = icmp sgt i32 %11, %20
  %21 = select i1 %.not, i32 0, i32 %11
  %spec.select = sub nsw i32 %20, %21
  br label %22

22:                                               ; preds = %15, %10
  %.0 = phi i32 [ %11, %10 ], [ %spec.select, %15 ]
  %23 = getelementptr inbounds i8, ptr %0, i64 68
  store i32 %.0, ptr %23, align 4, !tbaa !14
  %24 = sext i32 %.0 to i64
  %25 = getelementptr inbounds [500001 x ptr], ptr @eventlists, i64 0, i64 %24
  %26 = load ptr, ptr %25, align 8, !tbaa !15
  %27 = getelementptr inbounds i8, ptr %0, i64 56
  store ptr %26, ptr %27, align 8, !tbaa !16
  %28 = getelementptr inbounds i8, ptr %0, i64 48
  store ptr null, ptr %28, align 8, !tbaa !17
  %.not22 = icmp eq ptr %26, null
  br i1 %.not22, label %31, label %29

29:                                               ; preds = %22
  %30 = getelementptr inbounds i8, ptr %26, i64 48
  store ptr %0, ptr %30, align 8, !tbaa !17
  br label %31

31:                                               ; preds = %29, %22
  store ptr %0, ptr %25, align 8, !tbaa !15
  br label %32

32:                                               ; preds = %31, %7
  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, !7, i64 0}
!6 = !{!"sevent", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !8, i64 64, !11, i64 68, !11, i64 72}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!6, !11, i64 68}
!15 = !{!10, !10, i64 0}
!16 = !{!6, !10, i64 56}
!17 = !{!6, !10, i64 48}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass