// File: /workspace/github_c_makefile_star2_O3/Seclabs-htc[P]slip39/gf256.c
// Function: shamir_interpolate
bool shamir_interpolate(uint8_t *result, uint8_t x,
                        const uint8_t *share_indices,
                        const uint8_t **share_values, uint8_t share_count,
                        size_t len)
{
    size_t i, j;

    if (len > SHAMIR_MAX_LEN)
        return false;

    for (i = 0; i < share_count; i++)
        for (j = 0; j < share_count; j++)
            if ((i != j) && (share_indices[i] == share_indices[j]))
                return false;

    for (i = 0; i < share_count; i++)
        if (x == share_indices[i])
        {
            memcpy(result, share_values[i], len);
            return true;
        }

    memzero(result, len);
    for (i = 0; i < share_count; i++)
    {
        uint8_t t;
        uint32_t d;

        d = 0;
        for (j = 0; j < share_count; j++)
        if (i != j)
        {
            d += LOG_TABLE[x ^ share_indices[j]];
            d += 255 - LOG_TABLE[share_indices[i] ^ share_indices[j]];
            d %= 255;
        }

        for (j = 0; j < len; j++)
        {
            t = share_values[i][j];
            result[j] ^= t ? EXP_TABLE[(LOG_TABLE[t] + d) % 255] : 0;
        }
    }

    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, -0x38(%rbp)
movl %esi, -0x2c(%rbp)
cmpq $0x20, %r9
jbe 0xb635
xorl %eax, %eax
jmp 0xb77f
movq %r9, %rbx
movl %r8d, %r13d
movq %rdi, %r14
testb %r13b, %r13b
je 0xb772
movq %rdx, %r12
movzbl %r13b, %r15d
xorl %eax, %eax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0xb661
movb (%r12,%rax), %dl
cmpb (%r12,%rcx), %dl
je 0xb62e
incq %rcx
cmpq %rcx, %r15
jne 0xb652
incq %rax
cmpq %r15, %rax
jne 0xb650
testb %r13b, %r13b
je 0xb772
xorl %eax, %eax
movl -0x2c(%rbp), %ecx
cmpb %cl, (%r12,%rax)
je 0xb78e
incq %rax
cmpq %rax, %r15
jne 0xb67f
movq %r14, %rdi
movq %rbx, %rsi
callq 0x81bc
movb $0x1, %al
testb %r13b, %r13b
je 0xb77f
xorl %ecx, %ecx
leaq 0x2830(%rip), %rdx      # 0xdee0
movl $0x80808081, %esi       # imm = 0x80808081
leaq 0x2924(%rip), %rdi      # 0xdfe0
xorl %r8d, %r8d
xorl %r9d, %r9d
cmpq %r9, %rcx
je 0xb70d
movb (%r12,%r9), %r10b
movl %r10d, %r11d
xorb -0x2c(%rbp), %r11b
movzbl %r11b, %r11d
movzbl (%r11,%rdx), %r11d
xorb (%r12,%rcx), %r10b
addl %r11d, %r8d
movzbl %r10b, %r10d
movzbl (%r10,%rdx), %r10d
xorl $0xff, %r10d
addl %r8d, %r10d
movq %r10, %r8
imulq %rsi, %r8
shrq $0x27, %r8
movl %r8d, %r11d
shll $0x8, %r11d
subl %r11d, %r8d
addl %r10d, %r8d
incq %r9
cmpq %r9, %r15
jne 0xb6c2
testq %rbx, %rbx
je 0xb764
xorl %r9d, %r9d
movq -0x38(%rbp), %r10
movq (%r10,%rcx,8), %r10
movzbl (%r10,%r9), %r10d
testq %r10, %r10
je 0xb755
movzbl (%r10,%rdx), %r10d
addl %r8d, %r10d
movq %r10, %r11
imulq %rsi, %r11
shrq $0x27, %r11
movl %r11d, %r13d
shll $0x8, %r13d
subl %r13d, %r11d
addl %r10d, %r11d
movb (%r11,%rdi), %r10b
jmp 0xb758
xorl %r10d, %r10d
xorb %r10b, (%r14,%r9)
incq %r9
cmpq %r9, %rbx
jne 0xb71d
incq %rcx
cmpq %r15, %rcx
jne 0xb6bc
jmp 0xb77f
movq %r14, %rdi
movq %rbx, %rsi
callq 0x81bc
movb $0x1, %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x38(%rbp), %rcx
movq (%rcx,%rax,8), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x8080
jmp 0xb77d
nop