// File: /workspace/github_c_makefile_star2_O1/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
movq %r8, %r14
movl %ecx, %eax
movq %rsp, %r12
addq $0xf, %rax
andq $-0x10, %rax
subq %rax, %r12
movq %r12, %rsp
movq %rsi, -0x40(%rbp)
leal 0xf(,%rsi,8), %eax
andl $-0x10, %eax
movq %rsp, %r8
subq %rax, %r8
movq %r8, %rsp
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
testl %ecx, %ecx
je 0xa6a9
movl %r9d, %r15d
movl %ecx, %ebx
testl %r9d, %r9d
jle 0xa2a0
movl %r15d, %eax
xorl %esi, %esi
movb (%r14,%rsi), %r9b
addb $-0x20, %r9b
cmpb $0x5f, %r9b
jae 0xa6a9
incq %rsi
cmpq %rsi, %rax
jne 0xa286
movl %edi, -0x38(%rbp)
movq %r8, -0x60(%rbp)
leaq -0x2a(%rbp), %rdi
movl $0x2, %esi
movq %rdx, %r13
callq 0x9fc3
leaq -0x2a(%rbp), %rax
movw $0x3761, (%rax)         # imm = 0x3761
subq $0x8, %rsp
movzbl 0x10(%rbp), %eax
movq %r13, %rdi
movl %ebx, %esi
movq %r12, %rdx
movl %ebx, %ecx
movq %r14, %r8
movl %r15d, %r9d
pushq %rax
callq 0xa6bb
addq $0x10, %rsp
leaq 0x3b8a(%rip), %rdi      # 0xde74
callq 0x8050
movq %r12, %rdi
movl %ebx, %esi
callq 0xb81c
movq -0x40(%rbp), %r15
movzbl %r15b, %r14d
movl %r14d, %eax
movq %rbx, -0x48(%rbp)
imull %ebx, %eax
movslq %eax, %rdi
callq 0x8090
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
testq %rax, %rax
je 0xa6a9
testb %r15b, %r15b
movq -0x48(%rbp), %rcx
movq -0x60(%rbp), %r8
je 0xa346
movslq %ecx, %rdi
xorl %esi, %esi
movq %rax, %rdx
movq %rdx, (%r8,%rsi,8)
incq %rsi
addq %rdi, %rdx
cmpq %rsi, %r14
jne 0xa337
movq %rax, -0x68(%rbp)
movl -0x38(%rbp), %ebx
movzbl %bl, %edi
movl %r14d, %esi
movq %r12, %rdx
callq 0xa92d
movq -0x48(%rbp), %rdx
testb %r15b, %r15b
je 0xa69d
movb 0x10(%rbp), %al
andb $0x1f, %al
movzbl %al, %eax
movl %eax, -0x54(%rbp)
decb %bl
andb $0xf, %bl
movzbl %bl, %eax
movl %eax, -0x50(%rbp)
leal (,%rdx,8), %eax
movl $0xcccccccd, %ecx       # imm = 0xCCCCCCCD
imulq %rax, %rcx
shrq $0x23, %rcx
addl %ecx, %ecx
leal (%rcx,%rcx,4), %ecx
subl %ecx, %eax
movl $0xa, %ecx
subl %eax, %ecx
testl %eax, %eax
cmovel %eax, %ecx
movl %ecx, -0x4c(%rbp)
movq $0x0, -0x40(%rbp)
movq %r14, -0x70(%rbp)
cmpl $0x20, %edx
jg 0xa681
movzwl -0x2a(%rbp), %ebx
movq -0x60(%rbp), %rax
movq -0x40(%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 -0x54(%rbp), %ebx
movl %r12d, %ecx
shll $0x4, %ecx
movzbl %cl, %ecx
addl -0x50(%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 0xa4ac
xorl %eax, %eax
movl $0x4, %r13d
movl -0x4c(%rbp), %ecx
xorl %esi, %esi
leaq 0x3a73(%rip), %rbx      # 0xdeb0
shll $0x8, %esi
movzbl (%r14), %edx
orl %esi, %edx
cmpl $0x2, %ecx
jl 0xa49b
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 0xa45f
addl $-0xa, %esi
movl %esi, %ecx
jmp 0xa49e
addl $0x8, %ecx
incq %r14
incl %eax
movl %edx, %esi
cmpl %r10d, %eax
jne 0xa43d
jmp 0xa4b9
movl $0x4, %r13d
leaq 0x39f7(%rip), %rbx      # 0xdeb0
movl $0x1, -0x30(%rbp)
xorl %eax, %eax
leaq 0x1f97(%rip), %rdx      # 0xc460
movsbl (%rax,%rdx), %ecx
movl %ecx, -0x90(%rbp,%rax,4)
incq %rax
cmpq $0x6, %rax
jne 0xa4c9
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 0xa508
xorl (%rdi), %eax
incq %r8
addq $0x4, %rdi
cmpq $0xa, %r8
jne 0xa500
addq $0x4, %rdx
incl %ecx
cmpl $0x6, %ecx
jne 0xa4eb
movl %eax, -0x30(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x120(%rbp), %rsi
movl %r13d, %edx
callq 0xb59c
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 0xa574
xorl (%rdi), %eax
incq %r8
addq $0x4, %rdi
cmpq $0xa, %r8
jne 0xa56c
addq $0x4, %rdx
incl %ecx
cmpl $0x3, %ecx
jne 0xa557
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 $-0x2, %r13d
jl 0xa67d
leal 0x2(%r13), %eax
movl %eax, -0x38(%rbp)
leal 0x3(%r13), %ebx
cmpl $0x2, %ebx
movl $0x1, %eax
cmovll %eax, %ebx
xorl %r12d, %r12d
xorl %r14d, %r14d
leaq 0x9807(%rip), %rdx      # 0x13df0
movl -0x120(%rbp,%r12,4), %eax
movq (%rdx,%rax,8), %rdi
callq 0x8060
leaq 0x97ef(%rip), %rdx      # 0x13df0
addl %eax, %r14d
incl %r14d
incq %r12
cmpq %r12, %rbx
jne 0xa5e9
cmpl $0x16b, %r14d           # imm = 0x16B
ja 0xa681
movb $0x0, (%r15)
cmpl $-0x2, %r13d
jl 0xa681
movl -0x38(%rbp), %ecx
movq %rcx, -0x38(%rbp)
xorl %r12d, %r12d
movl -0x120(%rbp,%r12,4), %eax
movq (%rdx,%rax,8), %r14
movq %r14, %rdi
callq 0x8060
movl %eax, %r13d
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x8080
leaq 0x9798(%rip), %rdx      # 0x13df0
xorl %eax, %eax
cmpq %r12, -0x38(%rbp)
setne %al
movl %eax, %ecx
shlb $0x5, %cl
addq %r15, %rax
addq %r13, %rax
movb %cl, (%r15,%r13)
incq %r12
movq %rax, %r15
cmpq %r12, %rbx
jne 0xa62c
jmp 0xa681
movb $0x0, (%r15)
movq -0x40(%rbp), %rcx
incq %rcx
movq -0x70(%rbp), %r14
movq %rcx, -0x40(%rbp)
cmpq %r14, %rcx
movq -0x48(%rbp), %rdx
jne 0xa3b4
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