// File: /workspace/github_c_makefile_star2_O3/BernardTatin[P]s7sh/s7.c
// Function: g_magnitude
static s7_pointer g_magnitude(s7_scheme *sc, s7_pointer args)
    {
#define H_magnitude "(magnitude z) returns the magnitude of z"
#define Q_magnitude s7_make_signature(sc, 2, sc->is_real_symbol, sc->is_number_symbol)
        s7_pointer x;
        x = car(args);

        switch (type(x))
        {
            case T_INTEGER:
                if (integer(x) == s7_int_min)
                    return(make_integer(sc, s7_int_max));
                /* (magnitude -9223372036854775808) -> -9223372036854775808
                 *   same thing happens in abs, lcm and gcd: (gcd -9223372036854775808) -> -9223372036854775808
                 */
                if (integer(x) < 0)
                    return(make_integer(sc, -integer(x)));
                return(x);

            case T_RATIO:
                if (numerator(x) < 0)
                    return(make_simple_ratio(sc, -numerator(x), denominator(x)));
                return(x);

            case T_REAL:
                if (is_NaN(real(x)))                 /* (magnitude -nan.0) -> +nan.0, not -nan.0 */
                    return(real_NaN);
                if (real(x) < 0.0)
                    return(make_real(sc, -real(x)));
                return(x);

            case T_COMPLEX:
                return(make_real(sc, my_hypot(imag_part(x), real_part(x))));

            default:
                return(method_or_bust_with_type_one_arg(sc, x, sc->magnitude_symbol, args, a_number_string));
        }
    }

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movq 0x8(%rsi), %rax
movzbl (%rax), %edx
addl $-0xb, %edx
cmpl $0x3, %edx
ja 0x65c29
leaq 0xa1e65(%rip), %rcx     # 0x107954
movslq (%rcx,%rdx,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
movabsq $0x7fffffffffffffff, %r15 # imm = 0x7FFFFFFFFFFFFFFF
movq 0x8(%rax), %r14
xorl %ecx, %ecx
cmpb $0x0, 0xe4f19(%rip)     # 0x14aa28
leaq 0x1(%r15), %rdx
cmovneq %rdx, %rcx
cmpq %rcx, %r14
jne 0x65c4e
cmpb $0x0, 0xe50e1(%rip)     # 0x14ac08
je 0x65c89
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x65b4c
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 %r15, 0x8(%rax)
jmp 0x65cfa
movsd 0x8(%rax), %xmm1
ucomisd %xmm1, %xmm1
jp 0x65d59
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x65cfa
xorpd 0xa4320(%rip), %xmm1    # 0x109eb0
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x65bb9
movq %rbx, %rdi
movapd %xmm1, (%rsp)
callq 0xa550
movapd (%rsp), %xmm1
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rax
movq $0xd, (%rax)
movsd %xmm1, 0x8(%rax)
jmp 0x65cfa
movsd 0x8(%rax), %xmm2
movsd 0x10(%rax), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x65c77
jp 0x65c77
andpd 0xa42c1(%rip), %xmm2    # 0x109ec0
jmp 0x65cb6
movq 0x8(%rax), %rsi
testq %rsi, %rsi
jns 0x65cfa
negq %rsi
movq 0x10(%rax), %rdx
movq %rbx, %rdi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0xfa58d
movq %rsi, %rcx
movq 0x12c8(%rbx), %rdx
movq 0xef766(%rip), %r8      # 0x1553a0
movq %rbx, %rdi
movq %rax, %rsi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0xfa261
testq %r14, %r14
jns 0x65cfa
negq %r14
cmpq $0x7ff, %r14            # imm = 0x7FF
ja 0x65d04
leaq 0xe0ce2(%rip), %rax     # 0x146950
movq (%rax,%r14,8), %rax
jmp 0x65cfa
ucomisd %xmm1, %xmm2
jne 0x65c92
jp 0x65c92
andpd 0xa4239(%rip), %xmm0    # 0x109ec0
jmp 0x65cb2
movq 0xe0cc0(%rip), %rax     # 0x146950
jmp 0x65cfa
ucomisd %xmm2, %xmm0
jne 0x65d3f
jp 0x65d3f
andpd 0xa4216(%rip), %xmm0    # 0x109ec0
mulsd 0xa03d6(%rip), %xmm0    # 0x106088
movapd %xmm0, %xmm2
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x65cdf
movq %rbx, %rdi
movapd %xmm2, (%rsp)
callq 0xa550
movapd (%rsp), %xmm2
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rax
movq $0xd, (%rax)
movsd %xmm2, 0x8(%rax)
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x65d23
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 0x65cfa
jp 0x65d62
mulsd %xmm2, %xmm2
mulsd %xmm0, %xmm0
addsd %xmm2, %xmm0
xorps %xmm2, %xmm2
sqrtsd %xmm0, %xmm2
jmp 0x65cb6
movq 0xe8138(%rip), %rax     # 0x14de98
jmp 0x65cfa
movsd 0xa0316(%rip), %xmm2    # 0x106080
jmp 0x65cb6