#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 */

/* Variables and functions */
int /*<<< orphan*/ sleep(unsigned long);
int /*<<< orphan*/ usleep(unsigned long);
void sleep_abit(float cur_fps, float max_fps) {
  float diff;
  unsigned long msex;
  if (cur_fps <= max_fps)
    return;
  diff = cur_fps - max_fps;
  msex = (diff / max_fps) * 1000000;
  if (max_fps > .3 && msex / 1000000 > 3)
    msex = 3 * 1000000;
  sleep(msex / 1000000);
  usleep(msex % 1000000);
}


x86 assembly (clang, -O0):
<sleep_abit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  -0x4(%rbp),%xmm1
movss  -0x8(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jb     114a <sleep_abit+0x2a>
jmp    1208 <sleep_abit+0xe8>
movss  -0x4(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  0xe95(%rip),%xmm1
mulss  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttss2si %xmm1,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
movss  0xe7e(%rip),%xmm1
subss  %xmm1,%xmm0
cvttss2si %xmm0,%rcx
and    %rdx,%rcx
or     %rcx,%rax
mov    %rax,-0x18(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe4e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11dc <sleep_abit+0xbc>
mov    -0x18(%rbp),%rax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %rcx
cmp    $0x3,%rax
jbe    11dc <sleep_abit+0xbc>
movq   $0x2dc6c0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rdi
call   1030 <sleep@plt>
mov    -0x18(%rbp),%rax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,%rdi
call   1040 <usleep@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sleep_abit>:
ucomiss %xmm0,%xmm1
jae    11b7 <sleep_abit+0x97>
push   %r14
push   %rbx
push   %rax
subss  %xmm1,%xmm0
divss  %xmm1,%xmm0
mulss  0xec3(%rip),%xmm0
cvttss2si %xmm0,%rax
mov    %rax,%rcx
sar    $0x3f,%rcx
subss  0xeb3(%rip),%xmm0
cvttss2si %xmm0,%rdx
and    %rcx,%rdx
or     %rax,%rdx
cmp    $0x3d0900,%rdx
mov    $0x2dc6c0,%ebx
cmovb  %rdx,%rbx
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
ucomisd 0xe8d(%rip),%xmm0
cmovbe %rdx,%rbx
movabs $0x431bde82d7b634db,%rcx
de 1b 43
mov    %rbx,%rax
mul    %rcx
mov    %rdx,%r14
shr    $0x12,%r14
mov    %r14,%rdi
call   1030 <sleep@plt>
imul   $0xf4240,%r14,%rax
sub    %rax,%rbx
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <usleep@plt>
ret

LLVM IR (-O0):
define void @sleep_abit(float %0, float %1) {
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca i64
store float %0, float* %3
store float %1, float* %4
%7 = load float, float* %3
%8 = load float, float* %4
%9 = fcmp ole float %7, %8
br i1 %9, label %10, label %11
10: ; preds = %2
br label %35
11: ; preds = %2
%12 = load float, float* %3
%13 = load float, float* %4
%14 = fsub float %12, %13
store float %14, float* %5
%15 = load float, float* %5
%16 = load float, float* %4
%17 = fdiv float %15, %16
%18 = fmul float %17, 1.000000e+06
%19 = fptoui float %18 to i64
store i64 %19, i64* %6
%20 = load float, float* %4
%21 = fpext float %20 to double
%22 = fcmp ogt double %21, 3.000000e-01
br i1 %22, label %23, label %28
23: ; preds = %11
%24 = load i64, i64* %6
%25 = udiv i64 %24, 1000000
%26 = icmp ugt i64 %25, 3
br i1 %26, label %27, label %28
27: ; preds = %23
store i64 3000000, i64* %6
br label %28
28: ; preds = %27, %23, %11
%29 = load i64, i64* %6
%30 = udiv i64 %29, 1000000
%31 = call i32 @sleep(i64 %30)
%32 = load i64, i64* %6
%33 = urem i64 %32, 1000000
%34 = call i32 @usleep(i64 %33)
br label %35
35: ; preds = %28, %10
ret void
}

LLVM IR (-O2):
define void @sleep_abit(float %0, float %1) {
%3 = fcmp ugt float %0, %1
br i1 %3, label %4, label %18
4: ; preds = %2
%5 = fsub float %0, %1
%6 = fdiv float %5, %1
%7 = fmul float %6, 1.000000e+06
%8 = fptoui float %7 to i64
%9 = fpext float %1 to double
%10 = fcmp ogt double %9, 3.000000e-01
%11 = icmp ugt i64 %8, 3999999
%12 = select i1 %10, i1 %11, i1 false
%13 = select i1 %12, i64 3000000, i64 %8
%14 = udiv i64 %13, 1000000
%15 = tail call i32 @sleep(i64 %14)
%16 = urem i64 %13, 1000000
%17 = tail call i32 @usleep(i64 %16)
br label %18
18: ; preds = %2, %4
ret void
}