// File: /workspace/github_c_makefile_star2_O1/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, %r13
movl $0x21, %ebx
testq %rdi, %rdi
je 0xabe2
movq %rdi, %r15
xorl %eax, %eax
movq %rdi, %rcx
movzbl (%rcx), %edx
cmpl $0x20, %edx
je 0xab17
testl %edx, %edx
jne 0xab19
jmp 0xab1e
incl %eax
incq %rcx
jmp 0xab09
cmpl $0x20, %eax
jg 0xabe2
cmpb $0x0, (%r15)
je 0xabd5
xorl %esi, %esi
leaq 0x192d(%rip), %rdi      # 0xc467
leaq -0x60(%rbp), %r12
leaq 0x92ab(%rip), %rbx      # 0x13df0
xorl %r14d, %r14d
movslq %r14d, %rcx
addq %r15, %rcx
xorl %eax, %eax
movzbl (%rcx,%rax), %edx
testb $-0x21, %dl
je 0xab68
cmpq $0xb, %rax
je 0xabdd
movb %dl, -0x60(%rbp,%rax)
incq %rax
jmp 0xab50
movq %rsi, -0x40(%rbp)
movq %r13, -0x30(%rbp)
movl %r14d, %r14d
cmpb $0x1, %dl
sbbq $-0x1, %r14
movb $0x0, -0x60(%rbp,%rax)
addq %rax, %r14
xorl %r13d, %r13d
movq %rdi, %rsi
movq %r12, %rdi
callq 0x8070
testl %eax, %eax
je 0xaba3
movq 0x8(%rbx,%r13,8), %rsi
incq %r13
testq %rsi, %rsi
jne 0xab88
jmp 0xabd9
movq -0x40(%rbp), %rsi
cmpq $0x21, %rsi
je 0xabd9
movl %r13d, -0xf0(%rbp,%rsi,4)
incq %rsi
movslq %r14d, %rax
cmpb $0x0, (%r15,%rax)
movq -0x30(%rbp), %r13
leaq 0x189c(%rip), %rdi      # 0xc467
jne 0xab48
movl %esi, %ebx
jmp 0xabe2
xorl %ebx, %ebx
jmp 0xabe2
movq -0x30(%rbp), %r13
movl $0x21, %ebx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $0x7, %ebx
jl 0xadef
leaq 0x16(%r13), %r12
movl $0x1, -0x34(%rbp)
xorl %eax, %eax
leaq 0x185c(%rip), %rcx      # 0xc460
movsbl (%rax,%rcx), %edx
movl %edx, -0x60(%rbp,%rax,4)
incq %rax
cmpq $0x6, %rax
jne 0xac04
leaq -0x60(%rbp), %rcx
xorl %edx, %edx
movl $0x1, %eax
leaq 0x3289(%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 0xac45
xorl (%r8), %eax
incq %r9
addq $0x4, %r8
cmpq $0xa, %r9
jne 0xac3c
addq $0x4, %rcx
incl %edx
cmpl $0x6, %edx
jne 0xac27
leaq -0x34(%rbp), %r15
movl %eax, (%r15)
leaq -0xf0(%rbp), %rsi
movq %r15, %rdi
movl %ebx, %edx
callq 0xb59c
cmpl $0x1, (%r15)
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
jne 0xadef
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 $0x107, %edx            # imm = 0x107
jg 0xadef
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, (%r13)
andl $0x1f, %ecx
movw %cx, 0x2(%r13)
movl -0xe8(%rbp), %eax
movl %eax, %ecx
shrl $0x6, %ecx
movw %cx, 0x4(%r13)
movl %eax, %ecx
shrl $0x2, %ecx
andl $0xf, %ecx
incl %ecx
movw %cx, 0x6(%r13)
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(%r13)
movl %ecx, %eax
shrl $0x4, %eax
andl $0xf, %eax
movw %ax, 0xa(%r13)
andl $0xf, %ecx
incl %ecx
movw %cx, 0xc(%r13)
testl %edx, %edx
je 0xad65
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 0xadef
movb $0xb, %cl
subb %dl, %cl
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
shll %cl, %eax
notl %eax
andl %eax, %r8d
movl $0x5, %eax
jmp 0xad6f
xorl %r8d, %r8d
movl $0x4, %eax
xorl %esi, %esi
addl $-0x3, %ebx
cmpl %ebx, %eax
jge 0xadde
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 0xadea
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 0xada6
cmpq %r9, %rax
jne 0xad7e
sarl $0x3, %edi
movw %di, 0x14(%r13)
xorl %eax, %eax
jmp 0xadef
movl $0xfffffffc, %eax       # imm = 0xFFFFFFFC
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq