// File: /workspace/github_cpp_makefile_star2_O2/marxn[P]pupp/3rdparty/gmp/./mini-gmp/mini-gmp.c
// Function: mpz_gcdext
void
mpz_gcdext (mpz_t g, mpz_t s, mpz_t t, const mpz_t u, const mpz_t v)
{
  mpz_t tu, tv, s0, s1, t0, t1;
  mp_bitcnt_t uz, vz, gz;
  mp_bitcnt_t power;

  if (u->_mp_size == 0)
    {
      /* g = 0 u + sgn(v) v */
      signed long sign = mpz_sgn (v);
      mpz_abs (g, v);
      if (s)
	mpz_set_ui (s, 0);
      if (t)
	mpz_set_si (t, sign);
      return;
    }

  if (v->_mp_size == 0)
    {
      /* g = sgn(u) u + 0 v */
      signed long sign = mpz_sgn (u);
      mpz_abs (g, u);
      if (s)
	mpz_set_si (s, sign);
      if (t)
	mpz_set_ui (t, 0);
      return;
    }

  mpz_init (tu);
  mpz_init (tv);
  mpz_init (s0);
  mpz_init (s1);
  mpz_init (t0);
  mpz_init (t1);

  mpz_abs (tu, u);
  uz = mpz_make_odd (tu);
  mpz_abs (tv, v);
  vz = mpz_make_odd (tv);
  gz = GMP_MIN (uz, vz);

  uz -= gz;
  vz -= gz;

  /* Cofactors corresponding to odd gcd. gz handled later. */
  if (tu->_mp_size < tv->_mp_size)
    {
      mpz_swap (tu, tv);
      MPZ_SRCPTR_SWAP (u, v);
      MPZ_PTR_SWAP (s, t);
      MP_BITCNT_T_SWAP (uz, vz);
    }

  /* Maintain
   *
   * u = t0 tu + t1 tv
   * v = s0 tu + s1 tv
   *
   * where u and v denote the inputs with common factors of two
   * eliminated, and det (s0, t0; s1, t1) = 2^p. Then
   *
   * 2^p tu =  s1 u - t1 v
   * 2^p tv = -s0 u + t0 v
   */

  /* After initial division, tu = q tv + tu', we have
   *
   * u = 2^uz (tu' + q tv)
   * v = 2^vz tv
   *
   * or
   *
   * t0 = 2^uz, t1 = 2^uz q
   * s0 = 0,    s1 = 2^vz
   */

  mpz_setbit (t0, uz);
  mpz_tdiv_qr (t1, tu, tu, tv);
  mpz_mul_2exp (t1, t1, uz);

  mpz_setbit (s1, vz);
  power = uz + vz;

  if (tu->_mp_size > 0)
    {
      mp_bitcnt_t shift;
      shift = mpz_make_odd (tu);
      mpz_mul_2exp (t0, t0, shift);
      mpz_mul_2exp (s0, s0, shift);
      power += shift;

      for (;;)
	{
	  int c;
	  c = mpz_cmp (tu, tv);
	  if (c == 0)
	    break;

	  if (c < 0)
	    {
	      /* tv = tv' + tu
	       *
	       * u = t0 tu + t1 (tv' + tu) = (t0 + t1) tu + t1 tv'
	       * v = s0 tu + s1 (tv' + tu) = (s0 + s1) tu + s1 tv' */

	      mpz_sub (tv, tv, tu);
	      mpz_add (t0, t0, t1);
	      mpz_add (s0, s0, s1);

	      shift = mpz_make_odd (tv);
	      mpz_mul_2exp (t1, t1, shift);
	      mpz_mul_2exp (s1, s1, shift);
	    }
	  else
	    {
	      mpz_sub (tu, tu, tv);
	      mpz_add (t1, t0, t1);
	      mpz_add (s1, s0, s1);

	      shift = mpz_make_odd (tu);
	      mpz_mul_2exp (t0, t0, shift);
	      mpz_mul_2exp (s0, s0, shift);
	    }
	  power += shift;
	}
    }

  /* Now tv = odd part of gcd, and -s0 and t0 are corresponding
     cofactors. */

  mpz_mul_2exp (tv, tv, gz);
  mpz_neg (s0, s0);

  /* 2^p g = s0 u + t0 v. Eliminate one factor of two at a time. To
     adjust cofactors, we need u / g and v / g */

  mpz_divexact (s1, v, tv);
  mpz_abs (s1, s1);
  mpz_divexact (t1, u, tv);
  mpz_abs (t1, t1);

  while (power-- > 0)
    {
      /* s0 u + t0 v = (s0 - v/g) u - (t0 + u/g) v */
      if (mpz_odd_p (s0) || mpz_odd_p (t0))
	{
	  mpz_sub (s0, s0, s1);
	  mpz_add (t0, t0, t1);
	}
      mpz_divexact_ui (s0, s0, 2);
      mpz_divexact_ui (t0, t0, 2);
    }

  /* Arrange so that |s| < |u| / 2g */
  mpz_add (s1, s0, s1);
  if (mpz_cmpabs (s0, s1) > 0)
    {
      mpz_swap (s0, s1);
      mpz_sub (t0, t0, t1);
    }
  if (u->_mp_size < 0)
    mpz_neg (s0, s0);
  if (v->_mp_size < 0)
    mpz_neg (t0, t0);

  mpz_swap (g, tv);
  if (s)
    mpz_swap (s, s0);
  if (t)
    mpz_swap (t, t0);

  mpz_clear (tu);
  mpz_clear (tv);
  mpz_clear (s0);
  mpz_clear (s1);
  mpz_clear (t0);
  mpz_clear (t1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdx, %r13
movq %rsi, %rbx
movl 0x4(%rcx), %r12d
movl 0x4(%r8), %r15d
testl %r12d, %r12d
je 0x4521
movq %rcx, %r14
testl %r15d, %r15d
je 0x456b
movq %rbx, -0xb8(%rbp)
movq %rdi, -0xd0(%rbp)
movq %r13, -0xa8(%rbp)
pushq $0x1
popq %r13
leaq -0x80(%rbp), %rbx
movq %r13, (%rbx)
pushq $0x8
popq %r15
movq %r15, %rdi
movq %r8, %r12
callq *0xac88(%rip)           # 0xf098
movq %rax, 0x8(%rbx)
leaq -0x60(%rbp), %rbx
movq %r13, (%rbx)
movq %r15, %rdi
callq *0xac74(%rip)           # 0xf098
movq %rax, 0x8(%rbx)
movq %r13, -0x40(%rbp)
movq %r15, %rdi
callq *0xac63(%rip)           # 0xf098
movq %rax, -0x38(%rbp)
movq %r13, -0x70(%rbp)
movq %r15, %rdi
callq *0xac52(%rip)           # 0xf098
movq %rax, -0x68(%rbp)
movq %r13, -0x50(%rbp)
movq %r15, %rdi
callq *0xac41(%rip)           # 0xf098
movq %rax, -0x48(%rbp)
movq %r13, -0x90(%rbp)
movq %r15, %rdi
callq *0xac2d(%rip)           # 0xf098
movq %rax, -0x88(%rbp)
leaq -0x80(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2a2a
movq %rbx, %rdi
callq 0x434e
movq %rax, %r15
leaq -0x60(%rbp), %r13
movq %r13, %rdi
movq %r12, %rbx
movq %r12, %rsi
callq 0x2a2a
movq %r13, %rdi
movq %r13, %r12
callq 0x434e
movq %rax, %r13
cmpq %rax, %r15
cmovbq %r15, %rax
subq %rax, %r15
movq %rax, -0xc8(%rbp)
subq %rax, %r13
leaq -0x80(%rbp), %rax
movl 0x4(%rax), %eax
movl 0x4(%r12), %ecx
cmpl %ecx, %eax
jge 0x459e
movq %rbx, -0xa0(%rbp)
movl %ecx, -0x7c(%rbp)
movl %eax, -0x5c(%rbp)
movl -0x80(%rbp), %eax
movl -0x60(%rbp), %ecx
movl %ecx, -0x80(%rbp)
movl %eax, -0x60(%rbp)
movq -0x78(%rbp), %rax
movq -0x58(%rbp), %rcx
movq %rcx, -0x78(%rbp)
movq %rax, -0x58(%rbp)
movq %r15, -0xb0(%rbp)
movq %r13, %r12
movq %r14, -0x98(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, -0xc0(%rbp)
jmp 0x45d2
xorl %r14d, %r14d
testl %r15d, %r15d
setne %r12b
movq %r8, %rsi
callq 0x2a2a
testq %rbx, %rbx
je 0x453c
andl $0x0, 0x4(%rbx)
testq %r13, %r13
je 0x495d
sarl $0x1f, %r15d
movb %r12b, %r14b
orl %r15d, %r14d
movslq %r14d, %rsi
movq %r13, %rdi
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x21e8
movq %r14, %rsi
callq 0x2a2a
testq %rbx, %rbx
je 0x458b
sarl $0x1f, %r12d
orl $0x1, %r12d
movslq %r12d, %rsi
movq %rbx, %rdi
callq 0x21e8
testq %r13, %r13
je 0x495d
andl $0x0, 0x4(%r13)
jmp 0x495d
movq %r13, -0xb0(%rbp)
movq %r15, %r12
movq %rbx, -0x98(%rbp)
movq %r14, -0xa0(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0x50(%rbp), %rdi
movq %r12, %rsi
callq 0x496f
leaq -0x90(%rbp), %rbx
leaq -0x80(%rbp), %r14
leaq -0x60(%rbp), %rcx
movq %rbx, %rdi
movq %r14, %rsi
movq %r14, %rdx
callq 0x3686
movq %rbx, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x304c
leaq -0x70(%rbp), %rdi
movq -0xb0(%rbp), %rsi
callq 0x496f
addq %r15, %r13
cmpl $0x0, 0x4(%r14)
jle 0x4730
leaq -0x80(%rbp), %rbx
movq %rbx, %rdi
callq 0x434e
movq %rax, %r14
leaq -0x50(%rbp), %rdi
movq %rdi, %rsi
movq %rax, %rdx
callq 0x304c
leaq -0x40(%rbp), %rdi
movq %rdi, %rsi
movq %r14, %rdx
callq 0x304c
addq %r14, %r13
leaq -0x60(%rbp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2963
testl %eax, %eax
je 0x4730
js 0x46cc
movq %rbx, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2e4a
leaq -0x90(%rbp), %rdi
leaq -0x50(%rbp), %r15
movq %r15, %rsi
movq %rdi, %rdx
callq 0x2c3d
leaq -0x70(%rbp), %rdi
leaq -0x40(%rbp), %r12
movq %r12, %rsi
movq %rdi, %rdx
callq 0x2c3d
movq %rbx, %rdi
callq 0x434e
movq %rax, %r14
movq %r15, %rdi
movq %r15, %rsi
leaq -0x60(%rbp), %r15
movq %rax, %rdx
callq 0x304c
movq %r12, %rdi
movq %r12, %rsi
jmp 0x4720
movq %r15, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x2e4a
leaq -0x50(%rbp), %rdi
movq %rdi, %rsi
leaq -0x90(%rbp), %r12
movq %r12, %rdx
callq 0x2c3d
leaq -0x40(%rbp), %rdi
movq %rdi, %rsi
leaq -0x70(%rbp), %rdx
callq 0x2c3d
movq %r15, %rdi
callq 0x434e
movq %rax, %r14
movq %r12, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x304c
leaq -0x70(%rbp), %rdi
movq %rdi, %rsi
movq %r14, %rdx
callq 0x304c
addq %r14, %r13
jmp 0x465b
leaq -0x60(%rbp), %r14
movq %r14, %rdi
movq %r14, %rsi
movq -0xc8(%rbp), %rdx
callq 0x304c
leaq -0x40(%rbp), %rbx
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x2a4c
leaq -0x70(%rbp), %r15
movq %r15, %rdi
movq -0x98(%rbp), %rsi
movq %r14, %rdx
callq 0x3b0c
movq %r15, %rdi
movq %r15, %rsi
callq 0x2a2a
leaq -0x90(%rbp), %r15
movq %r15, %rdi
movq -0xa0(%rbp), %rsi
movq %r14, %rdx
callq 0x3b0c
movq %r15, %rdi
movq %r15, %rsi
callq 0x2a2a
pushq $0x2
popq %r12
leaq -0x50(%rbp), %r14
subq $0x1, %r13
jb 0x4807
cmpl $0x0, -0x3c(%rbp)
je 0x47ba
movq -0x38(%rbp), %rax
movq (%rax), %rax
andl $0x1, %eax
jne 0x47cc
cmpl $0x0, -0x4c(%rbp)
je 0x47e9
movq -0x48(%rbp), %rax
movq (%rax), %rax
andl $0x1, %eax
je 0x47e9
movq %rbx, %rdi
movq %rbx, %rsi
leaq -0x70(%rbp), %rdx
callq 0x2e4a
movq %r14, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x2c3d
movq %rbx, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x3ec5
movq %r14, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x3ec5
jmp 0x47a2
leaq -0x40(%rbp), %rbx
leaq -0x70(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x2c3d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x29d7
testl %eax, %eax
jle 0x484f
movaps -0x40(%rbp), %xmm0
movaps -0x70(%rbp), %xmm1
movaps %xmm1, -0x40(%rbp)
movaps %xmm0, -0x70(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x90(%rbp), %rdx
movq %rdi, %rsi
callq 0x2e4a
movq -0xa0(%rbp), %rax
cmpl $0x0, 0x4(%rax)
movq -0xa8(%rbp), %rbx
jns 0x486f
leaq -0x40(%rbp), %rdi
movq %rdi, %rsi
callq 0x2a4c
movq -0x98(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jns 0x4888
leaq -0x50(%rbp), %rdi
movq %rdi, %rsi
callq 0x2a4c
movq -0xd0(%rbp), %rdx
movl 0x4(%rdx), %eax
movl -0x5c(%rbp), %ecx
movl %ecx, 0x4(%rdx)
movl %eax, -0x5c(%rbp)
movl (%rdx), %eax
movl -0x60(%rbp), %ecx
movl %ecx, (%rdx)
movl %eax, -0x60(%rbp)
movq 0x8(%rdx), %rax
movq -0x58(%rbp), %rcx
movq %rcx, 0x8(%rdx)
movq %rax, -0x58(%rbp)
testq %rbx, %rbx
je 0x48e0
movl 0x4(%rbx), %eax
movl -0x3c(%rbp), %ecx
movl %ecx, 0x4(%rbx)
movl %eax, -0x3c(%rbp)
movl (%rbx), %eax
movl -0x40(%rbp), %ecx
movl %ecx, (%rbx)
movl %eax, -0x40(%rbp)
movq 0x8(%rbx), %rax
movq -0x38(%rbp), %rcx
movq %rcx, 0x8(%rbx)
movq %rax, -0x38(%rbp)
movq -0xc0(%rbp), %rdx
testq %rdx, %rdx
je 0x4912
movl 0x4(%rdx), %eax
movl -0x4c(%rbp), %ecx
movl %ecx, 0x4(%rdx)
movl %eax, -0x4c(%rbp)
movl (%rdx), %eax
movl -0x50(%rbp), %ecx
movl %ecx, (%rdx)
movl %eax, -0x50(%rbp)
movq 0x8(%rdx), %rax
movq -0x48(%rbp), %rcx
movq %rcx, 0x8(%rdx)
movq %rax, -0x48(%rbp)
movq -0x78(%rbp), %rdi
xorl %esi, %esi
callq *0xa78a(%rip)           # 0xf0a8
movq -0x58(%rbp), %rdi
xorl %esi, %esi
callq *0xa77e(%rip)           # 0xf0a8
movq -0x38(%rbp), %rdi
xorl %esi, %esi
callq *0xa772(%rip)           # 0xf0a8
movq -0x68(%rbp), %rdi
xorl %esi, %esi
callq *0xa766(%rip)           # 0xf0a8
movq -0x48(%rbp), %rdi
xorl %esi, %esi
callq *0xa75a(%rip)           # 0xf0a8
movq -0x88(%rbp), %rdi
xorl %esi, %esi
callq *0xa74b(%rip)           # 0xf0a8
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq