#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
long *brute_force_congruence(int, long *, long);
long *calloc(int, int);
int /*<<< orphan*/ free(long *);
long mod_eval_polynomial(int, long *, long, long);
long mod_inv(long, long);
long mod_product(long, int, long);
long *solve_prime_power_congruence(int funcDegree, long funcCoeffs[],
                                   long prime, int power) {
  long *baseSolutionList;
  int numOfBaseSolutions;
  long *baseSolutions;
  long *liftedSolutions;
  int numOfLiftedSolutions;
  long coeff;
  int derivDegree;
  long *derivCoeffs;
  long deriv;
  long func;
  int i, j, t;
  long currentMod;
  if (power == 1) {
    baseSolutions = brute_force_congruence(funcDegree, funcCoeffs, prime);
    return baseSolutions;
  }
  baseSolutionList =
      solve_prime_power_congruence(funcDegree, funcCoeffs, prime, power - 1);
  numOfBaseSolutions = *baseSolutionList;
  baseSolutions = baseSolutionList + 1;
  liftedSolutions = calloc(prime * numOfBaseSolutions + 1, sizeof(long));
  numOfLiftedSolutions = 0;
  derivDegree = funcDegree - 1;
  derivCoeffs = calloc(derivDegree + 1, sizeof(long));
  currentMod = prime;
  for (j = 1; j < power; j++) {
    currentMod *= prime;
  }
  for (j = 0; j <= derivDegree; j++) {
    coeff = funcCoeffs[j + 1] % prime;
    if (coeff < 0) {
      coeff += prime;
    }
    derivCoeffs[j] = mod_product(coeff, j + 1, prime);
  }
  for (j = 0; j < numOfBaseSolutions; j++) {
    deriv =
        mod_eval_polynomial(derivDegree, derivCoeffs, prime, baseSolutions[j]);
    func = mod_eval_polynomial(funcDegree, funcCoeffs, currentMod,
                               baseSolutions[j]);
    if (deriv % prime != 0) {
      t = ((-func / (currentMod / prime)) * mod_inv(deriv, currentMod) %
           prime) +
          prime;
      liftedSolutions[++numOfLiftedSolutions] = baseSolutions[j] + t * prime;
    } else if (func == 0) {
      for (t = 1; t <= prime; t++) {
        liftedSolutions[++numOfLiftedSolutions] =
            baseSolutions[j] + t * (currentMod / prime);
      }
    }
  }
  *liftedSolutions = numOfLiftedSolutions;
  free(derivCoeffs);
  free(baseSolutionList);
  return liftedSolutions;
}


x86 assembly (clang, -O0):
<solve_prime_power_congruence>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
jne    11b4 <solve_prime_power_congruence+0x44>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <brute_force_congruence@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    14b0 <solve_prime_power_congruence+0x340>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
call   1050 <solve_prime_power_congruence@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
imul   %rcx,%rax
add    $0x1,%rax
mov    %eax,%edi
mov    $0x8,%esi
call   1090 <calloc@plt>
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1090 <calloc@plt>
mov    %rax,-0x68(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x90(%rbp)
movl   $0x1,-0x80(%rbp)
mov    -0x80(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1267 <solve_prime_power_congruence+0xf7>
mov    -0x20(%rbp),%rax
imul   -0x90(%rbp),%rax
ff
mov    %rax,-0x90(%rbp)
mov    -0x80(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x80(%rbp)
jmp    123a <solve_prime_power_congruence+0xca>
movl   $0x0,-0x80(%rbp)
mov    -0x80(%rbp),%eax
cmp    -0x5c(%rbp),%eax
jg     12dc <solve_prime_power_congruence+0x16c>
mov    -0x18(%rbp),%rax
mov    -0x80(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
cqto
idivq  -0x20(%rbp)
mov    %rdx,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jge    12ac <solve_prime_power_congruence+0x13c>
mov    -0x20(%rbp),%rax
add    -0x58(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x80(%rbp),%esi
add    $0x1,%esi
mov    -0x20(%rbp),%rdx
call   1060 <mod_product@plt>
mov    %rax,%rdx
mov    -0x68(%rbp),%rax
movslq -0x80(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x80(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x80(%rbp)
jmp    126e <solve_prime_power_congruence+0xfe>
movl   $0x0,-0x80(%rbp)
mov    -0x80(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    148b <solve_prime_power_congruence+0x31b>
mov    -0x5c(%rbp),%edi
mov    -0x68(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x40(%rbp),%rax
movslq -0x80(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
call   1070 <mod_eval_polynomial@plt>
mov    %rax,-0x70(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x90(%rbp),%rdx
mov    -0x40(%rbp),%rax
movslq -0x80(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
call   1070 <mod_eval_polynomial@plt>
mov    %rax,-0x78(%rbp)
mov    -0x70(%rbp),%rax
cqto
idivq  -0x20(%rbp)
cmp    $0x0,%rdx
je     13da <solve_prime_power_congruence+0x26a>
xor    %eax,%eax
sub    -0x78(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x90(%rbp),%rax
cqto
idivq  -0x20(%rbp)
mov    %rax,%rcx
mov    -0xa0(%rbp),%rax
cqto
idiv   %rcx
mov    %rax,-0x98(%rbp)
mov    -0x70(%rbp),%rdi
mov    -0x90(%rbp),%rsi
call   1080 <mod_inv@plt>
mov    %rax,%rcx
mov    -0x98(%rbp),%rax
imul   %rcx,%rax
cqto
idivq  -0x20(%rbp)
add    -0x20(%rbp),%rdx
mov    %edx,%eax
mov    %eax,-0x84(%rbp)
mov    -0x40(%rbp),%rax
movslq -0x80(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
movslq -0x84(%rbp),%rax
imul   -0x20(%rbp),%rax
add    %rax,%rdx
mov    -0x48(%rbp),%rax
mov    -0x4c(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x4c(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    1478 <solve_prime_power_congruence+0x308>
cmpq   $0x0,-0x78(%rbp)
jne    1473 <solve_prime_power_congruence+0x303>
movl   $0x1,-0x84(%rbp)
movslq -0x84(%rbp),%rax
cmp    -0x20(%rbp),%rax
jg     146e <solve_prime_power_congruence+0x2fe>
mov    -0x40(%rbp),%rax
movslq -0x80(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0xb0(%rbp)
movslq -0x84(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x90(%rbp),%rax
cqto
idivq  -0x20(%rbp)
mov    -0xb0(%rbp),%rdx
mov    %rax,%rcx
mov    -0xa8(%rbp),%rax
imul   %rcx,%rax
add    %rax,%rdx
mov    -0x48(%rbp),%rax
mov    -0x4c(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x4c(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    13ef <solve_prime_power_congruence+0x27f>
jmp    1473 <solve_prime_power_congruence+0x303>
jmp    1478 <solve_prime_power_congruence+0x308>
jmp    147d <solve_prime_power_congruence+0x30d>
mov    -0x80(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x80(%rbp)
jmp    12e3 <solve_prime_power_congruence+0x173>
movslq -0x4c(%rbp),%rcx
mov    -0x48(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x68(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<solve_prime_power_congruence>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rdx,%r15
mov    %rsi,%r13
mov    %edi,%ebx
cmp    $0x1,%ecx
jne    11a6 <solve_prime_power_congruence+0x36>
mov    %ebx,%edi
mov    %r13,%rsi
mov    %r15,%rdx
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <brute_force_congruence@plt>
mov    %ecx,%r14d
lea    -0x1(%r14),%ebp
mov    %ebx,%edi
mov    %r13,%rsi
mov    %r15,%rdx
mov    %ebp,%ecx
call   1050 <solve_prime_power_congruence@plt>
mov    %rax,0x10(%rsp)
mov    (%rax),%r12
mov    %r15d,%edi
imul   %r12d,%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1090 <calloc@plt>
mov    %rax,(%rsp)
mov    %rbx,0x8(%rsp)
mov    %ebx,%edi
mov    $0x8,%esi
call   1090 <calloc@plt>
mov    %rax,0x18(%rsp)
mov    %r15,%rbx
cmp    $0x2,%r14d
jl     1259 <solve_prime_power_congruence+0xe9>
add    $0xfffffffe,%r14d
mov    %ebp,%eax
and    $0x7,%eax
mov    %r15,%rbx
cmp    $0x7,%r14d
jb     1245 <solve_prime_power_congruence+0xd5>
and    $0xfffffff8,%ebp
mov    %r15,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
imul   %r15,%rbx
imul   %r15,%rbx
imul   %r15,%rbx
imul   %r15,%rbx
imul   %r15,%rbx
imul   %r15,%rbx
imul   %r15,%rbx
imul   %r15,%rbx
add    $0xfffffff8,%ebp
jne    1220 <solve_prime_power_congruence+0xb0>
test   %eax,%eax
je     1259 <solve_prime_power_congruence+0xe9>
nopl   0x0(%rax)
imul   %r15,%rbx
add    $0xffffffff,%eax
jne    1250 <solve_prime_power_congruence+0xe0>
cmpl   $0x0,0x8(%rsp)
jle    12c0 <solve_prime_power_congruence+0x150>
mov    0x8(%rsp),%r14d
neg    %r14
mov    $0x1,%ebp
jmp    12a8 <solve_prime_power_congruence+0x138>
nop
cqto
idiv   %r15
mov    %rdx,%rdi
sar    $0x3f,%rdi
and    %r15,%rdi
add    %rdx,%rdi
mov    %ebp,%esi
mov    %r15,%rdx
call   1060 <mod_product@plt>
mov    0x18(%rsp),%rcx
mov    %rax,-0x8(%rcx,%rbp,8)
lea    (%r14,%rbp,1),%rax
add    $0x1,%rax
add    $0x1,%rbp
cmp    $0x1,%rax
je     12c0 <solve_prime_power_congruence+0x150>
mov    0x0(%r13,%rbp,8),%rax
mov    %rax,%rcx
or     %r15,%rcx
shr    $0x20,%rcx
jne    1270 <solve_prime_power_congruence+0x100>
xor    %edx,%edx
div    %r15d
jmp    1275 <solve_prime_power_congruence+0x105>
test   %r12d,%r12d
jle    170e <solve_prime_power_congruence+0x59e>
mov    %r13,0x70(%rsp)
mov    %r12d,%eax
mov    %rax,0x68(%rsp)
mov    0x8(%rsp),%r14
lea    -0x1(%r14),%eax
mov    %eax,0x24(%rsp)
cmp    $0x2,%r15
mov    $0x1,%eax
cmovge %r15,%rax
movabs $0x7ffffffffffffffc,%rcx
ff ff 7f
mov    %rax,%rdx
and    %rcx,%rdx
lea    -0x4(%rdx),%rsi
mov    %rsi,0x50(%rsp)
shr    $0x2,%rsi
add    $0x1,%rsi
mov    %rdx,0x58(%rsp)
add    $0x1,%rdx
mov    %rdx,0x40(%rsp)
or     $0x2,%rcx
mov    %rsi,%rdx
mov    %rsi,0x48(%rsp)
and    %rsi,%rcx
mov    %rcx,0x38(%rsp)
mov    (%rsp),%rcx
add    $0x38,%rcx
mov    %rcx,0x30(%rsp)
mov    %rax,0x28(%rsp)
add    $0x1,%rax
mov    %rax,0x60(%rsp)
xor    %r12d,%r12d
xor    %r13d,%r13d
jmp    1398 <solve_prime_power_congruence+0x228>
cs nopw 0x0(%rax,%rax,1)
cqto
idiv   %r15
mov    (%rsp),%rbp
add    %r15d,%edx
movslq %edx,%rax
imul   %r15,%rax
mov    0x10(%rsp),%rcx
add    0x8(%rcx,%r12,8),%rax
movslq %r13d,%rcx
add    $0x1,%r13d
mov    %rax,0x8(%rbp,%rcx,8)
add    $0x1,%r12
cmp    0x68(%rsp),%r12
je     1715 <solve_prime_power_congruence+0x5a5>
mov    0x10(%rsp),%r14
mov    0x8(%r14,%r12,8),%rcx
mov    0x24(%rsp),%edi
mov    0x18(%rsp),%rsi
mov    %r15,%rdx
call   1070 <mod_eval_polynomial@plt>
mov    %rax,%rbp
mov    0x8(%r14,%r12,8),%rcx
mov    0x8(%rsp),%rdi
mov    0x70(%rsp),%rsi
mov    %rbx,%rdx
call   1070 <mod_eval_polynomial@plt>
mov    %rax,%rcx
mov    %rbp,%rax
or     %r15,%rax
shr    $0x20,%rax
je     13f0 <solve_prime_power_congruence+0x280>
mov    %rbp,%rax
cqto
idiv   %r15
jmp    13f7 <solve_prime_power_congruence+0x287>
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%eax
xor    %edx,%edx
div    %r15d
movdqa 0xc10(%rip),%xmm8
movdqa 0xc17(%rip),%xmm9
movdqa 0xc1e(%rip),%xmm10
movdqa 0xc25(%rip),%xmm11
test   %rdx,%rdx
je     1440 <solve_prime_power_congruence+0x2d0>
mov    %rbx,%rax
or     %r15,%rax
shr    $0x20,%rax
je     1480 <solve_prime_power_congruence+0x310>
mov    %rbx,%rax
cqto
idiv   %r15
mov    %rax,%rsi
jmp    1489 <solve_prime_power_congruence+0x319>
nopl   0x0(%rax)
test   %rcx,%rcx
jne    14e5 <solve_prime_power_congruence+0x375>
test   %r15,%r15
jle    14e5 <solve_prime_power_congruence+0x375>
mov    0x10(%rsp),%rax
mov    0x8(%rax,%r12,8),%rcx
mov    %rbx,%rax
or     %r15,%rax
shr    $0x20,%rax
mov    (%rsp),%rbp
je     14ee <solve_prime_power_congruence+0x37e>
mov    %rbx,%rax
cqto
idiv   %r15
jmp    14f5 <solve_prime_power_congruence+0x385>
nopw   0x0(%rax,%rax,1)
mov    %ebx,%eax
xor    %edx,%edx
div    %r15d
mov    %eax,%esi
mov    %rcx,%rax
or     %rsi,%rax
shr    $0x20,%rax
je     14b0 <solve_prime_power_congruence+0x340>
mov    %rcx,%rax
cqto
idiv   %rsi
mov    %rax,%r14
jmp    14b9 <solve_prime_power_congruence+0x349>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ecx,%eax
xor    %edx,%edx
div    %esi
mov    %eax,%r14d
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1080 <mod_inv@plt>
imul   %r14,%rax
neg    %rax
mov    %rax,%rcx
or     %r15,%rcx
shr    $0x20,%rcx
jne    1360 <solve_prime_power_congruence+0x1f0>
xor    %edx,%edx
div    %r15d
jmp    1365 <solve_prime_power_congruence+0x1f5>
mov    (%rsp),%rbp
jmp    1389 <solve_prime_power_congruence+0x219>
mov    %ebx,%eax
xor    %edx,%edx
div    %r15d
movslq %r13d,%r13
mov    $0x1,%esi
cmpq   $0x4,0x28(%rsp)
jb     16c8 <solve_prime_power_congruence+0x558>
movq   %rax,%xmm0
pshufd $0x44,%xmm0,%xmm1
movq   %rcx,%xmm0
pshufd $0x44,%xmm0,%xmm0
movdqa %xmm1,%xmm2
psrlq  $0x20,%xmm2
cmpq   $0x0,0x50(%rsp)
je     16f7 <solve_prime_power_congruence+0x587>
mov    0x30(%rsp),%rdx
lea    (%rdx,%r13,8),%rsi
mov    0x38(%rsp),%rdi
xor    %edx,%edx
movdqa 0xab6(%rip),%xmm3
nopw   0x0(%rax,%rax,1)
movdqa %xmm3,%xmm4
paddq  %xmm8,%xmm4
movdqa %xmm2,%xmm5
pmuludq %xmm3,%xmm5
movdqa %xmm3,%xmm6
psrlq  $0x20,%xmm6
pmuludq %xmm1,%xmm6
paddq  %xmm5,%xmm6
psllq  $0x20,%xmm6
movdqa %xmm1,%xmm5
pmuludq %xmm3,%xmm5
paddq  %xmm6,%xmm5
movdqa %xmm2,%xmm6
pmuludq %xmm4,%xmm6
movdqa %xmm1,%xmm7
pmuludq %xmm4,%xmm7
psrlq  $0x20,%xmm4
pmuludq %xmm1,%xmm4
paddq  %xmm6,%xmm4
psllq  $0x20,%xmm4
paddq  %xmm7,%xmm4
paddq  %xmm0,%xmm5
paddq  %xmm0,%xmm4
movdqu %xmm5,-0x30(%rsi,%rdx,8)
movdqu %xmm4,-0x20(%rsi,%rdx,8)
movdqa %xmm3,%xmm4
paddq  %xmm9,%xmm4
movdqa %xmm3,%xmm5
paddq  %xmm10,%xmm5
movdqa %xmm2,%xmm6
pmuludq %xmm4,%xmm6
movdqa %xmm1,%xmm7
pmuludq %xmm4,%xmm7
psrlq  $0x20,%xmm4
pmuludq %xmm1,%xmm4
paddq  %xmm6,%xmm4
psllq  $0x20,%xmm4
paddq  %xmm7,%xmm4
movdqa %xmm2,%xmm6
pmuludq %xmm5,%xmm6
movdqa %xmm1,%xmm7
pmuludq %xmm5,%xmm7
psrlq  $0x20,%xmm5
pmuludq %xmm1,%xmm5
paddq  %xmm6,%xmm5
psllq  $0x20,%xmm5
paddq  %xmm7,%xmm5
paddq  %xmm0,%xmm4
paddq  %xmm0,%xmm5
movdqu %xmm4,-0x10(%rsi,%rdx,8)
movdqu %xmm5,(%rsi,%rdx,8)
add    $0x8,%rdx
paddq  %xmm11,%xmm3
add    $0xfffffffffffffffe,%rdi
jne    1550 <solve_prime_power_congruence+0x3e0>
testb  $0x1,0x48(%rsp)
je     16b0 <solve_prime_power_congruence+0x540>
add    %r13,%rdx
movdqa %xmm3,%xmm4
paddq  %xmm8,%xmm4
movdqa %xmm2,%xmm5
pmuludq %xmm3,%xmm5
movdqa %xmm1,%xmm6
pmuludq %xmm3,%xmm6
psrlq  $0x20,%xmm3
pmuludq %xmm1,%xmm3
paddq  %xmm5,%xmm3
psllq  $0x20,%xmm3
paddq  %xmm6,%xmm3
pmuludq %xmm4,%xmm2
movdqa %xmm4,%xmm5
psrlq  $0x20,%xmm5
pmuludq %xmm1,%xmm5
paddq  %xmm2,%xmm5
psllq  $0x20,%xmm5
pmuludq %xmm1,%xmm4
paddq  %xmm5,%xmm4
paddq  %xmm0,%xmm3
paddq  %xmm0,%xmm4
movdqu %xmm3,0x8(%rbp,%rdx,8)
movdqu %xmm4,0x18(%rbp,%rdx,8)
mov    0x58(%rsp),%rdx
add    %rdx,%r13
mov    0x40(%rsp),%rsi
cmp    %rdx,0x28(%rsp)
je     1389 <solve_prime_power_congruence+0x219>
mov    0x60(%rsp),%rdx
sub    %rsi,%rdx
imul   %rax,%rsi
add    %rsi,%rcx
nopw   0x0(%rax,%rax,1)
mov    %rcx,0x8(%rbp,%r13,8)
add    $0x1,%r13
add    %rax,%rcx
add    $0xffffffffffffffff,%rdx
jne    16e0 <solve_prime_power_congruence+0x570>
jmp    1389 <solve_prime_power_congruence+0x219>
xor    %edx,%edx
movdqa 0x8ff(%rip),%xmm3
testb  $0x1,0x48(%rsp)
jne    1648 <solve_prime_power_congruence+0x4d8>
jmp    16b0 <solve_prime_power_congruence+0x540>
xor    %r13d,%r13d
mov    (%rsp),%rbp
movslq %r13d,%rax
mov    %rax,0x0(%rbp)
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    %rbp,%rax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i64* @solve_prime_power_congruence(i32 %0, i64* %1, i64 %2, i32 %3) {
%5 = alloca i64*
%6 = alloca i32
%7 = alloca i64*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i64*
%11 = alloca i32
%12 = alloca i64*
%13 = alloca i64*
%14 = alloca i32
%15 = alloca i64
%16 = alloca i32
%17 = alloca i64*
%18 = alloca i64
%19 = alloca i64
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i64
store i32 %0, i32* %6
store i64* %1, i64** %7
store i64 %2, i64* %8
store i32 %3, i32* %9
%24 = load i32, i32* %9
%25 = icmp eq i32 %24, 1
br i1 %25, label %26, label %32
26: ; preds = %4
%27 = load i32, i32* %6
%28 = load i64*, i64** %7
%29 = load i64, i64* %8
%30 = call i64* @brute_force_congruence(i32 %27, i64* %28, i64 %29)
store i64* %30, i64** %12
%31 = load i64*, i64** %12
store i64* %31, i64** %5
br label %205
32: ; preds = %4
%33 = load i32, i32* %6
%34 = load i64*, i64** %7
%35 = load i64, i64* %8
%36 = load i32, i32* %9
%37 = sub nsw i32 %36, 1
%38 = call i64* @solve_prime_power_congruence(i32 %33, i64* %34, i64 %35, i32 %37)
store i64* %38, i64** %10
%39 = load i64*, i64** %10
%40 = load i64, i64* %39
%41 = trunc i64 %40 to i32
store i32 %41, i32* %11
%42 = load i64*, i64** %10
%43 = getelementptr inbounds i64, i64* %42, i64 1
store i64* %43, i64** %12
%44 = load i64, i64* %8
%45 = load i32, i32* %11
%46 = sext i32 %45 to i64
%47 = mul nsw i64 %44, %46
%48 = add nsw i64 %47, 1
%49 = trunc i64 %48 to i32
%50 = call i64* @calloc(i32 %49, i32 8)
store i64* %50, i64** %13
store i32 0, i32* %14
%51 = load i32, i32* %6
%52 = sub nsw i32 %51, 1
store i32 %52, i32* %16
%53 = load i32, i32* %16
%54 = add nsw i32 %53, 1
%55 = call i64* @calloc(i32 %54, i32 8)
store i64* %55, i64** %17
%56 = load i64, i64* %8
store i64 %56, i64* %23
store i32 1, i32* %21
br label %57
57: ; preds = %65, %32
%58 = load i32, i32* %21
%59 = load i32, i32* %9
%60 = icmp slt i32 %58, %59
br i1 %60, label %61, label %68
61: ; preds = %57
%62 = load i64, i64* %8
%63 = load i64, i64* %23
%64 = mul nsw i64 %63, %62
store i64 %64, i64* %23
br label %65
65: ; preds = %61
%66 = load i32, i32* %21
%67 = add nsw i32 %66, 1
store i32 %67, i32* %21
br label %57
68: ; preds = %57
store i32 0, i32* %21
br label %69
69: ; preds = %98, %68
%70 = load i32, i32* %21
%71 = load i32, i32* %16
%72 = icmp sle i32 %70, %71
br i1 %72, label %73, label %101
73: ; preds = %69
%74 = load i64*, i64** %7
%75 = load i32, i32* %21
%76 = add nsw i32 %75, 1
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i64, i64* %74, i64 %77
%79 = load i64, i64* %78
%80 = load i64, i64* %8
%81 = srem i64 %79, %80
store i64 %81, i64* %15
%82 = load i64, i64* %15
%83 = icmp slt i64 %82, 0
br i1 %83, label %84, label %88
84: ; preds = %73
%85 = load i64, i64* %8
%86 = load i64, i64* %15
%87 = add nsw i64 %86, %85
store i64 %87, i64* %15
br label %88
88: ; preds = %84, %73
%89 = load i64, i64* %15
%90 = load i32, i32* %21
%91 = add nsw i32 %90, 1
%92 = load i64, i64* %8
%93 = call i64 @mod_product(i64 %89, i32 %91, i64 %92)
%94 = load i64*, i64** %17
%95 = load i32, i32* %21
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds i64, i64* %94, i64 %96
store i64 %93, i64* %97
br label %98
98: ; preds = %88
%99 = load i32, i32* %21
%100 = add nsw i32 %99, 1
store i32 %100, i32* %21
br label %69
101: ; preds = %69
store i32 0, i32* %21
br label %102
102: ; preds = %193, %101
%103 = load i32, i32* %21
%104 = load i32, i32* %11
%105 = icmp slt i32 %103, %104
br i1 %105, label %106, label %196
106: ; preds = %102
%107 = load i32, i32* %16
%108 = load i64*, i64** %17
%109 = load i64, i64* %8
%110 = load i64*, i64** %12
%111 = load i32, i32* %21
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds i64, i64* %110, i64 %112
%114 = load i64, i64* %113
%115 = call i64 @mod_eval_polynomial(i32 %107, i64* %108, i64 %109, i64 %114)
store i64 %115, i64* %18
%116 = load i32, i32* %6
%117 = load i64*, i64** %7
%118 = load i64, i64* %23
%119 = load i64*, i64** %12
%120 = load i32, i32* %21
%121 = sext i32 %120 to i64
%122 = getelementptr inbounds i64, i64* %119, i64 %121
%123 = load i64, i64* %122
%124 = call i64 @mod_eval_polynomial(i32 %116, i64* %117, i64 %118, i64 %123)
store i64 %124, i64* %19
%125 = load i64, i64* %18
%126 = load i64, i64* %8
%127 = srem i64 %125, %126
%128 = icmp ne i64 %127, 0
br i1 %128, label %129, label %160
129: ; preds = %106
%130 = load i64, i64* %19
%131 = sub nsw i64 0, %130
%132 = load i64, i64* %23
%133 = load i64, i64* %8
%134 = sdiv i64 %132, %133
%135 = sdiv i64 %131, %134
%136 = load i64, i64* %18
%137 = load i64, i64* %23
%138 = call i64 @mod_inv(i64 %136, i64 %137)
%139 = mul nsw i64 %135, %138
%140 = load i64, i64* %8
%141 = srem i64 %139, %140
%142 = load i64, i64* %8
%143 = add nsw i64 %141, %142
%144 = trunc i64 %143 to i32
store i32 %144, i32* %22
%145 = load i64*, i64** %12
%146 = load i32, i32* %21
%147 = sext i32 %146 to i64
%148 = getelementptr inbounds i64, i64* %145, i64 %147
%149 = load i64, i64* %148
%150 = load i32, i32* %22
%151 = sext i32 %150 to i64
%152 = load i64, i64* %8
%153 = mul nsw i64 %151, %152
%154 = add nsw i64 %149, %153
%155 = load i64*, i64** %13
%156 = load i32, i32* %14
%157 = add nsw i32 %156, 1
store i32 %157, i32* %14
%158 = sext i32 %157 to i64
%159 = getelementptr inbounds i64, i64* %155, i64 %158
store i64 %154, i64* %159
br label %192
160: ; preds = %106
%161 = load i64, i64* %19
%162 = icmp eq i64 %161, 0
br i1 %162, label %163, label %191
163: ; preds = %160
store i32 1, i32* %22
br label %164
164: ; preds = %187, %163
%165 = load i32, i32* %22
%166 = sext i32 %165 to i64
%167 = load i64, i64* %8
%168 = icmp sle i64 %166, %167
br i1 %168, label %169, label %190
169: ; preds = %164
%170 = load i64*, i64** %12
%171 = load i32, i32* %21
%172 = sext i32 %171 to i64
%173 = getelementptr inbounds i64, i64* %170, i64 %172
%174 = load i64, i64* %173
%175 = load i32, i32* %22
%176 = sext i32 %175 to i64
%177 = load i64, i64* %23
%178 = load i64, i64* %8
%179 = sdiv i64 %177, %178
%180 = mul nsw i64 %176, %179
%181 = add nsw i64 %174, %180
%182 = load i64*, i64** %13
%183 = load i32, i32* %14
%184 = add nsw i32 %183, 1
store i32 %184, i32* %14
%185 = sext i32 %184 to i64
%186 = getelementptr inbounds i64, i64* %182, i64 %185
store i64 %181, i64* %186
br label %187
187: ; preds = %169
%188 = load i32, i32* %22
%189 = add nsw i32 %188, 1
store i32 %189, i32* %22
br label %164
190: ; preds = %164
br label %191
191: ; preds = %190, %160
br label %192
192: ; preds = %191, %129
br label %193
193: ; preds = %192
%194 = load i32, i32* %21
%195 = add nsw i32 %194, 1
store i32 %195, i32* %21
br label %102
196: ; preds = %102
%197 = load i32, i32* %14
%198 = sext i32 %197 to i64
%199 = load i64*, i64** %13
store i64 %198, i64* %199
%200 = load i64*, i64** %17
%201 = call i32 @free(i64* %200)
%202 = load i64*, i64** %10
%203 = call i32 @free(i64* %202)
%204 = load i64*, i64** %13
store i64* %204, i64** %5
br label %205
205: ; preds = %196, %26
%206 = load i64*, i64** %5
ret i64* %206
}

LLVM IR (-O2):
define i64* @solve_prime_power_congruence(i32 %0, i64* %1, i64 %2, i32 %3) {
%5 = icmp eq i32 %3, 1
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call i64* @brute_force_congruence(i32 %0, i64* %1, i64 %2)
br label %204
8: ; preds = %4
%9 = add nsw i32 %3, -1
%10 = tail call i64* @solve_prime_power_congruence(i32 %0, i64* %1, i64 %2, i32 %9)
%11 = load i64, i64* %10
%12 = trunc i64 %11 to i32
%13 = getelementptr inbounds i64, i64* %10, i64 1
%14 = shl i64 %11, 32
%15 = ashr exact i64 %14, 32
%16 = mul nsw i64 %15, %2
%17 = trunc i64 %16 to i32
%18 = add i32 %17, 1
%19 = tail call i64* @calloc(i32 %18, i32 8)
%20 = add nsw i32 %0, -1
%21 = tail call i64* @calloc(i32 %0, i32 8)
%22 = icmp sgt i32 %3, 1
br i1 %22, label %23, label %40
23: ; preds = %8
%24 = add i32 %3, -1
%25 = add i32 %3, -2
%26 = and i32 %24, 7
%27 = icmp ult i32 %25, 7
br i1 %27, label %30, label %28
28: ; preds = %23
%29 = and i32 %24, -8
br label %45
30: ; preds = %45, %23
%31 = phi i64 [ undef, %23 ], [ %55, %45 ]
%32 = phi i64 [ %2, %23 ], [ %55, %45 ]
%33 = icmp eq i32 %26, 0
br i1 %33, label %40, label %34
34: ; preds = %30, %34
%35 = phi i64 [ %37, %34 ], [ %32, %30 ]
%36 = phi i32 [ %38, %34 ], [ 0, %30 ]
%37 = mul nsw i64 %35, %2
%38 = add i32 %36, 1
%39 = icmp eq i32 %38, %26
br i1 %39, label %40, label %34
40: ; preds = %30, %34, %8
%41 = phi i64 [ %2, %8 ], [ %31, %30 ], [ %37, %34 ]
%42 = icmp sgt i32 %0, 0
br i1 %42, label %43, label %58
43: ; preds = %40
%44 = zext i32 %0 to i64
br label %76
45: ; preds = %45, %28
%46 = phi i64 [ %2, %28 ], [ %55, %45 ]
%47 = phi i32 [ 0, %28 ], [ %56, %45 ]
%48 = mul nsw i64 %46, %2
%49 = mul nsw i64 %48, %2
%50 = mul nsw i64 %49, %2
%51 = mul nsw i64 %50, %2
%52 = mul nsw i64 %51, %2
%53 = mul nsw i64 %52, %2
%54 = mul nsw i64 %53, %2
%55 = mul nsw i64 %54, %2
%56 = add i32 %47, 8
%57 = icmp eq i32 %56, %29
br i1 %57, label %30, label %45
58: ; preds = %76, %40
%59 = icmp sgt i32 %12, 0
br i1 %59, label %60, label %199
60: ; preds = %58
%61 = icmp slt i64 %2, 1
%62 = call i64 @llvm.smax.i64(i64 %2, i64 1)
%63 = and i64 %11, 4294967295
%64 = and i64 %62, 9223372036854775804
%65 = add nsw i64 %64, -4
%66 = lshr exact i64 %65, 2
%67 = add nuw nsw i64 %66, 1
%68 = icmp ult i64 %62, 4
%69 = and i64 %62, 9223372036854775804
%70 = or i64 %69, 1
%71 = and i64 %67, 1
%72 = icmp eq i64 %65, 0
%73 = and i64 %67, 9223372036854775806
%74 = icmp eq i64 %71, 0
%75 = icmp eq i64 %62, %69
br label %89
76: ; preds = %43, %76
%77 = phi i64 [ 0, %43 ], [ %78, %76 ]
%78 = add nuw nsw i64 %77, 1
%79 = getelementptr inbounds i64, i64* %1, i64 %78
%80 = load i64, i64* %79
%81 = srem i64 %80, %2
%82 = icmp slt i64 %81, 0
%83 = select i1 %82, i64 %2, i64 0
%84 = add nsw i64 %83, %81
%85 = trunc i64 %78 to i32
%86 = tail call i64 @mod_product(i64 %84, i32 %85, i64 %2)
%87 = getelementptr inbounds i64, i64* %21, i64 %77
store i64 %86, i64* %87
%88 = icmp eq i64 %78, %44
br i1 %88, label %58, label %76
89: ; preds = %60, %195
%90 = phi i64 [ 0, %60 ], [ %197, %195 ]
%91 = phi i32 [ 0, %60 ], [ %196, %195 ]
%92 = getelementptr inbounds i64, i64* %13, i64 %90
%93 = load i64, i64* %92
%94 = tail call i64 @mod_eval_polynomial(i32 %20, i64* %21, i64 %2, i64 %93)
%95 = load i64, i64* %92
%96 = tail call i64 @mod_eval_polynomial(i32 %0, i64* %1, i64 %41, i64 %95)
%97 = srem i64 %94, %2
%98 = icmp eq i64 %97, 0
br i1 %98, label %115, label %99
99: ; preds = %89
%100 = sdiv i64 %41, %2
%101 = sdiv i64 %96, %100
%102 = tail call i64 @mod_inv(i64 %94, i64 %41)
%103 = mul i64 %101, %102
%104 = sub i64 0, %103
%105 = srem i64 %104, %2
%106 = add nsw i64 %105, %2
%107 = load i64, i64* %92
%108 = shl i64 %106, 32
%109 = ashr exact i64 %108, 32
%110 = mul nsw i64 %109, %2
%111 = add nsw i64 %110, %107
%112 = add nsw i32 %91, 1
%113 = sext i32 %112 to i64
%114 = getelementptr inbounds i64, i64* %19, i64 %113
store i64 %111, i64* %114
br label %195
115: ; preds = %89
%116 = icmp ne i64 %96, 0
%117 = or i1 %116, %61
br i1 %117, label %195, label %118
118: ; preds = %115
%119 = load i64, i64* %92
%120 = sdiv i64 %41, %2
%121 = sext i32 %91 to i64
br i1 %68, label %180, label %122
122: ; preds = %118
%123 = add i64 %69, %121
%124 = insertelement <2 x i64> poison, i64 %120, i64 0
%125 = shufflevector <2 x i64> %124, <2 x i64> poison, <2 x i32> zeroinitializer
%126 = insertelement <2 x i64> poison, i64 %120, i64 0
%127 = shufflevector <2 x i64> %126, <2 x i64> poison, <2 x i32> zeroinitializer
%128 = insertelement <2 x i64> poison, i64 %119, i64 0
%129 = shufflevector <2 x i64> %128, <2 x i64> poison, <2 x i32> zeroinitializer
%130 = insertelement <2 x i64> poison, i64 %119, i64 0
%131 = shufflevector <2 x i64> %130, <2 x i64> poison, <2 x i32> zeroinitializer
br i1 %72, label %164, label %132
132: ; preds = %122, %132
%133 = phi i64 [ %160, %132 ], [ 0, %122 ]
%134 = phi <2 x i64> [ %161, %132 ], [ <i64 1, i64 2>, %122 ]
%135 = phi i64 [ %162, %132 ], [ 0, %122 ]
%136 = add i64 %133, %121
%137 = add <2 x i64> %134, <i64 2, i64 2>
%138 = mul nsw <2 x i64> %125, %134
%139 = mul nsw <2 x i64> %127, %137
%140 = add nsw <2 x i64> %138, %129
%141 = add nsw <2 x i64> %139, %131
%142 = add i64 %136, 1
%143 = getelementptr inbounds i64, i64* %19, i64 %142
%144 = bitcast i64* %143 to <2 x i64>*
store <2 x i64> %140, <2 x i64>* %144
%145 = getelementptr inbounds i64, i64* %143, i64 2
%146 = bitcast i64* %145 to <2 x i64>*
store <2 x i64> %141, <2 x i64>* %146
%147 = or i64 %133, 4
%148 = add <2 x i64> %134, <i64 4, i64 4>
%149 = add i64 %147, %121
%150 = add <2 x i64> %134, <i64 6, i64 6>
%151 = mul nsw <2 x i64> %125, %148
%152 = mul nsw <2 x i64> %127, %150
%153 = add nsw <2 x i64> %151, %129
%154 = add nsw <2 x i64> %152, %131
%155 = add i64 %149, 1
%156 = getelementptr inbounds i64, i64* %19, i64 %155
%157 = bitcast i64* %156 to <2 x i64>*
store <2 x i64> %153, <2 x i64>* %157
%158 = getelementptr inbounds i64, i64* %156, i64 2
%159 = bitcast i64* %158 to <2 x i64>*
store <2 x i64> %154, <2 x i64>* %159
%160 = add nuw i64 %133, 8
%161 = add <2 x i64> %134, <i64 8, i64 8>
%162 = add i64 %135, 2
%163 = icmp eq i64 %162, %73
br i1 %163, label %164, label %132
164: ; preds = %132, %122
%165 = phi i64 [ 0, %122 ], [ %160, %132 ]
%166 = phi <2 x i64> [ <i64 1, i64 2>, %122 ], [ %161, %132 ]
br i1 %74, label %179, label %167
167: ; preds = %164
%168 = add i64 %165, %121
%169 = add <2 x i64> %166, <i64 2, i64 2>
%170 = mul nsw <2 x i64> %125, %166
%171 = mul nsw <2 x i64> %127, %169
%172 = add nsw <2 x i64> %170, %129
%173 = add nsw <2 x i64> %171, %131
%174 = add i64 %168, 1
%175 = getelementptr inbounds i64, i64* %19, i64 %174
%176 = bitcast i64* %175 to <2 x i64>*
store <2 x i64> %172, <2 x i64>* %176
%177 = getelementptr inbounds i64, i64* %175, i64 2
%178 = bitcast i64* %177 to <2 x i64>*
store <2 x i64> %173, <2 x i64>* %178
br label %179
179: ; preds = %164, %167
br i1 %75, label %192, label %180
180: ; preds = %118, %179
%181 = phi i64 [ %121, %118 ], [ %123, %179 ]
%182 = phi i64 [ 1, %118 ], [ %70, %179 ]
br label %183
183: ; preds = %180, %183
%184 = phi i64 [ %188, %183 ], [ %181, %180 ]
%185 = phi i64 [ %190, %183 ], [ %182, %180 ]
%186 = mul nsw i64 %120, %185
%187 = add nsw i64 %186, %119
%188 = add i64 %184, 1
%189 = getelementptr inbounds i64, i64* %19, i64 %188
store i64 %187, i64* %189
%190 = add nuw nsw i64 %185, 1
%191 = icmp eq i64 %185, %62
br i1 %191, label %192, label %183
192: ; preds = %183, %179
%193 = phi i64 [ %123, %179 ], [ %188, %183 ]
%194 = trunc i64 %193 to i32
br label %195
195: ; preds = %192, %115, %99
%196 = phi i32 [ %112, %99 ], [ %91, %115 ], [ %194, %192 ]
%197 = add nuw nsw i64 %90, 1
%198 = icmp eq i64 %197, %63
br i1 %198, label %199, label %89
199: ; preds = %195, %58
%200 = phi i32 [ 0, %58 ], [ %196, %195 ]
%201 = sext i32 %200 to i64
store i64 %201, i64* %19
%202 = tail call i32 @free(i64* %21)
%203 = tail call i32 @free(i64* %10)
br label %204
204: ; preds = %199, %6
%205 = phi i64* [ %7, %6 ], [ %19, %199 ]
ret i64* %205
}