// File: /workspace/github_cpp_makefile_star2_O2/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 %rdi, -0x78(%rbp)
movq %rdx, -0x80(%rbp)
movl 0x4(%rdx), %eax
movl %eax, %r13d
negl %r13d
cmovsl %eax, %r13d
movl 0x4(%rcx), %edx
movl %edx, %r14d
negl %r14d
cmovsl %edx, %r14d
jae 0x4fb3
testl %eax, %eax
je 0x4d77
movq %rsi, -0x48(%rbp)
movq %rcx, -0x88(%rbp)
movq 0x8(%rcx), %r15
leaq -0xa8(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x5002
movl (%r12), %ebx
testl %ebx, %ebx
je 0x4d92
andl $0x0, -0xa8(%rbp)
leaq (,%r14,8), %rdi
callq *0xa367(%rip)           # 0xf098
movq %rax, %r12
movq %rax, %rdi
movq %r15, %rsi
movq %r14, %rdx
movl %ebx, %ecx
callq 0x187e
movq %r12, -0x50(%rbp)
movq %r12, -0x30(%rbp)
testq %rax, %rax
movl %ebx, %r15d
movq -0x48(%rbp), %r12
je 0x4da5
leaq 0x46d6(%rip), %rdi      # 0x9435
leaq 0x42fe(%rip), %rsi      # 0x9064
leaq 0x4781(%rip), %rcx      # 0x94ee
movl $0xc21, %edx            # imm = 0xC21
callq 0x1090
movq -0x78(%rbp), %rcx
movq 0x8(%rcx), %rax
movq $0x1, (%rax)
movl $0x1, 0x4(%rcx)
jmp 0x4fa1
movq %r15, -0x30(%rbp)
movq $0x0, -0x50(%rbp)
movl %ebx, %r15d
movq -0x48(%rbp), %r12
movq $0x1, -0x40(%rbp)
pushq $0x8
popq %rdi
callq *0xa2e2(%rip)           # 0xf098
movq %rax, -0x38(%rbp)
movq -0x80(%rbp), %rax
cmpl $0x0, 0x4(%rax)
movl %r15d, -0x54(%rbp)
js 0x4e1e
leaq -0x40(%rbp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2a2a
movslq 0x4(%rbx), %rbx
cmpl %r14d, %ebx
jl 0x4dff
movq -0x38(%rbp), %rsi
leaq -0xa8(%rbp), %r9
xorl %edi, %edi
movq %rbx, %rdx
movq -0x30(%rbp), %rcx
movq %r14, %r8
callq 0x5144
movq %r14, %rbx
cmpl $0x0, 0x4(%r12)
jns 0x4e63
cmpl -0x40(%rbp), %r14d
jle 0x4e41
leaq -0x40(%rbp), %rdi
movq %r14, %rsi
callq 0x228f
movq %rax, %rcx
jmp 0x4e45
leaq -0x40(%rbp), %rdi
movq %r12, %rsi
movq -0x88(%rbp), %rdx
callq 0x4aa7
testl %eax, %eax
jne 0x4e72
leaq 0x4712(%rip), %rdi      # 0x954e
callq 0x4fde
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %rsi
movq %rcx, %rdi
movq %r14, %rdx
movq %rbx, %r8
callq 0x151a
movq %r14, %rbx
testq %rax, %rax
jne 0x4fbf
movq -0x38(%rbp), %rdi
movq %rbx, %rsi
callq 0x1369
movl %eax, -0x3c(%rbp)
pushq $0x1
popq %rbx
leaq -0x70(%rbp), %r15
movl %ebx, (%r15)
pushq $0x8
popq %rdi
callq *0xa213(%rip)           # 0xf098
movq %rax, 0x8(%r15)
movq $0x1, (%rax)
movl %ebx, 0x4(%r15)
testq %r13, %r13
jle 0x4f2c
decq %r13
movq -0x80(%rbp), %rax
movq 0x8(%rax), %rax
movq %r13, -0x48(%rbp)
movq (%rax,%r13,8), %r12
movabsq $-0x8000000000000000, %r13 # imm = 0x8000000000000000
movq %r15, %rdi
movq %r15, %rsi
movq %r15, %rdx
callq 0x2f54
testq %r12, %r13
je 0x4edc
movq %r15, %rdi
movq %r15, %rsi
leaq -0x40(%rbp), %rdx
callq 0x2f54
movl -0x6c(%rbp), %ebx
cmpl %r14d, %ebx
jle 0x4f14
movslq %ebx, %rdx
movq -0x68(%rbp), %rbx
xorl %edi, %edi
movq %rbx, %rsi
movq -0x30(%rbp), %rcx
movq %r14, %r8
leaq -0xa8(%rbp), %r9
callq 0x5144
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1369
movq %rax, %rbx
movl %ebx, -0x6c(%rbp)
movq %r13, %rax
shrq %rax
cmpq $0x2, %r13
movq %rax, %r13
jae 0x4eba
movq -0x48(%rbp), %r13
jmp 0x4e94
cmpl %r14d, %ebx
jl 0x4f64
leaq -0xa8(%rbp), %r9
movl -0x54(%rbp), %eax
movl %eax, (%r9)
movq -0x68(%rbp), %r15
movslq %ebx, %rdx
xorl %edi, %edi
movq %r15, %rsi
movq -0x30(%rbp), %rcx
movq %r14, %r8
callq 0x5144
movq %r15, %rdi
movq %r14, %rsi
callq 0x1369
movq %rax, %rbx
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x4f75
xorl %esi, %esi
callq *0xa133(%rip)           # 0xf0a8
movq -0x78(%rbp), %rcx
movl %ebx, 0x4(%rcx)
movl -0x70(%rbp), %eax
movl %eax, (%rcx)
movq 0x8(%rcx), %rdi
movq -0x68(%rbp), %rax
movq %rax, 0x8(%rcx)
xorl %esi, %esi
callq *0xa113(%rip)           # 0xf0a8
movq -0x38(%rbp), %rdi
xorl %esi, %esi
callq *0xa107(%rip)           # 0xf0a8
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x451d(%rip), %rdi      # 0x94d7
callq 0x4fde
leaq 0x446f(%rip), %rdi      # 0x9435
leaq 0x4097(%rip), %rsi      # 0x9064
leaq 0x451a(%rip), %rcx      # 0x94ee
movl $0xc3e, %edx            # imm = 0xC3E
callq 0x1090