// File: /workspace/github_c_makefile_star2_O3/Seclabs-htc[P]slip39/slip39.c
// Function: decode_mnemonic
int decode_mnemonic(char *ml, group_shares *gs)
{
    uint32_t words[33];
    int i, j, wc, r, vc;
    int padding, msl;
    uint32_t p, bits;
    uint8_t *v = gs->s;

    wc = 33;
    mnemonic_to_indices(ml, words, &wc);

    if (wc <= 6)
        return -1;

    r = rs1024_verify_checksum(words, wc);
    if (r != 0)
        return -2;

    padding = (wc - 7) * 10 % 8;
    msl = (wc - 7) * 10 / 8;

    if (msl > 32)
        return -3;

    gs->id = words[0] << 5 | words[1] >> 5;
    gs->ie = words[1] & 0x1f;
    gs->gi = words[2] >> 6;
    gs->gt = ((words[2] >> 2) & 0xf) + 1;
    gs->gc = ((words[2] & 0x3) << 8 | (words[3] >> 8) & 0x3) + 1;
    gs->mi = (words[3] >> 4) & 0xf;
    gs->mt = (words[3] & 0xf) + 1;

    j = 4;
    if (padding)
    {
        bits = 10 - padding;
        // padding should be zero
        if( (words[j] >> bits) != 0)
            return -5;
        p = words[j++] & ((1<<(bits+1))-1);
    }
    else
    {
        p = 0;
        bits = 0;
    }

    vc = 0;
    while(j < wc - 3)
    {
        p = p << 10 | words[j++];
        bits += 10;

        while(bits >= 8)
        {
            *v++ = (p >> (bits - 8)) & 0xFF;
            vc++;
            if (vc > 32)
                return -4;
            bits -= 8;
            p = p & ((0x1UL << bits) - 1);
        }
    }
    gs->sl = msl;

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rsi, -0x38(%rbp)
testq %rdi, %rdi
je 0xab23
movq %rdi, %r15
xorl %eax, %eax
movq %rdi, %rcx
movzbl (%rcx), %edx
cmpl $0x20, %edx
je 0xab13
testl %edx, %edx
jne 0xab15
jmp 0xab1a
incl %eax
incq %rcx
jmp 0xab05
cmpl $0x20, %eax
jle 0xac9d
movl $0x21, %ebx
movq -0x38(%rbp), %r14
leaq 0x16(%r14), %r12
xorl %eax, %eax
leaq 0x1927(%rip), %rcx      # 0xc460
movsbl (%rax,%rcx), %edx
movl %edx, -0x60(%rbp,%rax,4)
incq %rax
cmpq $0x6, %rax
jne 0xab39
leaq -0x60(%rbp), %rcx
xorl %edx, %edx
movl $0x1, %eax
leaq 0x3354(%rip), %rsi      # 0xdeb0
movl %eax, %edi
shrl $0x14, %edi
shll $0xa, %eax
andl $0x3ffffc00, %eax       # imm = 0x3FFFFC00
xorl (%rcx), %eax
movq %rsi, %r8
xorl %r9d, %r9d
btl %r9d, %edi
jae 0xab7a
xorl (%r8), %eax
incq %r9
addq $0x4, %r8
cmpq $0xa, %r9
jne 0xab71
addq $0x4, %rcx
incl %edx
cmpl $0x6, %edx
jne 0xab5c
leaq -0x3c(%rbp), %r15
movl %eax, (%r15)
leaq -0xf0(%rbp), %rsi
movq %r15, %rdi
movl %ebx, %edx
callq 0xb5c0
cmpl $0x1, (%r15)
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
jne 0xadf4
leal (%rbx,%rbx), %eax
leal (%rax,%rax,4), %edx
addl $-0x46, %edx
leal (%rax,%rax,4), %edi
addl $-0x3f, %edi
testl %edx, %edx
cmovnsl %edx, %edi
movl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
cmpl $0x21, %ebx
ja 0xadf4
movl %edi, %eax
andl $-0x8, %eax
subl %eax, %edx
movl -0xf0(%rbp), %eax
movl -0xec(%rbp), %ecx
shll $0x5, %eax
movl %ecx, %esi
shrl $0x5, %esi
orl %eax, %esi
movw %si, (%r14)
andl $0x1f, %ecx
movw %cx, 0x2(%r14)
movl -0xe8(%rbp), %eax
movl %eax, %ecx
shrl $0x6, %ecx
movw %cx, 0x4(%r14)
movl %eax, %ecx
shrl $0x2, %ecx
andl $0xf, %ecx
incl %ecx
movw %cx, 0x6(%r14)
andl $0x3, %eax
shll $0x8, %eax
movl -0xe4(%rbp), %ecx
movl %ecx, %esi
shrl $0x8, %esi
andl $0x3, %esi
addl %esi, %eax
incl %eax
movw %ax, 0x8(%r14)
movl %ecx, %eax
shrl $0x4, %eax
andl $0xf, %eax
movw %ax, 0xa(%r14)
andl $0xf, %ecx
incl %ecx
movw %cx, 0xc(%r14)
testl %edx, %edx
je 0xad6a
movl $0xa, %esi
subl %edx, %esi
movl -0xe0(%rbp), %r8d
movl %r8d, %r9d
movl %esi, %ecx
shrl %cl, %r9d
movl $0xfffffffb, %eax       # imm = 0xFFFFFFFB
testl %r9d, %r9d
jne 0xadf4
movb $0xb, %cl
subb %dl, %cl
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
shll %cl, %eax
notl %eax
andl %eax, %r8d
movl $0x5, %eax
jmp 0xad74
cmpb $0x0, (%r15)
je 0xad60
movq $0x0, -0x30(%rbp)
leaq -0x60(%rbp), %r12
leaq 0x9136(%rip), %r13      # 0x13df0
xorl %ebx, %ebx
movslq %ebx, %rcx
addq %r15, %rcx
xorl %eax, %eax
movzbl (%rcx,%rax), %edx
testb $-0x21, %dl
je 0xace0
cmpq $0xb, %rax
je 0xab23
movb %dl, -0x60(%rbp,%rax)
incq %rax
jmp 0xacc4
movl %ebx, %ebx
cmpb $0x1, %dl
sbbq $-0x1, %rbx
movb $0x0, -0x60(%rbp,%rax)
addq %rax, %rbx
xorl %r14d, %r14d
leaq 0x176c(%rip), %rsi      # 0xc467
movq %r12, %rdi
callq 0x8070
testl %eax, %eax
je 0xad19
movq 0x8(%r13,%r14,8), %rsi
incq %r14
testq %rsi, %rsi
jne 0xacfb
jmp 0xab23
cmpq $0x21, -0x30(%rbp)
je 0xab23
movq -0x30(%rbp), %rax
movl %r14d, -0xf0(%rbp,%rax,4)
incq %rax
movq %rax, -0x30(%rbp)
movslq %ebx, %rax
cmpb $0x0, (%r15,%rax)
jne 0xacbc
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq -0x30(%rbp), %rbx
cmpl $0x7, %ebx
movq -0x38(%rbp), %r14
jge 0xab2c
jmp 0xadf4
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0xadf4
xorl %r8d, %r8d
movl $0x4, %eax
xorl %esi, %esi
addl $-0x3, %ebx
cmpl %ebx, %eax
jge 0xade3
movl %eax, %eax
movl %ebx, %r9d
xorl %r10d, %r10d
shll $0xa, %r8d
orl -0xf0(%rbp,%rax,4), %r8d
incq %rax
cmpl $0x21, %r10d
movl $0x20, %r11d
cmovgel %r10d, %r11d
leal 0xa(%rsi), %ecx
addl $0x2, %esi
movq %rsi, %rdx
movl %ecx, %esi
addl $-0x8, %esi
movl %r8d, %ebx
movl %esi, %ecx
shrl %cl, %ebx
movb %bl, (%r12)
cmpl %r10d, %r11d
je 0xadef
incl %r10d
incq %r12
movq $-0x1, %rbx
movl %edx, %ecx
shlq %cl, %rbx
notl %ebx
andl %ebx, %r8d
addq $-0x8, %rdx
cmpl $0x7, %esi
ja 0xadab
cmpq %r9, %rax
jne 0xad83
sarl $0x3, %edi
movw %di, 0x14(%r14)
xorl %eax, %eax
jmp 0xadf4
movl $0xfffffffc, %eax       # imm = 0xFFFFFFFC
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq