#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 */
unsigned int GET_BIT(unsigned long long, int);
int /*<<< orphan*/ fixed_point_set_sign(unsigned long long *, unsigned int,
                                        unsigned int);
int /*<<< orphan*/ is_fp2fd_overflow(double, unsigned int, unsigned int);
void fixed_point_fp2fd_peform(void *result, double fp, unsigned width,
                              unsigned frac_bits) {
  unsigned long long *tmp;
  unsigned sign;
  tmp = (unsigned long long *)&fp;
  sign = GET_BIT(*tmp, 63);
  tmp = result;
  if (!is_fp2fd_overflow(fp, width, frac_bits))
    *tmp = (unsigned long long)fp;
  else
    *tmp = (~0ull >> 1) >> (64 - width);
  *tmp &= (~0ull >> (64 - width));
  fixed_point_set_sign(tmp, width, sign);
}


x86 assembly (clang, -O0):
<fixed_point_fp2fd_peform>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
lea    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    $0x3f,%esi
call   1030 <GET_BIT@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1050 <is_fp2fd_overflow@plt>
cmp    $0x0,%eax
jne    11bb <fixed_point_fp2fd_peform+0x8b>
movsd  -0x10(%rbp),%xmm0
movsd  0xe6f(%rip),%xmm2
movaps %xmm0,%xmm1
subsd  %xmm2,%xmm1
cvttsd2si %xmm1,%rax
cvttsd2si %xmm0,%rcx
mov    %rcx,%rdx
sar    $0x3f,%rdx
and    %rdx,%rax
or     %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
jmp    11de <fixed_point_fp2fd_peform+0xae>
mov    $0x40,%eax
sub    -0x14(%rbp),%eax
mov    %eax,%eax
mov    %eax,%ecx
movabs $0x7fffffffffffffff,%rax
ff ff 7f
shr    %cl,%rax
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    $0x40,%eax
sub    -0x14(%rbp),%eax
mov    %eax,%eax
mov    %eax,%ecx
mov    $0xffffffffffffffff,%rax
shr    %cl,%rax
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
and    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1040 <fixed_point_set_sign@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fixed_point_fp2fd_peform>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebp
mov    %esi,%ebx
movdqa %xmm0,(%rsp)
mov    %rdi,%r14
movq   %xmm0,%rdi
mov    $0x3f,%esi
call   1030 <GET_BIT@plt>
mov    %eax,%r15d
movaps (%rsp),%xmm0
mov    %ebx,%edi
mov    %ebp,%esi
call   1050 <is_fp2fd_overflow@plt>
movapd (%rsp),%xmm0
cvttsd2si %xmm0,%rdx
mov    %rdx,%rcx
sar    $0x3f,%rcx
subsd  0xe82(%rip),%xmm0
cvttsd2si %xmm0,%rsi
and    %rcx,%rsi
mov    %ebx,%ecx
neg    %cl
movabs $0x7fffffffffffffff,%rdi
ff ff 7f
shr    %cl,%rdi
or     %rdx,%rsi
test   %eax,%eax
cmove  %rsi,%rdi
shl    %cl,%rdi
shr    %cl,%rdi
mov    %rdi,(%r14)
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r15d,%edx
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fixed_point_set_sign@plt>

LLVM IR (-O0):
define void @fixed_point_fp2fd_peform(i8* %0, double %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64*
%10 = alloca i32
store i8* %0, i8** %5
store double %1, double* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = bitcast double* %6 to i64*
store i64* %11, i64** %9
%12 = load i64*, i64** %9
%13 = load i64, i64* %12
%14 = call i32 @GET_BIT(i64 %13, i32 63)
store i32 %14, i32* %10
%15 = load i8*, i8** %5
%16 = bitcast i8* %15 to i64*
store i64* %16, i64** %9
%17 = load double, double* %6
%18 = load i32, i32* %7
%19 = load i32, i32* %8
%20 = call i32 @is_fp2fd_overflow(double %17, i32 %18, i32 %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %4
%23 = load double, double* %6
%24 = fptoui double %23 to i64
%25 = load i64*, i64** %9
store i64 %24, i64* %25
br label %32
26: ; preds = %4
%27 = load i32, i32* %7
%28 = sub i32 64, %27
%29 = zext i32 %28 to i64
%30 = lshr i64 9223372036854775807, %29
%31 = load i64*, i64** %9
store i64 %30, i64* %31
br label %32
32: ; preds = %26, %22
%33 = load i32, i32* %7
%34 = sub i32 64, %33
%35 = zext i32 %34 to i64
%36 = lshr i64 -1, %35
%37 = load i64*, i64** %9
%38 = load i64, i64* %37
%39 = and i64 %38, %36
store i64 %39, i64* %37
%40 = load i64*, i64** %9
%41 = load i32, i32* %7
%42 = load i32, i32* %10
%43 = call i32 @fixed_point_set_sign(i64* %40, i32 %41, i32 %42)
ret void
}

LLVM IR (-O2):
define void @fixed_point_fp2fd_peform(i8* %0, double %1, i32 %2, i32 %3) {
%5 = bitcast double %1 to i64
%6 = tail call i32 @GET_BIT(i64 %5, i32 63)
%7 = bitcast i8* %0 to i64*
%8 = tail call i32 @is_fp2fd_overflow(double %1, i32 %2, i32 %3)
%9 = icmp eq i32 %8, 0
%10 = fptoui double %1 to i64
%11 = sub i32 64, %2
%12 = zext i32 %11 to i64
%13 = lshr i64 9223372036854775807, %12
%14 = select i1 %9, i64 %10, i64 %13
%15 = lshr i64 -1, %12
%16 = and i64 %14, %15
store i64 %16, i64* %7
%17 = tail call i32 @fixed_point_set_sign(i64* %7, i32 %2, i32 %6)
ret void
}