// File: /workspace/github_c_makefile_star2_O3/BernardTatin[P]s7sh/s7.c
// Function: g_sqrt
static s7_pointer g_sqrt(s7_scheme *sc, s7_pointer args)
    {
#define H_sqrt "(sqrt z) returns the square root of z"
#define Q_sqrt sc->pl_nn

        s7_pointer n;
        s7_double sqx;

        n = car(args);
        switch (type(n))
        {
            case T_INTEGER:
                if (integer(n) >= 0)
                {
                    s7_int ix;
                    sqx = sqrt((s7_double)integer(n));
                    ix = (s7_int)sqx;
                    if ((ix * ix) == integer(n))
                        return(make_integer(sc, ix));
                    return(make_real(sc, sqx));
                    /* Mark Weaver notes that
                     *     (zero? (- (sqrt 9007199136250226) 94906265.0)) -> #t
                     * but (* 94906265 94906265) -> 9007199136250225 -- oops
                     * at least we return a real here, not an incorrect integer and
                     *     (sqrt 9007199136250225) -> 94906265
                     */
                }
                sqx = (s7_double)integer(n); /* we're trying to protect against (sqrt -9223372036854775808) where we can't negate the integer argument */
                return(s7_make_complex(sc, 0.0, sqrt((s7_double)(-sqx))));

            case T_RATIO:
                sqx = (s7_double)fraction(n);
                if (sqx > 0.0) /* else it's complex, so it can't be a ratio */
                {
                    s7_int nm = 0, dn = 1;
                    if (c_rationalize(sqx, 1.0e-16, &nm, &dn)) /* 1e-16 so that (sqrt 1/1099511627776) returns 1/1048576 */
                    {
#if HAVE_OVERFLOW_CHECKS
                        s7_int nm2, dn2;
                        if ((multiply_overflow(nm, nm, &nm2)) ||
                                (multiply_overflow(dn, dn, &dn2)))
                            return(make_real(sc, sqrt(sqx)));
                        if ((nm2 == numerator(n)) &&
                                (dn2 == denominator(n)))
                            return(s7_make_ratio(sc, nm, dn));
#else
                        if ((nm * nm == numerator(n)) &&
                                (dn * dn == denominator(n)))
                            return(s7_make_ratio(sc, nm, dn));
#endif
                    }
                    return(make_real(sc, sqrt(sqx)));
                }
                return(s7_make_complex(sc, 0.0, sqrt(-sqx)));

            case T_REAL:
                if (is_NaN(real(n)))
                    return(real_NaN);
                if (real(n) >= 0.0)
                    return(make_real(sc, sqrt(real(n))));
                return(s7_make_complex(sc, 0.0, sqrt(-real(n))));

            case T_COMPLEX:
                /* (* inf.0 (sqrt -1)) -> -nan+infi, but (sqrt -inf.0) -> 0+infi */
#if HAVE_COMPLEX_NUMBERS
                return(s7_from_c_complex(sc, csqrt(as_c_complex(n))));
#else
                return(out_of_range(sc, sc->sqrt_symbol, small_int(1), n, no_complex_numbers_string));
#endif

            default:
                return(method_or_bust_with_type_one_arg(sc, n, sc->sqrt_symbol, args, a_number_string));
        }
    }

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %rcx
movq %rdi, %rbx
movq 0x8(%rsi), %rsi
movzbl (%rsi), %eax
addl $-0xb, %eax
cmpl $0x3, %eax
ja 0x68062
leaq 0x9fb2a(%rip), %rcx     # 0x107a44
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x8(%rsi), %rax
testq %rax, %rax
js 0x68112
cvtsi2sd %rax, %xmm0
sqrtsd %xmm0, %xmm0
cvttsd2si %xmm0, %r14
movq %r14, %rcx
imulq %r14, %rcx
cmpq %rax, %rcx
jne 0x680c2
cmpq $0x7ff, %r14            # imm = 0x7FF
ja 0x6815e
leaq 0xde9ee(%rip), %rax     # 0x146950
movq (%rax,%r14,8), %rax
jmp 0x68106
movsd 0x8(%rsi), %xmm0
ucomisd %xmm0, %xmm0
jp 0x6819c
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jae 0x680a6
movapd 0xa1f20(%rip), %xmm1    # 0x109eb0
xorpd %xmm0, %xmm1
movsd 0x9e12c(%rip), %xmm2    # 0x1060c8
ucomisd %xmm0, %xmm2
jb 0x6813a
sqrtsd %xmm1, %xmm1
jmp 0x68147
movsd 0x10(%rsi), %xmm1
xorpd %xmm0, %xmm0
mulsd %xmm1, %xmm0
addsd 0x8(%rsi), %xmm0
callq 0x8560
jmp 0x6814b
movq 0x8(%rsi), %r12
movq 0x10(%rsi), %r15
movq %r12, 0x20(%rsp)
fildll 0x20(%rsp)
movq %r15, 0x18(%rsp)
fildll 0x18(%rsp)
fdivrp %st, %st(1)
fstpl 0x10(%rsp)
movsd 0x10(%rsp), %xmm2
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm2
jbe 0x68083
leaq 0x30(%rsp), %r14
movq $0x0, (%r14)
leaq 0x28(%rsp), %rsi
movq $0x1, (%rsi)
movsd 0x9e0b1(%rip), %xmm1    # 0x1060d0
movapd %xmm2, (%rsp)
movapd %xmm2, %xmm0
movq %r14, %rdi
callq 0xcc81
movq (%r14), %rsi
movq %rsi, %rax
imulq %rsi, %rax
jo 0x680ae
movq 0x28(%rsp), %rdx
movq %rdx, %rcx
imulq %rdx, %rcx
jo 0x680ae
xorq %r12, %rax
xorq %r15, %rcx
orq %rax, %rcx
jne 0x680ae
movq %rbx, %rdi
callq 0xcfa8
jmp 0x68106
movq 0x14f0(%rbx), %rdx
movq 0xed330(%rip), %r8      # 0x1553a0
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0xfa261
movapd 0xa1e25(%rip), %xmm0    # 0x109eb0
xorpd %xmm2, %xmm0
movsd 0x9e031(%rip), %xmm1    # 0x1060c8
ucomisd %xmm2, %xmm1
jae 0x68131
jmp 0x6813e
jb 0x680bd
sqrtsd %xmm0, %xmm0
jmp 0x680c2
xorpd %xmm1, %xmm1
movapd (%rsp), %xmm0
ucomisd %xmm1, %xmm0
jae 0x680a8
callq 0x8690
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x680eb
movq %rbx, %rdi
movsd %xmm0, (%rsp)
callq 0xa550
movsd (%rsp), %xmm0
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rax
movq $0xd, (%rax)
movsd %xmm0, 0x8(%rax)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
cvtsi2sd %rax, %xmm1
movapd 0xa1d91(%rip), %xmm0    # 0x109eb0
xorpd %xmm1, %xmm0
movsd 0x9df9d(%rip), %xmm2    # 0x1060c8
ucomisd %xmm1, %xmm2
jb 0x6813e
xorps %xmm1, %xmm1
sqrtsd %xmm0, %xmm1
jmp 0x68147
movapd %xmm1, %xmm0
callq 0x8690
movapd %xmm0, %xmm1
xorpd %xmm0, %xmm0
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0xd387
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x6817d
movq %rbx, %rdi
callq 0xa550
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rax
movq $0xb, (%rax)
movq %r14, 0x8(%rax)
jmp 0x68106
movq 0xe5cf5(%rip), %rax     # 0x14de98
jmp 0x68106