#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 */
typedef double int32_t;

/* Variables and functions */
double const copysignk(double, double);
double fabsk(double);
scalar_t__ xisinf(double);
__attribute__((visibility("default"))) const double xtrunc(double x) {
  double fr = x - (double)(1LL << 31) * (int32_t)(x * (1.0 / (1LL << 31)));
  fr = fr - (int32_t)fr;
  return (xisinf(x) || fabsk(x) >= (double)(1LL << 52)) ? x
                                                        : copysignk(x - fr, x);
}


x86 assembly (clang, -O0):
<xtrunc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm1
movsd  0xebe(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  0xea9(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1040 <xisinf@plt>
cmp    $0x0,%rax
jne    11a3 <xtrunc+0x73>
movsd  -0x8(%rbp),%xmm0
call   1050 <fabsk@plt>
movsd  0xe77(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11b2 <xtrunc+0x82>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11cb <xtrunc+0x9b>
movsd  -0x8(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
call   1030 <copysignk@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xtrunc>:
push   %rax
movsd  %xmm0,(%rsp)
call   1040 <xisinf@plt>
test   %rax,%rax
jne    1183 <xtrunc+0x53>
movsd  (%rsp),%xmm0
call   1050 <fabsk@plt>
ucomisd 0xebe(%rip),%xmm0
jae    1183 <xtrunc+0x53>
movsd  0xea4(%rip),%xmm2
movsd  (%rsp),%xmm1
mulsd  %xmm1,%xmm2
mulsd  0xe9b(%rip),%xmm2
addsd  %xmm1,%xmm2
subsd  %xmm2,%xmm2
movapd %xmm1,%xmm0
subsd  %xmm2,%xmm0
pop    %rax
jmp    1030 <copysignk@plt>
movsd  (%rsp),%xmm0
pop    %rax
ret

LLVM IR (-O0):
define double @xtrunc(double %0) {
%2 = alloca double
%3 = alloca double
store double %0, double* %2
%4 = load double, double* %2
%5 = load double, double* %2
%6 = fmul double %5, 0x3E00000000000000
%7 = call double @llvm.fmuladd.f64(double 0xC1E0000000000000, double %6, double %4)
store double %7, double* %3
%8 = load double, double* %3
%9 = load double, double* %3
%10 = fsub double %8, %9
store double %10, double* %3
%11 = load double, double* %2
%12 = call i64 @xisinf(double %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %1
%15 = load double, double* %2
%16 = call double @fabsk(double %15)
%17 = fcmp oge double %16, 0x4330000000000000
br i1 %17, label %18, label %20
18: ; preds = %14, %1
%19 = load double, double* %2
br label %26
20: ; preds = %14
%21 = load double, double* %2
%22 = load double, double* %3
%23 = fsub double %21, %22
%24 = load double, double* %2
%25 = call double @copysignk(double %23, double %24)
br label %26
26: ; preds = %20, %18
%27 = phi double [ %19, %18 ], [ %25, %20 ]
ret double %27
}

LLVM IR (-O2):
define double @xtrunc(double %0) {
%2 = fmul double %0, 0x3E00000000000000
%3 = tail call double @llvm.fmuladd.f64(double %2, double 0xC1E0000000000000, double %0)
%4 = fsub double %3, %3
%5 = tail call i64 @xisinf(double %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %1
%8 = tail call double @fabsk(double %0)
%9 = fcmp ult double %8, 0x4330000000000000
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = fsub double %0, %4
%12 = tail call double @copysignk(double %11, double %0)
br label %13
13: ; preds = %1, %7, %10
%14 = phi double [ %12, %10 ], [ %0, %7 ], [ %0, %1 ]
ret double %14
}