// File: /workspace/github_c_makefile_star2_O0/dlbeer[P]dhara/ecc/bch.c
// Function: berlekamp_massey
static void berlekamp_massey(const gf13_elem_t *s, int N,
			     gf13_elem_t *sigma)
{
	gf13_elem_t C[MAX_POLY];
	gf13_elem_t B[MAX_POLY];
	int L = 0;
	int m = 1;
	gf13_elem_t b = 1;
	int n;

	memset(sigma, 0, MAX_POLY * sizeof(sigma[0]));
	memset(B, 0, sizeof(B));
	memset(C, 0, sizeof(C));
	B[0] = 1;
	C[0] = 1;

	for (n = 0; n < N; n++) {
		gf13_elem_t d = s[n];
		gf13_elem_t mult;
		int i;

		for (i = 1; i <= L; i++) {
			if (!(C[i] && s[n - i]))
				continue;

			d ^= gf13_mul(C[i], s[n - i]);
		}

		mult = gf13_div(d, b);

		if (!d) {
			m++;
		} else if (L * 2 <= n) {
			gf13_elem_t T[MAX_POLY];

			memcpy(T, C, sizeof(T));
			poly_add(C, B, mult, m);
			memcpy(B, T, sizeof(B));
			L = n + 1 - L;
			b = d;
			m = 1;
		} else {
			poly_add(C, B, mult, m);
			m++;
		}
	}

	memcpy(sigma, C, MAX_POLY);
}

// Assembly:
subq $0x98, %rsp
movq %rdi, 0x90(%rsp)
movl %esi, 0x8c(%rsp)
movq %rdx, 0x80(%rsp)
movl $0x0, 0x3c(%rsp)
movl $0x1, 0x38(%rsp)
movw $0x1, 0x36(%rsp)
movq 0x80(%rsp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x1060
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x1060
leaq 0x60(%rsp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x1060
movw $0x1, 0x40(%rsp)
movw $0x1, 0x60(%rsp)
movl $0x0, 0x30(%rsp)
movl 0x30(%rsp), %eax
cmpl 0x8c(%rsp), %eax
jge 0x1941
movq 0x90(%rsp), %rax
movslq 0x30(%rsp), %rcx
movw (%rax,%rcx,2), %ax
movw %ax, 0x2e(%rsp)
movl $0x1, 0x28(%rsp)
movl 0x28(%rsp), %eax
cmpl 0x3c(%rsp), %eax
jg 0x183c
movslq 0x28(%rsp), %rax
movzwl 0x60(%rsp,%rax,2), %eax
cmpl $0x0, %eax
je 0x17f5
movq 0x90(%rsp), %rax
movl 0x30(%rsp), %ecx
subl 0x28(%rsp), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
cmpl $0x0, %eax
jne 0x17f7
jmp 0x182f
movslq 0x28(%rsp), %rax
movw 0x60(%rsp,%rax,2), %dx
movq 0x90(%rsp), %rax
movl 0x30(%rsp), %ecx
subl 0x28(%rsp), %ecx
movslq %ecx, %rcx
movzwl %dx, %edi
movzwl (%rax,%rcx,2), %esi
callq 0x1a50
movzwl %ax, %ecx
movzwl 0x2e(%rsp), %eax
xorl %ecx, %eax
movw %ax, 0x2e(%rsp)
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0x17c0
movw 0x2e(%rsp), %ax
movzwl %ax, %edi
movzwl 0x36(%rsp), %esi
callq 0x1af0
movw %ax, 0x2c(%rsp)
cmpw $0x0, 0x2e(%rsp)
jne 0x186b
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x192f
movl 0x3c(%rsp), %eax
shll %eax
cmpl 0x30(%rsp), %eax
jg 0x1907
movq 0x60(%rsp), %rax
movq %rax, (%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x78(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x40(%rsp), %rsi
movw 0x2c(%rsp), %ax
movl 0x38(%rsp), %ecx
movzwl %ax, %edx
callq 0x1b50
movq (%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x18(%rsp), %rax
movq %rax, 0x58(%rsp)
movl 0x30(%rsp), %eax
addl $0x1, %eax
subl 0x3c(%rsp), %eax
movl %eax, 0x3c(%rsp)
movw 0x2e(%rsp), %ax
movw %ax, 0x36(%rsp)
movl $0x1, 0x38(%rsp)
jmp 0x192d
leaq 0x60(%rsp), %rdi
leaq 0x40(%rsp), %rsi
movw 0x2c(%rsp), %ax
movl 0x38(%rsp), %ecx
movzwl %ax, %edx
callq 0x1b50
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x192f
jmp 0x1931
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0x1791
movq 0x80(%rsp), %rax
movq 0x60(%rsp), %rcx
movq %rcx, (%rax)
movq 0x68(%rsp), %rcx
movq %rcx, 0x8(%rax)
addq $0x98, %rsp
retq
nopw %cs:(%rax,%rax)