#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 */
typedef scalar_t__ time_t;
struct timespec {
  double tv_nsec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ __nsleep(struct timespec *, struct timespec *);
void gui_sleep(double ms) {
  struct timespec req = {}, rem = {};
  time_t sec;
  if (ms <= 0) {
    return;
  }
  sec = (time_t)(ms / 1000.0f);
  ms = ms - ((double)sec * 1000.0f);
  req.tv_sec = sec;
  req.tv_nsec = ms * 1000000L;
  __nsleep(&req, &rem);
}


x86 assembly (clang, -O0):
<gui_sleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jb     1160 <gui_sleep+0x40>
jmp    11d8 <gui_sleep+0xb8>
movsd  -0x8(%rbp),%xmm0
movsd  0xe9b(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm1
cvtsi2sdq -0x30(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xe64(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x10(%rbp)
movsd  0xe3f(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <__nsleep@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gui_sleep>:
sub    $0x28,%rsp
xorpd  %xmm1,%xmm1
movapd %xmm1,0x10(%rsp)
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jae    116c <gui_sleep+0x5c>
movsd  0xed0(%rip),%xmm1
movapd %xmm0,%xmm2
divsd  %xmm1,%xmm2
cvttsd2si %xmm2,%rax
xorps  %xmm2,%xmm2
cvtsi2sd %rax,%xmm2
mulsd  %xmm1,%xmm2
subsd  %xmm2,%xmm0
mov    %rax,0x8(%rsp)
mulsd  0xeae(%rip),%xmm0
movsd  %xmm0,(%rsp)
mov    %rsp,%rdi
lea    0x10(%rsp),%rsi
call   1030 <__nsleep@plt>
add    $0x28,%rsp
ret

LLVM IR (-O0):
%struct.timespec = type { double, i64 }
define void @gui_sleep(double %0) {
%2 = alloca double
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
%5 = alloca i64
store double %0, double* %2
%6 = bitcast %struct.timespec* %3 to i8*
%7 = bitcast %struct.timespec* %4 to i8*
%8 = load double, double* %2
%9 = fcmp ole double %8, 0.000000e+00
br i1 %9, label %10, label %11
10: ; preds = %1
br label %26
11: ; preds = %1
%12 = load double, double* %2
%13 = fdiv double %12, 1.000000e+03
%14 = fptosi double %13 to i64
store i64 %14, i64* %5
%15 = load double, double* %2
%16 = load i64, i64* %5
%17 = sitofp i64 %16 to double
%18 = fneg double %17
%19 = call double @llvm.fmuladd.f64(double %18, double 1.000000e+03, double %15)
store double %19, double* %2
%20 = load i64, i64* %5
%21 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
store i64 %20, i64* %21
%22 = load double, double* %2
%23 = fmul double %22, 1.000000e+06
%24 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
store double %23, double* %24
%25 = call i32 @__nsleep(%struct.timespec* %3, %struct.timespec* %4)
br label %26
26: ; preds = %11, %10
ret void
}

LLVM IR (-O2):
%struct.timespec = type { double, i64 }
define void @gui_sleep(double %0) {
%2 = alloca %struct.timespec
%3 = alloca %struct.timespec
%4 = bitcast %struct.timespec* %2 to i8*
%5 = bitcast %struct.timespec* %3 to i8*
%6 = fcmp ugt double %0, 0.000000e+00
br i1 %6, label %7, label %17
7: ; preds = %1
%8 = fdiv double %0, 1.000000e+03
%9 = fptosi double %8 to i64
%10 = sitofp i64 %9 to double
%11 = fneg double %10
%12 = tail call double @llvm.fmuladd.f64(double %11, double 1.000000e+03, double %0)
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
store i64 %9, i64* %13
%14 = fmul double %12, 1.000000e+06
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
store double %14, double* %15
%16 = call i32 @__nsleep(%struct.timespec* %2, %struct.timespec* %3)
br label %17
17: ; preds = %1, %7
ret void
}