// File: /workspace/github_c_makefile_star2_O0/BernardTatin[P]s7sh/s7.c
// Function: g_logbit
static s7_pointer g_logbit(s7_scheme *sc, s7_pointer args)
    {
#define H_logbit "(logbit? int index) returns #t if the index-th bit is on in int, otherwise #f. The argument \
        order here follows gmp, and is the opposite of the CL convention.  (logbit? int bit) is the same as (not (zero? (logand int (ash 1 bit))))."
#define Q_logbit s7_make_circular_signature(sc, 1, 2, sc->is_boolean_symbol, sc->is_integer_symbol)

        s7_pointer x, y;
        s7_int index;      /* index in gmp is mp_bitcnt which is an unsigned long int */

        x = car(args);
        y = cadr(args);

        if (!s7_is_integer(x))
            return(method_or_bust(sc, x, sc->logbit_symbol, args, T_INTEGER, 1));
        if (!s7_is_integer(y))
            return(method_or_bust(sc, y, sc->logbit_symbol, args, T_INTEGER, 2));

        index = s7_integer(y);
        if (index < 0)
            return(out_of_range(sc, sc->logbit_symbol, small_int(2), y, its_negative_string));

#if WITH_GMP
        if (is_t_big_integer(x))
            return(make_boolean(sc, (mpz_tstbit(big_integer(x), index) != 0)));
#endif

        if (index >= s7_int_bits)           /* not sure about the >: (logbit? -1 64) ?? */
            return(make_boolean(sc, integer(x) < 0));

        /* (zero? (logand most-positive-fixnum (ash 1 63))) -> ash argument 2, 63, is out of range (shift is too large)
         *   so logbit? has a wider range than the logand/ash shuffle above.
         */

        /* all these int64_ts are necessary, else C turns it into an int, gets confused about signs etc */
        return(make_boolean(sc, ((((int64_t)(1LL << (int64_t)index)) & (int64_t)integer(x)) != 0)));
    }

// 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 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x28(%rsp), %rdi
callq 0x11340
testb $0x1, %al
jne 0x89632
movq 0x38(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x38(%rsp), %rax
movq 0x12a0(%rax), %rdx
movq 0x30(%rsp), %rcx
movl $0xb, %r8d
movl $0x1, %r9d
callq 0x13c50
movq %rax, 0x40(%rsp)
jmp 0x8975b
movq 0x20(%rsp), %rdi
callq 0x11340
testb $0x1, %al
jne 0x89676
movq 0x38(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x38(%rsp), %rax
movq 0x12a0(%rax), %rdx
movq 0x30(%rsp), %rcx
movl $0xb, %r8d
movl $0x2, %r9d
callq 0x13c50
movq %rax, 0x40(%rsp)
jmp 0x8975b
movq 0x20(%rsp), %rdi
callq 0x10790
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
jge 0x896c4
movq 0x38(%rsp), %rdi
movq 0x38(%rsp), %rax
movq 0x12a0(%rax), %rax
movq 0x8(%rax), %rsi
movq 0x18cde7(%rip), %rdx    # 0x216490
movq 0x20(%rsp), %rcx
movq 0x190ec3(%rip), %r8     # 0x21a578
callq 0x13880
movq %rax, 0x40(%rsp)
jmp 0x8975b
movq 0x18(%rsp), %rax
movslq 0x1910c0(%rip), %rcx    # 0x21a790
cmpq %rcx, %rax
jl 0x89711
movq 0x28(%rsp), %rax
cmpq $0x0, 0x8(%rax)
jge 0x896f4
movq 0x38(%rsp), %rax
movq 0x118(%rax), %rax
movq %rax, 0x10(%rsp)
jmp 0x89705
movq 0x38(%rsp), %rax
movq 0x120(%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0x8975b
movq 0x18(%rsp), %rcx
movl $0x1, %eax
shlq %cl, %rax
movq 0x28(%rsp), %rcx
andq 0x8(%rcx), %rax
cmpq $0x0, %rax
je 0x89740
movq 0x38(%rsp), %rax
movq 0x118(%rax), %rax
movq %rax, 0x8(%rsp)
jmp 0x89751
movq 0x38(%rsp), %rax
movq 0x120(%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rax
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)