// File: /workspace/github_cpp_makefile_star2_O3/koraa[P]sbcrack/cube/crypto.cpp
// Function: gfield::invert(gfield const&)
bool invert(const gfield &x)
    {
        if(!x.len) return false;
        gfint u(x), v(P), A((gfint::digit)1), C((gfint::digit)0);
        while(!u.iszero())
        {
            int ushift = 0, ashift = 0;
            while(!u.hasbit(ushift))
            {
                ushift++;
                if(A.hasbit(ashift))
                {
                    if(ashift) { A.rshift(ashift); ashift = 0; }
                    A.add(P);
                }
                ashift++;
            }
            if(ushift) u.rshift(ushift);
            if(ashift) A.rshift(ashift);
            int vshift = 0, cshift = 0;
            while(!v.hasbit(vshift))
            {
                vshift++;
                if(C.hasbit(cshift))
                {
                    if(cshift) { C.rshift(cshift); cshift = 0; }
                    C.add(P);
                }
                cshift++;
            }
            if(vshift) v.rshift(vshift);
            if(cshift) C.rshift(cshift);
            if(u >= v)
            {
                u.sub(v);
                if(A < C) A.add(P);
                A.sub(C);
            }
            else
            {
                v.sub(v, u);
                if(C < A) C.add(P);
                C.sub(A);
            }
        }
        if(C >= P) gfint::sub(C, P);
        else { len = C.len; memcpy(digits, C.digits, len*sizeof(digit)); }
        ASSERT(*this < P);
        return true;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl (%rsi), %ebx
testl %ebx, %ebx
je 0x2890
movups (%rsi), %xmm0
movups 0x10(%rsi), %xmm1
movaps %xmm1, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movups 0x8ba5(%rip), %xmm0     # 0xb134
movaps %xmm0, 0x90(%rsp)
movups 0x8b86(%rip), %xmm0     # 0xb124
movaps %xmm0, 0x80(%rsp)
movw $0x1, 0x5c(%rsp)
movl $0x1, 0x58(%rsp)
movl $0x0, 0x10(%rsp)
movl 0x30(%rsp), %eax
testl %eax, %eax
je 0x2834
movq %rdi, 0x78(%rsp)
movl %ebx, 0xc(%rsp)
xorl %ebx, %ebx
leaq 0x80(%rsp), %r14
leaq 0x8b41(%rip), %r12      # 0xb124
leaq 0x10(%rsp), %r13
leaq 0x58(%rsp), %rbp
xorl %r15d, %r15d
movl %ebx, %ecx
shrl $0x4, %ecx
cmpl %eax, %ecx
jge 0x26b4
movl %ecx, %ecx
movzwl 0x34(%rsp,%rcx,2), %ecx
movl %ebx, %edx
andl $0xf, %edx
btl %edx, %ecx
jae 0x26b4
testl %ebx, %ebx
je 0x2625
leaq 0x30(%rsp), %rdi
movq %rdi, %rsi
movl %ebx, %edx
callq 0x296e
testl %r15d, %r15d
je 0x2638
movq %rbp, %rdi
movq %rbp, %rsi
movl %r15d, %edx
callq 0x296e
xorl %ebx, %ebx
xorl %r15d, %r15d
movl %ebx, %eax
shrl $0x4, %eax
cmpl 0x80(%rsp), %eax
jge 0x2663
movl %eax, %eax
movzwl 0x84(%rsp,%rax,2), %eax
movl %ebx, %ecx
andl $0xf, %ecx
btl %ecx, %eax
jb 0x270d
leal 0xf(%r15), %eax
testl %r15d, %r15d
cmovnsl %r15d, %eax
sarl $0x4, %eax
cmpl 0x10(%rsp), %eax
jge 0x26ad
cltq
movzwl 0x14(%rsp,%rax,2), %eax
movl %r15d, %ecx
andl $0xf, %ecx
btl %ecx, %eax
jae 0x26ad
testl %r15d, %r15d
je 0x269c
movq %r13, %rdi
movq %r13, %rsi
movl %r15d, %edx
callq 0x296e
movq %r13, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x2a6e
xorl %r15d, %r15d
incl %r15d
incl %ebx
jmp 0x263d
leal 0xf(%r15), %ecx
testl %r15d, %r15d
cmovnsl %r15d, %ecx
sarl $0x4, %ecx
cmpl 0x58(%rsp), %ecx
jge 0x2703
movslq %ecx, %rcx
movzwl 0x5c(%rsp,%rcx,2), %ecx
movl %r15d, %edx
andl $0xf, %edx
btl %edx, %ecx
jae 0x2703
testl %r15d, %r15d
je 0x26ee
movq %rbp, %rdi
movq %rbp, %rsi
movl %r15d, %edx
callq 0x296e
movq %rbp, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x2a6e
xorl %r15d, %r15d
movl 0x30(%rsp), %eax
incl %ebx
incl %r15d
jmp 0x25f0
testl %ebx, %ebx
je 0x271e
movq %r14, %rdi
movq %r14, %rsi
movl %ebx, %edx
callq 0x296e
testl %r15d, %r15d
je 0x2731
movq %r13, %rdi
movq %r13, %rsi
movl %r15d, %edx
callq 0x296e
movl 0x30(%rsp), %eax
movl 0x80(%rsp), %ecx
cmpl %ecx, %eax
jge 0x276c
movq %r14, %rdi
movq %r14, %rsi
leaq 0x30(%rsp), %rdx
callq 0x28a8
movl 0x10(%rsp), %eax
movl 0x58(%rsp), %ecx
cmpl %ecx, %eax
jge 0x27ba
movq %r13, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x2a6e
jmp 0x27d9
cmpl %ecx, %eax
jg 0x278e
testl %eax, %eax
jle 0x278e
movzwl 0x32(%rsp,%rax,2), %ecx
movzwl 0x82(%rsp,%rax,2), %edx
cmpw %dx, %cx
jb 0x2740
decq %rax
cmpw %dx, %cx
jbe 0x2770
leaq 0x30(%rsp), %rdi
movq %rdi, %rsi
movq %r14, %rdx
callq 0x28a8
movl 0x58(%rsp), %eax
movl 0x10(%rsp), %ecx
cmpl %ecx, %eax
jge 0x27e4
movq %rbp, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x2a6e
jmp 0x2803
cmpl %ecx, %eax
jg 0x27d9
testl %eax, %eax
jle 0x27d9
movzwl 0x12(%rsp,%rax,2), %ecx
movzwl 0x5a(%rsp,%rax,2), %edx
cmpw %dx, %cx
jb 0x275c
decq %rax
cmpw %dx, %cx
jbe 0x27be
movq %r13, %rdi
movq %r13, %rsi
movq %rbp, %rdx
jmp 0x280c
cmpl %ecx, %eax
jg 0x2803
testl %eax, %eax
jle 0x2803
movzwl 0x5a(%rsp,%rax,2), %ecx
movzwl 0x12(%rsp,%rax,2), %edx
cmpw %dx, %cx
jb 0x27aa
decq %rax
cmpw %dx, %cx
jbe 0x27e8
movq %rbp, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x28a8
movl 0x30(%rsp), %eax
xorl %ebx, %ebx
movl $0x0, %r15d
testl %eax, %eax
jne 0x25f0
movl 0x10(%rsp), %eax
movl 0xc(%rsp), %ebx
movq 0x78(%rsp), %rdi
jmp 0x2836
xorl %eax, %eax
cmpl 0x88e8(%rip), %eax      # 0xb124
jge 0x2856
movl %eax, (%rdi)
addq $0x4, %rdi
leaq 0x14(%rsp), %rsi
movslq %eax, %rdx
addq %rdx, %rdx
callq 0x10a0
jmp 0x2890
jg 0x287f
movl %eax, %ecx
leaq 0x88c3(%rip), %rdx      # 0xb124
testl %ecx, %ecx
jle 0x287f
movzwl 0x12(%rsp,%rcx,2), %esi
movzwl 0x2(%rdx,%rcx,2), %r8d
cmpw %r8w, %si
jb 0x283e
decq %rcx
cmpw %r8w, %si
jbe 0x2861
leaq 0x889e(%rip), %rdx      # 0xb124
leaq 0x10(%rsp), %rsi
callq 0x28a8
testl %ebx, %ebx
setne %al
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop