// File: /workspace/github_c_makefile_star2_O1/Seclabs-htc[P]slip39/slip39.c
// Function: split_secret
static int _split_secret(uint8_t t, uint8_t n, uint8_t *s, int sl, uint8_t **gs)
{
    uint8_t random_share_count;
    uint8_t *base_share[t];
    uint8_t pool[sl*t];
    uint8_t bi[t];
    uint8_t hash[SHA256_DIGEST_LENGTH];
    int i;

    if (t < 1)
        return -1;
    if (t > n)
        return -2;
    if (n > MAX_SHARE_COUNT)
        return -3;
    if (sl == 0)
        return -4;

    if (t == 1)
    {
        memscpy(gs[0], sl, s, sl);
        return 0;
    }

    for (i = 0; i < t; i++)
        base_share[i] = (uint8_t *)(pool + (i * sl));

    random_share_count = t - 2;
    for (i = 0; i < random_share_count; i++)
    {
        bi[i] = i;
        random_buffer(base_share[i], sl);
    }

    // SECRET_INDEX
    memcpy(base_share[t-1], s, sl);
    bi[t-1] = SECRET_INDEX;

    // DIGEST_INDEX
    random_buffer(&base_share[t-2][DIGEST_LENGTH_BYTES], sl - DIGEST_LENGTH_BYTES);
    hmac_sha256(&base_share[t-2][DIGEST_LENGTH_BYTES], sl - DIGEST_LENGTH_BYTES, s, sl, hash);
    memcpy(base_share[t-2], hash, DIGEST_LENGTH_BYTES);
    bi[t-2] = DIGEST_INDEX;

    for (i = 0; i < n; i++)
        if (!shamir_interpolate(gs[i], i, bi, (const uint8_t **)base_share, t, sl))
        {
            printf("shamir_interpolate error\n");
            return -5;
        }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
leal 0xf(,%rdi,8), %eax
andl $-0x10, %eax
movq %rsp, %r14
subq %rax, %r14
movq %r14, %rsp
movl %edi, %r9d
imull %ecx, %r9d
addq $0xf, %r9
andq $-0x10, %r9
movq %rsp, %rax
subq %r9, %rax
movq %rax, %rsp
movq %rsp, %rbx
leal 0xf(%rdi), %r10d
andl $-0x10, %r10d
subq %r10, %rbx
movq %rbx, %rsp
leal -0x1(%rdi), %r10d
cmpb %sil, %r10b
setae %r10b
cmpb $0x11, %sil
setae %r11b
orb %r10b, %r11b
je 0xa9a1
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x1, %dil
jne 0xa9c3
movq (%r8), %rdi
movslq %ecx, %rcx
movq %rcx, %rsi
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xb916
movq %rdx, -0x30(%rbp)
movq %r8, -0x50(%rbp)
movslq %ecx, %r13
movzbl %dil, %edx
xorl %ecx, %ecx
movq %rax, (%r14,%rcx,8)
incq %rcx
addq %r13, %rax
cmpq %rcx, %rdx
jne 0xa9d4
movq %rdx, -0x40(%rbp)
movl %esi, -0x38(%rbp)
movq %rdi, -0x48(%rbp)
leal -0x2(%rdi), %eax
movl %eax, -0x34(%rbp)
andl $0xff, %eax
je 0xaa19
movl %eax, %r15d
xorl %r12d, %r12d
movb %r12b, (%rbx,%r12)
movq (%r14,%r12,8), %rdi
movq %r13, %rsi
callq 0x9fc3
incq %r12
cmpq %r12, %r15
jne 0xaa01
movq -0x48(%rbp), %r15
decl %r15d
movq (%r14,%r15,8), %rdi
movq -0x30(%rbp), %rsi
movq %r13, %rdx
callq 0x8080
movb $-0x1, (%rbx,%r15)
movl -0x34(%rbp), %r15d
movq (%r14,%r15,8), %rdi
addq $0x4, %rdi
leal -0x4(%r13), %eax
movslq %eax, %r12
movq %r12, %rsi
callq 0x9fc3
movq (%r14,%r15,8), %rdi
addq $0x4, %rdi
leaq -0x70(%rbp), %r8
movl %r12d, %esi
movq -0x30(%rbp), %rdx
movl %r13d, %ecx
movq %r8, %r12
callq 0x9bdb
movq (%r14,%r15,8), %rax
movl (%r12), %ecx
movl %ecx, (%rax)
movb $-0x2, (%rbx,%r15)
movl -0x38(%rbp), %eax
testb %al, %al
movq %rbx, %rdx
movq -0x40(%rbp), %rbx
je 0xa992
movzbl %al, %eax
movq %rax, -0x30(%rbp)
xorl %r15d, %r15d
movq -0x50(%rbp), %rax
movq (%rax,%r15,8), %rdi
movzbl %r15b, %esi
movq %rdx, %r12
movq %r14, %rcx
movl %ebx, %r8d
movq %r13, %r9
callq 0xb5ec
testb %al, %al
je 0xaacb
incq %r15
cmpq %r15, -0x30(%rbp)
movq %r12, %rdx
jne 0xaa99
jmp 0xa992
leaq 0x33b8(%rip), %rdi      # 0xde8a
callq 0x8050
jmp 0xa992