// File: /workspace/github_c_makefile_star2_O1/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
subq $0x18, %rsp
cmpb $0x1, (%rsi)
jne 0x6ec5b
movq %rsi, %r14
movq %rdi, %rbx
movq 0x10(%rsi), %rax
cmpb $0x1, (%rax)
jne 0x6ec74
cmpb $0x1, (%r14)
jne 0x6eca1
movl $0x1, %r12d
xorl %r15d, %r15d
movq %r14, 0x8(%rsp)
movq 0x8(%r14), %rbp
movzbl (%rbp), %eax
cmpl $0xc, %eax
je 0x6eabf
cmpl $0xb, %eax
jne 0x6eb5d
movq 0x8(%rbp), %rsi
movq %r15, %rdi
callq 0x103913
movq %rax, %r15
jmp 0x6eafe
movq 0x8(%rbp), %rsi
movq %r15, %rdi
callq 0x103913
movq %rax, %r15
movq 0x10(%rbp), %rax
movq %rax, %rbp
negq %rbp
cmovsq %rax, %rbp
movq %r12, %rdi
movq %rbp, %rsi
callq 0x103913
movq %rax, %rcx
movq %r12, %rax
cqto
idivq %rcx
movq %rax, %r12
imulq %rbp, %r12
testq %r12, %r12
js 0x6eb09
movb $0x1, %al
testq %r15, %r15
jns 0x6ec47
movq 0xf38(%rbx), %rax
movq 0x8(%rax), %rax
movq 0xeeb1d(%rip), %rcx     # 0x15d638
movq 0x1ef8(%rbx), %rdx
movq 0x10(%rdx), %rdx
movq %rax, 0x8(%rdx)
movq 0x10(%rdx), %rax
movq 0x8(%rsp), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rax), %rax
movq %rcx, 0x8(%rax)
movq 0x1948(%rbx), %r13
movq 0x1ef8(%rbx), %rdx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3b366
jmp 0x6ec45
movq 0xf38(%rbx), %rax
cmpq $0x1, %r12
movq %rax, 0x10(%rsp)
jg 0x6eb85
cmpq $0x7ff, %r15            # imm = 0x7FF
ja 0x6eb98
leaq 0xdfdd1(%rip), %rax     # 0x14e950
movq (%rax,%r15,8), %r13
jmp 0x6ebd2
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0xdd7f
movq %rax, %r13
jmp 0x6ebd2
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x6ebb0
movq %rbx, %rdi
callq 0xb389
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r13
movq $0xb, (%r13)
movq %r15, 0x8(%r13)
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x6ebea
movq %rbx, %rdi
callq 0xb389
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rcx
movq $0x200001, (%rcx)       # imm = 0x200001
movq %r13, 0x8(%rcx)
movq %r14, 0x10(%rcx)
movq 0xee9e2(%rip), %r8      # 0x15d5f8
movq 0x8(%rsp), %rax
movl $0x1, %r9d
cmpq %rax, %r14
je 0x6ec32
incl %r9d
movq 0x10(%rax), %rax
cmpq %r14, %rax
jne 0x6ec26
movq %rbx, %rdi
movq %rbp, %rsi
movq 0x10(%rsp), %rdx
callq 0xf3da
movq %rax, %r13
xorl %eax, %eax
testb %al, %al
je 0x6ec62
movq 0x10(%r14), %r14
cmpb $0x1, (%r14)
je 0x6ea98
jmp 0x6ecaa
movq 0xdfcee(%rip), %r13     # 0x14e950
movq %r13, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%r14), %rsi
movzbl (%rsi), %eax
leaq 0xe3d6e(%rip), %rcx     # 0x1529f0
cmpb $0x0, (%rax,%rcx)
je 0x6ecc6
movq %rbx, %rdi
movq %r14, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6b20f
movl $0x1, %r12d
xorl %r15d, %r15d
cmpq $0x1, %r12
jg 0x6ecf3
cmpq $0x7ff, %r15            # imm = 0x7FF
ja 0x6ed0f
leaq 0xdfc90(%rip), %rax     # 0x14e950
movq (%rax,%r15,8), %r13
jmp 0x6ec62
movq 0xf38(%rbx), %rdx
movq 0xee924(%rip), %r8      # 0x15d5f8
movq %rbx, %rdi
movq %r14, %rcx
movl $0x1, %r9d
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xf3da
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x103338
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x6ed27
movq %rbx, %rdi
callq 0xb389
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r13
movq $0xb, (%r13)
movq %r15, 0x8(%r13)
jmp 0x6ec62