// File: /workspace/github_c_makefile_star2_O1/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 %r12
pushq %rbx
pushq %rax
movq 0x8(%rsi), %r14
movzbl (%r14), %eax
cmpl $0xb, %eax
je 0x6df63
movq %rdi, %rbx
cmpl $0xd, %eax
je 0x6de34
cmpl $0xc, %eax
jne 0x6dea9
movq 0x8(%r14), %rcx
movq %rcx, %rax
cqto
idivq 0x10(%r14)
movq %rax, %r15
testq %rcx, %rcx
jns 0x6ded9
movq %r15, %r12
decq %r12
cmpq $0x7ff, %r12            # imm = 0x7FF
ja 0x6df2a
leaq 0xe0b26(%rip), %rax     # 0x14e950
movq -0x8(%rax,%r15,8), %r14
jmp 0x6df63
movsd 0x8(%r14), %xmm0
ucomisd %xmm0, %xmm0
jp 0x6df72
movapd 0xa4f84(%rip), %xmm1    # 0x112dd0
andpd %xmm0, %xmm1
ucomisd 0xa1280(%rip), %xmm1    # 0x10f0d8
jbe 0x6decf
movq 0xf08(%rbx), %rax
movq 0x8(%rax), %rax
movq 0xe4bd4(%rip), %rcx     # 0x152a40
movq 0x1ef8(%rbx), %rdx
movq 0x10(%rdx), %rdx
movq %rax, 0x8(%rdx)
movq 0x10(%rdx), %rax
movq %r14, 0x8(%rax)
movq 0x10(%rax), %rax
movq %rcx, 0x8(%rax)
movq 0x1948(%rbx), %r14
movq 0x1ef8(%rbx), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3b366
jmp 0x6df63
movq %rsi, %rcx
movq 0xf08(%rbx), %rdx
movq %rbx, %rdi
movq %r14, %rsi
movl $0xd, %r8d
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x9b739
callq 0x95f0
cvttsd2si %xmm0, %r15
cmpq $0x7ff, %r15            # imm = 0x7FF
ja 0x6deef
leaq 0xe0a67(%rip), %rax     # 0x14e950
movq (%rax,%r15,8), %r14
jmp 0x6df63
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x6df07
movq %rbx, %rdi
callq 0xb389
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r14
movq $0xb, (%r14)
movq %r15, 0x8(%r14)
jmp 0x6df63
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x6df42
movq %rbx, %rdi
callq 0xb389
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r14
movq $0xb, (%r14)
movq %r12, 0x8(%r14)
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq 0xf08(%rbx), %rax
movq 0x8(%rax), %rax
movq 0xef6bc(%rip), %rcx     # 0x15d640
jmp 0x6de6c