; LLVM IR from ohler55/agoo :: ext/agoo (dtime)

; 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: 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
define dso_local double @dsleep(double noundef %0) #1 {
  %2 = alloca double, align 8
  %3 = alloca double, align 8
  %4 = alloca %struct.timespec, align 8
  %5 = alloca %struct.timespec, align 8
  %6 = alloca i32, align 4
  store double %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #4
  %7 = load double, ptr %3, align 8, !tbaa !5
  %8 = fcmp ogt double 0x3EB0C6F7A0B5ED8D, %7
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  store double 0x3EB0C6F7A0B5ED8D, ptr %3, align 8, !tbaa !5
  br label %10

10:                                               ; preds = %9, %1
  %11 = load double, ptr %3, align 8, !tbaa !5
  %12 = fptosi double %11 to i64
  %13 = getelementptr inbounds %struct.timespec, ptr %4, i32 0, i32 0
  store i64 %12, ptr %13, align 8, !tbaa !9
  %14 = load double, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.timespec, ptr %4, i32 0, i32 0
  %16 = load i64, ptr %15, align 8, !tbaa !9
  %17 = sitofp i64 %16 to double
  %18 = fsub double %14, %17
  %19 = fmul double 1.000000e+09, %18
  %20 = fptosi double %19 to i64
  %21 = getelementptr inbounds %struct.timespec, ptr %4, i32 0, i32 1
  store i64 %20, ptr %21, align 8, !tbaa !12
  %22 = call i32 @nanosleep(ptr noundef %4, ptr noundef %5)
  %23 = icmp eq i32 %22, -1
  br i1 %23, label %24, label %37

24:                                               ; preds = %10
  %25 = call ptr @__errno_location() #5
  %26 = load i32, ptr %25, align 4, !tbaa !13
  %27 = icmp eq i32 4, %26
  br i1 %27, label %28, label %37

28:                                               ; preds = %24
  %29 = getelementptr inbounds %struct.timespec, ptr %5, i32 0, i32 0
  %30 = load i64, ptr %29, align 8, !tbaa !9
  %31 = sitofp i64 %30 to double
  %32 = getelementptr inbounds %struct.timespec, ptr %5, i32 0, i32 1
  %33 = load i64, ptr %32, align 8, !tbaa !12
  %34 = sitofp i64 %33 to double
  %35 = fdiv double %34, 1.000000e+09
  %36 = fadd double %31, %35
  store double %36, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %38

37:                                               ; preds = %24, %10
  store double 0.000000e+00, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %38

38:                                               ; preds = %37, %28
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #4
  %39 = load double, ptr %2, align 8
  ret double %39
}

declare i32 @nanosleep(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #3

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 = { "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 willreturn memory(none) "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 #4 = { nounwind }
attributes #5 = { nounwind 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"timespec", !11, i64 0, !11, i64 8}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"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"

%struct.timespec = type { i64, i64 }

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

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

; Function Attrs: nounwind uwtable
define dso_local double @dsleep(double noundef %0) local_unnamed_addr #1 {
  %2 = alloca %struct.timespec, align 8
  %3 = alloca %struct.timespec, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #4
  %4 = fcmp olt double %0, 0x3EB0C6F7A0B5ED8D
  %.0 = select i1 %4, double 0x3EB0C6F7A0B5ED8D, double %0
  %5 = fptosi double %.0 to i64
  store i64 %5, ptr %2, align 8, !tbaa !5
  %6 = sitofp i64 %5 to double
  %7 = fsub double %.0, %6
  %8 = fmul double %7, 1.000000e+09
  %9 = fptosi double %8 to i64
  %10 = getelementptr inbounds i8, ptr %2, i64 8
  store i64 %9, ptr %10, align 8, !tbaa !10
  %11 = call i32 @nanosleep(ptr noundef nonnull %2, ptr noundef nonnull %3) #4
  %12 = icmp eq i32 %11, -1
  br i1 %12, label %13, label %25

13:                                               ; preds = %1
  %14 = tail call ptr @__errno_location() #5
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = icmp eq i32 %15, 4
  br i1 %16, label %17, label %25

17:                                               ; preds = %13
  %18 = load i64, ptr %3, align 8, !tbaa !5
  %19 = sitofp i64 %18 to double
  %20 = getelementptr inbounds i8, ptr %3, i64 8
  %21 = load i64, ptr %20, align 8, !tbaa !10
  %22 = sitofp i64 %21 to double
  %23 = fdiv double %22, 1.000000e+09
  %24 = fadd double %23, %19
  br label %25

25:                                               ; preds = %1, %13, %17
  %.04 = phi double [ %24, %17 ], [ 0.000000e+00, %13 ], [ 0.000000e+00, %1 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #4
  ret double %.04
}

declare i32 @nanosleep(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #3

attributes #0 = { mustprogress 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 = { "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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 #4 = { nounwind }
attributes #5 = { nounwind 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, !7, i64 0}
!6 = !{!"timespec", !7, i64 0, !7, i64 8}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !8, i64 0}


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