long *solve_congruence(int funcDegree, long funcCoeffs[], long mod) {
  long *solutionList;
  long *modFactorList = prime_factors(mod);
  long numOfModFactors = *modFactorList;
  long *modFactors = modFactorList + 1;
  long **primePowerSolutions = calloc(numOfModFactors, sizeof(long *));
  long *primePowers = calloc(numOfModFactors, sizeof(long));
  int *primePowerSolutionLengths = calloc(numOfModFactors, sizeof(int *));
  int power;
  int i, j, k;
  for (i = 0; i < numOfModFactors; i++) {
    primePowers[i] = modFactors[i];
    power = 1;
    while (mod % (primePowers[i] * modFactors[i]) == 0) {
      primePowers[i] *= modFactors[i];
      power++;
    }
    primePowerSolutions[i] = solve_prime_power_congruence(
        funcDegree, funcCoeffs, modFactors[i], power);
    primePowerSolutionLengths[i] = *(primePowerSolutions[i]++);
  }
  solutionList = solve_system_of_order_1_congruence_sets(
      numOfModFactors, primePowerSolutionLengths, primePowerSolutions,
      primePowers);
  for (i = 0; i < numOfModFactors; i++) {
    free(primePowerSolutions[i] - 1);
  }
  free(primePowerSolutionLengths);
  free(primePowerSolutions);
  free(primePowers);
  free(modFactorList);
  return solutionList;
}


x86 assembly (clang, -O0):
<solve_congruence>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x0,%al
call   1050 <prime_factors@plt>
cltq
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x50(%rbp)
movl   $0x0,-0x58(%rbp)
movslq -0x58(%rbp),%rax
cmp    -0x30(%rbp),%rax
jge    12ad <solve_congruence+0x15d>
mov    -0x38(%rbp),%rax
movslq -0x58(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x48(%rbp),%rax
movslq -0x58(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
movl   $0x1,-0x54(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x48(%rbp),%rcx
movslq -0x58(%rbp),%rdx
mov    (%rcx,%rdx,8),%rcx
mov    -0x38(%rbp),%rdx
movslq -0x58(%rbp),%rsi
imul   (%rdx,%rsi,8),%rcx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    124c <solve_congruence+0xfc>
mov    -0x38(%rbp),%rax
movslq -0x58(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x48(%rbp),%rax
movslq -0x58(%rbp),%rcx
imul   (%rax,%rcx,8),%rdx
mov    %rdx,(%rax,%rcx,8)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11f5 <solve_congruence+0xa5>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%rax
movslq -0x58(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x54(%rbp),%ecx
mov    $0x0,%al
call   1040 <solve_prime_power_congruence@plt>
movslq %eax,%rdx
mov    -0x40(%rbp),%rax
movslq -0x58(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x40(%rbp),%rcx
movslq -0x58(%rbp),%rdx
mov    (%rcx,%rdx,8),%rax
mov    %rax,%rsi
add    $0x8,%rsi
mov    %rsi,(%rcx,%rdx,8)
mov    (%rax),%rax
mov    %eax,%edx
mov    -0x50(%rbp),%rax
movslq -0x58(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    11c8 <solve_congruence+0x78>
mov    -0x30(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    $0x0,%al
call   1070 <solve_system_of_order_1_congruence_sets@plt>
cltq
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x58(%rbp)
movslq -0x58(%rbp),%rax
cmp    -0x30(%rbp),%rax
jge    1302 <solve_congruence+0x1b2>
mov    -0x40(%rbp),%rax
movslq -0x58(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
add    $0xfffffffffffffff8,%rdi
call   1030 <free@plt>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    12d1 <solve_congruence+0x181>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<solve_congruence>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%rbp
mov    %rsi,0x20(%rsp)
mov    %edi,0x14(%rsp)
mov    %rdx,%rdi
xor    %eax,%eax
call   1050 <prime_factors@plt>
movslq %eax,%r15
mov    (%r15),%r12
mov    $0x8,%esi
mov    %r12,%rdi
call   1060 <calloc@plt>
mov    %rax,%rbx
mov    $0x8,%esi
mov    %r12,%rdi
call   1060 <calloc@plt>
mov    %rax,%r13
mov    $0x8,%esi
mov    %r12,%rdi
call   1060 <calloc@plt>
test   %r12,%r12
mov    %rax,0x8(%rsp)
jle    12cd <solve_congruence+0x17d>
mov    %rbx,0x18(%rsp)
xor    %r14d,%r14d
jmp    11fa <solve_congruence+0xaa>
nop
mov    0x14(%rsp),%edi
mov    0x20(%rsp),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <solve_prime_power_congruence@plt>
cltq
lea    0x8(%rax),%rcx
mov    0x18(%rsp),%rdx
mov    %rcx,(%rdx,%r14,8)
mov    (%rax),%eax
mov    0x8(%rsp),%rsi
mov    %eax,(%rsi,%r14,4)
add    $0x1,%r14
cmp    %r12,%r14
je     1291 <solve_congruence+0x141>
mov    0x8(%r15,%r14,8),%rsi
mov    %rsi,0x0(%r13,%r14,8)
mov    0x8(%r15,%r14,8),%rbx
imul   %rbx,%rsi
mov    %rbp,%rax
or     %rsi,%rax
shr    $0x20,%rax
je     1230 <solve_congruence+0xe0>
mov    %rbp,%rax
cqto
idiv   %rsi
jmp    1236 <solve_congruence+0xe6>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%eax
xor    %edx,%edx
div    %esi
mov    $0x1,%ecx
test   %rdx,%rdx
je     1264 <solve_congruence+0x114>
jmp    11c0 <solve_congruence+0x70>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rax
cqto
idiv   %rsi
add    $0x1,%ecx
test   %rdx,%rdx
jne    11c0 <solve_congruence+0x70>
mov    %rsi,0x0(%r13,%r14,8)
mov    0x8(%r15,%r14,8),%rbx
imul   %rbx,%rsi
mov    %rbp,%rax
or     %rsi,%rax
shr    $0x20,%rax
jne    1250 <solve_congruence+0x100>
mov    %ebp,%eax
xor    %edx,%edx
div    %esi
add    $0x1,%ecx
test   %rdx,%rdx
je     1264 <solve_congruence+0x114>
jmp    11c0 <solve_congruence+0x70>
mov    %r12,%rdi
mov    0x18(%rsp),%rbx
mov    %rbx,%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1070 <solve_system_of_order_1_congruence_sets@plt>
mov    %eax,%r14d
test   %r12,%r12
jle    12c6 <solve_congruence+0x176>
xor    %ebp,%ebp
mov    (%rbx,%rbp,8),%rdi
add    $0xfffffffffffffff8,%rdi
call   1030 <free@plt>
add    $0x1,%rbp
cmp    %rbp,%r12
jne    12b0 <solve_congruence+0x160>
mov    0x8(%rsp),%rdi
jmp    12e8 <solve_congruence+0x198>
mov    %r12,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1070 <solve_system_of_order_1_congruence_sets@plt>
mov    0x8(%rsp),%rdi
mov    %eax,%r14d
movslq %r14d,%rbp
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbp,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i64* @solve_congruence(i32 %0, i64* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i64*
%6 = alloca i64
%7 = alloca i64*
%8 = alloca i64*
%9 = alloca i64
%10 = alloca i64*
%11 = alloca i64**
%12 = alloca i64*
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i32 %0, i32* %4
store i64* %1, i64** %5
store i64 %2, i64* %6
%18 = load i64, i64* %6
%19 = call i32 (i64, ...) bitcast (i32 (...)* @prime_factors to i32 (i64, ...)*)(i64 %18)
%20 = sext i32 %19 to i64
%21 = inttoptr i64 %20 to i64*
store i64* %21, i64** %8
%22 = load i64*, i64** %8
%23 = load i64, i64* %22
store i64 %23, i64* %9
%24 = load i64*, i64** %8
%25 = getelementptr inbounds i64, i64* %24, i64 1
store i64* %25, i64** %10
%26 = load i64, i64* %9
%27 = call i8* @calloc(i64 %26, i64 8)
%28 = bitcast i8* %27 to i64**
store i64** %28, i64*** %11
%29 = load i64, i64* %9
%30 = call i8* @calloc(i64 %29, i64 8)
%31 = bitcast i8* %30 to i64*
store i64* %31, i64** %12
%32 = load i64, i64* %9
%33 = call i8* @calloc(i64 %32, i64 8)
%34 = bitcast i8* %33 to i32*
store i32* %34, i32** %13
store i32 0, i32* %15
br label %35
35: ; preds = %107, %3
%36 = load i32, i32* %15
%37 = sext i32 %36 to i64
%38 = load i64, i64* %9
%39 = icmp slt i64 %37, %38
br i1 %39, label %40, label %110
40: ; preds = %35
%41 = load i64*, i64** %10
%42 = load i32, i32* %15
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i64, i64* %41, i64 %43
%45 = load i64, i64* %44
%46 = load i64*, i64** %12
%47 = load i32, i32* %15
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i64, i64* %46, i64 %48
store i64 %45, i64* %49
store i32 1, i32* %14
br label %50
50: ; preds = %65, %40
%51 = load i64, i64* %6
%52 = load i64*, i64** %12
%53 = load i32, i32* %15
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i64, i64* %52, i64 %54
%56 = load i64, i64* %55
%57 = load i64*, i64** %10
%58 = load i32, i32* %15
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i64, i64* %57, i64 %59
%61 = load i64, i64* %60
%62 = mul nsw i64 %56, %61
%63 = srem i64 %51, %62
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %79
65: ; preds = %50
%66 = load i64*, i64** %10
%67 = load i32, i32* %15
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i64, i64* %66, i64 %68
%70 = load i64, i64* %69
%71 = load i64*, i64** %12
%72 = load i32, i32* %15
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i64, i64* %71, i64 %73
%75 = load i64, i64* %74
%76 = mul nsw i64 %75, %70
store i64 %76, i64* %74
%77 = load i32, i32* %14
%78 = add nsw i32 %77, 1
store i32 %78, i32* %14
br label %50
79: ; preds = %50
%80 = load i32, i32* %4
%81 = load i64*, i64** %5
%82 = load i64*, i64** %10
%83 = load i32, i32* %15
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i64, i64* %82, i64 %84
%86 = load i64, i64* %85
%87 = load i32, i32* %14
%88 = call i32 (i32, i64*, i64, i32, ...) bitcast (i32 (...)* @solve_prime_power_congruence to i32 (i32, i64*, i64, i32, ...)*)(i32 %80, i64* %81, i64 %86, i32 %87)
%89 = sext i32 %88 to i64
%90 = inttoptr i64 %89 to i64*
%91 = load i64**, i64*** %11
%92 = load i32, i32* %15
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i64*, i64** %91, i64 %93
store i64* %90, i64** %94
%95 = load i64**, i64*** %11
%96 = load i32, i32* %15
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i64*, i64** %95, i64 %97
%99 = load i64*, i64** %98
%100 = getelementptr inbounds i64, i64* %99, i32 1
store i64* %100, i64** %98
%101 = load i64, i64* %99
%102 = trunc i64 %101 to i32
%103 = load i32*, i32** %13
%104 = load i32, i32* %15
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds i32, i32* %103, i64 %105
store i32 %102, i32* %106
br label %107
107: ; preds = %79
%108 = load i32, i32* %15
%109 = add nsw i32 %108, 1
store i32 %109, i32* %15
br label %35
110: ; preds = %35
%111 = load i64, i64* %9
%112 = load i32*, i32** %13
%113 = load i64**, i64*** %11
%114 = load i64*, i64** %12
%115 = call i32 (i64, i32*, i64**, i64*, ...) bitcast (i32 (...)* @solve_system_of_order_1_congruence_sets to i32 (i64, i32*, i64**, i64*, ...)*)(i64 %111, i32* %112, i64** %113, i64* %114)
%116 = sext i32 %115 to i64
%117 = inttoptr i64 %116 to i64*
store i64* %117, i64** %7
store i32 0, i32* %15
br label %118
118: ; preds = %131, %110
%119 = load i32, i32* %15
%120 = sext i32 %119 to i64
%121 = load i64, i64* %9
%122 = icmp slt i64 %120, %121
br i1 %122, label %123, label %134
123: ; preds = %118
%124 = load i64**, i64*** %11
%125 = load i32, i32* %15
%126 = sext i32 %125 to i64
%127 = getelementptr inbounds i64*, i64** %124, i64 %126
%128 = load i64*, i64** %127
%129 = getelementptr inbounds i64, i64* %128, i64 -1
%130 = bitcast i64* %129 to i8*
br label %131
131: ; preds = %123
%132 = load i32, i32* %15
%133 = add nsw i32 %132, 1
store i32 %133, i32* %15
br label %118
134: ; preds = %118
%135 = load i32*, i32** %13
%136 = bitcast i32* %135 to i8*
%137 = load i64**, i64*** %11
%138 = bitcast i64** %137 to i8*
%139 = load i64*, i64** %12
%140 = bitcast i64* %139 to i8*
%141 = load i64*, i64** %8
%142 = bitcast i64* %141 to i8*
%143 = load i64*, i64** %7
ret i64* %143
}

LLVM IR (-O2):
define i64* @solve_congruence(i32 %0, i64* %1, i64 %2) {
%4 = tail call i32 (i64, ...) bitcast (i32 (...)* @prime_factors to i32 (i64, ...)*)(i64 %2)
%5 = sext i32 %4 to i64
%6 = inttoptr i64 %5 to i64*
%7 = load i64, i64* %6
%8 = getelementptr inbounds i64, i64* %6, i64 1
%9 = tail call i8* @calloc(i64 %7, i64 8)
%10 = bitcast i8* %9 to i64**
%11 = tail call i8* @calloc(i64 %7, i64 8)
%12 = bitcast i8* %11 to i64*
%13 = tail call i8* @calloc(i64 %7, i64 8)
%14 = bitcast i8* %13 to i32*
%15 = icmp sgt i64 %7, 0
br i1 %15, label %18, label %16
16: ; preds = %3
%17 = tail call i32 (i64, i32*, i64**, i64*, ...) bitcast (i32 (...)* @solve_system_of_order_1_congruence_sets to i32 (i64, i32*, i64**, i64*, ...)*)(i64 %7, i32* %14, i64** %10, i64* %12)
br label %58
18: ; preds = %3, %35
%19 = phi i64 [ %46, %35 ], [ 0, %3 ]
%20 = getelementptr inbounds i64, i64* %8, i64 %19
%21 = load i64, i64* %20
%22 = getelementptr inbounds i64, i64* %12, i64 %19
store i64 %21, i64* %22
%23 = load i64, i64* %20
%24 = mul nsw i64 %23, %21
%25 = srem i64 %2, %24
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %35
27: ; preds = %18, %27
%28 = phi i64 [ %32, %27 ], [ %24, %18 ]
%29 = phi i32 [ %30, %27 ], [ 1, %18 ]
store i64 %28, i64* %22
%30 = add nuw nsw i32 %29, 1
%31 = load i64, i64* %20
%32 = mul nsw i64 %31, %28
%33 = srem i64 %2, %32
%34 = icmp eq i64 %33, 0
br i1 %34, label %27, label %35
35: ; preds = %27, %18
%36 = phi i32 [ 1, %18 ], [ %30, %27 ]
%37 = phi i64 [ %23, %18 ], [ %31, %27 ]
%38 = tail call i32 (i32, i64*, i64, i32, ...) bitcast (i32 (...)* @solve_prime_power_congruence to i32 (i32, i64*, i64, i32, ...)*)(i32 %0, i64* %1, i64 %37, i32 %36)
%39 = sext i32 %38 to i64
%40 = inttoptr i64 %39 to i64*
%41 = getelementptr inbounds i64*, i64** %10, i64 %19
%42 = getelementptr inbounds i64, i64* %40, i64 1
store i64* %42, i64** %41
%43 = load i64, i64* %40
%44 = trunc i64 %43 to i32
%45 = getelementptr inbounds i32, i32* %14, i64 %19
store i32 %44, i32* %45
%46 = add nuw nsw i64 %19, 1
%47 = icmp eq i64 %46, %7
br i1 %47, label %48, label %18
48: ; preds = %35
%49 = tail call i32 (i64, i32*, i64**, i64*, ...) bitcast (i32 (...)* @solve_system_of_order_1_congruence_sets to i32 (i64, i32*, i64**, i64*, ...)*)(i64 %7, i32* %14, i64** %10, i64* %12)
br i1 %15, label %50, label %58
50: ; preds = %48, %50
%51 = phi i64 [ %56, %50 ], [ 0, %48 ]
%52 = getelementptr inbounds i64*, i64** %10, i64 %51
%53 = load i64*, i64** %52
%54 = getelementptr inbounds i64, i64* %53, i64 -1
%55 = bitcast i64* %54 to i8*
tail call void @free(i8* %55)
%56 = add nuw nsw i64 %51, 1
%57 = icmp eq i64 %56, %7
br i1 %57, label %58, label %50
58: ; preds = %50, %16, %48
%59 = phi i32 [ %17, %16 ], [ %49, %48 ], [ %49, %50 ]
%60 = sext i32 %59 to i64
%61 = inttoptr i64 %60 to i64*
tail call void @free(i8* %13)
tail call void @free(i8* %9)
tail call void @free(i8* %11)
%62 = inttoptr i64 %5 to i8*
tail call void @free(i8* %62)
ret i64* %61
}