// File: /workspace/github_c_makefile_star2_O2/BernardTatin[P]s7sh/s7.c
// Function: g_gcd
static s7_pointer g_gcd(s7_scheme *sc, s7_pointer args)
    {
#define H_gcd "(gcd ...) returns the greatest common divisor of its rational arguments"
#define Q_gcd sc->pcl_f
        s7_int n = 0, d = 1;
        s7_pointer p;

        if (!is_pair(args))
            return(small_int(0));

        if (!is_pair(cdr(args)))
        {
            if (!is_rational(car(args)))
                return(method_or_bust_with_type(sc, car(args), sc->gcd_symbol, args, a_rational_string, 1));
            return(g_abs(sc, args));
        }

        for (p = args; is_pair(p); p = cdr(p))
        {
            s7_pointer x;
            s7_int b;
            x = car(p);
            switch (type(x))
            {
                case T_INTEGER:
                    n = c_gcd(n, integer(x));
                    break;

                case T_RATIO:
                    n = c_gcd(n, s7_numerator(x));
                    b = s7_denominator(x);
                    if (b < 0) b = -b;
                    d = (d / c_gcd(d, b)) * b;
                    if (d < 0) return(simple_out_of_range(sc, sc->gcd_symbol, args, result_is_too_large_string));
                    break;

                default:
                    return(method_or_bust_with_type(sc, x, sc->gcd_symbol, cons(sc, (d <= 1) ? make_integer(sc, n) : s7_make_ratio(sc, n, d), p),
                                a_rational_string, position_of(p, args)));
            }
            if (n < 0) return(simple_out_of_range(sc, sc->gcd_symbol, args, result_is_too_large_string));
        }

        if (d <= 1)
            return(make_integer(sc, n));
        return(make_simple_ratio(sc, n, d));
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
cmpb $0x1, (%rsi)
jne 0x54a02
movq %rsi, %r14
movq %rdi, %rbx
movq 0x10(%rsi), %rax
cmpb $0x1, (%rax)
jne 0x54a18
pushq $0x1
popq %r13
movb $0x1, %al
xorl %r12d, %r12d
movq %r14, %r15
cmpb $0x1, %al
jne 0x54a8d
movq 0x8(%r15), %rbp
movzbl (%rbp), %eax
cmpl $0xc, %eax
je 0x549b5
cmpl $0xb, %eax
jne 0x54ac8
movq 0x8(%rbp), %rsi
movq %r12, %rdi
callq 0xc7c7d
movq %rax, %r12
jmp 0x549f4
movq 0x8(%rbp), %rsi
movq %r12, %rdi
callq 0xc7c7d
movq %rax, %r12
movq 0x10(%rbp), %rax
movq %rax, %rbp
negq %rbp
cmovsq %rax, %rbp
movq %r13, %rdi
movq %rbp, %rsi
callq 0xc7c7d
movq %rax, %rcx
movq %r13, %rax
cqto
idivq %rcx
movq %rax, %r13
imulq %rbp, %r13
testq %r13, %r13
js 0x54a62
testq %r12, %r12
js 0x54a62
movq 0x10(%r15), %r15
movb (%r15), %al
jmp 0x54986
movq 0xc0f47(%rip), %rax     # 0x115950
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%r14), %rsi
movzbl (%rsi), %eax
leaq 0xc4fca(%rip), %rcx     # 0x1199f0
cmpb $0x0, (%rax,%rcx)
je 0x54a45
movq %rbx, %rdi
movq %r14, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x51b4e
movq 0xf38(%rbx), %rdx
movq 0xcfba5(%rip), %r8      # 0x1245f8
pushq $0x1
popq %r9
movq %rbx, %rdi
movq %r14, %rcx
jmp 0x54be2
movq 0xf38(%rbx), %rax
movq 0x8(%rax), %rsi
movq 0xcfbc4(%rip), %rcx     # 0x124638
movq %rbx, %rdi
movq %r14, %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x35b47
cmpq $0x1, %r13
jg 0x54aac
cmpq $0x7ff, %r12            # imm = 0x7FF
ja 0x54af2
leaq 0xc0ead(%rip), %rax     # 0x115950
movq (%rax,%r12,8), %rax
jmp 0x54a09
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xc761f
movq 0xf38(%rbx), %rax
movq %rax, (%rsp)
cmpq $0x1, %r13
jg 0x54b30
cmpq $0x7ff, %r12            # imm = 0x7FF
ja 0x54b43
leaq 0xc0e67(%rip), %rax     # 0x115950
movq (%rax,%r12,8), %r13
jmp 0x54b7d
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x54b11
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 %r12, 0x8(%rax)
jmp 0x54a09
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0xbd87
movq %rax, %r13
jmp 0x54b7d
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x54b62
movq %rbx, %rdi
callq 0x9c27
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r13
movq $0xb, (%r13)
movq %r12, 0x8(%r13)
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x54b9c
movq %rbx, %rdi
callq 0x9c27
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r12
movq $0x200001, (%r12)       # imm = 0x200001
movq %r13, 0x8(%r12)
movq %r15, 0x10(%r12)
movq 0xcfa34(%rip), %r13     # 0x1245f8
movq %r15, %rdi
movq %r14, %rsi
callq 0x72a82
movq %rbx, %rdi
movq %rbp, %rsi
movq (%rsp), %rdx
movq %r12, %rcx
movq %r13, %r8
movl %eax, %r9d
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xcf9a