#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;
  long 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 = (long)(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    $0x30,%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    11f5 <to_1750flt+0xe5>
cmpl   $0x7f,-0x1c(%rbp)
jle    1160 <to_1750flt+0x50>
movl   $0x1,-0x4(%rbp)
jmp    11f5 <to_1750flt+0xe5>
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,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
sar    $0x10,%rax
mov    %ax,%cx
mov    -0x18(%rbp),%rax
mov    %cx,(%rax)
mov    -0x28(%rbp),%rax
and    $0xff00,%rax
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    $0x30,%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     1186 <to_1750flt+0x76>
mov    $0x1,%eax
cmp    $0x7f,%ecx
jg     1186 <to_1750flt+0x76>
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,%rax
mov    %rax,%rdx
shr    $0x10,%rdx
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 i64
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 i64
store i64 %32, i64* %7
%33 = load i64, i64* %7
%34 = ashr i64 %33, 16
%35 = trunc i64 %34 to i16
%36 = load i16*, i16** %5
%37 = getelementptr inbounds i16, i16* %36, i64 0
store i16 %35, i16* %37
%38 = load i64, i64* %7
%39 = and i64 %38, 65280
%40 = trunc i64 %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 %28, label %8
8: ; preds = %2
%9 = icmp sgt i32 %6, 127
br i1 %9, label %28, 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 i64
%20 = lshr i64 %19, 16
%21 = trunc i64 %20 to i16
store i16 %21, i16* %1
%22 = trunc i64 %19 to i32
%23 = and i32 %22, 65280
%24 = and i32 %16, 255
%25 = or i32 %23, %24
%26 = trunc i32 %25 to i16
%27 = getelementptr inbounds i16, i16* %1, i64 1
store i16 %26, i16* %27
br label %28
28: ; preds = %8, %2, %10
%29 = phi i32 [ 0, %10 ], [ -1, %2 ], [ 1, %8 ]
ret i32 %29
}