; 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: nounwind uwtable
declare dso_local double @dtime() #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local double @dwait(double noundef %0) #0 {
  %2 = alloca double, align 8
  %3 = alloca double, align 8
  %4 = alloca %struct.timespec, align 8
  %5 = alloca %struct.timespec, align 8
  store double %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %6 = call double @dtime()
  %7 = load double, ptr %2, align 8, !tbaa !5
  %8 = fadd double %6, %7
  store double %8, ptr %3, align 8, !tbaa !5
  %9 = load double, ptr %2, align 8, !tbaa !5
  %10 = fcmp olt double 0x3EB0C6F7A0B5ED8D, %9
  br i1 %10, label %11, label %26

11:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #3
  %12 = load double, ptr %2, align 8, !tbaa !5
  %13 = fsub double %12, 0x3EB0C6F7A0B5ED8D
  store double %13, ptr %2, align 8, !tbaa !5
  %14 = load double, ptr %2, align 8, !tbaa !5
  %15 = fptosi double %14 to i64
  %16 = getelementptr inbounds %struct.timespec, ptr %4, i32 0, i32 0
  store i64 %15, ptr %16, align 8, !tbaa !9
  %17 = load double, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.timespec, ptr %4, i32 0, i32 0
  %19 = load i64, ptr %18, align 8, !tbaa !9
  %20 = sitofp i64 %19 to double
  %21 = fsub double %17, %20
  %22 = fmul double 1.000000e+09, %21
  %23 = fptosi double %22 to i64
  %24 = getelementptr inbounds %struct.timespec, ptr %4, i32 0, i32 1
  store i64 %23, ptr %24, align 8, !tbaa !12
  %25 = call i32 @nanosleep(ptr noundef %4, ptr noundef %5)
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #3
  br label %26

26:                                               ; preds = %11, %1
  br label %27

27:                                               ; preds = %31, %26
  %28 = call double @dtime()
  %29 = load double, ptr %3, align 8, !tbaa !5
  %30 = fcmp olt double %28, %29
  br i1 %30, label %31, label %32

31:                                               ; preds = %27
  br label %27, !llvm.loop !13

32:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret double 0.000000e+00
}

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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 = distinct !{!13, !14}
!14 = !{!"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"

%struct.timespec = type { i64, i64 }

; Function Attrs: nounwind uwtable
declare dso_local double @dtime() local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef double @dwait(double noundef %0) local_unnamed_addr #0 {
  %2 = alloca %struct.timespec, align 8
  %3 = alloca %struct.timespec, align 8
  %4 = tail call double @dtime()
  %5 = fadd double %4, %0
  %6 = fcmp ogt double %0, 0x3EB0C6F7A0B5ED8D
  br i1 %6, label %7, label %.preheader

7:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #3
  %8 = fadd double %0, 0xBEB0C6F7A0B5ED8D
  %9 = fptosi double %8 to i64
  store i64 %9, ptr %2, align 8, !tbaa !5
  %10 = sitofp i64 %9 to double
  %11 = fsub double %8, %10
  %12 = fmul double %11, 1.000000e+09
  %13 = fptosi double %12 to i64
  %14 = getelementptr inbounds i8, ptr %2, i64 8
  store i64 %13, ptr %14, align 8, !tbaa !10
  %15 = call i32 @nanosleep(ptr noundef nonnull %2, ptr noundef nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #3
  br label %.preheader

.preheader:                                       ; preds = %7, %1
  br label %16

16:                                               ; preds = %.preheader, %16
  %17 = call double @dtime()
  %18 = fcmp olt double %17, %5
  br i1 %18, label %16, label %19, !llvm.loop !11

19:                                               ; preds = %16
  ret double 0.000000e+00
}

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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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