// File: /workspace/github_c_makefile_star2_O3/Seclabs-htc[P]slip39/slip39.c
// Function: generate_mnemonics
int generate_mnemonics(uint8_t gt, uint8_t gn, uint8_t *ms, int msl, uint8_t *pp, int ppl, uint8_t ie, char **ml)
{
    int i;
    uint8_t ems[msl];
    uint16_t identifier;
    uint8_t *gs[gn];
    uint8_t *gs_pool;

    if (msl == 0)
        return -1;

    // check passphrase
    for (i = 0; i < ppl; i++)
        if (!((pp[i] >= 32) && (pp[i] <= 126)))
            return -1;

    random_buffer((void *)&identifier, sizeof(identifier));

    identifier = 0x3761; // for test
    identifier &= ((1 << ID_LENGTH_BITS) - 1);

    _encrypt(ms, msl, ems, msl, pp, ppl, ie, identifier);

    printf("encrypt master secret\n");
    dumphex(ems, msl);

    gs_pool = (uint8_t *)malloc(msl * gn);
    if (gs_pool == NULL)
        return -1;

    for (i = 0; i < gn; i++)
        gs[i] = gs_pool + i * msl;

    _split_secret(gt, gn, ems, msl, gs);

    for (i = 0; i < gn; i++)
        encode_mnemonic(identifier, ie, 0, 1, 1,
                i, gt, gs[i], msl, ml[i], MNEMONIC_LIST_LEN);

    free(gs_pool);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movl %esi, %r13d
movl %ecx, %eax
movq %rsp, %r15
addq $0xf, %rax
andq $-0x10, %rax
subq %rax, %r15
movq %r15, %rsp
leal 0xf(,%r13,8), %eax
andl $-0x10, %eax
movq %rsp, %rsi
subq %rax, %rsi
movq %rsi, %rsp
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
movq %rcx, -0x48(%rbp)
testl %ecx, %ecx
je 0xa6bb
movl %r9d, %r12d
movq %r8, %r14
testl %r9d, %r9d
jle 0xa29a
movl %r12d, %eax
xorl %ecx, %ecx
movb (%r14,%rcx), %r9b
addb $-0x20, %r9b
cmpb $0x5f, %r9b
jae 0xa6bb
incq %rcx
cmpq %rcx, %rax
jne 0xa280
movl %edi, -0x38(%rbp)
movq %rsi, -0x40(%rbp)
leaq -0x2a(%rbp), %rdi
movl $0x2, %esi
movq %rdx, %rbx
callq 0x9fbb
leaq -0x2a(%rbp), %rax
movw $0x3761, (%rax)         # imm = 0x3761
subq $0x8, %rsp
movzbl 0x10(%rbp), %eax
movq %rbx, %rdi
movq -0x48(%rbp), %rcx
movl %ecx, %esi
movq %r15, %rdx
movq %r14, %r8
movl %r12d, %r9d
movq %rcx, %r14
pushq %rax
callq 0xa6cd
addq $0x10, %rsp
leaq 0x3b8b(%rip), %rdi      # 0xde74
callq 0x8050
movq %r15, %rdi
movl %r14d, %esi
callq 0xb868
movzbl %r13b, %r12d
movl %r12d, %eax
imull %r14d, %eax
movslq %eax, %rdi
callq 0x8090
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
testq %rax, %rax
je 0xa6bb
movq %rax, %rdx
testb %r13b, %r13b
movq %rax, -0x68(%rbp)
je 0xa699
movq %r13, %rbx
movslq %r14d, %rax
xorl %ecx, %ecx
movq -0x40(%rbp), %r8
movl -0x38(%rbp), %r13d
movq %rdx, (%r8,%rcx,8)
incq %rcx
addq %rax, %rdx
cmpq %rcx, %r12
jne 0xa33b
movzbl %r13b, %edi
movl %r12d, %esi
movq %r15, %rdx
movl %r14d, %ecx
callq 0xa93c
testb %bl, %bl
je 0xa6af
movb 0x10(%rbp), %al
andb $0x1f, %al
movzbl %al, %eax
movl %eax, -0x5c(%rbp)
decb %r13b
andb $0xf, %r13b
movzbl %r13b, %eax
movl %eax, -0x58(%rbp)
leal (,%r14,8), %eax
movzwl %ax, %ecx
imull $0x6667, %ecx, %ecx     # imm = 0x6667
shrl $0x11, %ecx
andl $0x1ffe, %ecx           # imm = 0x1FFE
leal (%rcx,%rcx,4), %ecx
subl %ecx, %eax
movl $0xa, %ecx
subl %eax, %ecx
xorl %edx, %edx
testw %ax, %ax
movl $0x0, %eax
movq %rax, -0x50(%rbp)
cmovel %edx, %ecx
movzbl %cl, %eax
movl %eax, -0x54(%rbp)
movq %r12, -0x70(%rbp)
cmpl $0x20, %r14d
jg 0xa67b
movzwl -0x2a(%rbp), %ebx
movq -0x40(%rbp), %rax
movq -0x50(%rbp), %r12
movq (%rax,%r12,8), %r14
movq 0x18(%rbp), %rax
movq (%rax,%r12,8), %r15
movl $0x84, %esi
leaq -0x120(%rbp), %rdi
callq 0x81bc
movl %ebx, %eax
shrl $0x5, %eax
andl $0x1f, %ebx
shll $0x5, %ebx
addl -0x5c(%rbp), %ebx
movl %r12d, %ecx
shll $0x4, %ecx
movzbl %cl, %ecx
addl -0x58(%rbp), %ecx
movl %eax, -0x120(%rbp)
movl %ebx, -0x11c(%rbp)
movl $0x0, -0x118(%rbp)
movl %ecx, -0x114(%rbp)
movq -0x48(%rbp), %r10
testl %r10d, %r10d
jle 0xa4b7
xorl %eax, %eax
movl $0x4, %r13d
movl -0x54(%rbp), %ecx
xorl %esi, %esi
leaq 0x3a68(%rip), %rbx      # 0xdeb0
shll $0x8, %esi
movzbl (%r14), %edx
orl %esi, %edx
cmpl $0x2, %ecx
jl 0xa4a6
movslq %r13d, %rdi
leal 0x12(%rcx), %esi
addl $-0x2, %ecx
leaq -0x120(,%rdi,4), %rdi
addq %rbp, %rdi
movl %edx, %r8d
movl %edx, %r9d
shrl %cl, %r9d
andl $0x3ff, %r9d            # imm = 0x3FF
movq $-0x1, %rdx
shlq %cl, %rdx
movl %r9d, (%rdi)
notl %edx
andl %r8d, %edx
addl $-0xa, %esi
addq $-0xa, %rcx
addq $0x4, %rdi
incl %r13d
cmpl $0x13, %esi
jg 0xa46a
addl $-0xa, %esi
movl %esi, %ecx
jmp 0xa4a9
addl $0x8, %ecx
incq %r14
incl %eax
movl %edx, %esi
cmpl %r10d, %eax
jne 0xa448
jmp 0xa4c4
movl $0x4, %r13d
leaq 0x39ec(%rip), %rbx      # 0xdeb0
xorl %eax, %eax
leaq 0x1f93(%rip), %rdx      # 0xc460
movsbl (%rax,%rdx), %ecx
movl %ecx, -0x90(%rbp,%rax,4)
incq %rax
cmpq $0x6, %rax
jne 0xa4cd
xorl %ecx, %ecx
movl $0x1, %eax
leaq -0x90(%rbp), %rdx
movl %eax, %esi
shrl $0x14, %esi
shll $0xa, %eax
andl $0x3ffffc00, %eax       # imm = 0x3FFFFC00
xorl (%rdx), %eax
movq %rbx, %rdi
xorl %r8d, %r8d
btl %r8d, %esi
jae 0xa50c
xorl (%rdi), %eax
incq %r8
addq $0x4, %rdi
cmpq $0xa, %r8
jne 0xa504
addq $0x4, %rdx
incl %ecx
cmpl $0x6, %ecx
jne 0xa4ef
movl %eax, -0x30(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x120(%rbp), %rsi
movl %r13d, %edx
callq 0xb5c0
movl $0x0, -0x88(%rbp)
movq $0x0, -0x90(%rbp)
xorl %ecx, %ecx
movl -0x30(%rbp), %eax
leaq -0x90(%rbp), %rdx
movl %eax, %esi
shrl $0x14, %esi
shll $0xa, %eax
andl $0x3ffffc00, %eax       # imm = 0x3FFFFC00
xorl (%rdx), %eax
movq %rbx, %rdi
xorl %r8d, %r8d
btl %r8d, %esi
jae 0xa578
xorl (%rdi), %eax
incq %r8
addq $0x4, %rdi
cmpq $0xa, %r8
jne 0xa570
addq $0x4, %rdx
incl %ecx
cmpl $0x3, %ecx
jne 0xa55b
movl %eax, %ecx
shrl $0x14, %ecx
movl $0x3ff, %esi            # imm = 0x3FF
andl %esi, %ecx
movslq %r13d, %rdx
movl %ecx, -0x120(%rbp,%rdx,4)
movl %eax, %ecx
shrl $0xa, %ecx
andl %esi, %ecx
movl %ecx, -0x11c(%rbp,%rdx,4)
andl %esi, %eax
xorl $0x1, %eax
movl %eax, -0x118(%rbp,%rdx,4)
cmpl $-0x3, %r13d
jle 0xa677
leal 0x2(%r13), %ebx
addl $0x3, %r13d
cmpl $0x2, %r13d
movl $0x1, %eax
cmovll %eax, %r13d
xorl %r14d, %r14d
xorl %r12d, %r12d
leaq 0x9804(%rip), %rdx      # 0x13df0
movl -0x120(%rbp,%r14,4), %eax
movq (%rdx,%rax,8), %rdi
callq 0x8060
leaq 0x97ec(%rip), %rdx      # 0x13df0
addl %eax, %r12d
incl %r12d
incq %r14
cmpq %r14, %r13
jne 0xa5ec
cmpl $0x16b, %r12d           # imm = 0x16B
ja 0xa67b
movb $0x0, (%r15)
movl %ebx, %eax
movq %rax, -0x38(%rbp)
xorl %ebx, %ebx
movl -0x120(%rbp,%rbx,4), %eax
movq (%rdx,%rax,8), %r14
movq %r14, %rdi
callq 0x8060
movl %eax, %r12d
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x8080
leaq 0x979e(%rip), %rdx      # 0x13df0
xorl %eax, %eax
cmpq %rbx, -0x38(%rbp)
setne %al
movl %eax, %ecx
shlb $0x5, %cl
addq %r15, %rax
addq %r12, %rax
movb %cl, (%r15,%r12)
incq %rbx
movq %rax, %r15
cmpq %rbx, %r13
jne 0xa627
jmp 0xa67b
movb $0x0, (%r15)
movq -0x50(%rbp), %rcx
incq %rcx
movq -0x70(%rbp), %r12
movq %rcx, -0x50(%rbp)
cmpq %r12, %rcx
movq -0x48(%rbp), %r14
jne 0xa3be
jmp 0xa6af
movzbl -0x38(%rbp), %edi
movl %r12d, %esi
movq %r15, %rdx
movl %r14d, %ecx
movq -0x40(%rbp), %r8
callq 0xa93c
movq -0x68(%rbp), %rdi
callq 0x8030
xorl %r10d, %r10d
movl %r10d, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq