#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 */
double frexp(double, int *);
int to_1750flt(double input, short output[2]) {
  int exp;
  int mant;
  input = frexp(input, &exp);
  if (exp < -128)
    return -1;
  else if (exp > 127)
    return 1;
  if (input < 0.0 && input >= -0.5) {
    input *= 2.0;
    exp--;
  }
  mant = (int)(input * 2147483648.0);
  output[0] = (short)(mant >> 16);
  output[1] = (short)(mant & 0xFF00) | (exp & 0xFF);
  return 0;
}


x86 assembly (clang, -O0):
<to_1750flt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
lea    -0x1c(%rbp),%rdi
call   1030 <frexp@plt>
movsd  %xmm0,-0x10(%rbp)
cmpl   $0xffffff80,-0x1c(%rbp)
jge    114a <to_1750flt+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ef <to_1750flt+0xdf>
cmpl   $0x7f,-0x1c(%rbp)
jle    1160 <to_1750flt+0x50>
movl   $0x1,-0x4(%rbp)
jmp    11ef <to_1750flt+0xdf>
jmp    1165 <to_1750flt+0x55>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11a5 <to_1750flt+0x95>
movsd  -0x10(%rbp),%xmm0
movsd  0xe80(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11a5 <to_1750flt+0x95>
movsd  0xe76(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
movsd  0xe63(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
sar    $0x10,%eax
mov    %ax,%cx
mov    -0x18(%rbp),%rax
mov    %cx,(%rax)
mov    -0x20(%rbp),%eax
and    $0xff00,%eax
cwtl
mov    -0x1c(%rbp),%ecx
and    $0xff,%ecx
or     %ecx,%eax
mov    %ax,%cx
mov    -0x18(%rbp),%rax
mov    %cx,0x2(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<to_1750flt>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xc(%rsp),%rdi
call   1030 <frexp@plt>
mov    0xc(%rsp),%ecx
mov    $0xffffffff,%eax
cmp    $0xffffff80,%ecx
jl     1183 <to_1750flt+0x73>
mov    $0x1,%eax
cmp    $0x7f,%ecx
jg     1183 <to_1750flt+0x73>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
seta   %al
ucomisd 0xeb3(%rip),%xmm0
setae  %dl
and    %al,%dl
movzbl %dl,%eax
sub    %eax,%ecx
test   %al,%al
je     115f <to_1750flt+0x4f>
addsd  %xmm0,%xmm0
mulsd  0xea1(%rip),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,%edx
shr    $0x10,%edx
mov    %dx,(%rbx)
and    $0xff00,%eax
movzbl %cl,%ecx
or     %eax,%ecx
mov    %cx,0x2(%rbx)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @to_1750flt(double %0, i16* %1) {
%3 = alloca i32
%4 = alloca double
%5 = alloca i16*
%6 = alloca i32
%7 = alloca i32
store double %0, double* %4
store i16* %1, i16** %5
%8 = load double, double* %4
%9 = call double @frexp(double %8, i32* %6)
store double %9, double* %4
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, -128
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %48
13: ; preds = %2
%14 = load i32, i32* %6
%15 = icmp sgt i32 %14, 127
br i1 %15, label %16, label %17
16: ; preds = %13
store i32 1, i32* %3
br label %48
17: ; preds = %13
br label %18
18: ; preds = %17
%19 = load double, double* %4
%20 = fcmp olt double %19, 0.000000e+00
br i1 %20, label %21, label %29
21: ; preds = %18
%22 = load double, double* %4
%23 = fcmp oge double %22, -5.000000e-01
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = load double, double* %4
%26 = fmul double %25, 2.000000e+00
store double %26, double* %4
%27 = load i32, i32* %6
%28 = add nsw i32 %27, -1
store i32 %28, i32* %6
br label %29
29: ; preds = %24, %21, %18
%30 = load double, double* %4
%31 = fmul double %30, 0x41E0000000000000
%32 = fptosi double %31 to i32
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = ashr i32 %33, 16
%35 = trunc i32 %34 to i16
%36 = load i16*, i16** %5
%37 = getelementptr inbounds i16, i16* %36, i64 0
store i16 %35, i16* %37
%38 = load i32, i32* %7
%39 = and i32 %38, 65280
%40 = trunc i32 %39 to i16
%41 = sext i16 %40 to i32
%42 = load i32, i32* %6
%43 = and i32 %42, 255
%44 = or i32 %41, %43
%45 = trunc i32 %44 to i16
%46 = load i16*, i16** %5
%47 = getelementptr inbounds i16, i16* %46, i64 1
store i16 %45, i16* %47
store i32 0, i32* %3
br label %48
48: ; preds = %29, %16, %12
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
define i32 @to_1750flt(double %0, i16* nocapture writeonly %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call double @frexp(double %0, i32* %3)
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, -128
br i1 %7, label %27, label %8
8: ; preds = %2
%9 = icmp sgt i32 %6, 127
br i1 %9, label %27, label %10
10: ; preds = %8
%11 = fcmp olt double %5, 0.000000e+00
%12 = fcmp oge double %5, -5.000000e-01
%13 = and i1 %11, %12
%14 = fmul double %5, 2.000000e+00
%15 = sext i1 %13 to i32
%16 = add nsw i32 %6, %15
%17 = select i1 %13, double %14, double %5
%18 = fmul double %17, 0x41E0000000000000
%19 = fptosi double %18 to i32
%20 = lshr i32 %19, 16
%21 = trunc i32 %20 to i16
store i16 %21, i16* %1
%22 = and i32 %19, 65280
%23 = and i32 %16, 255
%24 = or i32 %22, %23
%25 = trunc i32 %24 to i16
%26 = getelementptr inbounds i16, i16* %1, i64 1
store i16 %25, i16* %26
br label %27
27: ; preds = %8, %2, %10
%28 = phi i32 [ 0, %10 ], [ -1, %2 ], [ 1, %8 ]
ret i32 %28
}