#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 ceil(double);
int write_S15Fixed16Number(double d, char *p) {
  signed long i32;
  d = ceil(d * 65536.0);
  if (d >= 2147483648.0)
    return 1;
  if (d < -2147483648.0)
    return 1;
  i32 = (signed long)d;
  ((signed char *)p)[0] = (signed char)((i32) >> 24);
  ((unsigned char *)p)[1] = (unsigned char)((i32) >> 16);
  ((unsigned char *)p)[2] = (unsigned char)((i32) >> 8);
  ((unsigned char *)p)[3] = (unsigned char)((i32));
  return 0;
}


x86 assembly (clang, -O0):
<write_S15Fixed16Number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
movsd  0xedf(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
call   1030 <ceil@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xebb(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     115b <write_S15Fixed16Number+0x4b>
movl   $0x1,-0x4(%rbp)
jmp    11ca <write_S15Fixed16Number+0xba>
movsd  0xead(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    117a <write_S15Fixed16Number+0x6a>
movl   $0x1,-0x4(%rbp)
jmp    11ca <write_S15Fixed16Number+0xba>
cvttsd2si -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
sar    $0x18,%rax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
sar    $0x10,%rax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x20(%rbp),%rax
sar    $0x8,%rax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x20(%rbp),%rax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x3(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_S15Fixed16Number>:
push   %rbx
mov    %rdi,%rbx
mulsd  0xee4(%rip),%xmm0
call   1030 <ceil@plt>
ucomisd 0xedf(%rip),%xmm0
mov    $0x1,%eax
jae    1149 <write_S15Fixed16Number+0x39>
movsd  0xed8(%rip),%xmm1
ucomisd %xmm0,%xmm1
ja     1149 <write_S15Fixed16Number+0x39>
cvttsd2si %xmm0,%rax
bswap  %eax
mov    %eax,(%rbx)
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @write_S15Fixed16Number(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 = fmul double %7, 6.553600e+04
%9 = call double @llvm.ceil.f64(double %8)
store double %9, double* %4
%10 = load double, double* %4
%11 = fcmp oge double %10, 0x41E0000000000000
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 1, i32* %3
br label %39
13: ; preds = %2
%14 = load double, double* %4
%15 = fcmp olt double %14, 0xC1E0000000000000
br i1 %15, label %16, label %17
16: ; preds = %13
store i32 1, i32* %3
br label %39
17: ; preds = %13
%18 = load double, double* %4
%19 = fptosi double %18 to i64
store i64 %19, i64* %6
%20 = load i64, i64* %6
%21 = ashr i64 %20, 24
%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 = ashr i64 %25, 16
%27 = trunc i64 %26 to i8
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i64 1
store i8 %27, i8* %29
%30 = load i64, i64* %6
%31 = ashr i64 %30, 8
%32 = trunc i64 %31 to i8
%33 = load i8*, i8** %5
%34 = getelementptr inbounds i8, i8* %33, i64 2
store i8 %32, i8* %34
%35 = load i64, i64* %6
%36 = trunc i64 %35 to i8
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i64 3
store i8 %36, i8* %38
store i32 0, i32* %3
br label %39
39: ; preds = %17, %16, %12
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
define i32 @write_S15Fixed16Number(double %0, i8* nocapture writeonly %1) {
%3 = fmul double %0, 6.553600e+04
%4 = tail call double @llvm.ceil.f64(double %3)
%5 = fcmp oge double %4, 0x41E0000000000000
%6 = fcmp olt double %4, 0xC1E0000000000000
%7 = or i1 %5, %6
br i1 %7, label %20, label %8
8: ; preds = %2
%9 = fptosi double %4 to i64
%10 = lshr i64 %9, 24
%11 = trunc i64 %10 to i8
store i8 %11, i8* %1
%12 = lshr i64 %9, 16
%13 = trunc i64 %12 to i8
%14 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %13, i8* %14
%15 = lshr i64 %9, 8
%16 = trunc i64 %15 to i8
%17 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %16, i8* %17
%18 = trunc i64 %9 to i8
%19 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %18, i8* %19
br label %20
20: ; preds = %2, %8
%21 = phi i32 [ 0, %8 ], [ 1, %2 ]
ret i32 %21
}