// File: /workspace/github_c_makefile_star2_O3/BernardTatin[P]s7sh/s7.c
// Function: g_quotient
static s7_pointer g_quotient(s7_scheme *sc, s7_pointer args)
    {
#define H_quotient "(quotient x1 x2) returns the integer quotient of x1 and x2; (quotient 4 3) = 1"
#define Q_quotient s7_make_signature(sc, 3, sc->is_integer_symbol, sc->is_real_symbol, sc->is_real_symbol)
        /* (define (quo x1 x2) (truncate (/ x1 x2))) ; slib */
        s7_pointer x, y;
        s7_int d1, d2, n1, n2;

        x = car(args);
        y = cadr(args);
        if ((is_t_integer(x)) && (is_t_integer(y)))
            return(make_integer(sc, c_quo_int(sc, integer(x), integer(y))));

        switch (type(x))
        {
            case T_INTEGER:
                switch (type(y))
                {
                    case T_INTEGER:
                        return(make_integer(sc, c_quo_int(sc, integer(x), integer(y))));

                    case T_RATIO:
                        n1 = integer(x);
                        d1 = 1;
                        n2 = numerator(y);
                        d2 = denominator(y);
                        /* (quotient -9223372036854775808 -1/9223372036854775807): arithmetic exception in the no-overflow-checks case */
                        goto RATIO_QUO_RATIO;

                    case T_REAL:
                        if (real(y) == 0.0)
                            return(division_by_zero_error(sc, sc->quotient_symbol, args));
                        if ((is_inf(real(y))) || (is_NaN(real(y))))
                            return(wrong_type_argument_with_type(sc, sc->quotient_symbol, 2, y, a_normal_real_string));
                        return(s7_truncate(sc, sc->quotient_symbol, (s7_double)integer(x) / real(y))); /* s7_truncate returns an integer */

                    default:
                        return(method_or_bust(sc, y, sc->quotient_symbol, args, T_REAL, 2));
                }

            case T_RATIO:
                switch (type(y))
                {
                    case T_INTEGER:
                        if (integer(y) == 0)
                            return(division_by_zero_error(sc, sc->quotient_symbol, args));
                        n1 = numerator(x);
                        d1 = denominator(x);
                        n2 = integer(y);
                        d2 = 1;
                        goto RATIO_QUO_RATIO;
                        /* this can lose:
                         *   (quotient 1 2305843009213693952/4611686018427387903) -> 2, not 1
                         *   (quotient 21053343141/6701487259 3587785776203/1142027682075) -> 1, not 0
                         */

                    case T_RATIO:
                        n1 = numerator(x);
                        d1 = denominator(x);
                        n2 = numerator(y);
                        d2 = denominator(y);
RATIO_QUO_RATIO:
                        if (d1 == d2)
                            return(make_integer(sc, n1 / n2));              /* (quotient 3/9223372036854775807 1/9223372036854775807) */
                        if (n1 == n2)
                            return(make_integer(sc, d2 / d1));              /* (quotient 9223372036854775807/2 9223372036854775807/8) */
#if HAVE_OVERFLOW_CHECKS
                        {
                            s7_int n1d2, n2d1;
                            if ((multiply_overflow(n1, d2, &n1d2)) ||
                                    (multiply_overflow(n2, d1, &n2d1)))
                                return(s7_truncate(sc, sc->quotient_symbol, ((long_double)n1 / (long_double)n2) * ((long_double)d2 / (long_double)d1)));
                            return(make_integer(sc, n1d2 / n2d1));
                        }
#else
                        return(make_integer(sc, (n1 * d2) / (n2 * d1)));
#endif

                    case T_REAL:
                        if (real(y) == 0.0)
                            return(division_by_zero_error(sc, sc->quotient_symbol, args));
                        if ((is_inf(real(y))) || (is_NaN(real(y))))
                            return(wrong_type_argument_with_type(sc, sc->quotient_symbol, 2, y, a_normal_real_string));
                        return(s7_truncate(sc, sc->quotient_symbol, (s7_double)fraction(x) / real(y)));

                    default:
                        return(method_or_bust(sc, y, sc->quotient_symbol, args, T_REAL, 2));
                }

            case T_REAL:
                if ((is_inf(real(x))) || (is_NaN(real(x))))
                    return(wrong_type_argument_with_type(sc, sc->quotient_symbol, 1, x, a_normal_real_string));

                /* if infs allowed we need to return infs/nans, else:
                 *    (quotient inf.0 1e-309) -> -9223372036854775808
                 *    (quotient inf.0 inf.0) -> -9223372036854775808
                 */

                switch (type(y))
                {
                    case T_INTEGER:
                        if (integer(y) == 0)
                            return(division_by_zero_error(sc, sc->quotient_symbol, args));
                        return(s7_truncate(sc, sc->quotient_symbol, real(x) / (s7_double)integer(y)));

                    case T_RATIO:
                        return(s7_truncate(sc, sc->quotient_symbol, real(x) / (s7_double)fraction(y)));

                    case T_REAL:
                        return(make_integer(sc, c_quo_dbl(sc, real(x), real(y)))); /* c_quo_dbl returns an integer */

                    default:
                        return(method_or_bust(sc, y, sc->quotient_symbol, args, T_REAL, 2));
                }

            default:
                return(method_or_bust(sc, x, sc->quotient_symbol, args, T_REAL, 2));
        }
    }

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x60, %rsp
movq %rsi, %r8
movq %rdi, %rbx
movq 0x8(%rsi), %r10
movq 0x10(%rsi), %rax
movq 0x8(%rax), %rcx
movzbl (%r10), %eax
cmpl $0xd, %eax
je 0x6bdeb
cmpl $0xc, %eax
je 0x6bdb2
cmpl $0xb, %eax
jne 0x6be3e
movzbl (%rcx), %eax
cmpl $0xd, %eax
je 0x6bf54
cmpl $0xc, %eax
je 0x6bf21
cmpl $0xb, %eax
jne 0x6be85
movq 0x8(%r10), %r14
movq 0x8(%rcx), %r15
cmpq $-0x1, %r15
je 0x6c067
testq %r15, %r15
jne 0x6c10a
movq 0x1418(%rbx), %rsi
movq 0x1f00(%rbx), %rax
movq %r14, 0x8(%rax)
movq 0x1f00(%rbx), %rax
movq 0x1f08(%rbx), %rcx
movq $0x0, 0x8(%rcx)
movq 0x1f08(%rbx), %rcx
movq 0x6e0(%rbx), %rdx
movq %rax, 0x8(%rdx)
movq 0x6e0(%rbx), %rax
movq 0x10(%rax), %rax
movq %rcx, 0x8(%rax)
movq 0x6e0(%rbx), %rdx
movq %rbx, %rdi
callq 0xd434
jmp 0x6c10a
movzbl (%rcx), %eax
cmpl $0xd, %eax
je 0x6bebd
cmpl $0xc, %eax
je 0x6beaf
cmpl $0xb, %eax
jne 0x6be85
movq 0x8(%rcx), %rdi
testq %rdi, %rdi
je 0x6bf6d
movq 0x10(%r10), %r8
movl $0x1, %eax
jmp 0x6bf2f
movq 0x8(%r10), %xmm0
movq %xmm0, %rax
btrq $0x3f, %rax
movabsq $0x7ff0000000000000, %rdx # imm = 0x7FF0000000000000
cmpq %rdx, %rax
jl 0x6be4d
movq 0x1418(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xdab3c(%rip), %rdx     # 0x146958
movq 0x140(%rbx), %r8
movq 0xdec0e(%rip), %r9      # 0x14aa38
movq %rbx, %rdi
movq %r10, %rcx
addq $0x60, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0xa4e4
movq 0x1418(%rbx), %rdx
movq %rbx, %rdi
movq %r10, %rsi
jmp 0x6be92
movzbl (%rcx), %eax
cmpl $0xd, %eax
je 0x6c010
cmpl $0xc, %eax
je 0x6bfde
cmpl $0xb, %eax
jne 0x6be85
movq 0x8(%rcx), %rax
movq 0x1418(%rbx), %rsi
testq %rax, %rax
je 0x6bf74
cvtsi2sd %rax, %xmm1
jmp 0x6c176
movq 0x1418(%rbx), %rdx
movq %rbx, %rdi
movq %rcx, %rsi
movq %r8, %rcx
movl $0xd, %r8d
movl $0x2, %r9d
addq $0x60, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0xe42d
movq 0x10(%r10), %r8
movq 0x8(%rcx), %rdi
movq 0x10(%rcx), %rax
jmp 0x6bf2f
movsd 0x8(%rcx), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x6bed2
jnp 0x6bf6d
movq %xmm1, %rax
btrq $0x3f, %rax
movabsq $0x7ff0000000000000, %rdx # imm = 0x7FF0000000000000
movq 0x1418(%rbx), %rsi
cmpq %rdx, %rax
jge 0x6c046
movq 0x8(%r10), %rax
movq 0x10(%r10), %rcx
movq %rax, 0x58(%rsp)
fildll 0x58(%rsp)
movq %rcx, 0x50(%rsp)
fildll 0x50(%rsp)
fdivrp %st, %st(1)
fstpl 0x48(%rsp)
movq 0x48(%rsp), %xmm0
jmp 0x6c176
movq 0x8(%rcx), %rdi
movq 0x10(%rcx), %rax
movl $0x1, %r8d
movq 0x8(%r10), %rcx
cmpq %rax, %r8
jne 0x6bf45
movq %rcx, %rax
cqto
idivq %rdi
jmp 0x6c112
cmpq %rdi, %rcx
jne 0x6bf88
cqto
idivq %r8
jmp 0x6c112
movsd 0x8(%rcx), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x6c022
jp 0x6c022
movq 0x1418(%rbx), %rsi
movq %rbx, %rdi
movq %r8, %rdx
addq $0x60, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0xd434
movq %rcx, %rdx
imulq %rax, %rdx
jo 0x6bf9e
movq %rdi, %rsi
imulq %r8, %rsi
jno 0x6c18b
movq 0x1418(%rbx), %rsi
movq %rcx, 0x10(%rsp)
fildll 0x10(%rsp)
movq %rdi, 0x18(%rsp)
fildll 0x18(%rsp)
fdivrp %st, %st(1)
movq %rax, 0x20(%rsp)
fildll 0x20(%rsp)
movq %r8, 0x28(%rsp)
fildll 0x28(%rsp)
fdivrp %st, %st(1)
fmulp %st, %st(1)
fstpl 0x8(%rsp)
movsd 0x8(%rsp), %xmm0
jmp 0x6c17a
movq 0x1418(%rbx), %rsi
movq 0x8(%rcx), %rax
movq 0x10(%rcx), %rcx
movq %rax, 0x40(%rsp)
fildll 0x40(%rsp)
movq %rcx, 0x38(%rsp)
fildll 0x38(%rsp)
fdivrp %st, %st(1)
fstpl 0x30(%rsp)
divsd 0x30(%rsp), %xmm0
jmp 0x6c17a
movsd 0x8(%rcx), %xmm1
movq %rbx, %rdi
callq 0xfc13e
jmp 0x6c112
movq %xmm1, %rax
btrq $0x3f, %rax
movabsq $0x7ff0000000000000, %rdx # imm = 0x7FF0000000000000
movq 0x1418(%rbx), %rsi
cmpq %rdx, %rax
jl 0x6c16d
movq 0x8(%rsi), %rsi
movq 0xda90f(%rip), %rdx     # 0x146960
movq 0x140(%rbx), %r8
movq 0xde9d9(%rip), %r9      # 0x14aa38
movq %rbx, %rdi
jmp 0x6be30
movl 0xde9bb(%rip), %eax     # 0x14aa28
shlq $0x3f, %rax
cmpq %r14, %rax
jne 0x6c10a
movq 0x1418(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x1f00(%rbx), %rcx
movq %r14, 0x8(%rcx)
movq 0x1f00(%rbx), %rcx
movq 0x1f08(%rbx), %rdx
movq $-0x1, 0x8(%rdx)
movq 0x1f08(%rbx), %rdx
movq 0x6e0(%rbx), %rsi
movq %rcx, 0x8(%rsi)
movq 0x6e0(%rbx), %rcx
movq 0x10(%rcx), %rcx
movq %rdx, 0x8(%rcx)
movq 0x6e0(%rbx), %rcx
movq 0xde96b(%rip), %rdx     # 0x14aa40
movq 0x1ef8(%rbx), %rsi
movq 0x10(%rsi), %rsi
movq %rax, 0x8(%rsi)
movq 0x10(%rsi), %rax
movq %rcx, 0x8(%rax)
movq 0x10(%rax), %rax
movq %rdx, 0x8(%rax)
movq 0x1948(%rbx), %rsi
movq 0x1ef8(%rbx), %rdx
movq %rbx, %rdi
callq 0x38dfa
movq %r14, %rax
cqto
idivq %r15
movq %rax, %r14
cmpq $0x7ff, %rax            # imm = 0x7FF
ja 0x6c12a
leaq 0xda82c(%rip), %rax     # 0x146950
movq (%rax,%r14,8), %rax
jmp 0x6c163
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x6c149
movq %rbx, %rdi
callq 0xa550
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rax
movq $0xb, (%rax)
movq %r14, 0x8(%rax)
addq $0x60, %rsp
popq %rbx
popq %r14
popq %r15
retq
xorps %xmm0, %xmm0
cvtsi2sdq 0x8(%r10), %xmm0
divsd %xmm1, %xmm0
movq %rbx, %rdi
addq $0x60, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0xfa9a8
movq %rdx, %rax
cqto
idivq %rsi
jmp 0x6c112