// File: /workspace/github_c_makefile_star2_O0/Seclabs-htc[P]slip39/slip39.c
// Function: encode_mnemonic
static int encode_mnemonic(uint16_t id, uint16_t ie, uint16_t gi, uint16_t gt, uint16_t gc,
                uint16_t mi, uint16_t mt, uint8_t *v, int vl, char *o, uint32_t ol)
{
    int i, ms = 33; // max words
    uint32_t words[ms];
    int vc, bits, w;
    uint32_t p;

    if ((vl == 0) || (vl > 32))
        return -1;

    memzero(words, sizeof(words));
    w = 0;
    words[w++] = id >> 5 & 0xFFFFF;                                                   // id(10)
    words[w++] = ((id & 0x1F) << 5) | (ie & 0x1F);                                    // id(5) + ie (5)
    words[w++] = ((gi & 0xF) << 6) | (((gt-1) & 0xF) << 2) | (((gc-1) >> 2) & 0x3);   // gi(4) + gt(4) + gc(2)
    words[w++] = (((gc-1) & 0x3) << 8) | (mi & 0xF) << 4 | ((mt-1) & 0xF);            // gc(2) + mi(4) + mt(4)

    vc = (vl * 8) / 10;
    if ((vl * 8) % 10)
    {
        vc++;
        bits = 10 - ((vl * 8) % 10);
    }
    else
    {
        bits = 0;
    }

    p = 0;
    for (i = 0; i < vl; i++)
    {
        p = p << 8 | *v++;
        bits += 8;

        while(bits >= 10)
        {
            words[w++] = (p >> (bits - 10)) & 0x3FF;
            bits -= 10;
            p = p & ((0x1UL << bits) - 1);
        }
    }

    if (rs1024_create_checksum(words, w, &p) != 0)
        return -2;

    words[w++] = (p >> 20) & 0x3FF;
    words[w++] = (p >> 10) & 0x3FF;
    words[w++] = p & 0x3FF;

    // check output length
    p = 0;
    for (i = 0; i < w; i++)
        p += strlen(slip39_wordlist[words[i]]) + 1;

    if (p > ol)
        return -3;

    *o = 0;
    for (i = 0; i < w; i++)
    {
        char *s;

        s = (char *)slip39_wordlist[words[i]];
        p = strlen(s);
        memcpy(o, s, p);
        o += p;

        if (i != (w - 1))
            *o++ = ' ';
        else
            *o = 0;
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movl %r8d, -0x68(%rbp)
movl %ecx, %eax
movl -0x68(%rbp), %ecx
movl %eax, -0x64(%rbp)
movl %edx, %eax
movl -0x64(%rbp), %edx
movl %eax, -0x60(%rbp)
movl %esi, %eax
movl -0x60(%rbp), %esi
movl %eax, -0x5c(%rbp)
movl %edi, %r8d
movl -0x5c(%rbp), %edi
movw %r9w, %ax
movl 0x30(%rbp), %r9d
movq 0x28(%rbp), %r9
movl 0x20(%rbp), %r9d
movq 0x18(%rbp), %r9
movw 0x10(%rbp), %r9w
movw %r8w, -0x6(%rbp)
movw %di, -0x8(%rbp)
movw %si, -0xa(%rbp)
movw %dx, -0xc(%rbp)
movw %cx, -0xe(%rbp)
movw %ax, -0x10(%rbp)
movl $0x21, -0x18(%rbp)
movl -0x18(%rbp), %eax
movq %rax, -0x58(%rbp)
movq %rsp, %rcx
movq %rcx, -0x20(%rbp)
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x50(%rbp)
movq %rcx, %rsp
movq %rax, -0x28(%rbp)
cmpl $0x0, 0x20(%rbp)
je 0xc5fa
cmpl $0x20, 0x20(%rbp)
jle 0xc60d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x3c(%rbp)
jmp 0xc95d
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
shlq $0x2, %rsi
callq 0x81c0
movq -0x50(%rbp), %rax
movl $0x0, -0x34(%rbp)
movzwl -0x6(%rbp), %edx
sarl $0x5, %edx
andl $0xfffff, %edx          # imm = 0xFFFFF
movl -0x34(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x34(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movzwl -0x6(%rbp), %edx
andl $0x1f, %edx
shll $0x5, %edx
movzwl -0x8(%rbp), %ecx
andl $0x1f, %ecx
orl %ecx, %edx
movl -0x34(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x34(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movzwl -0xa(%rbp), %edx
andl $0xf, %edx
shll $0x6, %edx
movzwl -0xc(%rbp), %ecx
subl $0x1, %ecx
andl $0xf, %ecx
shll $0x2, %ecx
orl %ecx, %edx
movzwl -0xe(%rbp), %ecx
subl $0x1, %ecx
sarl $0x2, %ecx
andl $0x3, %ecx
orl %ecx, %edx
movl -0x34(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x34(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movzwl -0xe(%rbp), %edx
subl $0x1, %edx
andl $0x3, %edx
shll $0x8, %edx
movzwl -0x10(%rbp), %ecx
andl $0xf, %ecx
shll $0x4, %ecx
orl %ecx, %edx
movzwl 0x10(%rbp), %ecx
subl $0x1, %ecx
andl $0xf, %ecx
orl %ecx, %edx
movl -0x34(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x34(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl 0x20(%rbp), %eax
shll $0x3, %eax
movl $0xa, %ecx
cltd
idivl %ecx
movl %eax, -0x2c(%rbp)
movl 0x20(%rbp), %eax
shll $0x3, %eax
movl $0xa, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0xc721
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl 0x20(%rbp), %eax
shll $0x3, %eax
movl $0xa, %ecx
cltd
idivl %ecx
movl $0xa, %eax
subl %edx, %eax
movl %eax, -0x30(%rbp)
jmp 0xc728
movl $0x0, -0x30(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl 0x20(%rbp), %eax
jge 0xc7ca
movl -0x38(%rbp), %eax
shll $0x8, %eax
movq 0x18(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, 0x18(%rbp)
movzbl (%rcx), %ecx
orl %ecx, %eax
movl %eax, -0x38(%rbp)
movl -0x30(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x30(%rbp)
cmpl $0xa, -0x30(%rbp)
jl 0xc7ba
movq -0x50(%rbp), %rax
movl -0x38(%rbp), %edx
movl -0x30(%rbp), %ecx
subl $0xa, %ecx
shrl %cl, %edx
andl $0x3ff, %edx            # imm = 0x3FF
movl -0x34(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x34(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x30(%rbp), %eax
subl $0xa, %eax
movl %eax, -0x30(%rbp)
movl -0x38(%rbp), %eax
movl -0x30(%rbp), %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
subq $0x1, %rcx
andq %rcx, %rax
movl %eax, -0x38(%rbp)
jmp 0xc768
jmp 0xc7bc
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xc736
movq -0x50(%rbp), %rdi
movl -0x34(%rbp), %esi
leaq -0x38(%rbp), %rdx
callq 0xdb50
cmpl $0x0, %eax
je 0xc7f2
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
movl $0x1, -0x3c(%rbp)
jmp 0xc95d
movq -0x50(%rbp), %rax
movl -0x38(%rbp), %edx
shrl $0x14, %edx
andl $0x3ff, %edx            # imm = 0x3FF
movl -0x34(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x34(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x38(%rbp), %edx
shrl $0xa, %edx
andl $0x3ff, %edx            # imm = 0x3FF
movl -0x34(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x34(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x38(%rbp), %edx
andl $0x3ff, %edx            # imm = 0x3FF
movl -0x34(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x34(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0xc898
movq -0x50(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, %ecx
leaq 0x957c(%rip), %rax      # 0x15df0
movq (%rax,%rcx,8), %rdi
callq 0x8040
movq %rax, %rcx
addq $0x1, %rcx
movl -0x38(%rbp), %eax
addq %rcx, %rax
movl %eax, -0x38(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xc858
movl -0x38(%rbp), %eax
cmpl 0x30(%rbp), %eax
jbe 0xc8b3
movl $0xfffffffd, -0x4(%rbp) # imm = 0xFFFFFFFD
movl $0x1, -0x3c(%rbp)
jmp 0xc95d
movq 0x28(%rbp), %rax
movb $0x0, (%rax)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0xc94f
movq -0x50(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, %ecx
leaq 0x950f(%rip), %rax      # 0x15df0
movq (%rax,%rcx,8), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0x8040
movl %eax, -0x38(%rbp)
movq 0x28(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl -0x38(%rbp), %eax
movl %eax, %edx
callq 0x8090
movl -0x38(%rbp), %ecx
movq 0x28(%rbp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0x28(%rbp)
movl -0x14(%rbp), %eax
movl -0x34(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
je 0xc938
movq 0x28(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x28(%rbp)
movb $0x20, (%rax)
jmp 0xc93f
movq 0x28(%rbp), %rax
movb $0x0, (%rax)
jmp 0xc941
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xc8c1
movl $0x0, -0x4(%rbp)
movl $0x1, -0x3c(%rbp)
movq -0x20(%rbp), %rax
movq %rax, %rsp
movl -0x4(%rbp), %eax
movq %rbp, %rsp
popq %rbp
retq
nopl (%rax)