// File: /workspace/github_c_makefile_star2_O1/BernardTatin[P]s7sh/s7.c
// Function: g_log
static s7_pointer g_log(s7_scheme *sc, s7_pointer args)
    {
#define H_log "(log z1 (z2 e)) returns log(z1) / log(z2) where z2 (the base) defaults to e: (log 8 2) = 3"
#define Q_log sc->pcl_n

        s7_pointer x;
        x = car(args);
        if (!s7_is_number(x))
            return(method_or_bust_with_type(sc, x, sc->log_symbol, args, a_number_string, 1));

        if (is_pair(cdr(args)))
        {
            s7_pointer y;

            y = cadr(args);
            if (!(s7_is_number(y)))
                return(method_or_bust_with_type(sc, y, sc->log_symbol, args, a_number_string, 2));

            if (y == small_int(2))
            {
                /* (define (2^n? x) (and (not (zero? x)) (zero? (logand x (- x 1))))) */
                if (is_t_integer(x))
                {
                    s7_int ix;
                    ix = s7_integer(x);
                    if (ix > 0)
                    {
                        s7_double fx;
#if (__ANDROID__) || (MS_WINDOWS) || ((__GNUC__) && ((__GNUC__ < 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ <= 4))))
                        /* just a guess -- log2 gets a warning in gcc 4.3.2, but not in 4.4.4 */
                        fx = log((double)ix) / log(2.0);
#else
                        fx = log2((double)ix);
#endif
                        /* (s7_int)fx rounds (log 8 2) to 2 in FreeBSD! */
#if ((__GNUC__) && ((__GNUC__ < 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ < 4))))
                        return(make_real(sc, fx));
#else
                        if ((ix & (ix - 1)) == 0)
                            return(make_integer(sc, (s7_int)s7_round(fx)));
                        return(make_real(sc, fx));
#endif
                    }
                }
                if ((s7_is_real(x)) &&
                        (s7_is_positive(x)))
                    return(make_real(sc, log(s7_real(x)) * LOG_2));
                return(s7_from_c_complex(sc, clog(s7_to_c_complex(x)) * LOG_2));
            }

            if ((x == small_int(1)) && (y == small_int(1)))  /* (log 1 1) -> 0 (this is NaN in the bignum case) */
                return(small_int(0));

            /* (log 1 0) must be 0 since everyone says (expt 0 0) is 1 */
            if (s7_is_zero(y))
            {
                if ((y == small_int(0)) &&
                        (x == small_int(1)))
                    return(y);
                return(out_of_range(sc, sc->log_symbol, small_int(2), y, wrap_string(sc, "can't be 0", 10)));
            }

            if (s7_is_one(y))          /* this used to raise an error, but the bignum case is simpler if we return inf */
            {
                if (s7_is_one(x))      /* but (log 1.0 1.0) -> 0.0 */
                    return(real_zero);
                return(real_infinity); /* currently (log 1/0 1) is inf? */
            }

            if ((s7_is_real(x)) &&
                    (s7_is_real(y)) &&
                    (s7_is_positive(x)) &&
                    (s7_is_positive(y)))
            {
                if ((s7_is_rational(x)) &&
                        (s7_is_rational(y)))
                {
                    s7_double res;
                    s7_int ires;
                    res = log(rational_to_double(sc, x)) / log(rational_to_double(sc, y));
                    ires = (s7_int)res;
                    if (res - ires == 0.0)
                        return(make_integer(sc, ires));   /* (log 8 2) -> 3 or (log 1/8 2) -> -3 */
                    return(make_real(sc, res));         /* perhaps use rationalize here? (log 2 8) -> 1/3 */
                }
                return(make_real(sc, log(s7_real(x)) / log(s7_real(y))));
            }
            return(s7_from_c_complex(sc, clog(s7_to_c_complex(x)) / clog(s7_to_c_complex(y))));
        }

        if (s7_is_real(x))
        {
            if (s7_is_positive(x))
                return(make_real(sc, log(s7_real(x))));
            return(s7_make_complex(sc, log(-s7_real(x)), M_PI));
        }
        return(s7_from_c_complex(sc, clog(s7_to_c_complex(x))));
    }

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %rcx
movq %rdi, %rbx
movq 0x8(%rsi), %r14
movzbl (%r14), %r12d
leaq 0xe746c(%rip), %rdx     # 0x152970
cmpb $0x0, (%r12,%rdx)
je 0x6b55e
movq 0x10(%rcx), %rax
cmpb $0x1, (%rax)
jne 0x6b588
movq 0x8(%rax), %r15
movzbl (%r15), %eax
cmpb $0x0, (%rax,%rdx)
je 0x6b5b3
movq 0xe3433(%rip), %rdx     # 0x14e960
cmpq %rdx, %r15
je 0x6b60b
movq 0xe341b(%rip), %rcx     # 0x14e958
movq %r14, %rsi
xorq %rcx, %rsi
movq %r15, %rdi
xorq %rcx, %rdi
orq %rsi, %rdi
jne 0x6b6b8
movq 0xe33f7(%rip), %r15     # 0x14e950
jmp 0x6b7b5
movq 0x1290(%rbx), %rdx
movq 0xf1e34(%rip), %r8      # 0x15d3a0
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %r9d
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0xf3da
leaq 0xe7421(%rip), %rax     # 0x1529b0
cmpb $0x1, (%r12,%rax)
jne 0x6b5cf
cmpl $0xc, %r12d
je 0x6b5a6
cmpl $0xb, %r12d
jne 0x6b680
cmpq $0x0, 0x8(%r14)
setg %al
jmp 0x6b691
movq 0x1290(%rbx), %rdx
movq 0xf1ddf(%rip), %r8      # 0x15d3a0
movq %rbx, %rdi
movq %r15, %rsi
movl $0x2, %r9d
jmp 0x6b578
movq %r14, %rdi
callq 0xefb9
xorpd %xmm2, %xmm2
xorpd %xmm1, %xmm1
cmpl $0xe, %r12d
jne 0x6b5eb
movsd 0x10(%r14), %xmm1
mulsd %xmm1, %xmm2
addsd %xmm2, %xmm0
callq 0x92a0
movq %rbx, %rdi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0xe101
cmpl $0xb, %r12d
jne 0x6b8ed
movq 0x8(%r14), %r12
testq %r12, %r12
jle 0x6b8e4
cvtsi2sd %r12, %xmm0
callq 0x92b0
divsd 0xa3a64(%rip), %xmm0    # 0x10f098
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x6b658
movq %rbx, %rdi
movsd %xmm0, 0x8(%rsp)
callq 0xb389
movsd 0x8(%rsp), %xmm0
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r15
movq $0xd, (%r15)
movsd %xmm0, 0x8(%r15)
jmp 0x6b8e4
movsd 0x8(%r14), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
seta %al
testb %al, %al
je 0x6b6a3
cmpl $0xd, %r12d
jne 0x6b6d9
movsd 0x8(%r14), %xmm0
jmp 0x6b6ef
cmpl $0xd, %r12d
jne 0x6b73d
movsd 0x8(%r14), %xmm0
jmp 0x6b753
cmpq $0xd, %rax
je 0x6b7c4
cmpl $0xb, %eax
jne 0x6b8ab
cmpq $0x0, 0x8(%r15)
sete %sil
jmp 0x6b7d7
movq 0xe7350(%rip), %rdi     # 0x152a30
leaq 0xa7881(%rip), %rdx     # 0x112f68
movq %r14, %rsi
callq 0xe212
callq 0x92b0
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x6b718
movq %rbx, %rdi
movsd %xmm0, 0x8(%rsp)
callq 0xb389
movsd 0x8(%rsp), %xmm0
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r15
movq $0xd, (%r15)
movsd %xmm0, 0x8(%r15)
jmp 0x6b7b5
movq 0xe72ec(%rip), %rdi     # 0x152a30
leaq 0xa781d(%rip), %rdx     # 0x112f68
movq %r14, %rsi
callq 0xe212
xorpd 0xa7665(%rip), %xmm0    # 0x112dc0
callq 0x92b0
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x6b784
movq %rbx, %rdi
movsd %xmm0, 0x8(%rsp)
callq 0xb389
movsd 0x8(%rsp), %xmm0
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r15
movq $0xe, (%r15)
movsd %xmm0, 0x8(%r15)
movabsq $0x400921fb54442d18, %rax # imm = 0x400921FB54442D18
movq %rax, 0x10(%r15)
movq %r15, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
xorpd %xmm0, %xmm0
cmpeqsd 0x8(%r15), %xmm0
movq %xmm0, %rsi
andl $0x1, %esi
testb %sil, %sil
je 0x6b83c
cmpq %rcx, %r14
jne 0x6b7ea
cmpq 0xe3168(%rip), %r15     # 0x14e950
je 0x6b7b5
movq 0x1290(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0x820(%rbx), %rax
movslq 0x7dc(%rbx), %rcx
movq (%rax,%rcx,8), %r8
leal 0x1(%rcx), %eax
andl $0x7, %eax
movl %eax, 0x7dc(%rbx)
leaq 0xb8dcd(%rip), %rax     # 0x1245e7
movq %rax, 0x10(%r8)
movq $0xa, 0x8(%r8)
movq %rbx, %rdi
movq %r15, %rcx
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0xef7f
cmpl $0xd, %eax
je 0x6b852
cmpl $0xb, %eax
jne 0x6b8ab
cmpq $0x1, 0x8(%r15)
je 0x6b864
cmpl $0xd, %eax
jne 0x6b8ab
movsd 0x8(%r15), %xmm0
ucomisd 0xa37d0(%rip), %xmm0    # 0x10f030
jne 0x6b8ab
jp 0x6b8ab
cmpl $0xd, %r12d
je 0x6b885
cmpl $0xb, %r12d
jne 0x6b9d4
cmpq $0x1, 0x8(%r14)
je 0x6b89f
cmpl $0xd, %r12d
jne 0x6b9d4
movsd 0x8(%r14), %xmm0
ucomisd 0xa379d(%rip), %xmm0    # 0x10f030
jne 0x6b9d4
jp 0x6b9d4
movq 0xe73b2(%rip), %r15     # 0x152c58
jmp 0x6b7b5
leaq 0xe70fe(%rip), %rcx     # 0x1529b0
cmpb $0x1, (%r12,%rcx)
jne 0x6ba56
cmpb $0x1, (%rax,%rcx)
jne 0x6ba56
cmpl $0xc, %r12d
je 0x6b8d7
cmpl $0xb, %r12d
jne 0x6b9e0
cmpq $0x0, 0x8(%r14)
setg %cl
jmp 0x6b9f1
testq %r12, %r12
jg 0x6b7b5
movzbl (%r14), %r15d
leaq 0xe70b8(%rip), %rax     # 0x1529b0
cmpb $0x1, (%r15,%rax)
jne 0x6b938
cmpl $0xc, %r15d
je 0x6b90b
cmpl $0xb, %r15d
jne 0x6b915
cmpq $0x0, 0x8(%r14)
setg %al
jmp 0x6b926
movsd 0x8(%r14), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
seta %al
testb %al, %al
je 0x6b938
cmpl $0xd, %r15d
jne 0x6b99a
movsd 0x8(%r14), %xmm0
jmp 0x6b9b0
movq %r14, %rdi
callq 0xefb9
xorpd %xmm2, %xmm2
xorpd %xmm1, %xmm1
cmpl $0xe, %r15d
jne 0x6b954
movsd 0x10(%r14), %xmm1
mulsd %xmm1, %xmm2
addsd %xmm2, %xmm0
callq 0x92a0
movsd %xmm0, 0x40(%rsp)
movsd %xmm1, 0x38(%rsp)
fldt 0xa750d(%rip)           # 0x112e80
fld %st(0)
fmull 0x40(%rsp)
fxch %st(1)
fmull 0x38(%rsp)
fxch %st(1)
fstpl 0x30(%rsp)
movsd 0x30(%rsp), %xmm0
fstpl 0x28(%rsp)
movsd 0x28(%rsp), %xmm1
jmp 0x6b5f8
movq 0xe708f(%rip), %rdi     # 0x152a30
leaq 0xa75c0(%rip), %rdx     # 0x112f68
movq %r14, %rsi
callq 0xe212
callq 0x92b0
movsd %xmm0, 0x20(%rsp)
fldt 0xa74bf(%rip)           # 0x112e80
fmull 0x20(%rsp)
fstpl 0x18(%rsp)
movsd 0x18(%rsp), %xmm0
jmp 0x6b6f4
movq 0xea4c5(%rip), %r15     # 0x155ea0
jmp 0x6b7b5
movsd 0x8(%r14), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
seta %cl
testb %cl, %cl
je 0x6ba56
cmpq $0xc, %rax
je 0x6ba00
cmpl $0xb, %eax
jne 0x6ba0a
cmpq $0x0, 0x8(%r15)
setg %cl
jmp 0x6ba1b
movsd 0x8(%r15), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
seta %cl
testb %cl, %cl
je 0x6ba56
leaq 0xe6fca(%rip), %rcx     # 0x1529f0
cmpb $0x1, (%r12,%rcx)
jne 0x6bad6
cmpb $0x1, (%rax,%rcx)
jne 0x6bad6
movq 0x8(%r14), %rax
cmpl $0xb, %r12d
jne 0x6bb41
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
jmp 0x6bb63
movq %r14, %rdi
callq 0xefb9
xorpd %xmm3, %xmm3
xorpd %xmm1, %xmm1
cmpl $0xe, %r12d
jne 0x6ba72
movsd 0x10(%r14), %xmm1
movapd %xmm1, %xmm2
mulsd %xmm3, %xmm2
addsd %xmm2, %xmm0
callq 0x92a0
movsd %xmm0, 0x8(%rsp)
movsd %xmm1, 0x10(%rsp)
movq %r15, %rdi
callq 0xefb9
xorpd %xmm1, %xmm1
cmpb $0xe, (%r15)
jne 0x6baa7
movsd 0x10(%r15), %xmm1
xorpd %xmm2, %xmm2
mulsd %xmm1, %xmm2
addsd %xmm2, %xmm0
callq 0x92a0
movapd %xmm0, %xmm2
movapd %xmm1, %xmm3
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
callq 0x10ea30
jmp 0x6b5f8
cmpl $0xd, %r12d
jne 0x6bae4
movsd 0x8(%r14), %xmm0
jmp 0x6bafa
movq 0xe6f45(%rip), %rdi     # 0x152a30
leaq 0xa7476(%rip), %rdx     # 0x112f68
movq %r14, %rsi
callq 0xe212
callq 0x92b0
movsd %xmm0, 0x8(%rsp)
cmpb $0xd, (%r15)
jne 0x6bb13
movsd 0x8(%r15), %xmm0
jmp 0x6bb29
movq 0xe6f16(%rip), %rdi     # 0x152a30
leaq 0xa7447(%rip), %rdx     # 0x112f68
movq %r15, %rsi
callq 0xe212
callq 0x92b0
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
movapd %xmm1, %xmm0
jmp 0x6b6f4
movq %rax, 0x68(%rsp)
fildll 0x68(%rsp)
movq 0x10(%r14), %rax
movq %rax, 0x70(%rsp)
fildll 0x70(%rsp)
fdivrp %st, %st(1)
fstpl 0x60(%rsp)
movsd 0x60(%rsp), %xmm0
callq 0x92b0
cmpb $0xb, (%r15)
movq 0x8(%r15), %rax
movsd %xmm0, 0x8(%rsp)
jne 0x6bb82
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
jmp 0x6bba4
movq %rax, 0x50(%rsp)
fildll 0x50(%rsp)
movq 0x10(%r15), %rax
movq %rax, 0x58(%rsp)
fildll 0x58(%rsp)
fdivrp %st, %st(1)
fstpl 0x48(%rsp)
movsd 0x48(%rsp), %xmm0
callq 0x92b0
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
cvttsd2si %xmm1, %r14
xorps %xmm0, %xmm0
cvtsi2sd %r14, %xmm0
ucomisd %xmm0, %xmm1
jne 0x6bbe1
jp 0x6bbe1
cmpq $0x7ff, %r14            # imm = 0x7FF
ja 0x6bc27
leaq 0xe2d78(%rip), %rax     # 0x14e950
movq (%rax,%r14,8), %r15
jmp 0x6b7b5
movsd %xmm1, 0x8(%rsp)
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x6bbff
movq %rbx, %rdi
callq 0xb389
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r15
movq $0xd, (%r15)
movsd 0x8(%rsp), %xmm0
jmp 0x6b735
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x6bc3f
movq %rbx, %rdi
callq 0xb389
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r15
movq $0xb, (%r15)
movq %r14, 0x8(%r15)
jmp 0x6b7b5