// File: /workspace/github_c_makefile_star2_O2/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 %r14
pushq %rbx
subq $0x68, %rsp
movq %rsi, %rax
movq %rdi, %rbx
movq 0x8(%rsi), %r10
movq 0x10(%rsi), %rcx
movq 0x8(%rcx), %rcx
movzbl (%r10), %edx
cmpl $0xd, %edx
je 0x56d4d
cmpl $0xc, %edx
je 0x56d16
cmpl $0xb, %edx
jne 0x56d9e
movzbl (%rcx), %edx
cmpl $0xd, %edx
je 0x56ecb
cmpl $0xc, %edx
je 0x56e83
cmpl $0xb, %edx
jne 0x56ded
movq 0x8(%r10), %rsi
movq 0x8(%rcx), %rdx
movq %rbx, %rdi
callq 0xc91db
jmp 0x56eac
movzbl (%rcx), %edx
cmpl $0xd, %edx
je 0x56e1f
cmpl $0xc, %edx
je 0x56e11
cmpl $0xb, %edx
jne 0x56ded
movq 0x8(%rcx), %rdi
testq %rdi, %rdi
je 0x56ee4
movq 0x10(%r10), %r8
pushq $0x1
popq %rax
jmp 0x56e8f
movq 0x8(%r10), %xmm0
movq %xmm0, %rdx
btrq $0x3f, %rdx
movabsq $0x7ff0000000000000, %r14 # imm = 0x7FF0000000000000
cmpq %r14, %rdx
jl 0x56db5
movq 0x1418(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xbebda(%rip), %rdx     # 0x115958
movq 0x140(%rbx), %r8
movq 0xc2cac(%rip), %r9      # 0x119a38
movq %rbx, %rdi
movq %r10, %rcx
addq $0x68, %rsp
popq %rbx
popq %r14
jmp 0x9bbb
movq 0x1418(%rbx), %rdx
pushq $0xd
popq %r8
pushq $0x2
popq %r9
movq %rbx, %rdi
movq %r10, %rsi
jmp 0x56e02
movzbl (%rcx), %edx
cmpl $0xd, %edx
je 0x56f85
cmpl $0xc, %edx
je 0x56f53
cmpl $0xb, %edx
jne 0x56ded
movq 0x8(%rcx), %rcx
movq 0x1418(%rbx), %rsi
testq %rcx, %rcx
je 0x56eeb
cvtsi2sd %rcx, %xmm1
jmp 0x570ce
movq 0x1418(%rbx), %rdx
pushq $0xd
popq %r8
pushq $0x2
popq %r9
movq %rbx, %rdi
movq %rcx, %rsi
movq %rax, %rcx
addq $0x68, %rsp
popq %rbx
popq %r14
jmp 0xcd70
movq 0x10(%r10), %r8
movq 0x8(%rcx), %rdi
movq 0x10(%rcx), %rax
jmp 0x56e8f
movsd 0x8(%rcx), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x56e34
jnp 0x56ee4
movq %xmm1, %rax
btrq $0x3f, %rax
movabsq $0x7ff0000000000000, %rdx # imm = 0x7FF0000000000000
movq 0x1418(%rbx), %rsi
cmpq %rdx, %rax
jge 0x5708a
movq 0x8(%r10), %rax
movq 0x10(%r10), %rcx
movq %rax, 0x60(%rsp)
fildll 0x60(%rsp)
movq %rcx, 0x58(%rsp)
fildll 0x58(%rsp)
fdivrp %st, %st(1)
fstpl 0x50(%rsp)
movq 0x50(%rsp), %xmm0
jmp 0x570ce
movq 0x8(%rcx), %rdi
movq 0x10(%rcx), %rax
pushq $0x1
popq %r8
movq 0x8(%r10), %rcx
cmpq %rax, %r8
jne 0x56ea2
movq %rcx, %rax
cqto
idivq %rdi
jmp 0x56eac
cmpq %rdi, %rcx
jne 0x56efd
cqto
idivq %r8
movq %rax, %r14
cmpq $0x7ff, %rax            # imm = 0x7FF
ja 0x5715b
leaq 0xbea8e(%rip), %rax     # 0x115950
movq (%rax,%r14,8), %rax
jmp 0x57194
movsd 0x8(%rcx), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x5706a
jp 0x5706a
movq 0x1418(%rbx), %rsi
movq %rbx, %rdi
movq %rax, %rdx
addq $0x68, %rsp
popq %rbx
popq %r14
jmp 0xc1ff
movq %rcx, %rdx
imulq %rax, %rdx
jo 0x56f13
movq %rdi, %rsi
imulq %r8, %rsi
jno 0x570e1
movq 0x1418(%rbx), %rsi
movq %rcx, 0x18(%rsp)
fildll 0x18(%rsp)
movq %rdi, 0x20(%rsp)
fildll 0x20(%rsp)
fdivrp %st, %st(1)
movq %rax, 0x28(%rsp)
fildll 0x28(%rsp)
movq %r8, 0x30(%rsp)
fildll 0x30(%rsp)
fdivrp %st, %st(1)
fmulp %st, %st(1)
fstpl 0x10(%rsp)
movsd 0x10(%rsp), %xmm0
jmp 0x570d2
movq 0x1418(%rbx), %rsi
movq 0x8(%rcx), %rax
movq 0x10(%rcx), %rcx
movq %rax, 0x48(%rsp)
fildll 0x48(%rsp)
movq %rcx, 0x40(%rsp)
fildll 0x40(%rsp)
fdivrp %st, %st(1)
fstpl 0x38(%rsp)
divsd 0x38(%rsp), %xmm0
jmp 0x570d2
movsd 0x8(%rcx), %xmm2
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm2
movsd %xmm0, (%rsp)
movsd %xmm2, 0x8(%rsp)
jne 0x57002
jp 0x57002
movq 0x1418(%rbx), %rsi
movq 0x1f18(%rbx), %rax
movsd %xmm0, 0x8(%rax)
movq 0x1f18(%rbx), %rax
movq 0x1f20(%rbx), %rcx
movsd %xmm2, 0x8(%rcx)
movq 0x1f20(%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 0xc1ff
movsd 0x8(%rsp), %xmm2
movsd (%rsp), %xmm0
movq %xmm2, %rax
btrq $0x3f, %rax
cmpq %r14, %rax
jl 0x57057
movq 0x1418(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xbe93d(%rip), %rdx     # 0x115960
movq 0x1f18(%rbx), %rax
movsd %xmm2, 0x8(%rax)
movq 0x1f18(%rbx), %rcx
movq 0x140(%rbx), %r8
movq 0xc29f4(%rip), %r9      # 0x119a38
movq %rbx, %rdi
callq 0x9bbb
movsd 0x8(%rsp), %xmm2
movsd (%rsp), %xmm0
divsd %xmm2, %xmm0
cmpb $0x0, 0xc2ba6(%rip)     # 0x119c08
jne 0x570ab
xorpd %xmm1, %xmm1
jmp 0x570b3
movq %xmm1, %rax
btrq $0x3f, %rax
movabsq $0x7ff0000000000000, %rdx # imm = 0x7FF0000000000000
movq 0x1418(%rbx), %rsi
cmpq %rdx, %rax
jl 0x570c8
movq 0x8(%rsi), %rsi
movq 0xbe8cb(%rip), %rdx     # 0x115960
movq 0x140(%rbx), %r8
movq 0xc2995(%rip), %r9      # 0x119a38
movq %rbx, %rdi
jmp 0x56d92
movsd 0x7af6d(%rip), %xmm1    # 0xd2020
ucomisd %xmm1, %xmm0
ja 0x570fc
cmpb $0x0, 0xc2968(%rip)     # 0x119a28
jne 0x570ee
xorpd %xmm1, %xmm1
jmp 0x570f6
cvtsi2sdq 0x8(%r10), %xmm0
divsd %xmm1, %xmm0
movq %rbx, %rdi
addq $0x68, %rsp
popq %rbx
popq %r14
jmp 0xc7b1c
movq %rdx, %rax
cqto
idivq %rsi
jmp 0x56eac
movsd 0x7af32(%rip), %xmm1    # 0xd2028
ucomisd %xmm0, %xmm1
jbe 0x57133
movq 0x1418(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0x1f18(%rbx), %rax
movsd %xmm0, 0x8(%rax)
movq 0x1f18(%rbx), %rdx
movq 0xc291f(%rip), %rcx     # 0x119a40
movq %rbx, %rdi
movsd %xmm0, (%rsp)
callq 0x35b47
movsd (%rsp), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x57144
callq 0x85f0
jmp 0x57149
callq 0x86c0
cvttsd2si %xmm0, %r14
cmpq $0x7ff, %r14            # imm = 0x7FF
jbe 0x56ebb
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x5717a
movq %rbx, %rdi
callq 0x9c27
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rax
movq $0xb, (%rax)
movq %r14, 0x8(%rax)
addq $0x68, %rsp
popq %rbx
popq %r14
retq