// File: /workspace/github_cpp_makefile_star2_O2/syzcch[P]FEC_C_version/./fec_rs.h
// Function: rscode::gf_invert_matrix(int*, int)
int *gf_invert_matrix(int *mat, int rows)
    {
        int *inv;
        int *copy;
        int cols, i, j, k, x, rs2;
        int row_start, tmp, inverse;

        cols = rows;

        inv = (int *) malloc(sizeof(int)*rows*cols);
        if (inv == NULL)
        {
            printf("gf_invert_matrix - inv");
        }
        copy = (int *) malloc(sizeof(int)*rows*cols);
        if (copy == NULL)
        {
            printf("gf_invert_matrix - copy");
        }

        k = 0;
        for (i = 0; i < rows; i++)
        {
            for (j = 0; j < cols; j++)
            {
                inv[k] = (i == j) ? 1 : 0;
                copy[k] = mat[k];
                k++;
            }
        }

        /* First -- convert into upper triangular */
        for (i = 0; i < cols; i++)
        {
            row_start = cols*i;

            /* Swap rows if we ave a zero i,i element.  If we can't swap, then the
            matrix was not invertible */

            if (copy[row_start+i] == 0)
            {
                for (j = i+1; j < rows && copy[cols*j+i] == 0; j++) ;
                if (j == rows)
                {
                    printf( "gf_invert_matrix: Matrix not invertible!!\n");
                    exit(1);
                }
                rs2 = j*cols;
                for (k = 0; k < cols; k++)
                {
                    tmp = copy[row_start+k];
                    copy[row_start+k] = copy[rs2+k];
                    copy[rs2+k] = tmp;
                    tmp = inv[row_start+k];
                    inv[row_start+k] = inv[rs2+k];
                    inv[rs2+k] = tmp;
                }
            }

            /* Multiply the row by 1/element i,i */
            tmp = copy[row_start+i];
            if (tmp != 1)
            {
                inverse = gf_single_divide(1, tmp);
                for (j = 0; j < cols; j++)
                {
                    copy[row_start+j] = gf_single_multiply(copy[row_start+j], inverse);
                    inv[row_start+j] = gf_single_multiply(inv[row_start+j], inverse);
                }
                /* pic(inv, copy, rows, "Divided through"); */
            }

            /* Now for each j>i, add A_ji*Ai to Aj */
            k = row_start+i;
            for (j = i+1; j != cols; j++)
            {
                k += cols;
                if (copy[k] != 0)
                {
                    if (copy[k] == 1)
                    {
                        rs2 = cols*j;
                        for (x = 0; x < cols; x++)
                        {
                            copy[rs2+x] ^= copy[row_start+x];
                            inv[rs2+x] ^= inv[row_start+x];
                        }
                    }
                    else
                    {
                        tmp = copy[k];
                        rs2 = cols*j;
                        for (x = 0; x < cols; x++)
                        {
                            copy[rs2+x] ^= gf_single_multiply(tmp, copy[row_start+x]);
                            inv[rs2+x] ^= gf_single_multiply(tmp, inv[row_start+x]);
                        }
                    }
                }
            }
            /* pic(inv, copy, rows, "Eliminated rows"); */
        }

        /* Now the matrix is upper triangular.  Start at the top and multiply down */

        for (i = rows-1; i >= 0; i--)
        {
            row_start = i*cols;
            for (j = 0; j < i; j++)
            {
                rs2 = j*cols;
                if (0 != copy[rs2+i])
                {
                    tmp = copy[rs2+i];
                    copy[rs2+i] = 0;
                    for (k = 0; k < cols; k++)
                    {
                        inv[rs2+k] ^= gf_single_multiply(tmp, inv[row_start+k]);
                    }
                }
            }
            /* pic(inv, copy, rows, "One Column"); */
        }
        free(copy);
        return inv;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %edx, %r12d
movq %rsi, %r13
movq %rdi, -0x70(%rbp)
movslq %edx, %rbx
movq %rbx, %r14
imulq %rbx, %r14
shlq $0x2, %r14
movq %r14, %rdi
callq 0x10f0
movq %rax, %r15
testq %rax, %rax
jne 0x23d8
leaq 0xdf5(%rip), %rdi       # 0x31c6
xorl %eax, %eax
callq 0x1040
movq %r14, %rdi
callq 0x10f0
movq %rax, -0x50(%rbp)
testq %rax, %rax
jne 0x23f7
leaq 0xded(%rip), %rdi       # 0x31dd
xorl %eax, %eax
callq 0x1040
xorl %ecx, %ecx
testl %r12d, %r12d
movl $0x0, %eax
cmovgl %r12d, %eax
xorl %edx, %edx
movq -0x50(%rbp), %r8
cmpl %eax, %edx
je 0x2439
movslq %ecx, %rcx
xorl %esi, %esi
cmpl %esi, %r12d
je 0x2435
xorl %edi, %edi
cmpl %esi, %edx
sete %dil
movl %edi, (%r15,%rcx,4)
movl (%r13,%rcx,4), %edi
movl %edi, (%r8,%rcx,4)
incq %rcx
incl %esi
jmp 0x2414
incl %edx
jmp 0x240b
leal 0x1(%r12), %ecx
movl %ecx, -0x9c(%rbp)
movl %eax, %r14d
movl %r12d, %eax
negl %eax
movq %rax, -0xb8(%rbp)
leaq (,%rbx,4), %rax
movq %rax, -0x48(%rbp)
movq -0x50(%rbp), %rdi
leaq (%rdi,%rbx,4), %rax
movq %rax, -0xa8(%rbp)
leaq 0x4(,%rbx,4), %rax
movq %rax, -0xc0(%rbp)
pushq $0x1
popq %rax
movq %rax, -0x88(%rbp)
movq $0x0, -0x80(%rbp)
movq %r15, -0x30(%rbp)
movq %rdi, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
xorl %ecx, %ecx
movq %rbx, -0x90(%rbp)
movq %r15, -0x78(%rbp)
movq %r12, -0xc8(%rbp)
cmpq %r14, %rcx
je 0x26ec
movq %rcx, %rax
imulq %rbx, %rax
leaq (%rdi,%rax,4), %rax
movq %rcx, -0xb0(%rbp)
movl (%rax,%rcx,4), %edx
testl %edx, %edx
jne 0x255e
movq -0xa8(%rbp), %rsi
movq -0x80(%rbp), %rcx
movq -0x88(%rbp), %rdx
cmpq %rbx, %rdx
jge 0x27aa
incq %rdx
addl %r12d, %ecx
cmpl $0x0, (%rsi)
movq -0x48(%rbp), %r8
leaq (%rsi,%r8), %rsi
je 0x24ea
addl -0xb8(%rbp), %edx
cmpl $0x1, %edx
je 0x27aa
movslq %ecx, %rdx
leaq (%rdi,%rdx,4), %rcx
leaq (%r15,%rdx,4), %rdx
xorl %esi, %esi
cmpq %rsi, %r14
je 0x2554
movq -0x38(%rbp), %r10
movl (%r10,%rsi,4), %r9d
movl (%rcx,%rsi,4), %r8d
movl %r8d, (%r10,%rsi,4)
movl %r9d, (%rcx,%rsi,4)
movq -0x30(%rbp), %r10
movl (%r10,%rsi,4), %r9d
movl (%rdx,%rsi,4), %r8d
movl %r8d, (%r10,%rsi,4)
movl %r9d, (%rdx,%rsi,4)
incq %rsi
jmp 0x2522
movq -0xb0(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movslq -0x88(%rbp), %r13
movq -0x48(%rbp), %r12
imulq %r13, %r12
leaq (%rdi,%r12), %rcx
movq %rcx, -0x60(%rbp)
addq %r15, %r12
movslq -0x3c(%rbp), %rax
cmpl $0x1, %edx
je 0x25e1
movq %rax, -0x98(%rbp)
movq -0x70(%rbp), %rdi
pushq $0x1
popq %rsi
callq 0x1dc0
movl %eax, -0x64(%rbp)
xorl %ebx, %ebx
movq %r13, -0x58(%rbp)
cmpq %rbx, %r14
je 0x2683
movq -0x38(%rbp), %r15
movl (%r15,%rbx,4), %esi
movq -0x70(%rbp), %r13
movq %r13, %rdi
movl -0x64(%rbp), %edx
callq 0x2054
movl %eax, (%r15,%rbx,4)
movq -0x30(%rbp), %r15
movl (%r15,%rbx,4), %esi
movq %r13, %rdi
movq -0x58(%rbp), %r13
movl -0x64(%rbp), %edx
callq 0x2054
movl %eax, (%r15,%rbx,4)
incq %rbx
jmp 0x259d
cmpq %rbx, %r13
je 0x269a
movq %r13, -0x58(%rbp)
addq %rbx, %rax
movq %rax, -0x98(%rbp)
movl (%rdi,%rax,4), %r13d
testl %r13d, %r13d
je 0x2671
cmpl $0x1, %r13d
jne 0x262c
xorl %eax, %eax
cmpq %rax, %r14
je 0x2671
movq -0x38(%rbp), %rcx
movl (%rcx,%rax,4), %ecx
movq -0x60(%rbp), %rdx
xorl %ecx, (%rdx,%rax,4)
movq -0x30(%rbp), %rcx
movl (%rcx,%rax,4), %ecx
xorl %ecx, (%r12,%rax,4)
incq %rax
jmp 0x2609
xorl %ebx, %ebx
cmpq %rbx, %r14
je 0x2671
movq -0x38(%rbp), %rax
movl (%rax,%rbx,4), %edx
movq %r14, %r15
movq -0x70(%rbp), %r14
movq %r14, %rdi
movl %r13d, %esi
callq 0x2054
movq -0x60(%rbp), %rcx
xorl %eax, (%rcx,%rbx,4)
movq -0x30(%rbp), %rax
movl (%rax,%rbx,4), %edx
movq %r14, %rdi
movq %r15, %r14
movl %r13d, %esi
callq 0x2054
xorl %eax, (%r12,%rbx,4)
incq %rbx
jmp 0x262e
movq -0x58(%rbp), %r13
incq %r13
movq -0x48(%rbp), %rax
addq %rax, -0x60(%rbp)
addq %rax, %r12
movq -0x90(%rbp), %rbx
movq -0x50(%rbp), %rdi
movq -0x98(%rbp), %rax
jmp 0x25e1
movq -0xb0(%rbp), %rcx
incq %rcx
incq -0x88(%rbp)
movl -0x3c(%rbp), %eax
addl -0x9c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0xc8(%rbp), %r12
movq -0x80(%rbp), %rax
addl %r12d, %eax
movq %rax, -0x80(%rbp)
movq -0xc0(%rbp), %rax
addq %rax, -0xa8(%rbp)
movq -0x48(%rbp), %rax
addq %rax, -0x38(%rbp)
addq %rax, -0x30(%rbp)
movq -0x78(%rbp), %r15
jmp 0x24b2
leaq -0x1(%rbx), %rax
imulq %rbx, %rax
leaq (%r15,%rax,4), %r15
movq -0x48(%rbp), %rax
negq %rax
movq %rax, -0x58(%rbp)
movq %rbx, %rax
testq %rax, %rax
jle 0x278f
decq %rax
leaq (%rdi,%rax,4), %rcx
movq %rcx, -0x30(%rbp)
movq -0x78(%rbp), %r13
xorl %ecx, %ecx
movq %rax, -0x38(%rbp)
cmpq %rax, %rcx
jge 0x2782
movq %rcx, -0x60(%rbp)
movq %rcx, %rax
imulq %rbx, %rax
movq -0x30(%rbp), %rcx
movl (%rcx,%rax,4), %r12d
testl %r12d, %r12d
je 0x276a
movq -0x30(%rbp), %rcx
andl $0x0, (%rcx,%rax,4)
xorl %ebx, %ebx
cmpq %rbx, %r14
je 0x276a
movl (%r15,%rbx,4), %edx
movq -0x70(%rbp), %rdi
movl %r12d, %esi
callq 0x2054
xorl %eax, (%r13,%rbx,4)
incq %rbx
jmp 0x274b
movq -0x60(%rbp), %rcx
incq %rcx
addq -0x48(%rbp), %r13
movq -0x90(%rbp), %rbx
movq -0x38(%rbp), %rax
jmp 0x2724
addq -0x58(%rbp), %r15
movq -0x50(%rbp), %rdi
jmp 0x2706
callq 0x10d0
movq -0x78(%rbp), %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb43(%rip), %rdi       # 0x32f4
callq 0x1120
pushq $0x1
popq %rdi
callq 0x10e0