// File: /workspace/github_c_makefile_star2_O0/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
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
addq $0x16, %rax
movq %rax, -0xd0(%rbp)
movl $0x21, -0xac(%rbp)
movq -0x10(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
leaq -0xac(%rbp), %rdx
callq 0xccb0
cmpl $0x6, -0xac(%rbp)
jg 0xc9c8
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xcc98
leaq -0xa0(%rbp), %rdi
movl -0xac(%rbp), %esi
callq 0xce90
movl %eax, -0xb0(%rbp)
cmpl $0x0, -0xb0(%rbp)
je 0xc9f5
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0xcc98
movl -0xac(%rbp), %eax
subl $0x7, %eax
imull $0xa, %eax, %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl %edx, -0xb8(%rbp)
movl -0xac(%rbp), %eax
subl $0x7, %eax
imull $0xa, %eax, %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl %eax, -0xbc(%rbp)
cmpl $0x20, -0xbc(%rbp)
jle 0xca3e
movl $0xfffffffd, -0x4(%rbp) # imm = 0xFFFFFFFD
jmp 0xcc98
movl -0xa0(%rbp), %eax
shll $0x5, %eax
movl -0x9c(%rbp), %ecx
shrl $0x5, %ecx
orl %ecx, %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, (%rax)
movl -0x9c(%rbp), %eax
andl $0x1f, %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0x2(%rax)
movl -0x98(%rbp), %eax
shrl $0x6, %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0x4(%rax)
movl -0x98(%rbp), %eax
shrl $0x2, %eax
andl $0xf, %eax
addl $0x1, %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0x6(%rax)
movl -0x98(%rbp), %eax
andl $0x3, %eax
shll $0x8, %eax
movl -0x94(%rbp), %ecx
shrl $0x8, %ecx
andl $0x3, %ecx
orl %ecx, %eax
addl $0x1, %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0x8(%rax)
movl -0x94(%rbp), %eax
shrl $0x4, %eax
andl $0xf, %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0xa(%rax)
movl -0x94(%rbp), %eax
andl $0xf, %eax
addl $0x1, %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0xc(%rax)
movl $0x4, -0xa8(%rbp)
cmpl $0x0, -0xb8(%rbp)
je 0xcb78
movl $0xa, %eax
subl -0xb8(%rbp), %eax
movl %eax, -0xc4(%rbp)
movslq -0xa8(%rbp), %rax
movl -0xa0(%rbp,%rax,4), %eax
movl -0xc4(%rbp), %ecx
shrl %cl, %eax
cmpl $0x0, %eax
je 0xcb3f
movl $0xfffffffb, -0x4(%rbp) # imm = 0xFFFFFFFB
jmp 0xcc98
movl -0xa8(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0xa8(%rbp)
cltq
movl -0xa0(%rbp,%rax,4), %eax
movl -0xc4(%rbp), %ecx
addl $0x1, %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
subl $0x1, %ecx
andl %ecx, %eax
movl %eax, -0xc0(%rbp)
jmp 0xcb8c
movl $0x0, -0xc0(%rbp)
movl $0x0, -0xc4(%rbp)
movl $0x0, -0xb4(%rbp)
movl -0xa8(%rbp), %eax
movl -0xac(%rbp), %ecx
subl $0x3, %ecx
cmpl %ecx, %eax
jge 0xcc80
movl -0xc0(%rbp), %eax
shll $0xa, %eax
movl -0xa8(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0xa8(%rbp)
movslq %ecx, %rcx
orl -0xa0(%rbp,%rcx,4), %eax
movl %eax, -0xc0(%rbp)
movl -0xc4(%rbp), %eax
addl $0xa, %eax
movl %eax, -0xc4(%rbp)
cmpl $0x8, -0xc4(%rbp)
jb 0xcc7b
movl -0xc0(%rbp), %eax
movl -0xc4(%rbp), %ecx
subl $0x8, %ecx
shrl %cl, %eax
andl $0xff, %eax
movb %al, %cl
movq -0xd0(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0xd0(%rbp)
movb %cl, (%rax)
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
cmpl $0x20, -0xb4(%rbp)
jle 0xcc43
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
jmp 0xcc98
movl -0xc4(%rbp), %eax
subl $0x8, %eax
movl %eax, -0xc4(%rbp)
movl -0xc0(%rbp), %eax
movl -0xc4(%rbp), %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
subq $0x1, %rcx
andq %rcx, %rax
movl %eax, -0xc0(%rbp)
jmp 0xcbe6
jmp 0xcb96
movl -0xbc(%rbp), %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0x14(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)