// File: /workspace/github_c_makefile_star2_O2/BernardTatin[P]s7sh/s7.c
// Function: g_acos
static s7_pointer g_acos(s7_scheme *sc, s7_pointer args)
    {
#define H_acos "(acos z) returns acos(z); (cos (acos 1)) = 1"
#define Q_acos sc->pl_nn
        s7_pointer n;

        n = car(args);
        switch (type(n))
        {
            case T_INTEGER:
                if (integer(n) == 1) return(small_int(0));
                return(c_acos(sc, (s7_double)integer(n)));

            case T_RATIO:
                return(c_acos(sc, (s7_double)numerator(n) / (s7_double)denominator(n)));

            case T_REAL:
                return(c_acos(sc, real(n)));

            case T_COMPLEX:
#if HAVE_COMPLEX_NUMBERS
                /* if either real or imag part is very large, use explicit formula, not cacos */
                /*   this code taken from sbcl's src/code/irrat.lisp */

                if ((fabs(real_part(n)) > 1.0e7) ||
                        (fabs(imag_part(n)) > 1.0e7))
                {
                    s7_complex sq1mz, sq1pz, z;
                    z = as_c_complex(n);
                    sq1mz = csqrt(1.0 - z);
                    sq1pz = csqrt(1.0 + z);	  /* creal(sq1pz) can be 0.0 */
                    if (creal(sq1pz) == 0.0)        /* so the atan arg will be inf, so the real part will be pi/2(?) */
                        return(s7_make_complex(sc, M_PI / 2.0, asinh(cimag(sq1mz * conj(sq1pz)))));
                    return(s7_make_complex(sc, 2.0 * atan(creal(sq1mz) / creal(sq1pz)), asinh(cimag(sq1mz * conj(sq1pz)))));
                }
                return(s7_from_c_complex(sc, cacos(s7_to_c_complex(n))));
#else
                return(out_of_range(sc, sc->acos_symbol, small_int(1), n, no_complex_numbers_string));
#endif

            default:
                return(method_or_bust_with_type_one_arg(sc, n, sc->acos_symbol, list_1(sc, n), a_number_string));
        }
    }

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
movq 0x8(%rsi), %r14
movzbl (%r14), %eax
addl $-0xb, %eax
cmpl $0x3, %eax
ja 0x52a21
leaq 0x8105b(%rip), %rcx     # 0xd39e4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x8(%r14), %rax
cmpq $0x1, %rax
jne 0x52b5a
movq 0xc2fa9(%rip), %rax     # 0x115950
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movsd 0x8(%r14), %xmm0
jmp 0x52b5f
movsd 0x8(%r14), %xmm3
movsd 0x10(%r14), %xmm2
movapd 0x834ee(%rip), %xmm0    # 0xd5ec0
movapd %xmm3, %xmm1
andpd %xmm0, %xmm1
ucomisd 0x7f6c6(%rip), %xmm1    # 0xd20a8
ja 0x52a8c
andpd %xmm2, %xmm0
ucomisd 0x7f6b4(%rip), %xmm0    # 0xd20a8
ja 0x52a8c
movq %r14, %rdi
callq 0xc779f
callq 0x8120
jmp 0x52b47
cvtsi2sdq 0x8(%r14), %xmm0
cvtsi2sdq 0x10(%r14), %xmm1
divsd %xmm1, %xmm0
jmp 0x52b5f
movq 0xb98(%rbx), %r15
movq 0x90(%rbx), %rax
movq 0x110(%rbx), %r12
cmpq 0x98(%rbx), %rax
ja 0x52a4e
movq %rbx, %rdi
callq 0x9c27
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rcx
movq $0x200001, (%rcx)       # imm = 0x200001
movq %r14, 0x8(%rcx)
movq %r12, 0x10(%rcx)
movq 0xd192d(%rip), %r8      # 0x1243a0
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0xc736d
xorpd %xmm1, %xmm1
movapd %xmm2, %xmm0
mulsd %xmm1, %xmm0
addsd %xmm0, %xmm3
movapd %xmm3, 0x10(%rsp)
movsd 0x7f586(%rip), %xmm0    # 0xd2030
subsd %xmm3, %xmm0
movapd 0x833fa(%rip), %xmm1    # 0xd5eb0
xorpd %xmm2, %xmm1
movapd %xmm2, 0x20(%rsp)
callq 0x8560
movsd %xmm0, (%rsp)
movsd %xmm1, 0x8(%rsp)
movapd 0x10(%rsp), %xmm0
addsd 0x7f552(%rip), %xmm0    # 0xd2030
movapd 0x20(%rsp), %xmm1
callq 0x8560
movapd %xmm0, %xmm3
ucomisd 0x7f5c3(%rip), %xmm0    # 0xd20b8
jne 0x52b72
jp 0x52b72
movsd (%rsp), %xmm5
movapd %xmm5, %xmm4
mulsd %xmm3, %xmm4
movapd %xmm3, %xmm0
movsd 0x8(%rsp), %xmm6
mulsd %xmm6, %xmm0
movapd %xmm6, %xmm2
mulsd %xmm1, %xmm2
addsd %xmm4, %xmm2
movapd %xmm5, %xmm4
mulsd %xmm1, %xmm4
subsd %xmm4, %xmm0
ucomisd %xmm2, %xmm2
jp 0x52bf2
callq 0x8740
movapd %xmm0, %xmm1
movsd 0x7f569(%rip), %xmm0    # 0xd20b0
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0xc152
cvtsi2sd %rax, %xmm0
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0xc7940
movsd (%rsp), %xmm0
divsd %xmm3, %xmm0
movsd %xmm3, 0x20(%rsp)
movapd %xmm1, 0x10(%rsp)
callq 0x8150
movapd 0x10(%rsp), %xmm3
movsd 0x20(%rsp), %xmm2
addsd %xmm0, %xmm0
movsd %xmm0, 0x30(%rsp)
movsd (%rsp), %xmm5
movapd %xmm5, %xmm1
mulsd %xmm2, %xmm1
movapd %xmm2, %xmm0
movsd 0x8(%rsp), %xmm4
mulsd %xmm4, %xmm0
movapd %xmm4, %xmm2
mulsd %xmm3, %xmm2
addsd %xmm1, %xmm2
movapd %xmm5, %xmm1
mulsd %xmm3, %xmm1
subsd %xmm1, %xmm0
ucomisd %xmm2, %xmm2
jp 0x52c2e
callq 0x8740
movapd %xmm0, %xmm1
movq %rbx, %rdi
movsd 0x30(%rsp), %xmm0
jmp 0x52b4a
ucomisd %xmm0, %xmm0
jnp 0x52b36
movapd %xmm5, %xmm2
movapd %xmm1, %xmm5
movapd %xmm3, %xmm4
movapd %xmm6, %xmm1
movapd 0x8329c(%rip), %xmm3    # 0xd5eb0
xorpd %xmm5, %xmm3
movapd %xmm2, %xmm0
movapd %xmm4, %xmm2
callq 0xd1640
movapd %xmm1, %xmm0
jmp 0x52b36
ucomisd %xmm0, %xmm0
jnp 0x52bdb
movapd %xmm4, %xmm1
movapd 0x83270(%rip), %xmm3    # 0xd5eb0
xorpd 0x10(%rsp), %xmm3
movapd %xmm5, %xmm0
movsd 0x20(%rsp), %xmm2
callq 0xd1640
movapd %xmm1, %xmm0
jmp 0x52bdb