// File: /workspace/github_c_makefile_star2_O1/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 %r14
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq 0x8(%rsi), %rax
movzbl (%rax), %edx
addl $-0xb, %edx
cmpl $0x3, %edx
ja 0x6ac94
leaq 0xa5d77(%rip), %rcx     # 0x1108d4
movslq (%rcx,%rdx,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
movq 0x8(%rax), %r14
xorl %edx, %edx
cmpb $0x0, 0xe7eab(%rip)     # 0x152a28
leaq 0x1(%rcx), %rsi
cmovneq %rsi, %rdx
cmpq %rdx, %r14
jne 0x6acb7
xorl %r14d, %r14d
cmpb $0x0, 0xe8070(%rip)     # 0x152c08
cmovneq %rcx, %r14
je 0x6acd0
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x6abba
movq %rbx, %rdi
callq 0xb389
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rax
movq $0xb, (%rax)
movq %r14, 0x8(%rax)
jmp 0x6ad76
movsd 0x8(%rax), %xmm1
ucomisd %xmm1, %xmm1
jp 0x6ad7e
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x6ad76
xorpd 0xa81bb(%rip), %xmm1    # 0x112dc0
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x6ac27
movq %rbx, %rdi
movapd %xmm1, (%rsp)
callq 0xb389
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 0x6ad76
movsd 0x8(%rax), %xmm2
movsd 0x10(%rax), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x6ace0
jp 0x6ace0
andpd 0xa8164(%rip), %xmm2    # 0x112dd0
jmp 0x6ad32
movq 0x8(%rax), %rsi
testq %rsi, %rsi
jns 0x6ad76
negq %rsi
movq 0x10(%rax), %rdx
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r14
jmp 0x103338
movq %rsi, %rcx
movq 0x12c8(%rbx), %rdx
movq 0xf26fb(%rip), %r8      # 0x15d3a0
movq %rbx, %rdi
movq %rax, %rsi
addq $0x18, %rsp
popq %rbx
popq %r14
jmp 0x103001
testq %r14, %r14
jns 0x6ad76
negq %r14
cmpq $0x7ff, %r14            # imm = 0x7FF
ja 0x6aba2
leaq 0xe3c79(%rip), %rax     # 0x14e950
movq (%rax,%r14,8), %rax
jmp 0x6ad76
ucomisd %xmm1, %xmm2
jne 0x6acf2
jp 0x6acf2
andpd 0xa80e0(%rip), %xmm0    # 0x112dd0
jmp 0x6ad2e
ucomisd %xmm2, %xmm0
jne 0x6ad0c
jp 0x6ad0c
andpd 0xa80ce(%rip), %xmm0    # 0x112dd0
mulsd 0xa437e(%rip), %xmm0    # 0x10f088
jmp 0x6ad2e
jp 0x6ad87
mulsd %xmm2, %xmm2
mulsd %xmm0, %xmm0
addsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jb 0x6ad29
xorps %xmm2, %xmm2
sqrtsd %xmm0, %xmm2
jmp 0x6ad32
callq 0x9690
movapd %xmm0, %xmm2
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x6ad54
movq %rbx, %rdi
movapd %xmm2, (%rsp)
callq 0xb389
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 $0x18, %rsp
popq %rbx
popq %r14
retq
movq 0xeb113(%rip), %rax     # 0x155e98
jmp 0x6ad76
movsd 0xa42f1(%rip), %xmm2    # 0x10f080
jmp 0x6ad32