; LLVM IR from NTHU-LSALAB/Gemini :: src/scheduler.ll (Z18get_timespec_afterd)

; 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.timespec = type { i64, i64 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local { i64, i64 } @_Z18get_timespec_afterd(double noundef %0) #0 {
  %2 = alloca %struct.timespec, align 8
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  store double %0, ptr %3, align 8, !tbaa !5
  %5 = call i32 @clock_gettime(i32 noundef 1, ptr noundef %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %6 = load double, ptr %3, align 8, !tbaa !5
  %7 = fdiv double %6, 1.000000e+03
  store double %7, ptr %4, align 8, !tbaa !5
  %8 = load double, ptr %4, align 8, !tbaa !5
  %9 = call double @llvm.floor.f64(double %8)
  %10 = getelementptr inbounds %struct.timespec, ptr %2, i32 0, i32 0
  %11 = load i64, ptr %10, align 8, !tbaa !9
  %12 = sitofp i64 %11 to double
  %13 = fadd double %12, %9
  %14 = fptosi double %13 to i64
  store i64 %14, ptr %10, align 8, !tbaa !9
  %15 = load double, ptr %4, align 8, !tbaa !5
  %16 = load double, ptr %4, align 8, !tbaa !5
  %17 = call double @llvm.floor.f64(double %16)
  %18 = fsub double %15, %17
  %19 = getelementptr inbounds %struct.timespec, ptr %2, i32 0, i32 1
  %20 = load i64, ptr %19, align 8, !tbaa !12
  %21 = sitofp i64 %20 to double
  %22 = call double @llvm.fmuladd.f64(double %18, double 1.000000e+09, double %21)
  %23 = fptosi double %22 to i64
  store i64 %23, ptr %19, align 8, !tbaa !12
  %24 = getelementptr inbounds %struct.timespec, ptr %2, i32 0, i32 1
  %25 = load i64, ptr %24, align 8, !tbaa !12
  %26 = sdiv i64 %25, 1000000000
  %27 = getelementptr inbounds %struct.timespec, ptr %2, i32 0, i32 0
  %28 = load i64, ptr %27, align 8, !tbaa !9
  %29 = add nsw i64 %28, %26
  store i64 %29, ptr %27, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct.timespec, ptr %2, i32 0, i32 1
  %31 = load i64, ptr %30, align 8, !tbaa !12
  %32 = srem i64 %31, 1000000000
  store i64 %32, ptr %30, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %33 = load { i64, i64 }, ptr %2, align 8
  ret { i64, i64 } %33
}

; Function Attrs: nounwind
declare i32 @clock_gettime(i32 noundef, ptr noundef) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

attributes #0 = { 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 #1 = { nounwind "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 willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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, !11, i64 0}
!10 = !{!"_ZTS8timespec", !11, i64 0, !11, i64 8}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !11, 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"

%struct.timespec = type { i64, i64 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local { i64, i64 } @_Z18get_timespec_afterd(double noundef %0) local_unnamed_addr #0 {
  %2 = alloca %struct.timespec, align 8
  %3 = call i32 @clock_gettime(i32 noundef 1, ptr noundef nonnull %2) #3
  %4 = fdiv double %0, 1.000000e+03
  %5 = call double @llvm.floor.f64(double %4)
  %6 = load i64, ptr %2, align 8, !tbaa !5
  %7 = sitofp i64 %6 to double
  %8 = fadd double %5, %7
  %9 = fptosi double %8 to i64
  %10 = fsub double %4, %5
  %11 = getelementptr inbounds i8, ptr %2, i64 8
  %12 = load i64, ptr %11, align 8, !tbaa !10
  %13 = sitofp i64 %12 to double
  %14 = call double @llvm.fmuladd.f64(double %10, double 1.000000e+09, double %13)
  %15 = fptosi double %14 to i64
  %16 = sdiv i64 %15, 1000000000
  %17 = add nsw i64 %16, %9
  %18 = srem i64 %15, 1000000000
  %.fca.0.insert = insertvalue { i64, i64 } poison, i64 %17, 0
  %.fca.1.insert = insertvalue { i64, i64 } %.fca.0.insert, i64 %18, 1
  ret { i64, i64 } %.fca.1.insert
}

; Function Attrs: nounwind
declare i32 @clock_gettime(i32 noundef, ptr noundef) local_unnamed_addr #1

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

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

attributes #0 = { 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 #1 = { nounwind "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 = { mustprogress 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, !7, i64 0}
!6 = !{!"_ZTS8timespec", !7, i64 0, !7, i64 8}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 8}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass