#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 int /*<<< orphan*/ int16_t;

/* Variables and functions */
scalar_t__ ms_reduce_rate(double, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int ms_genfactmult(double samprate, int16_t *factor, int16_t *multiplier) {
  int16_t factor1;
  int16_t factor2;
  if (!factor || !multiplier)
    return -1;
  if (samprate < 0.0)
    samprate = -1.0 / samprate;
  if (samprate == 0.0) {
    *factor = 0;
    *multiplier = 0;
    return 0;
  } else if (samprate >= 1.0) {
    if (ms_reduce_rate(samprate, &factor1, &factor2) == 0) {
      *factor = factor1;
      *multiplier = factor2;
      return 0;
    }
  } else {
    if (ms_reduce_rate(1.0 / samprate, &factor1, &factor2) == 0) {
      *factor = -factor1;
      *multiplier = -factor2;
      return 0;
    }
  }
  return -1;
}


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)
cmpq   $0x0,-0x18(%rbp)
je     113b <ms_genfactmult+0x2b>
cmpq   $0x0,-0x20(%rbp)
jne    1147 <ms_genfactmult+0x37>
movl   $0xffffffff,-0x4(%rbp)
jmp    124c <ms_genfactmult+0x13c>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1167 <ms_genfactmult+0x57>
movsd  0xea3(%rip),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    119f <ms_genfactmult+0x8f>
jp     119f <ms_genfactmult+0x8f>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    124c <ms_genfactmult+0x13c>
movsd  -0x10(%rbp),%xmm0
movsd  0xe5c(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11f5 <ms_genfactmult+0xe5>
movsd  -0x10(%rbp),%xmm0
lea    -0x24(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <ms_reduce_rate@plt>
cmp    $0x0,%rax
jne    11f0 <ms_genfactmult+0xe0>
mov    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    124c <ms_genfactmult+0x13c>
jmp    1240 <ms_genfactmult+0x130>
movsd  0xe0b(%rip),%xmm0
divsd  -0x10(%rbp),%xmm0
lea    -0x24(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <ms_reduce_rate@plt>
cmp    $0x0,%rax
jne    123b <ms_genfactmult+0x12b>
xor    %ecx,%ecx
sub    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
xor    %ecx,%ecx
sub    -0x28(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    124c <ms_genfactmult+0x13c>
jmp    1240 <ms_genfactmult+0x130>
jmp    1245 <ms_genfactmult+0x135>
movl   $0xffffffff,-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
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     115c <ms_genfactmult+0x4c>
mov    %rsi,%r14
test   %rsi,%rsi
je     115c <ms_genfactmult+0x4c>
mov    %rdi,%rbx
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    1147 <ms_genfactmult+0x37>
movsd  0xec1(%rip),%xmm2
divsd  %xmm0,%xmm2
movapd %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jne    1167 <ms_genfactmult+0x57>
jp     1167 <ms_genfactmult+0x57>
movl   $0x0,(%rbx)
xor    %eax,%eax
mov    %eax,(%r14)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
ucomisd 0xe99(%rip),%xmm0
jae    11a5 <ms_genfactmult+0x95>
movsd  0xe8f(%rip),%xmm1
divsd  %xmm0,%xmm1
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
movapd %xmm1,%xmm0
call   1030 <ms_reduce_rate@plt>
test   %rax,%rax
jne    115c <ms_genfactmult+0x4c>
xor    %ecx,%ecx
sub    0xc(%rsp),%ecx
xor    %eax,%eax
mov    %ecx,(%rbx)
sub    0x8(%rsp),%eax
jmp    1157 <ms_genfactmult+0x47>
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1030 <ms_reduce_rate@plt>
test   %rax,%rax
jne    115c <ms_genfactmult+0x4c>
mov    0xc(%rsp),%eax
mov    %eax,(%rbx)
mov    0x8(%rsp),%eax
jmp    1157 <ms_genfactmult+0x47>

LLVM IR (-O0):
define i32 @ms_genfactmult(double %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca double
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store double %0, double* %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%10 = load i32*, i32** %6
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %3
%13 = load i32*, i32** %7
%14 = icmp ne i32* %13, null
br i1 %14, label %16, label %15
15: ; preds = %12, %3
store i32 -1, i32* %4
br label %56
16: ; preds = %12
%17 = load double, double* %5
%18 = fcmp olt double %17, 0.000000e+00
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load double, double* %5
%21 = fdiv double -1.000000e+00, %20
store double %21, double* %5
br label %22
22: ; preds = %19, %16
%23 = load double, double* %5
%24 = fcmp oeq double %23, 0.000000e+00
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i32*, i32** %6
store i32 0, i32* %26
%27 = load i32*, i32** %7
store i32 0, i32* %27
store i32 0, i32* %4
br label %56
28: ; preds = %22
%29 = load double, double* %5
%30 = fcmp oge double %29, 1.000000e+00
br i1 %30, label %31, label %41
31: ; preds = %28
%32 = load double, double* %5
%33 = call i64 @ms_reduce_rate(double %32, i32* %8, i32* %9)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %31
%36 = load i32, i32* %8
%37 = load i32*, i32** %6
store i32 %36, i32* %37
%38 = load i32, i32* %9
%39 = load i32*, i32** %7
store i32 %38, i32* %39
store i32 0, i32* %4
br label %56
40: ; preds = %31
br label %54
41: ; preds = %28
%42 = load double, double* %5
%43 = fdiv double 1.000000e+00, %42
%44 = call i64 @ms_reduce_rate(double %43, i32* %8, i32* %9)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %53
46: ; preds = %41
%47 = load i32, i32* %8
%48 = sub nsw i32 0, %47
%49 = load i32*, i32** %6
store i32 %48, i32* %49
%50 = load i32, i32* %9
%51 = sub nsw i32 0, %50
%52 = load i32*, i32** %7
store i32 %51, i32* %52
store i32 0, i32* %4
br label %56
53: ; preds = %41
br label %54
54: ; preds = %53, %40
br label %55
55: ; preds = %54
store i32 -1, i32* %4
br label %56
56: ; preds = %55, %46, %35, %25, %15
%57 = load i32, i32* %4
ret i32 %57
}

LLVM IR (-O2):
define i32 @ms_genfactmult(double %0, i32* writeonly %1, i32* writeonly %2) {
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %4 to i8*
%7 = bitcast i32* %5 to i8*
%8 = icmp ne i32* %1, null
%9 = icmp ne i32* %2, null
%10 = and i1 %8, %9
br i1 %10, label %11, label %36
11: ; preds = %3
%12 = fcmp olt double %0, 0.000000e+00
%13 = fdiv double -1.000000e+00, %0
%14 = select i1 %12, double %13, double %0
%15 = fcmp oeq double %14, 0.000000e+00
br i1 %15, label %16, label %17
16: ; preds = %11
store i32 0, i32* %1
br label %34
17: ; preds = %11
%18 = fcmp ult double %14, 1.000000e+00
br i1 %18, label %25, label %19
19: ; preds = %17
%20 = call i64 @ms_reduce_rate(double %14, i32* %4, i32* %5)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %36
22: ; preds = %19
%23 = load i32, i32* %4
store i32 %23, i32* %1
%24 = load i32, i32* %5
br label %34
25: ; preds = %17
%26 = fdiv double 1.000000e+00, %14
%27 = call i64 @ms_reduce_rate(double %26, i32* %4, i32* %5)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %25
%30 = load i32, i32* %4
%31 = sub nsw i32 0, %30
store i32 %31, i32* %1
%32 = load i32, i32* %5
%33 = sub nsw i32 0, %32
br label %34
34: ; preds = %16, %22, %29
%35 = phi i32 [ %33, %29 ], [ %24, %22 ], [ 0, %16 ]
store i32 %35, i32* %2
br label %36
36: ; preds = %34, %25, %19, %3
%37 = phi i32 [ -1, %3 ], [ -1, %19 ], [ -1, %25 ], [ 0, %34 ]
ret i32 %37
}