// File: /workspace/github_c_makefile_star2_O2/BernardTatin[P]s7sh/s7.c
// Function: g_floor
static s7_pointer g_floor(s7_scheme *sc, s7_pointer args)
    {
#define H_floor "(floor x) returns the integer closest to x toward -inf"
#define Q_floor s7_make_signature(sc, 2, sc->is_integer_symbol, sc->is_real_symbol)

        s7_pointer x;

        x = car(args);
        switch (type(x))
        {
            case T_INTEGER:
                return(x);

            case T_RATIO:
                {
                    s7_int val;
                    val = numerator(x) / denominator(x);
                    /* C "/" truncates? -- C spec says "truncation toward 0" */
                    /* we're avoiding "floor" here because the int->double conversion introduces inaccuracies for big numbers */
                    if (numerator(x) < 0) /* not "val" because it might be truncated to 0 */
                        return(make_integer(sc, val - 1));
                    return(make_integer(sc, val));
                }

            case T_REAL:
                {
                    s7_double z;
                    z = real(x);
                    if (is_NaN(z))
                        return(simple_out_of_range(sc, sc->floor_symbol, x, its_nan_string));
                    if (fabs(z) > REAL_TO_INT_LIMIT)
                        return(simple_out_of_range(sc, sc->floor_symbol, x, its_too_large_string));
                    return(make_integer(sc, (s7_int)floor(z)));
                    /* floor here rounds down, whereas a straight int<=real coercion apparently rounds towards 0 */
                }

            case T_COMPLEX:
            default:
                return(method_or_bust_one_arg(sc, x, sc->floor_symbol, args, T_REAL));
        }
    }

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq 0x8(%rsi), %r9
movzbl (%r9), %ecx
cmpl $0xb, %ecx
je 0x53fc7
movq %rdi, %rbx
cmpl $0xd, %ecx
je 0x53eca
cmpl $0xc, %ecx
jne 0x53f12
movq 0x8(%r9), %rsi
movq %rsi, %rax
cqto
idivq 0x10(%r9)
movq %rax, %r14
testq %rsi, %rsi
jns 0x53f3d
movq %r14, %r15
decq %r15
cmpq $0x7ff, %r15            # imm = 0x7FF
ja 0x53f8e
leaq 0xc1a90(%rip), %rax     # 0x115950
movq -0x8(%rax,%r14,8), %r9
jmp 0x53fc7
movsd 0x8(%r9), %xmm0
ucomisd %xmm0, %xmm0
jp 0x53fd0
movapd 0x81fde(%rip), %xmm1    # 0xd5ec0
andpd %xmm0, %xmm1
ucomisd 0x7e1e2(%rip), %xmm1    # 0xd20d0
jbe 0x53f33
movq 0xf08(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xc5b3e(%rip), %rcx     # 0x119a40
movq %rbx, %rdi
movq %r9, %rdx
popq %rbx
popq %r14
popq %r15
jmp 0x35b47
movq %rsi, %rax
movq 0xf08(%rbx), %rdx
pushq $0xd
popq %r8
movq %rbx, %rdi
movq %r9, %rsi
movq %rax, %rcx
popq %rbx
popq %r14
popq %r15
jmp 0x77745
callq 0x85f0
cvttsd2si %xmm0, %r14
cmpq $0x7ff, %r14            # imm = 0x7FF
ja 0x53f53
leaq 0xc1a03(%rip), %rax     # 0x115950
movq (%rax,%r14,8), %r9
jmp 0x53fc7
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x53f72
movq %rbx, %rdi
callq 0x9c27
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r9
movq $0xb, (%r9)
movq %r14, 0x8(%r9)
jmp 0x53fc7
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x53fad
movq %rbx, %rdi
callq 0x9c27
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r9
movq $0xb, (%r9)
movq %r15, 0x8(%r9)
movq %r9, %rax
popq %rbx
popq %r14
popq %r15
retq
movq 0xf08(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xd065e(%rip), %rcx     # 0x124640
jmp 0x53f02