int write_PCSab16Number(double d, char *p) {
  unsigned long o32;
  d = (d + 128.0) * 256.0 + 0.5;
  if (d >= 65536.0)
    return 1;
  if (d < 0.0)
    return 1;
  o32 = (unsigned long)d;
  ((unsigned char *)p)[0] = (unsigned char)((o32) >> 8);
  ((unsigned char *)p)[1] = (unsigned char)((o32));
  return 0;
}


x86 assembly (clang, -O0):
<write_PCSab16Number>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
movsd  0xf03(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  0xee6(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xee2(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xebc(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     115a <write_PCSab16Number+0x5a>
movl   $0x1,-0x4(%rbp)
jmp    11c7 <write_PCSab16Number+0xc7>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1174 <write_PCSab16Number+0x74>
movl   $0x1,-0x4(%rbp)
jmp    11c7 <write_PCSab16Number+0xc7>
movsd  -0x10(%rbp),%xmm0
movsd  0xe9f(%rip),%xmm2
movaps %xmm0,%xmm1
subsd  %xmm2,%xmm1
cvttsd2si %xmm1,%rcx
cvttsd2si %xmm0,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
and    %rdx,%rcx
or     %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
shr    $0x8,%rax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_PCSab16Number>:
addsd  0xef8(%rip),%xmm0
mulsd  0xef8(%rip),%xmm0
addsd  0xef8(%rip),%xmm0
ucomisd 0xef8(%rip),%xmm0
mov    $0x1,%eax
jae    1157 <write_PCSab16Number+0x57>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     1157 <write_PCSab16Number+0x57>
cvttsd2si %xmm0,%rax
mov    %rax,%rcx
sar    $0x3f,%rcx
subsd  0xedb(%rip),%xmm0
cvttsd2si %xmm0,%rdx
and    %ecx,%edx
or     %edx,%eax
rol    $0x8,%ax
mov    %ax,(%rdi)
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @write_PCSab16Number(double %0, i8* %1) {
%3 = alloca i32
%4 = alloca double
%5 = alloca i8*
%6 = alloca i64
store double %0, double* %4
store i8* %1, i8** %5
%7 = load double, double* %4
%8 = fadd double %7, 1.280000e+02
%9 = call double @llvm.fmuladd.f64(double %8, double 2.560000e+02, double 5.000000e-01)
store double %9, double* %4
%10 = load double, double* %4
%11 = fcmp oge double %10, 6.553600e+04
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 1, i32* %3
br label %29
13: ; preds = %2
%14 = load double, double* %4
%15 = fcmp olt double %14, 0.000000e+00
br i1 %15, label %16, label %17
16: ; preds = %13
store i32 1, i32* %3
br label %29
17: ; preds = %13
%18 = load double, double* %4
%19 = fptoui double %18 to i64
store i64 %19, i64* %6
%20 = load i64, i64* %6
%21 = lshr i64 %20, 8
%22 = trunc i64 %21 to i8
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i64 0
store i8 %22, i8* %24
%25 = load i64, i64* %6
%26 = trunc i64 %25 to i8
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i64 1
store i8 %26, i8* %28
store i32 0, i32* %3
br label %29
29: ; preds = %17, %16, %12
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
define i32 @write_PCSab16Number(double %0, i8* nocapture writeonly %1) {
%3 = fadd double %0, 1.280000e+02
%4 = tail call double @llvm.fmuladd.f64(double %3, double 2.560000e+02, double 5.000000e-01)
%5 = fcmp oge double %4, 6.553600e+04
%6 = fcmp olt double %4, 0.000000e+00
%7 = or i1 %5, %6
br i1 %7, label %14, label %8
8: ; preds = %2
%9 = fptoui double %4 to i64
%10 = lshr i64 %9, 8
%11 = trunc i64 %10 to i8
store i8 %11, i8* %1
%12 = trunc i64 %9 to i8
%13 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %12, i8* %13
br label %14
14: ; preds = %2, %8
%15 = phi i32 [ 0, %8 ], [ 1, %2 ]
ret i32 %15
}