; 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
@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
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 11
  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 %72

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 11
  store i32 %44, ptr %46, align 4, !tbaa !15
  %47 = load ptr, ptr @eventlists, align 8, !tbaa !5
  %48 = load i32, ptr %4, align 4, !tbaa !14
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds ptr, ptr %47, i64 %49
  %51 = load ptr, ptr %50, align 8, !tbaa !5
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.sevent, ptr %52, i32 0, i32 2
  store ptr %51, ptr %53, align 8, !tbaa !16
  %54 = load ptr, ptr %2, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.sevent, ptr %54, i32 0, i32 1
  store ptr null, ptr %55, align 8, !tbaa !17
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.sevent, ptr %56, i32 0, i32 2
  %58 = load ptr, ptr %57, align 8, !tbaa !16
  %59 = icmp ne ptr %58, null
  br i1 %59, label %60, label %66

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

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

72:                                               ; preds = %66, %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, !6, i64 64, !6, i64 72, !12, i64 80, !12, i64 84}
!11 = !{!"double", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!12, !12, i64 0}
!15 = !{!10, !12, i64 84}
!16 = !{!10, !6, i64 16}
!17 = !{!10, !6, i64 8}


; 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
@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
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 84
  store i32 %8, ptr %9, align 4, !tbaa !14
  tail call void @addeventtotree(ptr noundef nonnull %0)
  br label %33

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 84
  store i32 %.0, ptr %23, align 4, !tbaa !14
  %24 = load ptr, ptr @eventlists, align 8, !tbaa !15
  %25 = sext i32 %.0 to i64
  %26 = getelementptr inbounds ptr, ptr %24, i64 %25
  %27 = load ptr, ptr %26, align 8, !tbaa !15
  %28 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %27, ptr %28, align 8, !tbaa !16
  %29 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr null, ptr %29, align 8, !tbaa !17
  %.not22 = icmp eq ptr %27, null
  br i1 %.not22, label %32, label %30

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

32:                                               ; preds = %30, %22
  store ptr %0, ptr %26, align 8, !tbaa !15
  br label %33

33:                                               ; preds = %32, %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, !10, i64 64, !10, i64 72, !11, i64 80, !11, i64 84}
!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 84}
!15 = !{!10, !10, i64 0}
!16 = !{!6, !10, i64 16}
!17 = !{!6, !10, i64 8}


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