// File: /workspace/github_c_makefile_star2_O0/BernardTatin[P]s7sh/s7.c
// Function: s7_random_state
s7_pointer s7_random_state(s7_scheme *sc, s7_pointer args)
    {
#define H_random_state "(random-state seed (carry plausible-default)) returns a new random number state initialized with 'seed'. \
        Pass this as the second argument to 'random' to get a repeatable random number sequence:\n\
        (let ((seed (random-state 1234))) (random 1.0 seed))"
#define Q_random_state s7_make_circular_signature(sc, 1, 2, sc->is_random_state_symbol, sc->is_integer_symbol)

        s7_pointer r1, r2, p;
        s7_int i1, i2;

        r1 = car(args);
        if (!s7_is_integer(r1))
            return(method_or_bust(sc, r1, sc->random_state_symbol, args, T_INTEGER, 1));
        i1 = integer(r1);
        if (i1 < 0)
            return(out_of_range(sc, sc->random_state_symbol, small_int(1), r1, its_negative_string));

        if (is_null(cdr(args)))
        {
            new_cell(sc, p, T_RANDOM_STATE);
            random_seed(p) = (uint64_t)i1;
            random_carry(p) = 1675393560;                          /* should this be dependent on the seed? */
            return(p);
        }

        r2 = cadr(args);
        if (!s7_is_integer(r2))
            return(method_or_bust(sc, r2, sc->random_state_symbol, args, T_INTEGER, 2));
        i2 = integer(r2);
        if (i2 < 0)
            return(out_of_range(sc, sc->random_state_symbol, small_int(2), r2, its_negative_string));

        new_cell(sc, p, T_RANDOM_STATE);
        random_seed(p) = (uint64_t)i1;
        random_carry(p) = (uint64_t)i2;
        return(p);
    }

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x38(%rsp)
movq %rsi, 0x30(%rsp)
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rdi
callq 0x11340
testb $0x1, %al
jne 0x13a40
movq 0x38(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x38(%rsp), %rax
movq 0x1420(%rax), %rdx
movq 0x30(%rsp), %rcx
movl $0xb, %r8d
movl $0x1, %r9d
callq 0x13c50
movq %rax, 0x40(%rsp)
jmp 0x13c3e
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
jge 0x13a8d
movq 0x38(%rsp), %rdi
movq 0x38(%rsp), %rax
movq 0x1420(%rax), %rax
movq 0x8(%rax), %rsi
movq 0x202a16(%rip), %rdx    # 0x216488
movq 0x28(%rsp), %rcx
movq 0x206afa(%rip), %r8     # 0x21a578
callq 0x13880
movq %rax, 0x40(%rsp)
jmp 0x13c3e
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x38(%rsp), %rcx
cmpq 0x110(%rcx), %rax
jne 0x13b23
jmp 0x13aa6
movq 0x38(%rsp), %rax
movq 0x90(%rax), %rax
movq 0x38(%rsp), %rcx
cmpq 0x98(%rcx), %rax
ja 0x13aca
movq 0x38(%rsp), %rdi
callq 0xc670
movq 0x38(%rsp), %rcx
movq 0x90(%rcx), %rax
movq %rax, %rdx
addq $-0x8, %rdx
movq %rdx, 0x90(%rcx)
movq -0x8(%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq $0x24, (%rax)
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x18(%rsp), %rax
movq $0x63dc7a18, 0x10(%rax) # imm = 0x63DC7A18
movq 0x18(%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0x13c3e
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rdi
callq 0x11340
testb $0x1, %al
jne 0x13b79
movq 0x38(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x38(%rsp), %rax
movq 0x1420(%rax), %rdx
movq 0x30(%rsp), %rcx
movl $0xb, %r8d
movl $0x2, %r9d
callq 0x13c50
movq %rax, 0x40(%rsp)
jmp 0x13c3e
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, 0x8(%rsp)
jge 0x13bc3
movq 0x38(%rsp), %rdi
movq 0x38(%rsp), %rax
movq 0x1420(%rax), %rax
movq 0x8(%rax), %rsi
movq 0x2028e5(%rip), %rdx    # 0x216490
movq 0x20(%rsp), %rcx
movq 0x2069c1(%rip), %r8     # 0x21a578
callq 0x13880
movq %rax, 0x40(%rsp)
jmp 0x13c3e
jmp 0x13bc5
movq 0x38(%rsp), %rax
movq 0x90(%rax), %rax
movq 0x38(%rsp), %rcx
cmpq 0x98(%rcx), %rax
ja 0x13be9
movq 0x38(%rsp), %rdi
callq 0xc670
movq 0x38(%rsp), %rcx
movq 0x90(%rcx), %rax
movq %rax, %rdx
addq $-0x8, %rdx
movq %rdx, 0x90(%rcx)
movq -0x8(%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq $0x24, (%rax)
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x8(%rsp), %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x18(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rax
addq $0x48, %rsp
retq
nopl (%rax,%rax)