// File: /workspace/github_c_makefile_star2_O2/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 0x535d0
leaq 0x80579(%rip), %rcx     # 0xd3a04
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x8(%rsi), %rax
testq %rax, %rax
js 0x53680
cvtsi2sd %rax, %xmm0
sqrtsd %xmm0, %xmm0
cvttsd2si %xmm0, %r14
movq %r14, %rcx
imulq %r14, %rcx
cmpq %rax, %rcx
jne 0x53630
cmpq $0x7ff, %r14            # imm = 0x7FF
ja 0x536c9
leaq 0xc247d(%rip), %rax     # 0x115950
movq (%rax,%r14,8), %rax
jmp 0x53674
movsd 0x8(%rsi), %xmm0
ucomisd %xmm0, %xmm0
jp 0x53707
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jae 0x53614
movapd 0x829af(%rip), %xmm1    # 0xd5eb0
xorpd %xmm0, %xmm1
movsd 0x7ebb3(%rip), %xmm2    # 0xd20c0
ucomisd %xmm0, %xmm2
jb 0x536a5
sqrtsd %xmm1, %xmm1
jmp 0x536b2
movsd 0x10(%rsi), %xmm1
xorpd %xmm0, %xmm0
mulsd %xmm1, %xmm0
addsd 0x8(%rsi), %xmm0
callq 0x8560
jmp 0x536b6
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 0x535f1
leaq 0x30(%rsp), %r14
andq $0x0, (%r14)
leaq 0x28(%rsp), %rsi
movq $0x1, (%rsi)
movsd 0x7eb3b(%rip), %xmm1    # 0xd20c8
movapd %xmm2, (%rsp)
movapd %xmm2, %xmm0
movq %r14, %rdi
callq 0xba8a
movq (%r14), %rsi
movq %rsi, %rax
imulq %rsi, %rax
jo 0x5361c
movq 0x28(%rsp), %rdx
movq %rdx, %rcx
imulq %rdx, %rcx
jo 0x5361c
xorq %r12, %rax
xorq %r15, %rcx
orq %rax, %rcx
jne 0x5361c
movq %rbx, %rdi
callq 0xbd87
jmp 0x53674
movq 0x14f0(%rbx), %rdx
movq 0xd0dc2(%rip), %r8      # 0x1243a0
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0xc736d
movapd 0x828b7(%rip), %xmm0    # 0xd5eb0
xorpd %xmm2, %xmm0
movsd 0x7eabb(%rip), %xmm1    # 0xd20c0
ucomisd %xmm2, %xmm1
jae 0x5369f
jmp 0x536a9
jb 0x5362b
sqrtsd %xmm0, %xmm0
jmp 0x53630
xorpd %xmm1, %xmm1
movapd (%rsp), %xmm0
ucomisd %xmm1, %xmm0
jae 0x53616
callq 0x8690
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x53659
movq %rbx, %rdi
movsd %xmm0, (%rsp)
callq 0x9c27
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 0x82823(%rip), %xmm0    # 0xd5eb0
xorpd %xmm1, %xmm0
movsd 0x7ea27(%rip), %xmm2    # 0xd20c0
ucomisd %xmm1, %xmm2
jb 0x536a9
sqrtsd %xmm0, %xmm1
jmp 0x536b2
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 0xc152
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x536e8
movq %rbx, %rdi
callq 0x9c27
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rax
movq $0xb, (%rax)
movq %r14, 0x8(%rax)
jmp 0x53674
movq 0xc978a(%rip), %rax     # 0x11ce98
jmp 0x53674