; LLVM IR from gem5/gem5 :: ext/dsent/model/timing_graph (ElectricalTimingTree)

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

; 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: mustprogress uwtable
define dso_local noundef double @_ZNK5DSENT20ElectricalTimingTree22calculateCritPathDelayEPNS_20ElectricalTimingNodeE(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef %1) #1 align 2 {
  %3 = alloca double, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %12

11:                                               ; preds = %2
  store double 0.000000e+00, ptr %3, align 8
  br label %38

12:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store double 0.000000e+00, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !11
  br label %13

13:                                               ; preds = %35, %12
  %14 = load i32, ptr %7, align 4, !tbaa !11
  %15 = icmp sge i32 %14, 0
  br i1 %15, label %16, label %36

16:                                               ; preds = %13
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = load ptr, ptr %17, align 8, !tbaa !13
  %19 = getelementptr inbounds ptr, ptr %18, i64 2
  %20 = load ptr, ptr %19, align 8
  %21 = call noundef double %20(ptr noundef nonnull align 8 dereferenceable(88) %17)
  %22 = load double, ptr %6, align 8, !tbaa !9
  %23 = fadd double %22, %21
  store double %23, ptr %6, align 8, !tbaa !9
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = call noundef i32 @_ZNK5DSENT20ElectricalTimingNode11getCritPathEv(ptr noundef nonnull align 8 dereferenceable(88) %24)
  store i32 %25, ptr %7, align 4, !tbaa !11
  %26 = load i32, ptr %7, align 4, !tbaa !11
  %27 = icmp sge i32 %26, 0
  br i1 %27, label %28, label %35

28:                                               ; preds = %16
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = call noundef ptr @_ZNK5DSENT20ElectricalTimingNode18getDownstreamNodesEv(ptr noundef nonnull align 8 dereferenceable(88) %29)
  %31 = load i32, ptr %7, align 4, !tbaa !11
  %32 = sext i32 %31 to i64
  %33 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIPN5DSENT20ElectricalTimingNodeESaIS2_EE2atEm(ptr noundef nonnull align 8 dereferenceable(24) %30, i64 noundef %32)
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  store ptr %34, ptr %5, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %28, %16
  br label %13, !llvm.loop !15

36:                                               ; preds = %13
  %37 = load double, ptr %6, align 8, !tbaa !9
  store double %37, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %38

38:                                               ; preds = %36, %11
  %39 = load double, ptr %3, align 8
  ret double %39
}

declare noundef ptr @_ZNK5DSENT20ElectricalTimingNode18getDownstreamNodesEv(ptr noundef nonnull align 8 dereferenceable(88)) #2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIPN5DSENT20ElectricalTimingNodeESaIS2_EE2atEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

declare noundef i32 @_ZNK5DSENT20ElectricalTimingNode11getCritPathEv(ptr noundef nonnull align 8 dereferenceable(88)) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { "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 #3 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"vtable pointer", !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZNK5DSENT20ElectricalTimingTree22calculateCritPathDelayEPNS_20ElectricalTimingNodeE(ptr nocapture noundef nonnull readnone align 8 dereferenceable(40) %0, ptr noundef %1) local_unnamed_addr #0 align 2 {
  %3 = icmp eq ptr %1, null
  br i1 %3, label %.loopexit, label %.preheader.preheader

.preheader.preheader:                             ; preds = %2
  %4 = load ptr, ptr %1, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 16
  %6 = load ptr, ptr %5, align 8
  %7 = tail call noundef double %6(ptr noundef nonnull align 8 dereferenceable(88) %1)
  %8 = fadd double %7, 0.000000e+00
  %9 = tail call noundef i32 @_ZNK5DSENT20ElectricalTimingNode11getCritPathEv(ptr noundef nonnull align 8 dereferenceable(88) %1)
  %10 = icmp sgt i32 %9, -1
  br i1 %10, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %.preheader.preheader, %.preheader
  %11 = phi i32 [ %22, %.preheader ], [ %9, %.preheader.preheader ]
  %12 = phi double [ %21, %.preheader ], [ %8, %.preheader.preheader ]
  %.0111518 = phi ptr [ %16, %.preheader ], [ %1, %.preheader.preheader ]
  %13 = tail call noundef ptr @_ZNK5DSENT20ElectricalTimingNode18getDownstreamNodesEv(ptr noundef nonnull align 8 dereferenceable(88) %.0111518)
  %14 = zext nneg i32 %11 to i64
  %15 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIPN5DSENT20ElectricalTimingNodeESaIS2_EE2atEm(ptr noundef nonnull align 8 dereferenceable(24) %13, i64 noundef %14)
  %16 = load ptr, ptr %15, align 8, !tbaa !8
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 16
  %19 = load ptr, ptr %18, align 8
  %20 = tail call noundef double %19(ptr noundef nonnull align 8 dereferenceable(88) %16)
  %21 = fadd double %12, %20
  %22 = tail call noundef i32 @_ZNK5DSENT20ElectricalTimingNode11getCritPathEv(ptr noundef nonnull align 8 dereferenceable(88) %16)
  %23 = icmp sgt i32 %22, -1
  br i1 %23, label %.preheader, label %.loopexit, !llvm.loop !11

.loopexit:                                        ; preds = %.preheader, %.preheader.preheader, %2
  %.012 = phi double [ 0.000000e+00, %2 ], [ %8, %.preheader.preheader ], [ %21, %.preheader ]
  ret double %.012
}

declare noundef ptr @_ZNK5DSENT20ElectricalTimingNode18getDownstreamNodesEv(ptr noundef nonnull align 8 dereferenceable(88)) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIPN5DSENT20ElectricalTimingNodeESaIS2_EE2atEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

declare noundef i32 @_ZNK5DSENT20ElectricalTimingNode11getCritPathEv(ptr noundef nonnull align 8 dereferenceable(88)) local_unnamed_addr #1

attributes #0 = { mustprogress 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 #1 = { "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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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