// File: /workspace/github_c_makefile_star2_O0/BernardTatin[P]s7sh/s7.c
// Function: g_rationalize
static s7_pointer g_rationalize(s7_scheme *sc, s7_pointer args)
    {
#define H_rationalize "(rationalize x err) returns the ratio with smallest denominator within err of x"
#define Q_rationalize s7_make_signature(sc, 3, sc->is_rational_symbol, sc->is_real_symbol, sc->is_real_symbol)
        /* I can't find a case where this returns a non-rational result */

        s7_double err;
        s7_pointer x;

        x = car(args);
        if (!s7_is_real(x))
            return(method_or_bust(sc, x, sc->rationalize_symbol, args, T_REAL, 1));

        if (is_not_null(cdr(args)))
        {
            s7_pointer ex;
            ex = cadr(args);
            if (!s7_is_real(ex))
                return(method_or_bust(sc, ex, sc->rationalize_symbol, args, T_REAL, 2));

            err = real_to_double(sc, ex, "rationalize");
            if (is_NaN(err))
                return(out_of_range(sc, sc->rationalize_symbol, small_int(2), cadr(args), its_nan_string));
            if (err < 0.0) err = -err;
        }
        else err = sc->default_rationalize_error;

        switch (type(x))
        {
            case T_INTEGER:
                {
                    s7_int a, b, pa;
                    if (err < 1.0) return(x);
                    a = s7_integer(x);
                    if (a < 0) pa = -a; else pa = a;
                    if (err >= pa) return(small_int(0));
                    b = (s7_int)err;
                    pa -= b;
                    if (a < 0)
                        return(make_integer(sc, -pa));
                    return(make_integer(sc, pa));
                }

            case T_RATIO:
                if (err == 0.0)
                    return(x);

            case T_REAL:
                {
                    s7_double rat;
                    s7_int numer = 0, denom = 1;

                    rat = s7_real(x); /* possible fall through from above */
                    if ((is_NaN(rat)) || (is_inf(rat)))
                        return(out_of_range(sc, sc->rationalize_symbol, small_int(1), x, a_normal_real_string));

                    if (err >= fabs(rat))
                        return(small_int(0));

                    if ((rat > 9.2233720368548e+18) || (rat < -9.2233720368548e+18))
                        return(out_of_range(sc, sc->rationalize_symbol, small_int(1), x, its_too_large_string));

                    if ((fabs(rat) + fabs(err)) < 1.0e-18)
                        err = 1.0e-18;
                    /* (/ 1.0 most-positive-fixnum) is 1.0842021e-19, so if we let err be less than that,
                     * (rationalize 1e-19 1e-20) hangs, but this only affects the initial ceiling, I believe.
                     */

                    if (fabs(rat) < fabs(err))
                        return(small_int(0));

                    if (c_rationalize(rat, err, &numer, &denom))
                        return(s7_make_ratio(sc, numer, denom));
                    return(sc->F);
                }
        }
        return(sc->F); /* make compiler happy */
    }

// Assembly:
subq $0xd8, %rsp
movq %rdi, 0xc8(%rsp)
movq %rsi, 0xc0(%rsp)
movq 0xc0(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0xb0(%rsp)
movq 0xb0(%rsp), %rdi
callq 0x11360
testb $0x1, %al
jne 0x71ba1
movq 0xc8(%rsp), %rdi
movq 0xb0(%rsp), %rsi
movq 0xc8(%rsp), %rax
movq 0x1438(%rax), %rdx
movq 0xc0(%rsp), %rcx
movl $0xd, %r8d
movl $0x1, %r9d
callq 0x13c50
movq %rax, 0xd0(%rsp)
jmp 0x72295
movq 0xc0(%rsp), %rax
movq 0x10(%rax), %rax
movq 0xc8(%rsp), %rcx
cmpq 0x110(%rcx), %rax
je 0x71d40
movq 0xc0(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, 0xa8(%rsp)
movq 0xa8(%rsp), %rdi
callq 0x11360
testb $0x1, %al
jne 0x71c30
movq 0xc8(%rsp), %rdi
movq 0xa8(%rsp), %rsi
movq 0xc8(%rsp), %rax
movq 0x1438(%rax), %rdx
movq 0xc0(%rsp), %rcx
movl $0xd, %r8d
movl $0x2, %r9d
callq 0x13c50
movq %rax, 0xd0(%rsp)
jmp 0x72295
movq 0xa8(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq 0xa0(%rsp), %rax
movzbl (%rax), %eax
cmpl $0xd, %eax
jne 0x71c65
movq 0xa0(%rsp), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
jmp 0x71c87
movq 0xc8(%rsp), %rdi
movq 0xa0(%rsp), %rsi
leaq 0x1744dc(%rip), %rdx    # 0x1e6158
callq 0x12460
movsd %xmm0, 0x20(%rsp)
movsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x98(%rsp)
movsd 0x98(%rsp), %xmm0
movsd %xmm0, 0xb8(%rsp)
movsd 0xb8(%rsp), %xmm0
callq 0x13860
testb $0x1, %al
jne 0x71cbc
jmp 0x71d07
movq 0xc8(%rsp), %rdi
movq 0xc8(%rsp), %rax
movq 0x1438(%rax), %rax
movq 0x8(%rax), %rsi
movq 0x1a47b2(%rip), %rdx    # 0x216490
movq 0xc0(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rcx
movq 0x1b34fb(%rip), %r8     # 0x2251f0
callq 0x13880
movq %rax, 0xd0(%rsp)
jmp 0x72295
xorps %xmm0, %xmm0
ucomisd 0xb8(%rsp), %xmm0
jbe 0x71d3e
movsd 0xb8(%rsp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, 0xb8(%rsp)
jmp 0x71d59
movq 0xc8(%rsp), %rax
movsd 0x258(%rax), %xmm0
movsd %xmm0, 0xb8(%rsp)
movq 0xb0(%rsp), %rax
movzbl (%rax), %eax
movl %eax, 0x1c(%rsp)
subl $0xb, %eax
je 0x71d90
jmp 0x71d6f
movl 0x1c(%rsp), %eax
subl $0xc, %eax
je 0x72015
jmp 0x71d7e
movl 0x1c(%rsp), %eax
subl $0xd, %eax
je 0x72040
jmp 0x7227e
movsd 0x16fbd0(%rip), %xmm0   # 0x1e1968
ucomisd 0xb8(%rsp), %xmm0
jbe 0x71db8
movq 0xb0(%rsp), %rax
movq %rax, 0xd0(%rsp)
jmp 0x72295
movq 0xb0(%rsp), %rdi
callq 0x10790
movq %rax, 0x90(%rsp)
cmpq $0x0, 0x90(%rsp)
jge 0x71dec
xorl %eax, %eax
subq 0x90(%rsp), %rax
movq %rax, 0x80(%rsp)
jmp 0x71dfc
movq 0x90(%rsp), %rax
movq %rax, 0x80(%rsp)
movsd 0xb8(%rsp), %xmm0
cvtsi2sdq 0x80(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jb 0x71e29
movq 0x1a4664(%rip), %rax    # 0x216480
movq %rax, 0xd0(%rsp)
jmp 0x72295
cvttsd2si 0xb8(%rsp), %rax
movq %rax, 0x88(%rsp)
movq 0x88(%rsp), %rcx
movq 0x80(%rsp), %rax
subq %rcx, %rax
movq %rax, 0x80(%rsp)
cmpq $0x0, 0x90(%rsp)
jge 0x71f3e
xorl %eax, %eax
subq 0x80(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x78(%rsp), %rax
andq $-0x800, %rax           # imm = 0xF800
cmpq $0x0, %rax
jne 0x71e9f
movq 0x78(%rsp), %rcx
leaq 0x1a45ef(%rip), %rax    # 0x216480
movq (%rax,%rcx,8), %rax
movq %rax, 0x10(%rsp)
jmp 0x71f22
jmp 0x71ea1
movq 0xc8(%rsp), %rax
movq 0x90(%rax), %rax
movq 0xc8(%rsp), %rcx
cmpq 0x98(%rcx), %rax
ja 0x71ece
movq 0xc8(%rsp), %rdi
callq 0xc670
movq 0xc8(%rsp), %rcx
movq 0x90(%rcx), %rax
movq %rax, %rdx
addq $-0x8, %rdx
movq %rdx, 0x90(%rcx)
movq -0x8(%rax), %rax
movq %rax, 0x68(%rsp)
movq 0x68(%rsp), %rax
movq $0xb, (%rax)
movq 0x78(%rsp), %rcx
movq 0x68(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x68(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0xd0(%rsp)
jmp 0x72295
movq 0x80(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x58(%rsp), %rax
andq $-0x800, %rax           # imm = 0xF800
cmpq $0x0, %rax
jne 0x71f76
movq 0x58(%rsp), %rcx
leaq 0x1a4518(%rip), %rax    # 0x216480
movq (%rax,%rcx,8), %rax
movq %rax, 0x8(%rsp)
jmp 0x71ff9
jmp 0x71f78
movq 0xc8(%rsp), %rax
movq 0x90(%rax), %rax
movq 0xc8(%rsp), %rcx
cmpq 0x98(%rcx), %rax
ja 0x71fa5
movq 0xc8(%rsp), %rdi
callq 0xc670
movq 0xc8(%rsp), %rcx
movq 0x90(%rcx), %rax
movq %rax, %rdx
addq $-0x8, %rdx
movq %rdx, 0x90(%rcx)
movq -0x8(%rax), %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
movq $0xb, (%rax)
movq 0x58(%rsp), %rcx
movq 0x48(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x48(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0xd0(%rsp)
jmp 0x72295
movsd 0xb8(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x7203e
jp 0x7203e
movq 0xb0(%rsp), %rax
movq %rax, 0xd0(%rsp)
jmp 0x72295
jmp 0x72040
movq $0x0, 0x30(%rsp)
movq $0x1, 0x28(%rsp)
movq 0xb0(%rsp), %rdi
callq 0x128d0
movsd %xmm0, 0x38(%rsp)
movsd 0x38(%rsp), %xmm0
callq 0x13860
testb $0x1, %al
jne 0x720be
movsd 0x38(%rsp), %xmm1
movaps %xmm1, %xmm0
movaps 0x16fa1c(%rip), %xmm2   # 0x1e1aa0
pand %xmm2, %xmm0
movq %xmm1, %rdx
movl $0x1, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq $0x0, %rdx
cmovll %eax, %ecx
movsd 0x16f8ca(%rip), %xmm1   # 0x1e1970
xorl %eax, %eax
ucomisd %xmm1, %xmm0
setnp %sil
sete %dl
testb %sil, %dl
cmovnel %ecx, %eax
cmpl $0x0, %eax
je 0x72101
movq 0xc8(%rsp), %rdi
movq 0xc8(%rsp), %rax
movq 0x1438(%rax), %rax
movq 0x8(%rax), %rsi
movq 0x1a43a8(%rip), %rdx    # 0x216488
movq 0xb0(%rsp), %rcx
movq 0x1a8479(%rip), %r8     # 0x21a568
callq 0x13880
movq %rax, 0xd0(%rsp)
jmp 0x72295
movsd 0xb8(%rsp), %xmm0
movsd 0x38(%rsp), %xmm1
movaps 0x16f989(%rip), %xmm2   # 0x1e1aa0
pand %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jb 0x72135
movq 0x1a4358(%rip), %rax    # 0x216480
movq %rax, 0xd0(%rsp)
jmp 0x72295
movsd 0x38(%rsp), %xmm0
movsd 0x16f83d(%rip), %xmm1   # 0x1e1980
ucomisd %xmm1, %xmm0
ja 0x72159
movsd 0x16f837(%rip), %xmm0   # 0x1e1988
ucomisd 0x38(%rsp), %xmm0
jbe 0x7219c
movq 0xc8(%rsp), %rdi
movq 0xc8(%rsp), %rax
movq 0x1438(%rax), %rax
movq 0x8(%rax), %rsi
movq 0x1a430d(%rip), %rdx    # 0x216488
movq 0xb0(%rsp), %rcx
movq 0x1a83e6(%rip), %r8     # 0x21a570
callq 0x13880
movq %rax, 0xd0(%rsp)
jmp 0x72295
movsd 0x38(%rsp), %xmm1
movaps 0x16f8f7(%rip), %xmm0   # 0x1e1aa0
pand %xmm0, %xmm1
movsd 0xb8(%rsp), %xmm0
movaps 0x16f8e3(%rip), %xmm2   # 0x1e1aa0
pand %xmm2, %xmm0
addsd %xmm0, %xmm1
movsd 0x16f813(%rip), %xmm0   # 0x1e19e0
ucomisd %xmm1, %xmm0
jbe 0x721e4
movsd 0x16f805(%rip), %xmm0   # 0x1e19e0
movsd %xmm0, 0xb8(%rsp)
movsd 0x38(%rsp), %xmm1
movaps 0x16f8af(%rip), %xmm0   # 0x1e1aa0
pand %xmm0, %xmm1
movsd 0xb8(%rsp), %xmm0
movaps 0x16f89b(%rip), %xmm2   # 0x1e1aa0
pand %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x72220
movq 0x1a426a(%rip), %rax    # 0x216480
movq %rax, 0xd0(%rsp)
jmp 0x72295
movsd 0x38(%rsp), %xmm0
movsd 0xb8(%rsp), %xmm1
leaq 0x30(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x114e0
testb $0x1, %al
jne 0x72244
jmp 0x72265
movq 0xc8(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x28(%rsp), %rdx
callq 0x11a80
movq %rax, 0xd0(%rsp)
jmp 0x72295
movq 0xc8(%rsp), %rax
movq 0x120(%rax), %rax
movq %rax, 0xd0(%rsp)
jmp 0x72295
movq 0xc8(%rsp), %rax
movq 0x120(%rax), %rax
movq %rax, 0xd0(%rsp)
movq 0xd0(%rsp), %rax
addq $0xd8, %rsp
retq
nopw %cs:(%rax,%rax)