// File: /workspace/github_c_makefile_star2_O0/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:
subq $0xb8, %rsp
movq %rdi, 0xa8(%rsp)
movq %rsi, 0xa0(%rsp)
movq 0xa0(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x98(%rsp)
movq 0x98(%rsp), %rax
movzbl (%rax), %eax
addl $-0xb, %eax
movl %eax, %ecx
movq %rcx, 0x20(%rsp)
subl $0x3, %eax
ja 0x78185
movq 0x20(%rsp), %rax
leaq 0x166cbb(%rip), %rcx    # 0x1dea90
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x98(%rsp), %rax
movq %rax, 0xb0(%rsp)
jmp 0x781bf
movq 0x98(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x98(%rsp), %rcx
cqto
idivq 0x10(%rcx)
movq %rax, 0x90(%rsp)
movq 0x98(%rsp), %rax
cmpq $0x0, 0x8(%rax)
jge 0x77f15
movq 0x90(%rsp), %rax
subq $0x1, %rax
movq %rax, 0x88(%rsp)
movq 0x88(%rsp), %rax
andq $-0x800, %rax           # imm = 0xF800
cmpq $0x0, %rax
jne 0x77e6d
movq 0x88(%rsp), %rcx
leaq 0x19e621(%rip), %rax    # 0x216480
movq (%rax,%rcx,8), %rax
movq %rax, 0x18(%rsp)
jmp 0x77ef3
jmp 0x77e6f
movq 0xa8(%rsp), %rax
movq 0x90(%rax), %rax
movq 0xa8(%rsp), %rcx
cmpq 0x98(%rcx), %rax
ja 0x77e9c
movq 0xa8(%rsp), %rdi
callq 0xc670
movq 0xa8(%rsp), %rcx
movq 0x90(%rcx), %rax
movq %rax, %rdx
addq $-0x8, %rdx
movq %rdx, 0x90(%rcx)
movq -0x8(%rax), %rax
movq %rax, 0x78(%rsp)
movq 0x78(%rsp), %rax
movq $0xb, (%rax)
movq 0x88(%rsp), %rcx
movq 0x78(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x78(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0xb0(%rsp)
jmp 0x781bf
movq 0x90(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x68(%rsp), %rax
andq $-0x800, %rax           # imm = 0xF800
cmpq $0x0, %rax
jne 0x77f4d
movq 0x68(%rsp), %rcx
leaq 0x19e541(%rip), %rax    # 0x216480
movq (%rax,%rcx,8), %rax
movq %rax, 0x10(%rsp)
jmp 0x77fd0
jmp 0x77f4f
movq 0xa8(%rsp), %rax
movq 0x90(%rax), %rax
movq 0xa8(%rsp), %rcx
cmpq 0x98(%rcx), %rax
ja 0x77f7c
movq 0xa8(%rsp), %rdi
callq 0xc670
movq 0xa8(%rsp), %rcx
movq 0x90(%rcx), %rax
movq %rax, %rdx
addq $-0x8, %rdx
movq %rdx, 0x90(%rcx)
movq -0x8(%rax), %rax
movq %rax, 0x58(%rsp)
movq 0x58(%rsp), %rax
movq $0xb, (%rax)
movq 0x68(%rsp), %rcx
movq 0x58(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x58(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0xb0(%rsp)
jmp 0x781bf
movq 0x98(%rsp), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x48(%rsp), %xmm0
callq 0x13860
testb $0x1, %al
jne 0x78010
jmp 0x7804c
movq 0xa8(%rsp), %rdi
movq 0xa8(%rsp), %rax
movq 0xf08(%rax), %rax
movq 0x8(%rax), %rsi
movq 0x98(%rsp), %rdx
movq 0x1ad1b6(%rip), %rcx    # 0x2251f0
callq 0x45240
movq %rax, 0xb0(%rsp)
jmp 0x781bf
movsd 0x48(%rsp), %xmm0
movaps 0x169a47(%rip), %xmm1   # 0x1e1aa0
pand %xmm1, %xmm0
movsd 0x1699bb(%rip), %xmm1   # 0x1e1a20
ucomisd %xmm1, %xmm0
jbe 0x780a7
movq 0xa8(%rsp), %rdi
movq 0xa8(%rsp), %rax
movq 0xf08(%rax), %rax
movq 0x8(%rax), %rsi
movq 0x98(%rsp), %rdx
movq 0x1a24db(%rip), %rcx    # 0x21a570
callq 0x45240
movq %rax, 0xb0(%rsp)
jmp 0x781bf
movsd 0x48(%rsp), %xmm0
callq 0x95f0
cvttsd2si %xmm0, %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rax
andq $-0x800, %rax           # imm = 0xF800
cmpq $0x0, %rax
jne 0x780e7
movq 0x40(%rsp), %rcx
leaq 0x19e3a7(%rip), %rax    # 0x216480
movq (%rax,%rcx,8), %rax
movq %rax, 0x8(%rsp)
jmp 0x7816a
jmp 0x780e9
movq 0xa8(%rsp), %rax
movq 0x90(%rax), %rax
movq 0xa8(%rsp), %rcx
cmpq 0x98(%rcx), %rax
ja 0x78116
movq 0xa8(%rsp), %rdi
callq 0xc670
movq 0xa8(%rsp), %rcx
movq 0x90(%rcx), %rax
movq %rax, %rdx
addq $-0x8, %rdx
movq %rdx, 0x90(%rcx)
movq -0x8(%rax), %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
movq $0xb, (%rax)
movq 0x40(%rsp), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x30(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0xb0(%rsp)
jmp 0x781bf
jmp 0x78185
movq 0xa8(%rsp), %rdi
movq 0x98(%rsp), %rsi
movq 0xa8(%rsp), %rax
movq 0xf08(%rax), %rdx
movq 0xa0(%rsp), %rcx
movl $0xd, %r8d
callq 0xcfd30
movq %rax, 0xb0(%rsp)
movq 0xb0(%rsp), %rax
addq $0xb8, %rsp
retq
nop