// File: /workspace/github_c_makefile_star2_O0/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
subq $0x90, %rsp
movb %sil, %al
movb %dil, %sil
movb %sil, -0x5(%rbp)
movb %al, -0x6(%rbp)
movq %rdx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movq %r8, -0x20(%rbp)
movzbl -0x5(%rbp), %edx
movl %edx, %eax
movq %rsp, %rcx
movq %rcx, -0x30(%rbp)
movl %edx, %ecx
leal 0xf(,%rcx,8), %ecx
andl $-0x10, %ecx
movl %ecx, %edx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x90(%rbp)
movq %rcx, %rsp
movq %rax, -0x38(%rbp)
movl -0x14(%rbp), %eax
movzbl -0x5(%rbp), %ecx
imull %ecx, %eax
movq %rax, %rdx
addq $0xf, %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x88(%rbp)
movq %rcx, %rsp
movq %rax, -0x40(%rbp)
movzbl -0x5(%rbp), %ecx
movl %ecx, %eax
addl $0xf, %ecx
andl $-0x10, %ecx
movl %ecx, %edx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x80(%rbp)
movq %rcx, %rsp
movq %rax, -0x48(%rbp)
movzbl -0x5(%rbp), %eax
cmpl $0x1, %eax
jge 0xc2f6
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x78(%rbp)
jmp 0xc545
movzbl -0x5(%rbp), %eax
movzbl -0x6(%rbp), %ecx
cmpl %ecx, %eax
jle 0xc315
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
movl $0x1, -0x78(%rbp)
jmp 0xc545
movzbl -0x6(%rbp), %eax
cmpl $0x10, %eax
jle 0xc331
movl $0xfffffffd, -0x4(%rbp) # imm = 0xFFFFFFFD
movl $0x1, -0x78(%rbp)
jmp 0xc545
cmpl $0x0, -0x14(%rbp)
jne 0xc34a
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
movl $0x1, -0x78(%rbp)
jmp 0xc545
movzbl -0x5(%rbp), %eax
cmpl $0x1, %eax
jne 0xc37e
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movslq -0x14(%rbp), %rsi
movq -0x10(%rbp), %rdx
movslq -0x14(%rbp), %rcx
callq 0xe330
movl $0x0, -0x4(%rbp)
movl $0x1, -0x78(%rbp)
jmp 0xc545
movl $0x0, -0x74(%rbp)
movl -0x74(%rbp), %eax
movzbl -0x5(%rbp), %ecx
cmpl %ecx, %eax
jge 0xc3be
movq -0x90(%rbp), %rax
movq -0x88(%rbp), %rdx
movl -0x74(%rbp), %ecx
imull -0x14(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rdx
movslq -0x74(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0xc385
movzbl -0x5(%rbp), %eax
subl $0x2, %eax
movb %al, -0x21(%rbp)
movl $0x0, -0x74(%rbp)
movl -0x74(%rbp), %eax
movzbl -0x21(%rbp), %ecx
cmpl %ecx, %eax
jge 0xc40f
movq -0x90(%rbp), %rax
movq -0x80(%rbp), %rcx
movl -0x74(%rbp), %edx
movb %dl, %sil
movslq -0x74(%rbp), %rdx
movb %sil, (%rcx,%rdx)
movslq -0x74(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movslq -0x14(%rbp), %rsi
callq 0xb7c0
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0xc3cf
movq -0x90(%rbp), %rax
movzbl -0x5(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
movq -0x10(%rbp), %rsi
movslq -0x14(%rbp), %rdx
callq 0x8090
movq -0x90(%rbp), %rax
movq -0x80(%rbp), %rcx
movzbl -0x5(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
movb $-0x1, (%rcx,%rdx)
movzbl -0x5(%rbp), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
addq $0x4, %rdi
movl -0x14(%rbp), %eax
subl $0x4, %eax
movslq %eax, %rsi
callq 0xb7c0
movq -0x90(%rbp), %rax
movzbl -0x5(%rbp), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
addq $0x4, %rdi
movl -0x14(%rbp), %esi
subl $0x4, %esi
movq -0x10(%rbp), %rdx
movl -0x14(%rbp), %ecx
leaq -0x70(%rbp), %r8
callq 0xb190
movq -0x90(%rbp), %rcx
movq -0x80(%rbp), %rax
movzbl -0x5(%rbp), %edx
subl $0x2, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movl -0x70(%rbp), %edx
movl %edx, (%rcx)
movzbl -0x5(%rbp), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movb $-0x2, (%rax,%rcx)
movl $0x0, -0x74(%rbp)
movl -0x74(%rbp), %eax
movzbl -0x6(%rbp), %ecx
cmpl %ecx, %eax
jge 0xc537
movq -0x90(%rbp), %rcx
movq -0x80(%rbp), %rdx
movq -0x20(%rbp), %rax
movslq -0x74(%rbp), %rsi
movq (%rax,%rsi,8), %rdi
movl -0x74(%rbp), %eax
movb %al, %sil
movb -0x5(%rbp), %al
movslq -0x14(%rbp), %r9
movzbl %sil, %esi
movzbl %al, %r8d
callq 0xdd20
testb $0x1, %al
jne 0xc52a
leaq 0x2f71(%rip), %rdi      # 0xf484
movb $0x0, %al
callq 0x8050
movl $0xfffffffb, -0x4(%rbp) # imm = 0xFFFFFFFB
movl $0x1, -0x78(%rbp)
jmp 0xc545
jmp 0xc52c
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0xc4cc
movl $0x0, -0x4(%rbp)
movl $0x1, -0x78(%rbp)
movq -0x30(%rbp), %rax
movq %rax, %rsp
movl -0x4(%rbp), %eax
movq %rbp, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)