// File: /workspace/github_c_makefile_star2_O3/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 0x698bd
movq %rsi, %r13
movq %rdi, %rbx
movq 0x10(%rsi), %rax
cmpb $0x1, (%rax)
jne 0x698c6
movl $0x1, %ebp
xorl %r15d, %r15d
movq %r13, %r14
movq 0x8(%r14), %r12
movzbl (%r12), %eax
cmpl $0xc, %eax
je 0x69846
cmpl $0xb, %eax
jne 0x6996e
movq 0x8(%r12), %rsi
movq %r15, %rdi
callq 0xfab36
movq %rax, %r15
jmp 0x69887
movq 0x8(%r12), %rsi
movq %r15, %rdi
callq 0xfab36
movq %rax, %r15
movq 0x10(%r12), %rax
movq %rax, %r12
negq %r12
cmovsq %rax, %r12
movq %rbp, %rdi
movq %r12, %rsi
callq 0xfab36
movq %rax, %rcx
movq %rbp, %rax
cqto
idivq %rcx
movq %rax, %rbp
imulq %r12, %rbp
testq %rbp, %rbp
js 0x698f3
testq %r15, %r15
js 0x698f3
movq 0x10(%r14), %r14
cmpb $0x1, (%r14)
je 0x6981d
cmpq $0x1, %rbp
jg 0x69998
cmpq $0x7ff, %r15            # imm = 0x7FF
ja 0x699c7
leaq 0xdd09c(%rip), %rax     # 0x146950
movq (%rax,%r15,8), %r14
jmp 0x6993d
movq 0xdd08c(%rip), %r14     # 0x146950
jmp 0x6993d
movq 0x8(%r13), %rsi
movzbl (%rsi), %eax
leaq 0xe111c(%rip), %rcx     # 0x14a9f0
cmpb $0x0, (%rax,%rcx)
je 0x6994f
movq %rbx, %rdi
movq %r13, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x661b9
movq 0xf38(%rbx), %rax
movq 0x8(%rax), %rax
movq 0xebd33(%rip), %rcx     # 0x155638
movq 0x1ef8(%rbx), %rdx
movq 0x10(%rdx), %rdx
movq %rax, 0x8(%rdx)
movq 0x10(%rdx), %rax
movq %r13, 0x8(%rax)
movq 0x10(%rax), %rax
movq %rcx, 0x8(%rax)
movq 0x1948(%rbx), %r14
movq 0x1ef8(%rbx), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x38dfa
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xf38(%rbx), %rdx
movq 0xebc9b(%rip), %r8      # 0x1555f8
movq %rbx, %rdi
movq %r13, %rcx
movl $0x1, %r9d
jmp 0x69aa4
movq 0xf38(%rbx), %rax
movq %rax, (%rsp)
cmpq $0x1, %rbp
jg 0x699b4
cmpq $0x7ff, %r15            # imm = 0x7FF
ja 0x69a05
leaq 0xdcfc1(%rip), %rax     # 0x146950
movq (%rax,%r15,8), %rbp
jmp 0x69a3f
movq %rbx, %rdi
movq %r15, %rsi
movq %rbp, %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xfa58d
movq %rbx, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0xcfa8
movq %rax, %rbp
jmp 0x69a3f
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x699e6
movq %rbx, %rdi
callq 0xa550
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %r14
movq $0xb, (%r14)
movq %r15, 0x8(%r14)
jmp 0x6993d
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x69a24
movq %rbx, %rdi
callq 0xa550
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rbp
movq $0xb, (%rbp)
movq %r15, 0x8(%rbp)
movq 0x90(%rbx), %rax
cmpq 0x98(%rbx), %rax
ja 0x69a5e
movq %rbx, %rdi
callq 0xa550
movq 0x90(%rbx), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x90(%rbx)
movq -0x8(%rax), %rcx
movq $0x200001, (%rcx)       # imm = 0x200001
movq %rbp, 0x8(%rcx)
movq %r14, 0x10(%rcx)
movq 0xebb75(%rip), %r8      # 0x1555f8
movl $0x1, %r9d
cmpq %r13, %r14
je 0x69a9a
incl %r9d
movq 0x10(%r13), %r13
cmpq %r14, %r13
jne 0x69a8e
movq %rbx, %rdi
movq %r12, %rsi
movq (%rsp), %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe659