// File: /workspace/github_c_makefile_star2_O2/BernardTatin[P]s7sh/s7.c
// Function: remainder_p_pp
static s7_pointer remainder_p_pp(s7_scheme *sc, s7_pointer x, s7_pointer y)
    {
#define H_remainder "(remainder x1 x2) returns the remainder of x1/x2; (remainder 10 3) = 1"
#define Q_remainder sc->pcl_r
        /* (define (rem x1 x2) (- x1 (* x2 (quo x1 x2)))) ; slib, if x2 is an integer (- x1 (truncate x1 x2)), fractional part: (remainder x 1) */

        s7_int quo, d1, d2, n1, n2;
        s7_double pre_quo;

        if ((is_t_integer(x)) && (is_t_integer(y)))
            return(make_integer(sc, c_rem_int(sc, integer(x), integer(y))));

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

                    case T_RATIO:
                        n1 = integer(x);
                        d1 = 1;
                        n2 = numerator(y);
                        d2 = denominator(y);
                        goto RATIO_REM_RATIO;

                    case T_REAL:
                        if (real(y) == 0.0)
                            return(division_by_zero_error(sc, sc->remainder_symbol, set_elist_2(sc, x, y)));
                        if ((is_inf(real(y))) || (is_NaN(real(y))))
                            return(wrong_type_argument_with_type(sc, sc->remainder_symbol, 2, y, a_normal_real_string));

                        pre_quo = (s7_double)integer(x) / real(y);
                        if ((pre_quo > s7_int_max) || (pre_quo < s7_int_min))
                            return(simple_out_of_range(sc, sc->remainder_symbol, set_elist_2(sc, x, y), its_too_large_string));
                        if (pre_quo > 0.0) quo = (s7_int)floor(pre_quo); else quo = (s7_int)ceil(pre_quo);
                        return(make_real(sc, integer(x) - real(y) * quo));

                    default:
                        return(method_or_bust(sc, y, sc->remainder_symbol, list_2(sc, x, y), T_REAL, 2));
                }

            case T_RATIO:
                switch (type(y))
                {
                    case T_INTEGER:
                        n2 = integer(y);
                        if (n2 == 0)
                            return(division_by_zero_error(sc, sc->remainder_symbol, set_elist_2(sc, x, y)));
                        n1 = numerator(x);
                        d1 = denominator(x);
                        d2 = 1;
                        goto RATIO_REM_RATIO;

                    case T_RATIO:
                        n1 = numerator(x);
                        d1 = denominator(x);
                        n2 = numerator(y);
                        d2 = denominator(y);
RATIO_REM_RATIO:
                        if (d1 == d2)
                            quo = (s7_int)(n1 / n2);
                        else
                        {
                            if (n1 == n2)
                                quo = (s7_int)(d2 / d1);
                            else
                            {
#if HAVE_OVERFLOW_CHECKS
                                s7_int n1d2, n2d1;
                                if ((multiply_overflow(n1, d2, &n1d2)) ||
                                        (multiply_overflow(n2, d1, &n2d1)))
                                {
                                    pre_quo = ((long_double)n1 / (long_double)n2) * ((long_double)d2 / (long_double)d1);
                                    if ((pre_quo > s7_int_max) || (pre_quo < s7_int_min))
                                        return(simple_out_of_range(sc, sc->remainder_symbol, set_elist_2(sc, x, y), its_too_large_string));
                                    if (pre_quo > 0.0) quo = (s7_int)floor(pre_quo); else quo = (s7_int)ceil(pre_quo);
                                }
                                else quo = n1d2 / n2d1;
#else
                                quo = (n1 * d2) / (n2 * d1);
#endif
                            }
                        }
                        if (quo == 0)
                            return(x);

#if HAVE_OVERFLOW_CHECKS
                        {
                            s7_int dn, nq;
                            if (!multiply_overflow(n2, quo, &nq))
                            {
                                if ((d1 == d2) &&
                                        (!subtract_overflow(n1, nq, &dn)))
                                    return(s7_make_ratio(sc, dn, d1));

                                if ((!multiply_overflow(n1, d2, &dn)) &&
                                        (!multiply_overflow(nq, d1, &nq)) &&
                                        (!subtract_overflow(dn, nq, &nq)) &&
                                        (!multiply_overflow(d1, d2, &d1)))
                                    return(s7_make_ratio(sc, nq, d1));
                            }
                        }
#else
                        if (d1 == d2)
                            return(s7_make_ratio(sc, n1 - n2 * quo, d1));

                        return(s7_make_ratio(sc, n1 * d2 - n2 * d1 * quo, d1 * d2));
#endif
                        return(simple_out_of_range(sc, sc->remainder_symbol, set_elist_2(sc, x, y), wrap_string(sc, "intermediate (a/b) is too large", 31)));

                    case T_REAL:
                        {
                            s7_double frac;
                            if (real(y) == 0.0)
                                return(division_by_zero_error(sc, sc->remainder_symbol, set_elist_2(sc, x, y)));
                            if ((is_inf(real(y))) || (is_NaN(real(y))))
                                return(wrong_type_argument_with_type(sc, sc->remainder_symbol, 2, y, a_normal_real_string));
                            frac = (s7_double)fraction(x);
                            pre_quo = frac / real(y);
                            if ((pre_quo > s7_int_max) || (pre_quo < s7_int_min))
                                return(simple_out_of_range(sc, sc->remainder_symbol, set_elist_2(sc, x, y), its_too_large_string));
                            if (pre_quo > 0.0) quo = (s7_int)floor(pre_quo); else quo = (s7_int)ceil(pre_quo);
                            return(make_real(sc, frac - real(y) * quo));
                        }

                    default:
                        return(method_or_bust(sc, y, sc->remainder_symbol, list_2(sc, x, y), T_REAL, 2));
                }

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

                switch (type(y))
                {
                    case T_INTEGER:
                        if (integer(y) == 0)
                            return(division_by_zero_error(sc, sc->remainder_symbol, set_elist_2(sc, x, y)));
                        pre_quo = real(x) / (s7_double)integer(y);
                        if ((pre_quo > s7_int_max) || (pre_quo < s7_int_min))
                            return(simple_out_of_range(sc, sc->remainder_symbol, set_elist_2(sc, x, y), its_too_large_string));
                        if (pre_quo > 0.0) quo = (s7_int)floor(pre_quo); else quo = (s7_int)ceil(pre_quo);
                        return(make_real(sc, real(x) - integer(y) * quo));
                        /* but... (remainder 1e+18 9223372036854775807) -> 1e+18 */

                    case T_RATIO:
                        {
                            /* bad cases here start around 1e16: (remainder 1e15 3/13) -> 0.0 with loss of digits earlier
                             *   would long double help?
                             */
                            s7_double frac;
                            frac = (s7_double)fraction(y);
                            pre_quo = real(x) / frac;
                            if ((pre_quo > s7_int_max) || (pre_quo < s7_int_min))
                                return(simple_out_of_range(sc, sc->remainder_symbol, set_elist_2(sc, x, y), its_too_large_string));
                            if (pre_quo > 0.0) quo = (s7_int)floor(pre_quo); else quo = (s7_int)ceil(pre_quo);
                            return(make_real(sc, real(x) - frac * quo));
                        }

                    case T_REAL:
                        return(make_real(sc, c_rem_dbl(sc, real(x), real(y))));

                        /* see under sin -- this calculation is completely bogus if "a" is large
                         * (quotient 1e22 (* 2 pi)) -> -9223372036854775808 -- should this return arithmetic-overflow?
                         *          but it should be 1591549430918953357688,
                         * (remainder 1e22 (* 2 pi)) -> 1.0057952155665e+22
                         * -- the "remainder" is greater than the original argument!
                         * Clisp gives 0.0 here, as does sbcl
                         * currently s7 throws an error (out-of-range).
                         */

                    default:
                        return(method_or_bust(sc, y, sc->remainder_symbol, list_2(sc, x, y), T_REAL, 2));
                }

            default:
                return(method_or_bust(sc, x, sc->remainder_symbol, list_2(sc, x, y), T_REAL, 1));
        }
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movzbl (%rsi), %eax
cmpl $0xd, %eax
je 0x6a7b3
cmpl $0xc, %eax
je 0x6a77a
cmpl $0xb, %eax
jne 0x6a80f
movzbl (%r14), %eax
cmpl $0xd, %eax
je 0x6aac0
cmpl $0xc, %eax
je 0x6a9f3
cmpl $0xb, %eax
jne 0x6a8da
movq 0x8(%r15), %rsi
movq 0x8(%r14), %rdx
movq %rbx, %rdi
callq 0xd04c4
movq %rax, %r14
cmpq $0x7ff, %rax            # imm = 0x7FF
ja 0x6abba
leaq 0xab1df(%rip), %rax     # 0x115950
movq (%rax,%r14,8), %r15
jmp 0x6ae60
movzbl (%r14), %eax
cmpl $0xd, %eax
je 0x6a97c
cmpl $0xc, %eax
je 0x6a96b
cmpl $0xb, %eax
jne 0x6a8da
movq 0x8(%r14), %r12
testq %r12, %r12
je 0x6aada
movq 0x10(%r15), %r8
pushq $0x1
popq %r13
jmp 0x6a9ff
movq 0x8(%r15), %xmm2
movq %xmm2, %rax
btrq $0x3f, %rax
movabsq $0x7ff0000000000000, %rcx # imm = 0x7FF0000000000000
cmpq %rcx, %rax
jl 0x6a88f
movq 0x1470(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xab170(%rip), %rdx     # 0x115958
movq 0x140(%rbx), %r8
movq 0xaf242(%rip), %r9      # 0x119a38
movq %rbx, %rdi
movq %r15, %rcx
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9bbb
movq 0x1470(%rbx), %r12
movq 0x90(%rbx), %rax
movq 0x110(%rbx), %r13
cmpq 0x98(%rbx), %rax
ja 0x6a83c
movq %rbx, %rdi
callq 0x9c27
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rax
movl $0x200001, %edx         # imm = 0x200001
movq %rdx, (%rax)
movq %r14, 0x8(%rax)
movq %r13, 0x10(%rax)
movq 0x90(%rbx), %rcx
leaq -0x8(%rcx), %rsi
movq %rsi, 0x90(%rbx)
movq -0x8(%rcx), %rcx
movq %rdx, (%rcx)
movq %r15, 0x8(%rcx)
movq %rax, 0x10(%rcx)
pushq $0xd
popq %r8
pushq $0x1
popq %r9
movq %rbx, %rdi
movq %r15, %rsi
jmp 0x6a955
movzbl (%r14), %eax
cmpl $0xd, %eax
je 0x6aba3
cmpl $0xc, %eax
je 0x6ab78
cmpl $0xb, %eax
jne 0x6a8da
movq 0x8(%r14), %r12
testq %r12, %r12
je 0x6aada
cvtsi2sd %r12, %xmm1
movdqa %xmm2, %xmm0
divsd %xmm1, %xmm0
cmpb $0x0, 0xaf33d(%rip)     # 0x119c08
jne 0x6ace7
xorpd %xmm1, %xmm1
jmp 0x6acef
movq 0x1470(%rbx), %r12
movq 0x90(%rbx), %rax
movq 0x110(%rbx), %r13
cmpq 0x98(%rbx), %rax
ja 0x6a907
movq %rbx, %rdi
callq 0x9c27
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rax
movl $0x200001, %edx         # imm = 0x200001
movq %rdx, (%rax)
movq %r14, 0x8(%rax)
movq %r13, 0x10(%rax)
movq 0x90(%rbx), %rcx
leaq -0x8(%rcx), %rsi
movq %rsi, 0x90(%rbx)
movq -0x8(%rcx), %rcx
movq %rdx, (%rcx)
movq %r15, 0x8(%rcx)
movq %rax, 0x10(%rcx)
pushq $0xd
popq %r8
pushq $0x2
popq %r9
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xcd70
movq 0x10(%r15), %r8
movq 0x8(%r14), %r12
movq 0x10(%r14), %r13
jmp 0x6a9ff
movsd 0x8(%r14), %xmm2
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm2
jne 0x6a992
jnp 0x6aada
movq %xmm2, %rax
btrq $0x3f, %rax
movabsq $0x7ff0000000000000, %rcx # imm = 0x7FF0000000000000
cmpq %rcx, %rax
jge 0x6ac11
movq 0x8(%r15), %rax
movq 0x10(%r15), %rcx
movq %rax, 0x60(%rsp)
fildll 0x60(%rsp)
movq %rcx, 0x58(%rsp)
fildll 0x58(%rsp)
fdivrp %st, %st(1)
fstpl 0x50(%rsp)
movsd 0x50(%rsp), %xmm3
movapd %xmm3, %xmm0
divsd %xmm2, %xmm0
cmpb $0x0, 0xaf224(%rip)     # 0x119c08
jne 0x6ad2b
xorpd %xmm1, %xmm1
jmp 0x6ad33
movq 0x8(%r14), %r12
movq 0x10(%r14), %r13
pushq $0x1
popq %r8
movq 0x8(%r15), %rbp
cmpq %r13, %r8
jne 0x6aa12
movq %rbp, %rax
cqto
idivq %r12
jmp 0x6aa23
cmpq %r12, %rbp
jne 0x6ab18
movq %r13, %rax
cqto
idivq %r8
testq %rax, %rax
je 0x6ae60
imulq %rax, %r12
jo 0x6aa5e
cmpq %r13, %r8
jne 0x6aa43
movq %rbp, %rsi
subq %r12, %rsi
jno 0x6aca2
imulq %r13, %rbp
jo 0x6aa5e
imulq %r8, %r12
jo 0x6aa5e
subq %r12, %rbp
jo 0x6aa5e
imulq %r13, %r8
jno 0x6aed5
movq 0x1470(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0x6e0(%rbx), %rax
movq %r15, 0x8(%rax)
movq 0x6e0(%rbx), %rax
movq 0x10(%rax), %rax
movq %r14, 0x8(%rax)
movq 0x6e0(%rbx), %rdx
movq 0x820(%rbx), %rax
movslq 0x7dc(%rbx), %rdi
movq (%rax,%rdi,8), %rcx
leal 0x1(%rdi), %eax
andl $0x7, %eax
movl %eax, 0x7dc(%rbx)
leaq 0x7cc19(%rip), %rax     # 0xe76c8
movq %rax, 0x10(%rcx)
movq $0x1f, 0x8(%rcx)
jmp 0x6adc7
movsd 0x8(%r14), %xmm3
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm3
jne 0x6abf8
jp 0x6abf8
movq 0x1470(%rbx), %rsi
movq 0x6e0(%rbx), %rax
movq %r15, 0x8(%rax)
movq 0x6e0(%rbx), %rax
movq 0x10(%rax), %rax
movq %r14, 0x8(%rax)
movq 0x6e0(%rbx), %rdx
movq %rbx, %rdi
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xc1ff
movq %rbp, %rax
imulq %r13, %rax
jo 0x6ab2e
movq %r12, %rcx
imulq %r8, %rcx
jno 0x6acdd
movq %rbp, 0x18(%rsp)
fildll 0x18(%rsp)
movq %r12, 0x20(%rsp)
fildll 0x20(%rsp)
fdivrp %st, %st(1)
movq %r13, 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
cmpb $0x0, 0xaf09f(%rip)     # 0x119c08
jne 0x6ac3c
xorpd %xmm1, %xmm1
jmp 0x6ac44
movq 0x8(%r14), %rax
movq 0x10(%r14), %rcx
movq %rax, 0x48(%rsp)
fildll 0x48(%rsp)
movq %rcx, 0x40(%rsp)
fildll 0x40(%rsp)
fdivrp %st, %st(1)
fstpl 0x38(%rsp)
movsd 0x38(%rsp), %xmm3
jmp 0x6ac6a
movsd 0x8(%r14), %xmm1
movq %rbx, %rdi
movdqa %xmm2, %xmm0
callq 0xd0546
jmp 0x6ae1b
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x6abd9
movq %rbx, %rdi
callq 0x9c27
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r15
movq $0xb, (%r15)
movq %r14, 0x8(%r15)
jmp 0x6ae60
movq %xmm3, %rax
btrq $0x3f, %rax
movabsq $0x7ff0000000000000, %rcx # imm = 0x7FF0000000000000
cmpq %rcx, %rax
jl 0x6ac64
movq 0x1470(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xaad3d(%rip), %rdx     # 0x115960
movq 0x140(%rbx), %r8
movq 0xaee07(%rip), %r9      # 0x119a38
movq %rbx, %rdi
movq %r14, %rcx
jmp 0x6a7fc
movsd 0x673dc(%rip), %xmm1    # 0xd2020
ucomisd %xmm1, %xmm0
ja 0x6ad94
cmpb $0x0, 0xaedd3(%rip)     # 0x119a28
jne 0x6ad08
xorpd %xmm1, %xmm1
jmp 0x6ad10
cvtsi2sdq 0x8(%r15), %xmm2
movapd %xmm2, %xmm0
divsd %xmm3, %xmm0
cmpb $0x0, 0xaef8f(%rip)     # 0x119c08
jne 0x6ac81
xorpd %xmm1, %xmm1
jmp 0x6ac89
movsd 0x67397(%rip), %xmm1    # 0xd2020
ucomisd %xmm1, %xmm0
ja 0x6ad94
cmpb $0x0, 0xaed8e(%rip)     # 0x119a28
jne 0x6acbb
xorpd %xmm1, %xmm1
jmp 0x6acc3
movq %rbx, %rdi
movq %r13, %rdx
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xbd87
movsd 0x67365(%rip), %xmm1    # 0xd2028
ucomisd %xmm0, %xmm1
ja 0x6ad94
movsd %xmm3, 0x8(%rsp)
movsd %xmm2, (%rsp)
jmp 0x6ade8
cqto
idivq %rcx
jmp 0x6aa23
movsd 0x67331(%rip), %xmm1    # 0xd2020
ucomisd %xmm1, %xmm0
ja 0x6ad94
cmpb $0x0, 0xaed28(%rip)     # 0x119a28
jne 0x6ad48
xorpd %xmm1, %xmm1
jmp 0x6ad50
movsd 0x67318(%rip), %xmm1    # 0xd2028
ucomisd %xmm0, %xmm1
ja 0x6ad94
movq %r8, (%rsp)
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x6ad73
callq 0x85f0
jmp 0x6ad78
movsd 0x672ed(%rip), %xmm1    # 0xd2020
ucomisd %xmm1, %xmm0
ja 0x6ad94
cmpb $0x0, 0xaece8(%rip)     # 0x119a28
jne 0x6ad86
xorpd %xmm1, %xmm1
jmp 0x6ad8e
movsd 0x672d8(%rip), %xmm1    # 0xd2028
ucomisd %xmm0, %xmm1
ja 0x6ad94
movq %xmm2, (%rsp)
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x6ae72
callq 0x85f0
jmp 0x6ae77
callq 0x86c0
cvttsd2si %xmm0, %rax
movq (%rsp), %r8
jmp 0x6aa23
movsd 0x6729a(%rip), %xmm1    # 0xd2028
ucomisd %xmm0, %xmm1
jbe 0x6addd
movq 0x1470(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0x6e0(%rbx), %rax
movq %r15, 0x8(%rax)
movq 0x6e0(%rbx), %rax
movq 0x10(%rax), %rax
movq %r14, 0x8(%rax)
movq 0x6e0(%rbx), %rdx
movq 0xaec79(%rip), %rcx     # 0x119a40
movq %rbx, %rdi
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x35b47
movsd %xmm3, (%rsp)
movsd %xmm2, 0x8(%rsp)
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x6adf9
callq 0x85f0
jmp 0x6adfe
callq 0x86c0
cvttsd2si %xmm0, %rax
cvtsi2sd %rax, %xmm0
movsd 0x8(%rsp), %xmm1
mulsd %xmm0, %xmm1
movsd (%rsp), %xmm0
subsd %xmm1, %xmm0
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x6ae44
movq %rbx, %rdi
movsd %xmm0, (%rsp)
callq 0x9c27
movsd (%rsp), %xmm0
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r15
movq $0xd, (%r15)
movsd %xmm0, 0x8(%r15)
movq %r15, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x86c0
cvttsd2si %xmm0, %rax
imulq %rax, %r12
cvtsi2sd %r12, %xmm0
movsd (%rsp), %xmm1
subsd %xmm0, %xmm1
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x6aeb7
movq %rbx, %rdi
movsd %xmm1, (%rsp)
callq 0x9c27
movsd (%rsp), %xmm1
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r15
movq $0xd, (%r15)
movsd %xmm1, 0x8(%r15)
jmp 0x6ae60
movq %rbx, %rdi
movq %rbp, %rsi
movq %r8, %rdx
jmp 0x6aca8