// File: /workspace/github_cpp_makefile_star2_O3/marxn[P]pupp/3rdparty/gmp/./mini-gmp/mini-gmp.c
// Function: mpz_powm
void
mpz_powm (mpz_t r, const mpz_t b, const mpz_t e, const mpz_t m)
{
  mpz_t tr;
  mpz_t base;
  mp_size_t en, mn;
  mp_srcptr mp;
  struct gmp_div_inverse minv;
  unsigned shift;
  mp_ptr tp = NULL;

  en = GMP_ABS (e->_mp_size);
  mn = GMP_ABS (m->_mp_size);
  if (mn == 0)
    gmp_die ("mpz_powm: Zero modulo.");

  if (en == 0)
    {
      mpz_set_ui (r, 1);
      return;
    }

  mp = m->_mp_d;
  mpn_div_qr_invert (&minv, mp, mn);
  shift = minv.shift;

  if (shift > 0)
    {
      /* To avoid shifts, we do all our reductions, except the final
	 one, using a *normalized* m. */
      minv.shift = 0;

      tp = gmp_xalloc_limbs (mn);
      gmp_assert_nocarry (mpn_lshift (tp, mp, mn, shift));
      mp = tp;
    }

  mpz_init (base);

  if (e->_mp_size < 0)
    {
      if (!mpz_invert (base, b, m))
	gmp_die ("mpz_powm: Negative exponent and non-invertible base.");
    }
  else
    {
      mp_size_t bn;
      mpz_abs (base, b);

      bn = base->_mp_size;
      if (bn >= mn)
	{
	  mpn_div_qr_preinv (NULL, base->_mp_d, base->_mp_size, mp, mn, &minv);
	  bn = mn;
	}

      /* We have reduced the absolute value. Now take care of the
	 sign. Note that we get zero represented non-canonically as
	 m. */
      if (b->_mp_size < 0)
	{
	  mp_ptr bp = MPZ_REALLOC (base, mn);
	  gmp_assert_nocarry (mpn_sub (bp, mp, mn, bp, bn));
	  bn = mn;
	}
      base->_mp_size = mpn_normalized_size (base->_mp_d, bn);
    }
  mpz_init_set_ui (tr, 1);

  while (--en >= 0)
    {
      mp_limb_t w = e->_mp_d[en];
      mp_limb_t bit;

      bit = GMP_LIMB_HIGHBIT;
      do
	{
	  mpz_mul (tr, tr, tr);
	  if (w & bit)
	    mpz_mul (tr, tr, base);
	  if (tr->_mp_size > mn)
	    {
	      mpn_div_qr_preinv (NULL, tr->_mp_d, tr->_mp_size, mp, mn, &minv);
	      tr->_mp_size = mpn_normalized_size (tr->_mp_d, mn);
	    }
	  bit >>= 1;
	}
      while (bit > 0);
    }

  /* Final reduction */
  if (tr->_mp_size >= mn)
    {
      minv.shift = shift;
      mpn_div_qr_preinv (NULL, tr->_mp_d, tr->_mp_size, mp, mn, &minv);
      tr->_mp_size = mpn_normalized_size (tr->_mp_d, mn);
    }
  if (tp)
    gmp_free (tp);

  mpz_swap (r, tr);
  mpz_clear (tr);
  mpz_clear (base);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rcx, %rbx
movq %rdx, -0x88(%rbp)
movl 0x4(%rdx), %eax
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
movl 0x4(%rcx), %ecx
movl %ecx, %r13d
negl %r13d
cmovsl %ecx, %r13d
jae 0x59dd
testl %eax, %eax
je 0x5714
movq %rsi, -0x50(%rbp)
movq %rdx, -0x58(%rbp)
movq %rdi, -0x80(%rbp)
movq 0x8(%rbx), %r15
leaq -0xa8(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x5a01
movl (%r12), %r12d
testl %r12d, %r12d
je 0x572b
movl $0x0, -0xa8(%rbp)
leaq (,%r13,8), %rdi
callq *0xa9c8(%rip)           # 0x100a0
movq %rax, %r14
movq %rax, %rdi
movq %r15, %rsi
movq %r13, %rdx
movl %r12d, %ecx
callq 0x1a5d
movq %r14, -0x48(%rbp)
testq %rax, %rax
je 0x5732
leaq 0x4d39(%rip), %rdi      # 0xa435
leaq 0x4961(%rip), %rsi      # 0xa064
leaq 0x4de4(%rip), %rcx      # 0xa4ee
movl $0xc21, %edx            # imm = 0xC21
callq 0x1090
movq 0x8(%rdi), %rax
movq $0x1, (%rax)
movl $0x1, 0x4(%rdi)
jmp 0x59cb
movq %r15, -0x48(%rbp)
xorl %r14d, %r14d
movl %r12d, -0x5c(%rbp)
movq $0x1, -0x40(%rbp)
movl $0x8, %edi
callq *0xa957(%rip)           # 0x100a0
movq %rax, -0x38(%rbp)
movq -0x88(%rbp), %rax
cmpl $0x0, 0x4(%rax)
movq %r14, -0x78(%rbp)
js 0x5801
leaq -0x40(%rbp), %r12
movq %r12, %rdi
movq -0x50(%rbp), %r14
movq %r14, %rsi
callq 0x24a2
movl 0x4(%r12), %eax
movl %eax, %ebx
negl %ebx
cmovsl %eax, %ebx
movl %ebx, 0x4(%r12)
cmpl %r13d, %ebx
jb 0x57aa
movq -0x38(%rbp), %rsi
leaq -0xa8(%rbp), %r9
xorl %edi, %edi
movq %rbx, %rdx
movq -0x48(%rbp), %rcx
movq %r13, %r8
callq 0x5b6b
movq %r13, %rbx
cmpl $0x0, 0x4(%r14)
movq -0x58(%rbp), %r15
jns 0x5840
cmpl -0x40(%rbp), %r13d
jle 0x581e
cmpq $0x1, %r13
movq %r13, %r14
adcq $0x0, %r14
movq -0x38(%rbp), %rdi
leaq (,%r14,8), %rdx
xorl %esi, %esi
callq *0xa8ca(%rip)           # 0x100a8
movq %rax, %rcx
movq %rax, -0x38(%rbp)
movl %r14d, -0x40(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
cmpq %rdx, %r14
jae 0x5822
movl $0x0, -0x3c(%rbp)
jmp 0x5822
leaq -0x40(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq %rbx, %rdx
callq 0x5441
testl %eax, %eax
movq -0x58(%rbp), %r15
jne 0x5863
callq 0x11a8
movq -0x38(%rbp), %rcx
movq -0x48(%rbp), %rsi
movq %rcx, %rdi
movq %r13, %rdx
movq %rbx, %r8
callq 0x16e4
movq %r13, %rbx
testq %rax, %rax
jne 0x59e2
testq %rbx, %rbx
je 0x585e
movq -0x38(%rbp), %rax
cmpq $0x0, -0x8(%rax,%rbx,8)
jne 0x5860
leaq -0x1(%rbx), %rcx
cmpq $0x1, %rbx
movq %rcx, %rbx
jg 0x5849
xorl %ebx, %ebx
movl %ebx, -0x3c(%rbp)
movl $0x1, %r14d
leaq -0x70(%rbp), %rbx
movl %r14d, (%rbx)
movl $0x8, %edi
callq *0xa825(%rip)           # 0x100a0
movq %rax, 0x8(%rbx)
movq $0x1, (%rax)
movl %r14d, 0x4(%rbx)
leaq -0x1(%r15), %rax
movq %rax, -0x50(%rbp)
movq -0x88(%rbp), %rax
movq 0x8(%rax), %rax
movq %r15, -0x58(%rbp)
movq -0x8(%rax,%r15,8), %r15
movabsq $-0x8000000000000000, %r12 # imm = 0x8000000000000000
movq %rbx, %rdi
movq %rbx, %rsi
movq %rbx, %rdx
callq 0x3512
testq %r15, %r12
je 0x58d2
movq %rbx, %rdi
movq %rbx, %rsi
leaq -0x40(%rbp), %rdx
callq 0x3512
movl -0x6c(%rbp), %r14d
cmpl %r13d, %r14d
jle 0x591f
movslq %r14d, %rdx
movq %r13, %r14
movq -0x68(%rbp), %r13
xorl %edi, %edi
movq %r13, %rsi
movq -0x48(%rbp), %rcx
movq %r14, %r8
leaq -0xa8(%rbp), %r9
callq 0x5b6b
movq %r14, %rcx
cmpq $0x0, -0x8(%r13,%r14,8)
jne 0x5918
leaq -0x1(%r14), %rax
cmpq $0x1, %r14
movq %rax, %r14
jg 0x5900
xorl %r14d, %r14d
movl %r14d, -0x6c(%rbp)
movq %rcx, %r13
movq %r12, %rax
shrq %rax
cmpq $0x1, %r12
movq %rax, %r12
ja 0x58b0
cmpq $0x1, -0x58(%rbp)
movq -0x50(%rbp), %r15
jg 0x588a
cmpl %r13d, %r14d
jge 0x594c
movq -0x80(%rbp), %r15
movq -0x78(%rbp), %rdi
jmp 0x5994
leaq -0xa8(%rbp), %r9
movl -0x5c(%rbp), %eax
movl %eax, (%r9)
movq -0x68(%rbp), %rbx
movslq %r14d, %rdx
xorl %edi, %edi
movq %rbx, %rsi
movq -0x48(%rbp), %rcx
movq %r13, %r8
callq 0x5b6b
movq -0x80(%rbp), %r15
movq -0x78(%rbp), %rdi
cmpq $0x0, -0x8(%rbx,%r13,8)
jne 0x5991
leaq -0x1(%r13), %rax
cmpq $0x1, %r13
movq %rax, %r13
jg 0x5979
xorl %r13d, %r13d
movl %r13d, %r14d
testq %rdi, %rdi
je 0x59a1
xorl %esi, %esi
callq *0xa70f(%rip)           # 0x100b0
movl %r14d, 0x4(%r15)
movl -0x70(%rbp), %eax
movl %eax, (%r15)
movq 0x8(%r15), %rdi
movq -0x68(%rbp), %rax
movq %rax, 0x8(%r15)
xorl %esi, %esi
callq *0xa6f1(%rip)           # 0x100b0
movq -0x38(%rbp), %rdi
xorl %esi, %esi
callq *0xa6e5(%rip)           # 0x100b0
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x11d0
leaq 0x4a4c(%rip), %rdi      # 0xa435
leaq 0x4674(%rip), %rsi      # 0xa064
leaq 0x4af7(%rip), %rcx      # 0xa4ee
movl $0xc3e, %edx            # imm = 0xC3E
callq 0x1090