#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct timespec {
  double tv_sec;
  double tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ bail(char *);
double floor(double);
int nanosleep(struct timespec *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, double);
void compute_time(double task_length) {
  int ret;
  struct timespec tim;
  double sleep_interval = (double)task_length;
  printf("sleep interval: %f\n", sleep_interval);
  tim.tv_sec = floor(sleep_interval);
  tim.tv_nsec = (sleep_interval - tim.tv_sec) * 1000000000;
  ret = nanosleep(&tim, NULL);
  if (ret < 0)
    bail("cannot sleep");
  return;
}


x86 assembly (clang, -O0):
<compute_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
lea    0xea5(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x28(%rbp),%xmm0
call   1060 <floor@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  0xe77(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <nanosleep@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11b8 <compute_time+0x78>
lea    0xe69(%rip),%rdi
call   1050 <bail@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_time>:
sub    $0x18,%rsp
movsd  %xmm0,(%rsp)
lea    0xeb8(%rip),%rdi
call   1030 <printf@plt>
movsd  (%rsp),%xmm0
call   1060 <floor@plt>
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
mulsd  0xe8a(%rip),%xmm1
movsd  %xmm1,0x10(%rsp)
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
test   %eax,%eax
js     1191 <compute_time+0x51>
add    $0x18,%rsp
ret
lea    0xe84(%rip),%rdi
call   1050 <bail@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timespec = type { double, double }
@.str = [20 x i8] c"sleep interval: %f\0A\00"
@.str.1 = [13 x i8] c"cannot sleep\00"
define void @compute_time(double %0) {
%2 = alloca double
%3 = alloca i32
%4 = alloca %struct.timespec
%5 = alloca double
store double %0, double* %2
%6 = load double, double* %2
store double %6, double* %5
%7 = load double, double* %5
%8 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), double %7)
%9 = load double, double* %5
%10 = call double @llvm.floor.f64(double %9)
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
store double %10, double* %11
%12 = load double, double* %5
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%14 = load double, double* %13
%15 = fsub double %12, %14
%16 = fmul double %15, 1.000000e+09
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
store double %16, double* %17
%18 = call i32 @nanosleep(%struct.timespec* %4, i32* null)
store i32 %18, i32* %3
%19 = load i32, i32* %3
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %1
%22 = call i32 @bail(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %1
ret void
}

LLVM IR (-O2):
%struct.timespec = type { double, double }
@.str = [20 x i8] c"sleep interval: %f\0A\00"
@.str.1 = [13 x i8] c"cannot sleep\00"
define void @compute_time(double %0) {
%2 = alloca %struct.timespec
%3 = bitcast %struct.timespec* %2 to i8*
%4 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), double %0)
%5 = tail call double @llvm.floor.f64(double %0)
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
store double %5, double* %6
%7 = fsub double %0, %5
%8 = fmul double %7, 1.000000e+09
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
store double %8, double* %9
%10 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @bail(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %1
ret void
}