// File: /workspace/github_c_makefile_star2_O2/BernardTatin[P]s7sh/s7.c
// Function: g_max
static s7_pointer g_max(s7_scheme *sc, s7_pointer args)
    {
#define H_max "(max ...) returns the maximum of its arguments"
#define Q_max sc->pcl_r

        s7_pointer x, y, p;
        s7_int num_a, num_b, den_a, den_b;

        x = car(args);
        p = cdr(args);

        switch (type(x))
        {
            case T_INTEGER:
MAX_INTEGERS:
                if (is_null(p)) return(x);
                y = car(p);
                p = cdr(p);
                switch (type(y))
                {
                    case T_INTEGER:
                        if (integer(x) < integer(y)) x = y;
                        goto MAX_INTEGERS;

                    case T_RATIO:
                        num_a = integer(x);
                        den_a = 1;
                        num_b = numerator(y);
                        den_b = denominator(y);
                        goto RATIO_MAX_RATIO;

                    case T_REAL:
                        if (is_NaN(real(y)))
                            return(nan_with_error_check(sc, y, p, args, sc->max_symbol));
                        if (integer(x) < real(y))
                        {
                            x = y;
                            goto MAX_REALS;
                        }
                        goto MAX_INTEGERS;

                    default:
                        return(method_or_bust(sc, y, sc->max_symbol, cons_unchecked(sc, x, cons(sc, y, p)), T_REAL, position_of(p, args) - 1));
                }

            case T_RATIO:
MAX_RATIOS:
                if (is_null(p)) return(x);
                y = car(p);
                p = cdr(p);
                switch (type(y))
                {
                    case T_INTEGER:
                        num_a = numerator(x);
                        den_a = denominator(x);
                        num_b = integer(y);
                        den_b = 1;
                        goto RATIO_MAX_RATIO;

                    case T_RATIO:
                        num_a = numerator(x);
                        den_a = denominator(x);
                        num_b = numerator(y);
                        den_b = denominator(y);

RATIO_MAX_RATIO:
                        /* there are tricky cases here where long ints outrun doubles:
                         *   (max 92233720368547758/9223372036854775807 92233720368547757/9223372036854775807)
                         * which should be 92233720368547758/9223372036854775807) but first the fraction gets reduced
                         * to 13176245766935394/1317624576693539401, so we fall into the double comparison, and
                         * there we should be comparing
                         *    9.999999999999999992410584792601468961145E-3 and
                         *    9.999999999999999883990367544051025548645E-3
                         * but if using doubles we get
                         *    0.010000000000000000208166817117 and
                         *    0.010000000000000000208166817117
                         * that is, we can't distinguish these two fractions once they're coerced to doubles.
                         * Even long doubles fail in innocuous-looking cases:
                         *     (min 21053343141/6701487259 3587785776203/1142027682075) -> 3587785776203/1142027682075
                         *     (max 21053343141/6701487259 3587785776203/1142027682075) -> 3587785776203/1142027682075
                         */

                        if ((num_a < 0) && (num_b >= 0)) /* x < 0, y >= 0 -> y */
                            x = y;
                        else
                        {
                            if ((num_a < 0) || (num_b >= 0))
                            {
                                if (den_a == den_b)
                                {
                                    if (num_a < num_b)
                                        x = y;
                                }
                                else
                                {
                                    if (num_a == num_b)
                                    {
                                        if (((num_a >= 0) &&
                                                    (den_a > den_b)) ||
                                                ((num_a < 0) &&
                                                 (den_a < den_b)))
                                            x = y;
                                    }
                                    else
                                    {
                                        s7_int vala, valb;
                                        vala = num_a / den_a;
                                        valb = num_b / den_b;
                                        if (!((vala > valb) ||
                                                    ((vala == valb) && (is_t_integer(y)))))
                                        {
                                            if ((valb > vala) ||
                                                    ((vala == valb) && (is_t_integer(x))) ||
                                                    /* sigh -- both are ratios and the int32_t parts are equal */
                                                    (((long_double)(num_a % den_a) / (long_double)den_a) <= ((long_double)(num_b % den_b) / (long_double)den_b)))
                                                x = y;
                                        }}}}
                        }
                        if (is_t_ratio(x))
                            goto MAX_RATIOS;
                        goto MAX_INTEGERS;

                    case T_REAL:
                        /* (max 3/4 +nan.0) should probably return NaN */
                        if (is_NaN(real(y)))
                            return(nan_with_error_check(sc, y, p, args, sc->max_symbol));

                        if (fraction(x) < real(y))
                        {
                            x = y;
                            goto MAX_REALS;
                        }
                        goto MAX_RATIOS;

                    default:
                        return(method_or_bust(sc, y, sc->max_symbol, cons_unchecked(sc, x, cons(sc, y, p)), T_REAL, position_of(p, args) - 1));
                }

            case T_REAL:
                if (is_NaN(real(x)))
                    return(nan_with_error_check(sc, x, p, args, sc->max_symbol));

MAX_REALS:
                if (is_null(p)) return(x);
                y = car(p);
                p = cdr(p);

                switch (type(y))
                {
                    case T_INTEGER:
                        if (real(x) < integer(y))
                        {
                            x = y;
                            goto MAX_INTEGERS;
                        }
                        goto MAX_REALS;

                    case T_RATIO:
                        if (real(x) < fraction(y))
                        {
                            x = y;
                            goto MAX_RATIOS;
                        }
                        goto MAX_REALS;

                    case T_REAL:
                        if (is_NaN(real(y)))
                            return(nan_with_error_check(sc, y, p, args, sc->max_symbol));
                        if (real(x) < real(y)) x = y;
                        goto MAX_REALS;

                    default:
                        return(method_or_bust(sc, y, sc->max_symbol, cons_unchecked(sc, x, cons(sc, y, p)), T_REAL, position_of(p, args) - 1));
                }

            default:
                return(method_or_bust(sc, x, sc->max_symbol, cons(sc, x, p), T_REAL, 1));
        }
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r15
movq %rdi, %rbx
movq 0x8(%rsi), %r12
movq 0x10(%rsi), %r14
movzbl (%r12), %eax
pushq $0x1
popq %r8
cmpl $0xb, %eax
je 0x5640f
cmpl $0xd, %eax
je 0x563f2
cmpl $0xc, %eax
jne 0x5641b
movq 0x110(%rbx), %r9
jmp 0x56475
movsd 0x8(%r12), %xmm0
ucomisd %xmm0, %xmm0
jp 0x5662d
movq 0x110(%rbx), %r9
jmp 0x564d5
movq 0x110(%rbx), %r9
jmp 0x5663f
movq 0x1328(%rbx), %r15
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x56441
movq %rbx, %rdi
callq 0x9c27
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rcx
movq $0x200001, (%rcx)       # imm = 0x200001
movq %r12, 0x8(%rcx)
movq %r14, 0x10(%rcx)
pushq $0xd
popq %r8
pushq $0x1
popq %r9
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
jmp 0x56726
cmpq %r9, %r14
je 0x56583
movq 0x8(%r14), %r13
movq 0x10(%r14), %r14
movzbl (%r13), %eax
cmpl $0xd, %eax
jne 0x5655e
movsd 0x8(%r13), %xmm0
ucomisd %xmm0, %xmm0
jp 0x56739
movq 0x8(%r12), %rax
movq 0x10(%r12), %rcx
movq %rax, 0x30(%rsp)
fildll 0x30(%rsp)
movq %rcx, 0x28(%rsp)
fildll 0x28(%rsp)
fdivrp %st, %st(1)
movsd %xmm0, 0x20(%rsp)
fldl 0x20(%rsp)
fucompi %st(1), %st
fstp %st(0)
jbe 0x56475
movq %r13, %r12
movq %r12, %r13
cmpq %r9, %r14
je 0x56580
movq 0x8(%r14), %r12
movq 0x10(%r14), %r14
movzbl (%r12), %eax
cmpl $0xb, %eax
je 0x56525
cmpl $0xc, %eax
jne 0x56539
fldl 0x8(%r13)
movq 0x8(%r12), %rax
movq 0x10(%r12), %rcx
movq %rax, 0x18(%rsp)
fildll 0x18(%rsp)
movq %rcx, 0x10(%rsp)
fildll 0x10(%rsp)
fdivrp %st, %st(1)
fucompi %st(1), %st
fstp %st(0)
jbe 0x564d8
jmp 0x56475
cvtsi2sdq 0x8(%r12), %xmm0
ucomisd 0x8(%r13), %xmm0
jbe 0x564d8
jmp 0x5663f
cmpl $0xd, %eax
jne 0x56595
movsd 0x8(%r12), %xmm0
ucomisd %xmm0, %xmm0
jp 0x5662d
ucomisd 0x8(%r13), %xmm0
cmovaq %r12, %r13
jmp 0x564d8
cmpl $0xc, %eax
je 0x5661f
cmpl $0xb, %eax
jne 0x56699
movq 0x10(%r12), %r10
movb $0x1, %bpl
movq %r8, %r11
jmp 0x56769
movq %r13, %r12
movq %r12, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1328(%rbx), %rax
movq %rax, 0x8(%rsp)
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x565c0
movq %rbx, %rdi
callq 0x9c27
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rax
movl $0x200001, %ecx         # imm = 0x200001
movq %rcx, (%rax)
movq %r12, 0x8(%rax)
movq %r14, 0x10(%rax)
movq 0x90(%rbx), %rdx
leaq -0x8(%rdx), %rsi
movq %rsi, 0x90(%rbx)
movq -0x8(%rdx), %rbp
movq %rcx, (%rbp)
movq %r13, 0x8(%rbp)
movq %rax, 0x10(%rbp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x72a82
leal -0x1(%rax), %r9d
pushq $0xd
popq %r8
movq %rbx, %rdi
movq %r12, %rsi
jmp 0x5671e
movq 0x10(%r12), %r10
movq 0x10(%r13), %r11
jmp 0x56767
movq 0x1328(%rbx), %r8
movq %rbx, %rdi
movq %r12, %rsi
jmp 0x56746
cmpq %r9, %r14
je 0x56583
movq 0x8(%r14), %r13
movq 0x10(%r14), %r14
movzbl (%r13), %eax
cmpl $0xd, %eax
jne 0x5667c
movsd 0x8(%r13), %xmm0
ucomisd %xmm0, %xmm0
jp 0x56739
cvtsi2sdq 0x8(%r12), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x5663f
jmp 0x564d2
cmpl $0xc, %eax
je 0x5675f
cmpl $0xb, %eax
jne 0x56699
movq 0x8(%r12), %rax
cmpq 0x8(%r13), %rax
cmovlq %r13, %r12
jmp 0x5663f
movq 0x1328(%rbx), %rax
movq %rax, 0x8(%rsp)
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x566c4
movq %rbx, %rdi
callq 0x9c27
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rax
movl $0x200001, %ecx         # imm = 0x200001
movq %rcx, (%rax)
movq %r13, 0x8(%rax)
movq %r14, 0x10(%rax)
movq 0x90(%rbx), %rdx
leaq -0x8(%rdx), %rsi
movq %rsi, 0x90(%rbx)
movq -0x8(%rdx), %rbp
movq %rcx, (%rbp)
movq %r12, 0x8(%rbp)
movq %rax, 0x10(%rbp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x72a82
leal -0x1(%rax), %r9d
pushq $0xd
popq %r8
movq %rbx, %rdi
movq %r13, %rsi
movq 0x8(%rsp), %rdx
movq %rbp, %rcx
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xcd70
movq 0x1328(%rbx), %r8
movq %rbx, %rdi
movq %r13, %rsi
movq %r14, %rdx
movq %r15, %rcx
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xc904b
movq 0x10(%r13), %r11
pushq $0x1
popq %r10
xorl %ebp, %ebp
movq 0x8(%r12), %rax
movq 0x8(%r13), %rcx
testq %rax, %rax
jns 0x56781
testq %rcx, %rcx
js 0x56781
movq %r13, %r12
jmp 0x56797
testq %rax, %rax
js 0x5678b
testq %rcx, %rcx
js 0x56797
cmpq %r11, %r10
jne 0x567a7
cmpq %rcx, %rax
cmovlq %r13, %r12
cmpb $0xc, (%r12)
je 0x56475
jmp 0x5663f
cmpq %rcx, %rax
jne 0x567cd
cmpq %r11, %r10
movq %r12, %rcx
cmovlq %r13, %rcx
testq %rax, %rax
cmovnsq %r12, %rcx
cmpq %r11, %r10
cmovleq %rcx, %r13
testq %rax, %rax
cmovsq %rcx, %r13
jmp 0x5677c
cqto
idivq %r10
movq %rdx, %rsi
movq %rax, %rdi
movq %rcx, %rax
cqto
idivq %r11
cmpq %rax, %rdi
jg 0x56797
jne 0x567f6
testb $0x1, %bpl
jne 0x56797
cmpb $0xb, (%r12)
je 0x5677c
jmp 0x567f8
jl 0x5677c
movq %rsi, 0x38(%rsp)
fildll 0x38(%rsp)
movq %r10, 0x40(%rsp)
fildll 0x40(%rsp)
fdivrp %st, %st(1)
movq %rdx, 0x48(%rsp)
fildll 0x48(%rsp)
movq %r11, 0x50(%rsp)
fildll 0x50(%rsp)
fdivrp %st, %st(1)
fucompi %st(1), %st
fstp %st(0)
jae 0x5677c
jmp 0x56797