// File: /workspace/github_c_makefile_star2_O1/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 0x714d9
cmpl $0xc, %eax
je 0x714a0
cmpl $0xb, %eax
jne 0x7152c
cmpb $0xb, (%rcx)
jne 0x7146a
movq 0x8(%r10), %r14
movq 0x8(%rcx), %r15
cmpq $-0x1, %r15
je 0x71602
testq %r15, %r15
jne 0x716a5
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 0xe1ae
jmp 0x716a5
cmpl $0xd, %eax
je 0x714d9
cmpl $0xc, %eax
je 0x714a0
cmpl $0xb, %eax
jne 0x7152c
movzbl (%rcx), %eax
cmpl $0xd, %eax
je 0x7182b
cmpl $0xc, %eax
je 0x71818
cmpl $0xb, %eax
je 0x713f2
jmp 0x7156f
movzbl (%rcx), %eax
cmpl $0xd, %eax
je 0x715bb
cmpl $0xc, %eax
je 0x71599
cmpl $0xb, %eax
jne 0x7156f
movq 0x8(%rcx), %rdi
testq %rdi, %rdi
je 0x715d4
movq 0x10(%r10), %r8
movl $0x1, %eax
jmp 0x715a5
movq 0x8(%r10), %xmm0
movq %xmm0, %rax
btrq $0x3f, %rax
movabsq $0x7ff0000000000000, %rdx # imm = 0x7FF0000000000000
cmpq %rdx, %rax
jl 0x7153b
movq 0x1418(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xdd44e(%rip), %rdx     # 0x14e958
movq 0x140(%rbx), %r8
movq 0xe1520(%rip), %r9      # 0x152a38
movq %rbx, %rdi
movq %r10, %rcx
addq $0x60, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0xb31d
movq 0x1418(%rbx), %rdx
movq %rbx, %rdi
movq %r10, %rsi
jmp 0x7157c
movzbl (%rcx), %eax
cmpl $0xd, %eax
je 0x716e1
cmpl $0xc, %eax
je 0x716af
cmpl $0xb, %eax
jne 0x7156f
movq 0x8(%rcx), %rax
movq 0x1418(%rbx), %rsi
testq %rax, %rax
je 0x715db
cvtsi2sd %rax, %xmm1
jmp 0x71803
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 0xf1ae
movq 0x10(%r10), %r8
movq 0x8(%rcx), %rdi
movq 0x10(%rcx), %rax
movq 0x8(%r10), %rcx
cmpq %rax, %r8
jne 0x715ef
movq %rcx, %rax
cqto
idivq %rdi
jmp 0x716ee
movsd 0x8(%rcx), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x7179c
jp 0x7179c
movq 0x1418(%rbx), %rsi
movq %rbx, %rdi
movq %r8, %rdx
addq $0x60, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0xe1ae
cmpq %rdi, %rcx
jne 0x71749
cqto
idivq %r8
jmp 0x716ee
movl 0xe1420(%rip), %eax     # 0x152a28
shlq $0x3f, %rax
cmpq %r14, %rax
jne 0x716a5
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 0xe13d0(%rip), %rdx     # 0x152a40
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 0x3b366
movq %r14, %rax
cqto
idivq %r15
jmp 0x716ee
movq 0x1418(%rbx), %rsi
movq 0x8(%rcx), %rax
movq 0x10(%rcx), %rcx
movq %rax, 0x58(%rsp)
fildll 0x58(%rsp)
movq %rcx, 0x50(%rsp)
fildll 0x50(%rsp)
fdivrp %st, %st(1)
fstpl 0x48(%rsp)
divsd 0x48(%rsp), %xmm0
jmp 0x71807
movsd 0x8(%rcx), %xmm1
movq %rbx, %rdi
callq 0x1052d5
movq %rax, %r14
cmpq $0x7ff, %rax            # imm = 0x7FF
ja 0x71706
leaq 0xdd250(%rip), %rax     # 0x14e950
movq (%rax,%r14,8), %rax
jmp 0x7173f
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x7171e
movq %rbx, %rdi
callq 0xb389
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
movq %rcx, %rdx
imulq %rax, %rdx
jo 0x7175f
movq %rdi, %rsi
imulq %r8, %rsi
jno 0x7186f
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 0x71807
movq %xmm1, %rax
btrq $0x3f, %rax
movabsq $0x7ff0000000000000, %rdx # imm = 0x7FF0000000000000
movq 0x1418(%rbx), %rsi
cmpq %rdx, %rax
jl 0x717dd
movq 0x8(%rsi), %rsi
movq 0xdd199(%rip), %rdx     # 0x14e960
movq 0x140(%rbx), %r8
movq 0xe1263(%rip), %r9      # 0x152a38
movq %rbx, %rdi
jmp 0x7151e
movq 0x8(%r10), %rax
movq 0x10(%r10), %rcx
movq %rax, 0x40(%rsp)
fildll 0x40(%rsp)
movq %rcx, 0x38(%rsp)
fildll 0x38(%rsp)
fdivrp %st, %st(1)
fstpl 0x30(%rsp)
movq 0x30(%rsp), %xmm0
divsd %xmm1, %xmm0
movq %rbx, %rdi
addq $0x60, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0x103785
movq 0x8(%rcx), %rdi
movq 0x10(%rcx), %rax
movl $0x1, %r8d
jmp 0x715a5
movsd 0x8(%rcx), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x71840
jnp 0x715d4
movq %xmm1, %rax
btrq $0x3f, %rax
movabsq $0x7ff0000000000000, %rdx # imm = 0x7FF0000000000000
movq 0x1418(%rbx), %rsi
cmpq %rdx, %rax
jge 0x717bc
xorps %xmm0, %xmm0
cvtsi2sdq 0x8(%r10), %xmm0
jmp 0x71803
movq %rdx, %rax
cqto
idivq %rsi
jmp 0x716ee