// File: /workspace/github_c_makefile_star2_O0/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 %rbx
subq $0x68, %rsp
movb %sil, %al
movb %dil, %sil
movq 0x18(%rbp), %rdi
movb 0x10(%rbp), %dil
movb %sil, -0xd(%rbp)
movb %al, -0xe(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movl -0x1c(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x38(%rbp)
movq %rax, %rdx
addq $0xf, %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x70(%rbp)
movq %rcx, %rsp
movq %rax, -0x40(%rbp)
movzbl -0xe(%rbp), %edx
movl %edx, %eax
movl %edx, %ecx
leal 0xf(,%rcx,8), %ecx
andl $-0x10, %ecx
movl %ecx, %edx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x68(%rbp)
movq %rcx, %rsp
movq %rax, -0x50(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0xbc01
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x5c(%rbp)
jmp 0xbdf1
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0xbc52
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x20, %eax
jl 0xbc32
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x7e, %eax
jle 0xbc45
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x5c(%rbp)
jmp 0xbdf1
jmp 0xbc47
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xbc08
leaq -0x42(%rbp), %rdi
movl $0x2, %esi
callq 0xb7c0
movq -0x70(%rbp), %rdx
movw $0x3761, -0x42(%rbp)    # imm = 0x3761
movzwl -0x42(%rbp), %eax
andl $0x7fff, %eax           # imm = 0x7FFF
movw %ax, -0x42(%rbp)
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl -0x1c(%rbp), %ecx
movq -0x28(%rbp), %r8
movl -0x2c(%rbp), %r9d
movb 0x10(%rbp), %al
subq $0x10, %rsp
movzbl %al, %eax
movl %eax, (%rsp)
movzwl -0x42(%rbp), %eax
movl %eax, 0x8(%rsp)
callq 0xbe10
addq $0x10, %rsp
leaq 0x37b8(%rip), %rdi      # 0xf466
movb $0x0, %al
callq 0x8050
movq -0x70(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0xe180
movl -0x1c(%rbp), %eax
movzbl -0xe(%rbp), %ecx
imull %ecx, %eax
movslq %eax, %rdi
callq 0x80a0
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0xbcf1
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x5c(%rbp)
jmp 0xbdf1
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movzbl -0xe(%rbp), %ecx
cmpl %ecx, %eax
jge 0xbd2b
movq -0x68(%rbp), %rax
movq -0x58(%rbp), %rdx
movl -0x30(%rbp), %ecx
imull -0x1c(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rdx
movslq -0x30(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xbcf8
movq -0x68(%rbp), %r8
movq -0x70(%rbp), %rdx
movb -0xd(%rbp), %sil
movb -0xe(%rbp), %al
movl -0x1c(%rbp), %ecx
movzbl %sil, %edi
movzbl %al, %esi
callq 0xc240
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movzbl -0xe(%rbp), %ecx
cmpl %ecx, %eax
jge 0xbdda
movq -0x68(%rbp), %rax
movw -0x42(%rbp), %si
movzbl 0x10(%rbp), %ecx
movl -0x30(%rbp), %edx
movw %dx, %r9w
movzbl -0xd(%rbp), %edx
movw %dx, %bx
movslq -0x30(%rbp), %rdx
movq (%rax,%rdx,8), %r11
movl -0x1c(%rbp), %r10d
movq 0x18(%rbp), %rax
movslq -0x30(%rbp), %rdx
movq (%rax,%rdx,8), %rax
xorl %edx, %edx
movl $0x1, %r8d
subq $0x30, %rsp
movzwl %si, %edi
movzwl %cx, %esi
movl %r8d, %ecx
movzwl %r9w, %r9d
movzwl %bx, %ebx
movl %ebx, (%rsp)
movq %r11, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movl $0x16b, 0x20(%rsp)      # imm = 0x16B
callq 0xc560
addq $0x30, %rsp
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xbd50
movq -0x58(%rbp), %rdi
callq 0x8030
movl $0x0, -0xc(%rbp)
movl $0x1, -0x5c(%rbp)
movq -0x38(%rbp), %rax
movq %rax, %rsp
movl -0xc(%rbp), %eax
leaq -0x8(%rbp), %rsp
popq %rbx
popq %rbp
retq
nopw %cs:(%rax,%rax)