// File: /workspace/github_c_makefile_star2_O2/BernardTatin[P]s7sh/s7.c
// Function: g_round
static s7_pointer g_round(s7_scheme *sc, s7_pointer args)
    {
#define H_round "(round x) returns the integer closest to x"
#define Q_round s7_make_signature(sc, 2, sc->is_integer_symbol, sc->is_real_symbol)

        s7_pointer x;
        x = car(args);
        switch (type(x))
        {
            case T_INTEGER:
                return(x);

            case T_RATIO:
                {
                    s7_int truncated, remains;
                    long double frac;

                    truncated = numerator(x) / denominator(x);
                    remains = numerator(x) % denominator(x);
                    frac = s7_fabsl((long_double)remains / (long_double)denominator(x));

                    if ((frac > 0.5) ||
                            ((frac == 0.5) &&
                             (truncated % 2 != 0)))
                    {
                        if (numerator(x) < 0)
                            return(make_integer(sc, truncated - 1));
                        return(make_integer(sc, truncated + 1));
                    }
                    return(make_integer(sc, truncated));
                }

            case T_REAL:
                {
                    s7_double z;
                    z = real(x);
                    if (is_NaN(z))
                        return(simple_out_of_range(sc, sc->round_symbol, x, its_nan_string));
                    if ((is_inf(z)) ||
                            (z > REAL_TO_INT_LIMIT) ||
                            (z < -REAL_TO_INT_LIMIT))
                        return(simple_out_of_range(sc, sc->round_symbol, x, its_too_large_string));
                    return(make_integer(sc, (s7_int)r5rs_round(z)));
                }

            case T_COMPLEX:
            default:
                return(method_or_bust_one_arg(sc, x, sc->round_symbol, args, T_REAL));
        }
    }

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq 0x8(%rsi), %rax
movzbl (%rax), %edx
cmpl $0xb, %edx
je 0x544b5
movq %rdi, %rbx
cmpl $0xd, %edx
je 0x5436e
cmpl $0xc, %edx
jne 0x543c2
movq 0x8(%rax), %rcx
movq 0x10(%rax), %rsi
movq %rcx, %rax
cqto
idivq %rsi
movq %rax, %r14
movq %rdx, 0x8(%rsp)
fildll 0x8(%rsp)
movq %rsi, (%rsp)
fildll (%rsp)
fdivrp %st, %st(1)
fabs
flds 0x81c75(%rip)           # 0xd5f80
fxch %st(1)
fucomi %st(1), %st
ja 0x5433d
fucompi %st(1), %st
fstp %st(0)
fldz
fldz
fxch %st(1)
jne 0x54462
jp 0x54462
fstp %st(0)
fstp %st(0)
movl %r14d, %eax
andl $0x1, %eax
fldz
fldz
fxch %st(1)
je 0x54462
fstp %st(0)
fstp %st(0)
movq %r14, %r15
testq %rcx, %rcx
js 0x5440a
incq %r15
cmpq $0x7ff, %r15            # imm = 0x7FF
ja 0x54427
leaq 0xc15ec(%rip), %rax     # 0x115950
movq 0x8(%rax,%r14,8), %rax
jmp 0x544b5
movsd 0x8(%rax), %xmm0
ucomisd %xmm0, %xmm0
jp 0x544bf
movq %xmm0, %rcx
btrq $0x3f, %rcx
movabsq $0x7ff0000000000000, %rdx # imm = 0x7FF0000000000000
cmpq %rdx, %rcx
sete %cl
movsd 0x7dd39(%rip), %xmm1    # 0xd20d8
ucomisd %xmm0, %xmm1
ja 0x543e4
ucomisd 0x7dd23(%rip), %xmm0    # 0xd20d0
ja 0x543e4
testb %cl, %cl
jne 0x543e4
callq 0xc7bfc
cvttsd2si %xmm0, %r14
jmp 0x54466
movq %rsi, %rcx
movq 0x1498(%rbx), %rdx
pushq $0xd
popq %r8
movq %rbx, %rdi
movq %rax, %rsi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0x77745
movq 0x1498(%rbx), %rcx
movq 0x8(%rcx), %rsi
movq 0xc564a(%rip), %rcx     # 0x119a40
movq %rbx, %rdi
movq %rax, %rdx
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0x35b47
decq %r15
cmpq $0x7ff, %r15            # imm = 0x7FF
ja 0x54427
leaq 0xc1533(%rip), %rax     # 0x115950
movq -0x8(%rax,%r14,8), %rax
jmp 0x544b5
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x54446
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 %r15, 0x8(%rax)
jmp 0x544b5
fstp %st(0)
fstp %st(0)
cmpq $0x7ff, %r14            # imm = 0x7FF
ja 0x5447c
leaq 0xc14da(%rip), %rax     # 0x115950
movq (%rax,%r14,8), %rax
jmp 0x544b5
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x5449b
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)
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
movq 0x1498(%rbx), %rcx
movq 0x8(%rcx), %rsi
movq 0xd016f(%rip), %rcx     # 0x124640
jmp 0x543f6