// File: /workspace/github_c_makefile_star2_O3/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), %r15
movzbl (%r15), %r12d
leaq 0xe447d(%rip), %rdx     # 0x14a970
cmpb $0x0, (%r12,%rdx)
je 0x6654d
movq 0x10(%rcx), %rax
cmpb $0x1, (%rax)
jne 0x66577
movq 0x8(%rax), %r14
movzbl (%r14), %eax
cmpb $0x0, (%rax,%rdx)
je 0x6660b
movq 0xe0444(%rip), %rdx     # 0x146960
cmpq %rdx, %r14
je 0x66666
movq 0xe042c(%rip), %rcx     # 0x146958
movq %r15, %rsi
xorq %rcx, %rsi
movq %r14, %rdi
xorq %rcx, %rdi
orq %rsi, %rdi
jne 0x666b3
movq 0xe0408(%rip), %r14     # 0x146950
jmp 0x667da
movq 0x1290(%rbx), %rdx
movq 0xeee45(%rip), %r8      # 0x1553a0
movq %rbx, %rdi
movq %r15, %rsi
movl $0x1, %r9d
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0xe659
leaq 0xe4432(%rip), %rax     # 0x14a9b0
cmpb $0x1, (%r12,%rax)
jne 0x6662a
cmpl $0xb, %r12d
je 0x66599
cmpl $0xc, %r12d
jne 0x66690
cmpq $0x0, 0x8(%r15)
jle 0x66762
movq 0xe4485(%rip), %rdi     # 0x14aa30
leaq 0xa3ac6(%rip), %rdx     # 0x10a078
movq %r15, %rsi
callq 0xd498
callq 0x82b0
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x665ea
movq %rbx, %rdi
movsd %xmm0, 0x8(%rsp)
callq 0xa550
movsd 0x8(%rsp), %xmm0
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r14
movq $0xd, (%r14)
movsd %xmm0, 0x8(%r14)
jmp 0x667da
movq 0x1290(%rbx), %rdx
movq 0xeed87(%rip), %r8      # 0x1553a0
movq %rbx, %rdi
movq %r14, %rsi
movl $0x2, %r9d
jmp 0x66567
movq %r15, %rdi
callq 0xe238
xorpd %xmm2, %xmm2
xorpd %xmm1, %xmm1
cmpl $0xe, %r12d
jne 0x66646
movsd 0x10(%r15), %xmm1
mulsd %xmm1, %xmm2
addsd %xmm2, %xmm0
callq 0x82a0
movq %rbx, %rdi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0xd387
cmpl $0xb, %r12d
jne 0x666f5
movq 0x8(%r15), %rax
testq %rax, %rax
jle 0x666f5
cvtsi2sd %rax, %xmm0
callq 0x82b0
divsd 0x9fa0d(%rip), %xmm0    # 0x106098
jmp 0x665bf
movsd 0x8(%r15), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x6675c
cmpl $0xd, %r12d
jne 0x665a4
jmp 0x665ba
cmpq $0xb, %rax
je 0x667e9
cmpl $0xd, %eax
jne 0x6685c
movsd 0x8(%r14), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x666dc
jnp 0x667fc
ucomisd 0x9f94c(%rip), %xmm0    # 0x106030
jne 0x6685c
jnp 0x6689f
jmp 0x6685c
leaq 0xe42b4(%rip), %rax     # 0x14a9b0
cmpb $0x1, (%r12,%rax)
jne 0x668f8
cmpq $0xb, %r12
je 0x66717
cmpl $0xc, %r12d
jne 0x668d9
cmpq $0x0, 0x8(%r15)
jle 0x66912
movq 0xe4307(%rip), %rdi     # 0x14aa30
leaq 0xa3948(%rip), %rdx     # 0x10a078
movq %r15, %rsi
callq 0xd498
callq 0x82b0
movsd %xmm0, 0x20(%rsp)
fldt 0xa3827(%rip)           # 0x109f70
fmull 0x20(%rsp)
fstpl 0x18(%rsp)
movsd 0x18(%rsp), %xmm0
jmp 0x665bf
cmpl $0xd, %r12d
je 0x66778
movq 0xe42c7(%rip), %rdi     # 0x14aa30
leaq 0xa3908(%rip), %rdx     # 0x10a078
movq %r15, %rsi
callq 0xd498
xorpd 0xa3730(%rip), %xmm0    # 0x109eb0
callq 0x82b0
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x667b0
movq %rbx, %rdi
movsd %xmm0, 0x8(%rsp)
callq 0xa550
movsd 0x8(%rsp), %xmm0
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r14
movq $0xe, (%r14)
movsd %xmm0, 0x8(%r14)
movabsq $0x400921fb54442d18, %rax # imm = 0x400921FB54442D18
movq %rax, 0x10(%r14)
movq %r14, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq 0x8(%r14), %rsi
cmpq $0x1, %rsi
je 0x6689f
testq %rsi, %rsi
jne 0x6685c
cmpq %rcx, %r15
jne 0x6680a
cmpq 0xe0148(%rip), %r14     # 0x146950
je 0x667da
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 0xb4ebd(%rip), %rax     # 0x11b6f7
movq %rax, 0x10(%r8)
movq $0xa, 0x8(%r8)
movq %rbx, %rdi
movq %r14, %rcx
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0xe1fe
leaq 0xe414d(%rip), %rcx     # 0x14a9b0
cmpb $0x1, (%r12,%rcx)
jne 0x66a3f
cmpb $0x1, (%rax,%rcx)
jne 0x66a3f
cmpl $0xb, %r12d
je 0x66888
cmpl $0xc, %r12d
jne 0x66983
movq 0x8(%r15), %rcx
testq %rcx, %rcx
jle 0x66a1d
movq %rcx, %xmm0
jmp 0x6699c
cmpl $0xb, %r12d
je 0x6696c
cmpl $0xd, %r12d
jne 0x66977
movsd 0x8(%r15), %xmm0
ucomisd 0x9f76f(%rip), %xmm0    # 0x106030
jne 0x66977
jp 0x66977
movq 0xe4384(%rip), %r14     # 0x14ac58
jmp 0x667da
movsd 0x8(%r15), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x668f8
cmpl $0xd, %r12d
jne 0x66722
jmp 0x66738
movq %r15, %rdi
callq 0xe238
xorpd %xmm1, %xmm1
cmpl $0xe, %r12d
jne 0x6691e
movsd 0x10(%r15), %xmm1
jmp 0x6691e
movq %r15, %rdi
callq 0xe238
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
mulsd %xmm1, %xmm2
addsd %xmm0, %xmm2
movapd %xmm2, %xmm0
callq 0x82a0
movsd %xmm0, 0x40(%rsp)
movsd %xmm1, 0x38(%rsp)
fldt 0xa362b(%rip)           # 0x109f70
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 0x66653
cmpq $0x1, 0x8(%r15)
je 0x668cd
movq 0xe7522(%rip), %r14     # 0x14dea0
jmp 0x667da
movsd 0x8(%r15), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x66a3f
movq %xmm0, %rcx
cmpq $0xb, %rax
je 0x669ab
cmpl $0xc, %eax
jne 0x66a2b
cmpq $0x0, 0x8(%r14)
jle 0x66a3f
leaq 0xe4033(%rip), %rdx     # 0x14a9f0
cmpb $0x1, (%r12,%rdx)
jne 0x669e1
cmpb $0x1, (%rax,%rdx)
jne 0x669e1
cmpl $0xb, %r12d
jne 0x66af1
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
jmp 0x66b13
cmpl $0xd, %r12d
je 0x669fd
movq 0xe4042(%rip), %rdi     # 0x14aa30
leaq 0xa3683(%rip), %rdx     # 0x10a078
movq %r15, %rsi
callq 0xd498
callq 0x82b0
movsd %xmm0, 0x8(%rsp)
cmpb $0xd, (%r14)
jne 0x66ac3
movsd 0x8(%r14), %xmm0
jmp 0x66ad9
movq %r15, %rdi
callq 0xe238
xorpd %xmm1, %xmm1
jmp 0x66a57
movsd 0x8(%r14), %xmm1
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm1
ja 0x669b6
movq %r15, %rdi
callq 0xe238
xorpd %xmm1, %xmm1
cmpl $0xe, %r12d
jne 0x66a57
movsd 0x10(%r15), %xmm1
xorpd %xmm3, %xmm3
movapd %xmm1, %xmm2
mulsd %xmm3, %xmm2
addsd %xmm0, %xmm2
movapd %xmm2, %xmm0
callq 0x82a0
movsd %xmm0, 0x8(%rsp)
movsd %xmm1, 0x10(%rsp)
movq %r14, %rdi
callq 0xe238
cmpb $0xe, (%r14)
xorpd %xmm1, %xmm1
jne 0x66a94
movsd 0x10(%r14), %xmm1
xorpd %xmm2, %xmm2
mulsd %xmm1, %xmm2
addsd %xmm2, %xmm0
callq 0x82a0
movapd %xmm0, %xmm2
movapd %xmm1, %xmm3
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
callq 0x1054a0
jmp 0x66653
movq 0xe3f66(%rip), %rdi     # 0x14aa30
leaq 0xa35a7(%rip), %rdx     # 0x10a078
movq %r14, %rsi
callq 0xd498
callq 0x82b0
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
movapd %xmm1, %xmm0
jmp 0x665bf
movq %rcx, 0x68(%rsp)
fildll 0x68(%rsp)
movq 0x10(%r15), %rax
movq %rax, 0x70(%rsp)
fildll 0x70(%rsp)
fdivrp %st, %st(1)
fstpl 0x60(%rsp)
movsd 0x60(%rsp), %xmm0
callq 0x82b0
cmpb $0xb, (%r14)
movq 0x8(%r14), %rax
movsd %xmm0, 0x8(%rsp)
jne 0x66b32
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
jmp 0x66b54
movq %rax, 0x50(%rsp)
fildll 0x50(%rsp)
movq 0x10(%r14), %rax
movq %rax, 0x58(%rsp)
fildll 0x58(%rsp)
fdivrp %st, %st(1)
fstpl 0x48(%rsp)
movsd 0x48(%rsp), %xmm0
callq 0x82b0
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
cvttsd2si %xmm1, %r15
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
ucomisd %xmm0, %xmm1
jne 0x66b91
jp 0x66b91
cmpq $0x7ff, %r15            # imm = 0x7FF
ja 0x66bdd
leaq 0xdfdc8(%rip), %rax     # 0x146950
movq (%rax,%r15,8), %r14
jmp 0x667da
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x66bbc
movq %rbx, %rdi
movsd %xmm1, 0x8(%rsp)
callq 0xa550
movsd 0x8(%rsp), %xmm1
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r14
movq $0xd, (%r14)
movsd %xmm1, 0x8(%r14)
jmp 0x667da
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x66bfc
movq %rbx, %rdi
callq 0xa550
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r14
movq $0xb, (%r14)
movq %r15, 0x8(%r14)
jmp 0x667da