#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 *adjust_coeffs_to_mod(int, long *, long);
long *calloc(int, int);
int /*<<< orphan*/ free(long *);
scalar_t__ mod_eval_polynomial(int, long *, long, long);
long *brute_force_congruence(int degree, long coeffs[], long primeMod) {
  long *adjustedCoeffs = adjust_coeffs_to_mod(degree, coeffs, primeMod);
  long *solutionList = calloc(degree + 1, sizeof(long));
  long *solutions = solutionList + 1;
  int numberOfSolutions = 0;
  long x;
#pragma omp parallel for
  for (x = 0; x < primeMod; x++) {
    if (mod_eval_polynomial(degree, adjustedCoeffs, primeMod, x) == 0) {
#pragma omp critical
      solutions[numberOfSolutions++] = x;
    }
  }
  *solutionList = numberOfSolutions;
  free(adjustedCoeffs);
  return solutionList;
}


x86 assembly (clang, -O0):
<brute_force_congruence>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <adjust_coeffs_to_mod@plt>
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    11f2 <brute_force_congruence+0xb2>
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x40(%rbp),%rcx
call   1050 <mod_eval_polynomial@plt>
cmp    $0x0,%rax
jne    11dc <brute_force_congruence+0x9c>
mov    -0x40(%rbp),%rdx
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x34(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    11e1 <brute_force_congruence+0xa1>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    1196 <brute_force_congruence+0x56>
movslq -0x34(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<brute_force_congruence>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r13
mov    %edi,%r15d
call   1040 <adjust_coeffs_to_mod@plt>
mov    %rax,%r14
lea    0x1(%r15),%edi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,%r12
test   %r13,%r13
jle    11ac <brute_force_congruence+0x6c>
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    1189 <brute_force_congruence+0x49>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbx
cmp    %rbx,%r13
je     11ae <brute_force_congruence+0x6e>
mov    %r15d,%edi
mov    %r14,%rsi
mov    %r13,%rdx
mov    %rbx,%rcx
call   1050 <mod_eval_polynomial@plt>
test   %rax,%rax
jne    1180 <brute_force_congruence+0x40>
movslq %ebp,%rax
add    $0x1,%ebp
mov    %rbx,0x8(%r12,%rax,8)
jmp    1180 <brute_force_congruence+0x40>
xor    %ebp,%ebp
movslq %ebp,%rax
mov    %rax,(%r12)
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i64* @brute_force_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 i32
%11 = alloca i64
store i32 %0, i32* %4
store i64* %1, i64** %5
store i64 %2, i64* %6
%12 = load i32, i32* %4
%13 = load i64*, i64** %5
%14 = load i64, i64* %6
%15 = call i64* @adjust_coeffs_to_mod(i32 %12, i64* %13, i64 %14)
store i64* %15, i64** %7
%16 = load i32, i32* %4
%17 = add nsw i32 %16, 1
%18 = call i64* @calloc(i32 %17, i32 8)
store i64* %18, i64** %8
%19 = load i64*, i64** %8
%20 = getelementptr inbounds i64, i64* %19, i64 1
store i64* %20, i64** %9
store i32 0, i32* %10
store i64 0, i64* %11
br label %21
21: ; preds = %40, %3
%22 = load i64, i64* %11
%23 = load i64, i64* %6
%24 = icmp slt i64 %22, %23
br i1 %24, label %25, label %43
25: ; preds = %21
%26 = load i32, i32* %4
%27 = load i64*, i64** %7
%28 = load i64, i64* %6
%29 = load i64, i64* %11
%30 = call i64 @mod_eval_polynomial(i32 %26, i64* %27, i64 %28, i64 %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %39
32: ; preds = %25
%33 = load i64, i64* %11
%34 = load i64*, i64** %9
%35 = load i32, i32* %10
%36 = add nsw i32 %35, 1
store i32 %36, i32* %10
%37 = sext i32 %35 to i64
%38 = getelementptr inbounds i64, i64* %34, i64 %37
store i64 %33, i64* %38
br label %39
39: ; preds = %32, %25
br label %40
40: ; preds = %39
%41 = load i64, i64* %11
%42 = add nsw i64 %41, 1
store i64 %42, i64* %11
br label %21
43: ; preds = %21
%44 = load i32, i32* %10
%45 = sext i32 %44 to i64
%46 = load i64*, i64** %8
store i64 %45, i64* %46
%47 = load i64*, i64** %7
%48 = call i32 @free(i64* %47)
%49 = load i64*, i64** %8
ret i64* %49
}

LLVM IR (-O2):
define noalias i64* @brute_force_congruence(i32 %0, i64* %1, i64 %2) {
%4 = tail call i64* @adjust_coeffs_to_mod(i32 %0, i64* %1, i64 %2)
%5 = add nsw i32 %0, 1
%6 = tail call i64* @calloc(i32 %5, i32 8)
%7 = getelementptr inbounds i64, i64* %6, i64 1
%8 = icmp sgt i64 %2, 0
br i1 %8, label %9, label %22
9: ; preds = %3, %18
%10 = phi i64 [ %20, %18 ], [ 0, %3 ]
%11 = phi i32 [ %19, %18 ], [ 0, %3 ]
%12 = tail call i64 @mod_eval_polynomial(i32 %0, i64* %4, i64 %2, i64 %10)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = add nsw i32 %11, 1
%16 = sext i32 %11 to i64
%17 = getelementptr inbounds i64, i64* %7, i64 %16
store i64 %10, i64* %17
br label %18
18: ; preds = %9, %14
%19 = phi i32 [ %15, %14 ], [ %11, %9 ]
%20 = add nuw nsw i64 %10, 1
%21 = icmp eq i64 %20, %2
br i1 %21, label %22, label %9
22: ; preds = %18, %3
%23 = phi i32 [ 0, %3 ], [ %19, %18 ]
%24 = sext i32 %23 to i64
store i64 %24, i64* %6
%25 = tail call i32 @free(i64* %4)
ret i64* %6
}