// File: /workspace/github_c_makefile_star2_O0/Seclabs-htc[P]slip39/slip39.c
// Function: combine_mnemonics
int combine_mnemonics(int gn, char *ml[], uint8_t *pp, int ppl, uint8_t *ms, int *msl)
{
    int i, j, k, r, ret = 0;
    group_shares *gs;
    uint16_t id, ie, gt, gc, gi, sl;
    uint8_t gm[16]; // group index member
    uint16_t gmc, gmt, mic, gmic = 0;
    uint8_t *m_share[16];
    uint8_t m_share_index[16];
    uint8_t *g_share[16];
    uint8_t g_share_index[16];
    uint8_t gsv[MAX_SAHRE_VALUE_LEN];

    gs = malloc(sizeof(group_shares) * gn);
    if (gs == NULL)
        return -1;

    for (i = 0; i < gn; i++)
    {
        r = decode_mnemonic(ml[i], &gs[i]);
        if (r != 0)
        {
            ret = -2;
            goto exit;
        }
    }

    id = gs[0].id;
    ie = gs[0].ie;
    gt = gs[0].gt;
    gc = gs[0].gc;
    sl = gs[0].sl;
    for (i = 1; i < gn; i++)
    {
        if ((id != gs[i].id) || (ie != gs[i].ie) ||
            (gt != gs[i].gt) || (gc != gs[i].gc) ||
            (sl != gs[i].sl))
        {
            ret = -3;
            goto exit;
        }
    }

    if ((sl < 16) || (sl & 1))
    {
        ret = -4;
        goto exit;
    }
    if (gt > gc)
    {
        ret = -5;
        goto exit;
    }

    memset(gm, 0, sizeof(gm));
    for (i = 0; i < gn; i++)
        gm[gs[i].gi]++;

    gmc = 0;
    for (i = 0; i < 16; i++)
        if (gm[i] != 0)
            gmc++;
    if (gmc < gt)
    {
        ret = -6;
        goto exit;
    }

    for (i = 0; i < gn; i++)
    {
        gi = gs[i].gi;
        for (j = 0; j < gn; j++)
        {
            if ((i != j) && (gi == gs[j].gi))
            {
                if (gs[i].mt != gs[j].mt)
                {
                    ret = -7;
                    goto exit;
                }
            }
        }
    }

    memset(g_share, 0, sizeof(g_share));
    memset(g_share_index, 0, sizeof(g_share_index));

    for (i = 0; i < 16; i++)
    {
        if (gm[i] != 0)
        {
            mic = 0; gmt = 0;
            for (j = 0; j < gn; j++)
            {
                if (i == gs[j].gi)
                {
                    for (k = 0; k < gn; k++)
                    {
                        if ((j != k) && (i == gs[k].gi) && (gs[j].mi == gs[k].mi))
                        {
                            ret = -8;
                            goto exit;
                        }
                    }
                    gmt = gs[j].mt;
                    m_share[mic] = gs[j].s;
                    m_share_index[mic] = gs[j].mi;
                    mic++;
                }
            }
            r = _recover_secret(gmt, sl, m_share_index, (const uint8_t **)m_share, gsv);
            if (r == 0)
            {
                g_share[gmic] = (uint8_t *)malloc(MAX_SAHRE_VALUE_LEN);
                memcpy(g_share[gmic], gsv, sl);

                g_share_index[gmic] = i;
                gmic++;
            }
            else
            {
                ret = -9;
                goto exit;
            }
            if (mic < gmt)
            {
                ret = -10;
                goto exit;
            }
        }
    }

    if ((ms == NULL) || (*msl < sl))
    {
        ret = -11;
        goto exit;
    }

    r = _recover_secret(gmic, sl, g_share_index, (const uint8_t **)g_share, gsv);
    if (r == 0)
    {
        _decrypt(gsv, sl, gsv, sl, pp, ppl, ie, id);

        memcpy(ms, gsv, sl);
        *msl = sl;
    }
    else
    {
        ret = -12;
    }

exit:

    if (gs != NULL)
        free(gs);

    for (i = 0; i < gmic; i++)
        if (g_share[i] != NULL)
            free(g_share[i]);

    return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1d0, %rsp            # imm = 0x1D0
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movl $0x0, -0x44(%rbp)
movw $0x0, -0x78(%rbp)
movslq -0x8(%rbp), %rax
imulq $0x38, %rax, %rdi
callq 0x80a0
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0xcf72
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xd560
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0xcfc3
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x50(%rbp), %rsi
movslq -0x34(%rbp), %rax
imulq $0x38, %rax, %rax
addq %rax, %rsi
callq 0xc970
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x40(%rbp)
je 0xcfb6
movl $0xfffffffe, -0x44(%rbp) # imm = 0xFFFFFFFE
jmp 0xd50b
jmp 0xcfb8
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xcf79
movq -0x50(%rbp), %rax
movw (%rax), %ax
movw %ax, -0x52(%rbp)
movq -0x50(%rbp), %rax
movw 0x2(%rax), %ax
movw %ax, -0x54(%rbp)
movq -0x50(%rbp), %rax
movw 0x6(%rax), %ax
movw %ax, -0x56(%rbp)
movq -0x50(%rbp), %rax
movw 0x8(%rax), %ax
movw %ax, -0x58(%rbp)
movq -0x50(%rbp), %rax
movw 0x14(%rax), %ax
movw %ax, -0x5c(%rbp)
movl $0x1, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0xd0b3
movzwl -0x52(%rbp), %eax
movq -0x50(%rbp), %rcx
movslq -0x34(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rcx
movzwl (%rcx), %ecx
cmpl %ecx, %eax
jne 0xd097
movzwl -0x54(%rbp), %eax
movq -0x50(%rbp), %rcx
movslq -0x34(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rcx
movzwl 0x2(%rcx), %ecx
cmpl %ecx, %eax
jne 0xd097
movzwl -0x56(%rbp), %eax
movq -0x50(%rbp), %rcx
movslq -0x34(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rcx
movzwl 0x6(%rcx), %ecx
cmpl %ecx, %eax
jne 0xd097
movzwl -0x58(%rbp), %eax
movq -0x50(%rbp), %rcx
movslq -0x34(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rcx
movzwl 0x8(%rcx), %ecx
cmpl %ecx, %eax
jne 0xd097
movzwl -0x5c(%rbp), %eax
movq -0x50(%rbp), %rcx
movslq -0x34(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rcx
movzwl 0x14(%rcx), %ecx
cmpl %ecx, %eax
je 0xd0a3
movl $0xfffffffd, -0x44(%rbp) # imm = 0xFFFFFFFD
jmp 0xd50b
jmp 0xd0a5
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xd005
movzwl -0x5c(%rbp), %eax
cmpl $0x10, %eax
jl 0xd0c8
movzwl -0x5c(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xd0d4
movl $0xfffffffc, -0x44(%rbp) # imm = 0xFFFFFFFC
jmp 0xd50b
movzwl -0x56(%rbp), %eax
movzwl -0x58(%rbp), %ecx
cmpl %ecx, %eax
jle 0xd0ec
movl $0xfffffffb, -0x44(%rbp) # imm = 0xFFFFFFFB
jmp 0xd50b
leaq -0x70(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x8060
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0xd134
movq -0x50(%rbp), %rax
movslq -0x34(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movzwl 0x4(%rax), %eax
movb -0x70(%rbp,%rax), %cl
addb $0x1, %cl
movb %cl, -0x70(%rbp,%rax)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xd103
movw $0x0, -0x72(%rbp)
movl $0x0, -0x34(%rbp)
cmpl $0x10, -0x34(%rbp)
jge 0xd16e
movslq -0x34(%rbp), %rax
movzbl -0x70(%rbp,%rax), %eax
cmpl $0x0, %eax
je 0xd161
movw -0x72(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x72(%rbp)
jmp 0xd163
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xd141
movzwl -0x72(%rbp), %eax
movzwl -0x56(%rbp), %ecx
cmpl %ecx, %eax
jge 0xd186
movl $0xfffffffa, -0x44(%rbp) # imm = 0xFFFFFFFA
jmp 0xd50b
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0xd237
movq -0x50(%rbp), %rax
movslq -0x34(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movw 0x4(%rax), %ax
movw %ax, -0x5a(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0xd227
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
je 0xd21a
movzwl -0x5a(%rbp), %eax
movq -0x50(%rbp), %rcx
movslq -0x38(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rcx
movzwl 0x4(%rcx), %ecx
cmpl %ecx, %eax
jne 0xd21a
movq -0x50(%rbp), %rax
movslq -0x34(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movzwl 0xc(%rax), %eax
movq -0x50(%rbp), %rcx
movslq -0x38(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rcx
movzwl 0xc(%rcx), %ecx
cmpl %ecx, %eax
je 0xd218
movl $0xfffffff9, -0x44(%rbp) # imm = 0xFFFFFFF9
jmp 0xd50b
jmp 0xd21a
jmp 0xd21c
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0xd1b7
jmp 0xd229
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xd18d
leaq -0x190(%rbp), %rdi
xorl %esi, %esi
movl $0x80, %edx
callq 0x8060
leaq -0x1a0(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x8060
movl $0x0, -0x34(%rbp)
cmpl $0x10, -0x34(%rbp)
jge 0xd45c
movslq -0x34(%rbp), %rax
movzbl -0x70(%rbp,%rax), %eax
cmpl $0x0, %eax
je 0xd44c
movw $0x0, -0x76(%rbp)
movw $0x0, -0x74(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0xd3a3
movl -0x34(%rbp), %eax
movq -0x50(%rbp), %rcx
movslq -0x38(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rcx
movzwl 0x4(%rcx), %ecx
cmpl %ecx, %eax
jne 0xd393
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0xd331
movl -0x38(%rbp), %eax
cmpl -0x3c(%rbp), %eax
je 0xd324
movl -0x34(%rbp), %eax
movq -0x50(%rbp), %rcx
movslq -0x3c(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rcx
movzwl 0x4(%rcx), %ecx
cmpl %ecx, %eax
jne 0xd324
movq -0x50(%rbp), %rax
movslq -0x38(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movzwl 0xa(%rax), %eax
movq -0x50(%rbp), %rcx
movslq -0x3c(%rbp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rcx
movzwl 0xa(%rcx), %ecx
cmpl %ecx, %eax
jne 0xd324
movl $0xfffffff8, -0x44(%rbp) # imm = 0xFFFFFFF8
jmp 0xd50b
jmp 0xd326
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xd2c4
movq -0x50(%rbp), %rax
movslq -0x38(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movw 0xc(%rax), %ax
movw %ax, -0x74(%rbp)
movq -0x50(%rbp), %rcx
movslq -0x38(%rbp), %rax
imulq $0x38, %rax, %rax
addq %rax, %rcx
addq $0x16, %rcx
movzwl -0x76(%rbp), %eax
movq %rcx, -0x100(%rbp,%rax,8)
movq -0x50(%rbp), %rax
movslq -0x38(%rbp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movw 0xa(%rax), %ax
movb %al, %cl
movzwl -0x76(%rbp), %eax
movb %cl, -0x110(%rbp,%rax)
movw -0x76(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x76(%rbp)
jmp 0xd395
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0xd293
movw -0x74(%rbp), %ax
movzwl -0x5c(%rbp), %esi
leaq -0x110(%rbp), %rdx
leaq -0x100(%rbp), %rcx
leaq -0x1c0(%rbp), %r8
movzbl %al, %edi
callq 0xd570
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x40(%rbp)
jne 0xd426
movl $0x20, %edi
callq 0x80a0
movq %rax, %rcx
movzwl -0x78(%rbp), %eax
movq %rcx, -0x190(%rbp,%rax,8)
movzwl -0x78(%rbp), %eax
movq -0x190(%rbp,%rax,8), %rdi
leaq -0x1c0(%rbp), %rsi
movzwl -0x5c(%rbp), %eax
movl %eax, %edx
callq 0x8090
movl -0x34(%rbp), %eax
movb %al, %cl
movzwl -0x78(%rbp), %eax
movb %cl, -0x1a0(%rbp,%rax)
movw -0x78(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x78(%rbp)
jmp 0xd432
movl $0xfffffff7, -0x44(%rbp) # imm = 0xFFFFFFF7
jmp 0xd50b
movzwl -0x76(%rbp), %eax
movzwl -0x74(%rbp), %ecx
cmpl %ecx, %eax
jge 0xd44a
movl $0xfffffff6, -0x44(%rbp) # imm = 0xFFFFFFF6
jmp 0xd50b
jmp 0xd44c
jmp 0xd44e
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xd264
cmpq $0x0, -0x28(%rbp)
je 0xd471
movq -0x30(%rbp), %rax
movl (%rax), %eax
movzwl -0x5c(%rbp), %ecx
cmpl %ecx, %eax
jge 0xd47d
movl $0xfffffff5, -0x44(%rbp) # imm = 0xFFFFFFF5
jmp 0xd50b
movw -0x78(%rbp), %ax
movzwl -0x5c(%rbp), %esi
leaq -0x1a0(%rbp), %rdx
leaq -0x190(%rbp), %rcx
leaq -0x1c0(%rbp), %r8
movzbl %al, %edi
callq 0xd570
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x40(%rbp)
jne 0xd502
leaq -0x1c0(%rbp), %rdi
movzwl -0x5c(%rbp), %esi
leaq -0x1c0(%rbp), %rdx
movzwl -0x5c(%rbp), %ecx
movq -0x18(%rbp), %r8
movl -0x1c(%rbp), %r9d
movw -0x54(%rbp), %ax
movzbl %al, %eax
movl %eax, (%rsp)
movzwl -0x52(%rbp), %eax
movl %eax, 0x8(%rsp)
callq 0xd720
movq -0x28(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
movzwl -0x5c(%rbp), %eax
movl %eax, %edx
callq 0x8090
movzwl -0x5c(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
jmp 0xd509
movl $0xfffffff4, -0x44(%rbp) # imm = 0xFFFFFFF4
jmp 0xd50b
cmpq $0x0, -0x50(%rbp)
je 0xd51b
movq -0x50(%rbp), %rdi
callq 0x8030
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movzwl -0x78(%rbp), %ecx
cmpl %ecx, %eax
jge 0xd55a
movslq -0x34(%rbp), %rax
cmpq $0x0, -0x190(%rbp,%rax,8)
je 0xd54d
movslq -0x34(%rbp), %rax
movq -0x190(%rbp,%rax,8), %rdi
callq 0x8030
jmp 0xd54f
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xd522
movl -0x44(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbp
retq
nopl (%rax)