int quicktime_get_timescale(double frame_rate) {
  int timescale = 600;
  if (frame_rate - (int)frame_rate != 0)
    timescale = (int)(frame_rate * 1001 + 0.5);
  else if ((600 / frame_rate) - (int)(600 / frame_rate) != 0)
    timescale = (int)(frame_rate * 100 + 0.5);
  return timescale;
}


x86 assembly (clang, -O0):
<quicktime_get_timescale>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
movl   $0x258,-0xc(%rbp)
movsd  -0x8(%rbp),%xmm0
cvttsd2si -0x8(%rbp),%eax
cvtsi2sd %eax,%xmm1
subsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    113a <quicktime_get_timescale+0x3a>
jp     113a <quicktime_get_timescale+0x3a>
jmp    1163 <quicktime_get_timescale+0x63>
movsd  -0x8(%rbp),%xmm0
movsd  0xed1(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xebd(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0xc(%rbp)
jmp    11ca <quicktime_get_timescale+0xca>
movsd  0xe95(%rip),%xmm0
divsd  -0x8(%rbp),%xmm0
movsd  0xe88(%rip),%xmm1
divsd  -0x8(%rbp),%xmm1
cvttsd2si %xmm1,%eax
cvtsi2sd %eax,%xmm1
subsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11a1 <quicktime_get_timescale+0xa1>
jp     11a1 <quicktime_get_timescale+0xa1>
jmp    11c5 <quicktime_get_timescale+0xc5>
movsd  -0x8(%rbp),%xmm0
movsd  0xe5a(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe56(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0xc(%rbp)
jmp    11ca <quicktime_get_timescale+0xca>
mov    -0xc(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<quicktime_get_timescale>:
cvttpd2dq %xmm0,%xmm1
cvtdq2pd %xmm1,%xmm1
movapd %xmm0,%xmm2
subsd  %xmm1,%xmm2
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm2
jne    111c <quicktime_get_timescale+0x1c>
jnp    1126 <quicktime_get_timescale+0x26>
mulsd  0xef4(%rip),%xmm0
jmp    114e <quicktime_get_timescale+0x4e>
movsd  0xed2(%rip),%xmm2
divsd  %xmm0,%xmm2
cvttpd2dq %xmm2,%xmm3
cvtdq2pd %xmm3,%xmm3
subsd  %xmm3,%xmm2
ucomisd %xmm1,%xmm2
jne    1146 <quicktime_get_timescale+0x46>
jnp    115b <quicktime_get_timescale+0x5b>
mulsd  0xeba(%rip),%xmm0
addsd  0xeba(%rip),%xmm0
cvttsd2si %xmm0,%eax
ret
mov    $0x258,%eax
ret

LLVM IR (-O0):
define i32 @quicktime_get_timescale(double %0) {
%2 = alloca double
%3 = alloca i32
store double %0, double* %2
store i32 600, i32* %3
%4 = load double, double* %2
%5 = load double, double* %2
%6 = fptosi double %5 to i32
%7 = sitofp i32 %6 to double
%8 = fsub double %4, %7
%9 = fcmp une double %8, 0.000000e+00
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load double, double* %2
%12 = call double @llvm.fmuladd.f64(double %11, double 1.001000e+03, double 5.000000e-01)
%13 = fptosi double %12 to i32
store i32 %13, i32* %3
br label %28
14: ; preds = %1
%15 = load double, double* %2
%16 = fdiv double 6.000000e+02, %15
%17 = load double, double* %2
%18 = fdiv double 6.000000e+02, %17
%19 = fptosi double %18 to i32
%20 = sitofp i32 %19 to double
%21 = fsub double %16, %20
%22 = fcmp une double %21, 0.000000e+00
br i1 %22, label %23, label %27
23: ; preds = %14
%24 = load double, double* %2
%25 = call double @llvm.fmuladd.f64(double %24, double 1.000000e+02, double 5.000000e-01)
%26 = fptosi double %25 to i32
store i32 %26, i32* %3
br label %27
27: ; preds = %23, %14
br label %28
28: ; preds = %27, %10
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
define i32 @quicktime_get_timescale(double %0) {
%2 = fptosi double %0 to i32
%3 = sitofp i32 %2 to double
%4 = fsub double %0, %3
%5 = fcmp une double %4, 0.000000e+00
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = tail call double @llvm.fmuladd.f64(double %0, double 1.001000e+03, double 5.000000e-01)
%8 = fptosi double %7 to i32
br label %18
9: ; preds = %1
%10 = fdiv double 6.000000e+02, %0
%11 = fptosi double %10 to i32
%12 = sitofp i32 %11 to double
%13 = fsub double %10, %12
%14 = fcmp une double %13, 0.000000e+00
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = tail call double @llvm.fmuladd.f64(double %0, double 1.000000e+02, double 5.000000e-01)
%17 = fptosi double %16 to i32
br label %18
18: ; preds = %9, %15, %6
%19 = phi i32 [ %8, %6 ], [ %17, %15 ], [ 600, %9 ]
ret i32 %19
}