#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 double int16_t;

/* Variables and functions */
int /*<<< orphan*/ ms_log(int, char *, double);
int /*<<< orphan*/ ms_ratapprox(double, int *, int *, int, int);
int ms_genfactmult(double samprate, int16_t *factor, int16_t *multiplier) {
  int num, den;
  if (samprate > 32767.0 || samprate < 0.0) {
    ms_log(2, "ms_genfactmult(): samprate out of range: %g\n", samprate);
    return -1;
  }
  if ((samprate - (int16_t)samprate) < 0.000001) {
    *factor = (int16_t)samprate;
    if (*factor)
      *multiplier = 1;
  } else {
    ms_ratapprox(samprate, &num, &den, 32767, 1e-12);
    *factor = (int16_t)num;
    *multiplier = (int16_t)-den;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ms_genfactmult>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xebe(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     115a <ms_genfactmult+0x3a>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    117c <ms_genfactmult+0x5c>
movsd  -0x10(%rbp),%xmm0
mov    $0x2,%edi
lea    0xead(%rip),%rsi
call   1040 <ms_log@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1218 <ms_genfactmult+0xf8>
movsd  -0x10(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm1
movsd  0xe7a(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11da <ms_genfactmult+0xba>
movsd  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11c5 <ms_genfactmult+0xa5>
jp     11c5 <ms_genfactmult+0xa5>
jmp    11d5 <ms_genfactmult+0xb5>
mov    -0x20(%rbp),%rax
movsd  0xe3f(%rip),%xmm0
movsd  %xmm0,(%rax)
jmp    1211 <ms_genfactmult+0xf1>
movsd  -0x10(%rbp),%xmm0
lea    -0x24(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x7fff,%edx
xor    %ecx,%ecx
call   1030 <ms_ratapprox@plt>
cvtsi2sdl -0x24(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
xor    %eax,%eax
sub    -0x28(%rbp),%eax
cvtsi2sd %eax,%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ms_genfactmult>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
ucomisd 0xed0(%rip),%xmm0
ja     1179 <ms_genfactmult+0x59>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     1179 <ms_genfactmult+0x59>
mov    %rsi,%r14
mov    %rdi,%rbx
movapd %xmm0,%xmm1
subsd  %xmm0,%xmm1
movsd  0xeb6(%rip),%xmm2
ucomisd %xmm1,%xmm2
jbe    1191 <ms_genfactmult+0x71>
movsd  %xmm0,(%rbx)
xor    %ebp,%ebp
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    116a <ms_genfactmult+0x4a>
jnp    11c8 <ms_genfactmult+0xa8>
movabs $0x3ff0000000000000,%rax
mov    %rax,(%r14)
jmp    11c8 <ms_genfactmult+0xa8>
lea    0xe90(%rip),%rsi
mov    $0x2,%edi
call   1040 <ms_log@plt>
mov    $0xffffffff,%ebp
jmp    11c8 <ms_genfactmult+0xa8>
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
xor    %ebp,%ebp
mov    $0x7fff,%edx
xor    %ecx,%ecx
call   1030 <ms_ratapprox@plt>
xorps  %xmm0,%xmm0
cvtsi2sdl 0xc(%rsp),%xmm0
movsd  %xmm0,(%rbx)
xor    %eax,%eax
sub    0x8(%rsp),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,(%r14)
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [45 x i8] c"ms_genfactmult(): samprate out of range: %g\0A\00"
define i32 @ms_genfactmult(double %0, double* %1, double* %2) {
%4 = alloca i32
%5 = alloca double
%6 = alloca double*
%7 = alloca double*
%8 = alloca i32
%9 = alloca i32
store double %0, double* %5
store double* %1, double** %6
store double* %2, double** %7
%10 = load double, double* %5
%11 = fcmp ogt double %10, 3.276700e+04
br i1 %11, label %15, label %12
12: ; preds = %3
%13 = load double, double* %5
%14 = fcmp olt double %13, 0.000000e+00
br i1 %14, label %15, label %18
15: ; preds = %12, %3
%16 = load double, double* %5
%17 = call i32 @ms_log(i32 2, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), double %16)
store i32 -1, i32* %4
br label %43
18: ; preds = %12
%19 = load double, double* %5
%20 = load double, double* %5
%21 = fsub double %19, %20
%22 = fcmp olt double %21, 0x3EB0C6F7A0B5ED8D
br i1 %22, label %23, label %32
23: ; preds = %18
%24 = load double, double* %5
%25 = load double*, double** %6
store double %24, double* %25
%26 = load double*, double** %6
%27 = load double, double* %26
%28 = fcmp une double %27, 0.000000e+00
br i1 %28, label %29, label %31
29: ; preds = %23
%30 = load double*, double** %7
store double 1.000000e+00, double* %30
br label %31
31: ; preds = %29, %23
br label %42
32: ; preds = %18
%33 = load double, double* %5
%34 = call i32 @ms_ratapprox(double %33, i32* %8, i32* %9, i32 32767, i32 0)
%35 = load i32, i32* %8
%36 = sitofp i32 %35 to double
%37 = load double*, double** %6
store double %36, double* %37
%38 = load i32, i32* %9
%39 = sub nsw i32 0, %38
%40 = sitofp i32 %39 to double
%41 = load double*, double** %7
store double %40, double* %41
br label %42
42: ; preds = %32, %31
store i32 0, i32* %4
br label %43
43: ; preds = %42, %15
%44 = load i32, i32* %4
ret i32 %44
}

LLVM IR (-O2):
@.str = [45 x i8] c"ms_genfactmult(): samprate out of range: %g\0A\00"
define i32 @ms_genfactmult(double %0, double* nocapture writeonly %1, double* nocapture writeonly %2) {
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %4 to i8*
%7 = bitcast i32* %5 to i8*
%8 = fcmp ogt double %0, 3.276700e+04
%9 = fcmp olt double %0, 0.000000e+00
%10 = or i1 %8, %9
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = tail call i32 @ms_log(i32 2, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), double %0)
br label %26
13: ; preds = %3
%14 = fsub double %0, %0
%15 = fcmp olt double %14, 0x3EB0C6F7A0B5ED8D
br i1 %15, label %16, label %19
16: ; preds = %13
store double %0, double* %1
%17 = fcmp une double %0, 0.000000e+00
br i1 %17, label %18, label %26
18: ; preds = %16
store double 1.000000e+00, double* %2
br label %26
19: ; preds = %13
%20 = call i32 @ms_ratapprox(double %0, i32* %4, i32* %5, i32 32767, i32 0)
%21 = load i32, i32* %4
%22 = sitofp i32 %21 to double
store double %22, double* %1
%23 = load i32, i32* %5
%24 = sub nsw i32 0, %23
%25 = sitofp i32 %24 to double
store double %25, double* %2
br label %26
26: ; preds = %19, %18, %16, %11
%27 = phi i32 [ -1, %11 ], [ 0, %16 ], [ 0, %18 ], [ 0, %19 ]
ret i32 %27
}