; LLVM IR from gem5/gem5 :: ext/systemc/src/sysc/tracing/sc_trace.ll (ZN7sc_core23double_to_special_int64EdPjS0_)

; 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 nounwind uwtable
define dso_local void @_ZN7sc_core23double_to_special_int64EdPjS0_(double noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca double, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  store double %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %9 = load double, ptr %4, align 8, !tbaa !5
  store double %9, ptr %7, align 8, !tbaa !5
  %10 = load double, ptr %7, align 8, !tbaa !5
  %11 = fcmp ogt double %10, 5.000000e+17
  br i1 %11, label %12, label %13

12:                                               ; preds = %3
  store double 5.000000e+17, ptr %7, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %12, %3
  %14 = load double, ptr %7, align 8, !tbaa !5
  %15 = fcmp olt double %14, 0.000000e+00
  br i1 %15, label %16, label %17

16:                                               ; preds = %13
  store double 0.000000e+00, ptr %7, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %16, %13
  %18 = load double, ptr %7, align 8, !tbaa !5
  %19 = fadd double %18, 5.000000e-01
  store double %19, ptr %7, align 8, !tbaa !5
  %20 = load double, ptr %7, align 8, !tbaa !5
  %21 = fdiv double %20, 1.000000e+09
  %22 = fptoui double %21 to i32
  %23 = load ptr, ptr %5, align 8, !tbaa !9
  store i32 %22, ptr %23, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %24 = load double, ptr %7, align 8, !tbaa !5
  %25 = load ptr, ptr %5, align 8, !tbaa !9
  %26 = load i32, ptr %25, align 4, !tbaa !11
  %27 = uitofp i32 %26 to double
  %28 = call double @llvm.fmuladd.f64(double -1.000000e+09, double %27, double %24)
  store double %28, ptr %8, align 8, !tbaa !5
  %29 = load double, ptr %8, align 8, !tbaa !5
  %30 = fcmp olt double %29, 0.000000e+00
  br i1 %30, label %31, label %33

31:                                               ; preds = %17
  %32 = load ptr, ptr %6, align 8, !tbaa !9
  store i32 0, ptr %32, align 4, !tbaa !11
  br label %37

33:                                               ; preds = %17
  %34 = load double, ptr %8, align 8, !tbaa !5
  %35 = fptoui double %34 to i32
  %36 = load ptr, ptr %6, align 8, !tbaa !9
  store i32 %35, ptr %36, align 4, !tbaa !11
  br label %37

37:                                               ; preds = %33, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}


; 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 nofree norecurse nosync nounwind willreturn memory(argmem: write) uwtable
define dso_local void @_ZN7sc_core23double_to_special_int64EdPjS0_(double noundef %0, ptr nocapture noundef writeonly %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = fcmp ogt double %0, 5.000000e+17
  %.0 = select i1 %4, double 5.000000e+17, double %0
  %5 = fcmp olt double %.0, 0.000000e+00
  %.1 = select i1 %5, double 0.000000e+00, double %.0
  %6 = fadd double %.1, 5.000000e-01
  %7 = fdiv double %6, 1.000000e+09
  %8 = fptoui double %7 to i32
  store i32 %8, ptr %1, align 4, !tbaa !5
  %9 = uitofp i32 %8 to double
  %10 = tail call double @llvm.fmuladd.f64(double %9, double -1.000000e+09, double %6)
  %.inv = fcmp ole double %10, 0.000000e+00
  %storemerge14 = select i1 %.inv, double 0.000000e+00, double %10
  %storemerge = fptoui double %storemerge14 to i32
  store i32 %storemerge, ptr %2, align 4, !tbaa !5
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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++ TBAA"}


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