// File: /workspace/github_cpp_makefile_star2_O1/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 %rsi, -0x68(%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 0x5a67
testl %eax, %eax
je 0x579a
movq %r13, -0x70(%rbp)
movq %rdi, -0x90(%rbp)
movq %rcx, %r13
movq 0x8(%rcx), %r15
leaq -0xb0(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x5a8b
movl (%r12), %ebx
testl %ebx, %ebx
je 0x57b1
movl $0x0, -0xb0(%rbp)
leaq (,%r14,8), %rdi
callq *0xa944(%rip)           # 0x100a0
movq %rax, %r12
movq %rax, %rdi
movq %r15, %rsi
movq %r14, %rdx
movl %ebx, %ecx
callq 0x1a6f
movq %r12, -0x48(%rbp)
testq %rax, %rax
movl %ebx, %r15d
je 0x57bb
leaq 0x4cb3(%rip), %rdi      # 0xa435
leaq 0x48db(%rip), %rsi      # 0xa064
leaq 0x4d5e(%rip), %rcx      # 0xa4ee
movl $0xc21, %edx            # imm = 0xC21
callq 0x1090
movl $0x1, 0x4(%rdi)
movq 0x8(%rdi), %rax
movq $0x1, (%rax)
jmp 0x5a55
movq %r15, -0x48(%rbp)
xorl %r12d, %r12d
movl %ebx, %r15d
movq %r12, -0x88(%rbp)
movq $0x1, -0x40(%rbp)
movl $0x8, %edi
callq *0xa8cb(%rip)           # 0x100a0
movq %rax, -0x38(%rbp)
movq -0x80(%rbp), %rax
cmpl $0x0, 0x4(%rax)
movl %r15d, -0x74(%rbp)
js 0x5889
leaq -0x40(%rbp), %r12
movq %r12, %rdi
movq -0x68(%rbp), %rsi
callq 0x24be
movl 0x4(%r12), %eax
movl %eax, %ebx
negl %ebx
cmovsl %eax, %ebx
movl %ebx, 0x4(%r12)
cmpl %r14d, %ebx
jb 0x5830
movq -0x38(%rbp), %rsi
leaq -0xb0(%rbp), %r9
xorl %edi, %edi
movq %rbx, %rdx
movq -0x48(%rbp), %rcx
movq %r14, %r8
callq 0x5bf5
movq %r14, %rbx
movq -0x68(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jns 0x58c4
cmpl -0x40(%rbp), %r14d
jle 0x58a2
cmpq $0x2, %r14
movl $0x1, %r15d
cmovgeq %r14, %r15
movq -0x38(%rbp), %rdi
leaq (,%r15,8), %rdx
xorl %esi, %esi
callq *0xa842(%rip)           # 0x100a8
movq %rax, %rcx
movq %rax, -0x38(%rbp)
movl %r15d, -0x40(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
cmpq %rdx, %r15
jae 0x58a6
movl $0x0, -0x3c(%rbp)
jmp 0x58a6
leaq -0x40(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq %r13, %rdx
callq 0x54a9
testl %eax, %eax
jne 0x58e7
callq 0x11a8
movq -0x38(%rbp), %rcx
movq -0x48(%rbp), %rsi
movq %rcx, %rdi
movq %r14, %rdx
movq %rbx, %r8
callq 0x16e4
movq %r14, %rbx
testq %rax, %rax
jne 0x5a6c
testq %rbx, %rbx
jle 0x58e4
movq -0x38(%rbp), %rax
cmpq $0x0, -0x8(%rax,%rbx,8)
jne 0x58e4
leaq -0x1(%rbx), %rcx
cmpq $0x1, %rbx
movq %rcx, %rbx
jg 0x58cd
xorl %ebx, %ebx
movl %ebx, -0x3c(%rbp)
movl $0x1, %r15d
leaq -0x60(%rbp), %rbx
movq %r15, (%rbx)
movl $0x8, %edi
callq *0xa7a1(%rip)           # 0x100a0
movq %rax, 0x8(%rbx)
movl $0x1, 0x4(%rbx)
movq %r15, (%rax)
movq -0x70(%rbp), %r13
leaq -0x1(%r13), %rax
movq %rax, -0x68(%rbp)
movq -0x80(%rbp), %rax
movq 0x8(%rax), %rax
movq %r13, -0x70(%rbp)
movq -0x8(%rax,%r13,8), %r15
movabsq $-0x8000000000000000, %r12 # imm = 0x8000000000000000
movq %rbx, %rdi
movq %rbx, %rsi
movq %rbx, %rdx
callq 0x3555
testq %r15, %r12
je 0x5956
movq %rbx, %rdi
movq %rbx, %rsi
leaq -0x40(%rbp), %rdx
callq 0x3555
movslq -0x5c(%rbp), %rdx
cmpl %r14d, %edx
jle 0x5998
movq -0x58(%rbp), %r13
xorl %edi, %edi
movq %r13, %rsi
movq -0x48(%rbp), %rcx
movq %r14, %r8
leaq -0xb0(%rbp), %r9
callq 0x5bf5
movq %r14, %rax
cmpq $0x0, -0x8(%r13,%rax,8)
jne 0x5995
leaq -0x1(%rax), %rcx
cmpq $0x1, %rax
movq %rcx, %rax
jg 0x597e
xorl %eax, %eax
movl %eax, -0x5c(%rbp)
movq %r12, %rax
shrq %rax
cmpq $0x1, %r12
movq %rax, %r12
ja 0x5934
cmpq $0x1, -0x70(%rbp)
movq -0x68(%rbp), %r13
jg 0x5911
movslq -0x5c(%rbp), %rdx
cmpl %r14d, %edx
movq -0x88(%rbp), %r15
jl 0x5a04
leaq -0xb0(%rbp), %r9
movl -0x74(%rbp), %eax
movl %eax, (%r9)
movq -0x58(%rbp), %rbx
xorl %edi, %edi
movq %rbx, %rsi
movq -0x48(%rbp), %rcx
movq %r14, %r8
callq 0x5bf5
cmpq $0x0, -0x8(%rbx,%r14,8)
jne 0x5a00
leaq -0x1(%r14), %rax
cmpq $0x1, %r14
movq %rax, %r14
jg 0x59e8
xorl %r14d, %r14d
movl %r14d, -0x5c(%rbp)
testq %r15, %r15
je 0x5a14
movq %r15, %rdi
xorl %esi, %esi
callq *0xa69c(%rip)           # 0x100b0
movq -0x90(%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), %rdi
movq -0x58(%rbp), %rax
movq %rax, 0x8(%rdx)
movq %rdi, -0x58(%rbp)
xorl %esi, %esi
callq *0xa667(%rip)           # 0x100b0
movq -0x38(%rbp), %rdi
xorl %esi, %esi
callq *0xa65b(%rip)           # 0x100b0
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x11d0
leaq 0x49c2(%rip), %rdi      # 0xa435
leaq 0x45ea(%rip), %rsi      # 0xa064
leaq 0x4a6d(%rip), %rcx      # 0xa4ee
movl $0xc3e, %edx            # imm = 0xC3E
callq 0x1090