// File: /workspace/github_c_makefile_star2_O0/BernardTatin[P]s7sh/s7.c
// Function: g_random
static s7_pointer g_random(s7_scheme *sc, s7_pointer args)
    {
#define H_random "(random num (state #f)) returns a random number between 0 and num (0 if num=0)."
#define Q_random s7_make_signature(sc, 3, sc->is_number_symbol, sc->is_number_symbol, sc->is_random_state_symbol)
        s7_pointer r, num;

        if (is_not_null(cdr(args)))
        {
            r = cadr(args);
            if (!is_random_state(r))
                return(method_or_bust_with_type(sc, r, sc->random_symbol, args, a_random_state_object_string, 2));
        }
        else r = sc->default_rng;
        num = car(args);

        switch (type(num))
        {
            case T_INTEGER:
                return(make_integer(sc, (s7_int)(integer(num) * next_random(r))));

            case T_RATIO:
                {
                    s7_double x, error;
                    s7_int numer = 0, denom = 1;
                    /* the error here needs to take the size of the fraction into account.  Otherwise, if
                     *    error is (say) 1e-6 and the fraction is (say) 9000000/9223372036854775807,
                     *    c_rationalize will always return 0.  But even that isn't foolproof:
                     *    (random 1/562949953421312) -> 1/376367230475000
                     */
                    x = fraction(num);
                    if ((x < 1.0e-10) && (x > -1.0e-10))
                    {
                        /* 1e-12 is not tight enough:
                         *    (random 1/2251799813685248) -> 1/2250240579436280
                         *    (random -1/4503599627370496) -> -1/4492889778435526
                         *    (random 1/140737488355328) -> 1/140730223985746
                         *    (random -1/35184372088832) -> -1/35183145492420
                         *    (random -1/70368744177664) -> -1/70366866392738
                         *    (random 1/4398046511104) -> 1/4398033095756
                         *    (random 1/137438953472) -> 1/137438941127
                         */
                        if (numerator(num) < -10)
                            numer = -(s7_int)(floor(-numerator(num) * next_random(r)));
                        else
                        {
                            if (numerator(num) > 10)
                                numer = (s7_int)floor(numerator(num) * next_random(r));
                            else
                            {
                                int64_t diff;
                                numer = numerator(num);
                                diff = s7_int_max - denominator(num);
                                if (diff < 100)
                                    return(s7_make_ratio(sc, numer, denominator(num)));
                                denom = denominator(num) + (s7_int)floor(diff * next_random(r));
                                return(s7_make_ratio(sc, numer, denom));
                            }
                        }
                        return(s7_make_ratio(sc, numer, denominator(num)));
                    }
                    if ((x < 1e-6) && (x > -1e-6))
                        error = 1e-18;
                    else error = 1e-12;
                    c_rationalize(x * next_random(r), error, &numer, &denom);
                    return(s7_make_ratio(sc, numer, denom));
                }

            case T_REAL:
                return(make_real(sc, real(num) * next_random(r)));

            case T_COMPLEX:
                return(s7_make_complex(sc, real_part(num) * next_random(r), imag_part(num) * next_random(r)));

            default:
                return(method_or_bust_with_type(sc, num, sc->random_symbol, args, a_number_string, 1));
        }
        return(sc->F);
    }

// Assembly:
subq $0x108, %rsp            # imm = 0x108
movq %rdi, 0xf8(%rsp)
movq %rsi, 0xf0(%rsp)
movq 0xf0(%rsp), %rax
movq 0x10(%rax), %rax
movq 0xf8(%rsp), %rcx
cmpq 0x110(%rcx), %rax
je 0x882d4
movq 0xf0(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, 0xe8(%rsp)
movq 0xe8(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x24, %eax
je 0x882d2
movq 0xf8(%rsp), %rdi
movq 0xe8(%rsp), %rsi
movq 0xf8(%rsp), %rax
movq 0x1430(%rax), %rdx
movq 0xf0(%rsp), %rcx
movq 0x1922c6(%rip), %r8     # 0x21a580
movl $0x2, %r9d
callq 0x14130
movq %rax, 0x100(%rsp)
jmp 0x888fd
jmp 0x882eb
movq 0xf8(%rsp), %rax
movq 0xaa0(%rax), %rax
movq %rax, 0xe8(%rsp)
movq 0xf0(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0xe0(%rsp)
movq 0xe0(%rsp), %rax
movzbl (%rax), %eax
addl $-0xb, %eax
movl %eax, %ecx
movq %rcx, 0x60(%rsp)
subl $0x3, %eax
ja 0x888bc
movq 0x60(%rsp), %rax
leaq 0x156887(%rip), %rcx    # 0x1debb0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0xe0(%rsp), %rax
cvtsi2sdq 0x8(%rax), %xmm0
movsd %xmm0, 0x58(%rsp)
movq 0xe8(%rsp), %rdi
callq 0x143a0
movaps %xmm0, %xmm1
movsd 0x58(%rsp), %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, 0xd8(%rsp)
movq 0xd8(%rsp), %rax
andq $-0x800, %rax           # imm = 0xF800
cmpq $0x0, %rax
jne 0x8839e
movq 0xd8(%rsp), %rcx
leaq 0x18e0f0(%rip), %rax    # 0x216480
movq (%rax,%rcx,8), %rax
movq %rax, 0x50(%rsp)
jmp 0x88436
jmp 0x883a0
movq 0xf8(%rsp), %rax
movq 0x90(%rax), %rax
movq 0xf8(%rsp), %rcx
cmpq 0x98(%rcx), %rax
ja 0x883cd
movq 0xf8(%rsp), %rdi
callq 0xc670
movq 0xf8(%rsp), %rcx
movq 0x90(%rcx), %rax
movq %rax, %rdx
addq $-0x8, %rdx
movq %rdx, 0x90(%rcx)
movq -0x8(%rax), %rax
movq %rax, 0xc8(%rsp)
movq 0xc8(%rsp), %rax
movq $0xb, (%rax)
movq 0xd8(%rsp), %rcx
movq 0xc8(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0xc8(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq 0xc0(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0xd0(%rsp)
movq 0xd0(%rsp), %rax
movq %rax, 0x100(%rsp)
jmp 0x888fd
movq $0x0, 0xa8(%rsp)
movq $0x1, 0xa0(%rsp)
movq 0xe0(%rsp), %rax
movq 0x8(%rax), %rcx
movq 0x10(%rax), %rax
movq %rcx, 0x78(%rsp)
fildll 0x78(%rsp)
movq %rax, 0x70(%rsp)
fildll 0x70(%rsp)
fdivrp %st, %st(1)
fstpl 0x68(%rsp)
movsd 0x68(%rsp), %xmm0
movsd %xmm0, 0xb8(%rsp)
movsd 0x159591(%rip), %xmm0   # 0x1e1a40
ucomisd 0xb8(%rsp), %xmm0
jbe 0x886a2
movsd 0xb8(%rsp), %xmm0
movsd 0x159579(%rip), %xmm1   # 0x1e1a48
ucomisd %xmm1, %xmm0
jbe 0x886a2
movq 0xe0(%rsp), %rax
cmpq $-0xa, 0x8(%rax)
jge 0x88537
movq 0xe0(%rsp), %rcx
xorl %eax, %eax
subq 0x8(%rcx), %rax
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0xe8(%rsp), %rdi
callq 0x143a0
movaps %xmm0, %xmm1
movsd 0x48(%rsp), %xmm0
mulsd %xmm1, %xmm0
callq 0x95f0
cvttsd2si %xmm0, %rcx
xorl %eax, %eax
subq %rcx, %rax
movq %rax, 0xa8(%rsp)
jmp 0x88674
movq 0xe0(%rsp), %rax
cmpq $0xa, 0x8(%rax)
jle 0x8858b
movq 0xe0(%rsp), %rax
cvtsi2sdq 0x8(%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
movq 0xe8(%rsp), %rdi
callq 0x143a0
movaps %xmm0, %xmm1
movsd 0x40(%rsp), %xmm0
mulsd %xmm1, %xmm0
callq 0x95f0
cvttsd2si %xmm0, %rax
movq %rax, 0xa8(%rsp)
jmp 0x88672
movq 0xe0(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0xa8(%rsp)
movq 0x192192(%rip), %rax    # 0x21a738
movq 0xe0(%rsp), %rcx
subq 0x10(%rcx), %rax
movq %rax, 0x98(%rsp)
cmpq $0x64, 0x98(%rsp)
jge 0x885f3
movq 0xf8(%rsp), %rdi
movq 0xa8(%rsp), %rsi
movq 0xe0(%rsp), %rax
movq 0x10(%rax), %rdx
callq 0x11a80
movq %rax, 0x100(%rsp)
jmp 0x888fd
movq 0xe0(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x38(%rsp)
cvtsi2sdq 0x98(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movq 0xe8(%rsp), %rdi
callq 0x143a0
movaps %xmm0, %xmm1
movsd 0x30(%rsp), %xmm0
mulsd %xmm1, %xmm0
callq 0x95f0
movq 0x38(%rsp), %rax
cvttsd2si %xmm0, %rcx
addq %rcx, %rax
movq %rax, 0xa0(%rsp)
movq 0xf8(%rsp), %rdi
movq 0xa8(%rsp), %rsi
movq 0xa0(%rsp), %rdx
callq 0x11a80
movq %rax, 0x100(%rsp)
jmp 0x888fd
jmp 0x88674
movq 0xf8(%rsp), %rdi
movq 0xa8(%rsp), %rsi
movq 0xe0(%rsp), %rax
movq 0x10(%rax), %rdx
callq 0x11a80
movq %rax, 0x100(%rsp)
jmp 0x888fd
movsd 0x159306(%rip), %xmm0   # 0x1e19b0
ucomisd 0xb8(%rsp), %xmm0
jbe 0x886df
movsd 0xb8(%rsp), %xmm0
movsd 0x15938a(%rip), %xmm1   # 0x1e1a50
ucomisd %xmm1, %xmm0
jbe 0x886df
movsd 0x15930c(%rip), %xmm0   # 0x1e19e0
movsd %xmm0, 0xb0(%rsp)
jmp 0x886f0
movsd 0x1592c1(%rip), %xmm0   # 0x1e19a8
movsd %xmm0, 0xb0(%rsp)
movsd 0xb8(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
movq 0xe8(%rsp), %rdi
callq 0x143a0
movaps %xmm0, %xmm1
movsd 0x28(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd 0xb0(%rsp), %xmm1
leaq 0xa8(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x114e0
movq 0xf8(%rsp), %rdi
movq 0xa8(%rsp), %rsi
movq 0xa0(%rsp), %rdx
callq 0x11a80
movq %rax, 0x100(%rsp)
jmp 0x888fd
movq 0xe0(%rsp), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0xe8(%rsp), %rdi
callq 0x143a0
movaps %xmm0, %xmm1
movsd 0x20(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x88(%rsp)
movq 0xf8(%rsp), %rax
movq 0x90(%rax), %rax
movq 0xf8(%rsp), %rcx
cmpq 0x98(%rcx), %rax
ja 0x887c4
movq 0xf8(%rsp), %rdi
callq 0xc670
movq 0xf8(%rsp), %rcx
movq 0x90(%rcx), %rax
movq %rax, %rdx
addq $-0x8, %rdx
movq %rdx, 0x90(%rcx)
movq -0x8(%rax), %rax
movq %rax, 0x90(%rsp)
movq 0x90(%rsp), %rax
movq $0xd, (%rax)
movsd 0x88(%rsp), %xmm0
movq 0x90(%rsp), %rax
movsd %xmm0, 0x8(%rax)
movq 0x90(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0x100(%rsp)
jmp 0x888fd
movq 0xf8(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0xe0(%rsp), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, (%rsp)
movq 0xe8(%rsp), %rdi
callq 0x143a0
movaps %xmm0, %xmm1
movsd (%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0xe0(%rsp), %rax
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0xe8(%rsp), %rdi
callq 0x143a0
movsd 0x8(%rsp), %xmm1
movq 0x10(%rsp), %rdi
movaps %xmm0, %xmm2
movsd 0x18(%rsp), %xmm0
mulsd %xmm2, %xmm1
callq 0x122a0
movq %rax, 0x100(%rsp)
jmp 0x888fd
movq 0xf8(%rsp), %rdi
movq 0xe0(%rsp), %rsi
movq 0xf8(%rsp), %rax
movq 0x1430(%rax), %rdx
movq 0xf0(%rsp), %rcx
movq 0x19c606(%rip), %r8     # 0x224ef0
movl $0x1, %r9d
callq 0x14130
movq %rax, 0x100(%rsp)
movq 0x100(%rsp), %rax
addq $0x108, %rsp            # imm = 0x108
retq
nopl (%rax)