// File: /workspace/github_c_makefile_star2_O0/Seclabs-htc[P]slip39/test.c
// Function: simple_test
int simple_test(void)
{
    uint8_t master_secret[32];
    int master_secret_len;
    uint16_t gt;
    int i, j;
    int gn = 5;
    char *ml[gn];
    char *dml[5];
    uint8_t ms[32];
    int msl;

    // create

    #if 1
    master_secret_len = sizeof(master_secret);
    fromhex(master_secret, &master_secret_len, "dbc4ac53fcc6d33e38c63fde60dae89f");
    #else
    master_secret_len = 16;
    random_buffer(master_secret, master_secret_len);
    #endif

    printf("master secret\n");
    dumphex(master_secret, master_secret_len);

    for (i = 0; i < gn; i++)
        ml[i] = (char *)malloc(MNEMONIC_LIST_LEN);

    gt = 3;
    generate_mnemonics(gt, gn, master_secret, master_secret_len,
            NULL, 0, 0, ml);

    printf("\n");
    for (i = 0; i < gn; i++)
        printf("%s\n", ml[i]);
    printf("\n");

    // choice 4, 3, 0 for decode
    dml[0] = ml[4];
    dml[1] = ml[3];
    dml[2] = ml[0];
    msl = sizeof(ms);
    combine_mnemonics(gt, dml, NULL, 0, ms, &msl);

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

    if ((msl == master_secret_len) &&
        memcmp(master_secret, ms, msl) == 0)
    {
        printf("\n--- pass ---\n\n");
    }
    else
    {
        printf("\n--- fail ---\n\n");
    }

    for (i = 0; i < gn; i++)
        free(ml[i]);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movl $0x5, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x40(%rbp)
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xa0(%rbp)
movq %rcx, %rsp
movq %rax, -0x48(%rbp)
movl $0x20, -0x24(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x24(%rbp), %rsi
leaq 0x3abf(%rip), %rdx      # 0xf421
callq 0xdfb0
leaq 0x3b00(%rip), %rdi      # 0xf46e
movb $0x0, %al
callq 0x8050
leaq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0xe180
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0xb9b7
movl $0x16b, %edi            # imm = 0x16B
callq 0x80a0
movq %rax, %rdx
movq -0xa0(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xb988
movq -0xa0(%rbp), %rax
movw $0x3, -0x26(%rbp)
movw -0x26(%rbp), %cx
movb %cl, %dil
movl -0x34(%rbp), %ecx
movb %cl, %sil
leaq -0x20(%rbp), %rdx
movl -0x24(%rbp), %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
subq $0x10, %rsp
movzbl %dil, %edi
movzbl %sil, %esi
movl $0x0, (%rsp)
movq %rax, 0x8(%rsp)
callq 0xbb70
addq $0x10, %rsp
leaq 0x3a5e(%rip), %rdi      # 0xf464
movb $0x0, %al
callq 0x8050
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0xba44
movq -0xa0(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0x3a10(%rip), %rdi      # 0xf442
movb $0x0, %al
callq 0x8050
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xba14
leaq 0x3a19(%rip), %rdi      # 0xf464
movb $0x0, %al
callq 0x8050
movq -0xa0(%rbp), %rax
movq 0x20(%rax), %rcx
movq %rcx, -0x70(%rbp)
movq 0x18(%rax), %rcx
movq %rcx, -0x68(%rbp)
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movl $0x20, -0x94(%rbp)
movzwl -0x26(%rbp), %edi
leaq -0x70(%rbp), %rsi
leaq -0x90(%rbp), %r8
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
leaq -0x94(%rbp), %r9
callq 0xcf20
leaq 0x39cc(%rip), %rdi      # 0xf46e
movb $0x0, %al
callq 0x8050
leaq -0x90(%rbp), %rdi
movl -0x94(%rbp), %esi
callq 0xe180
movl -0x94(%rbp), %eax
cmpl -0x24(%rbp), %eax
jne 0xbaf2
leaq -0x20(%rbp), %rdi
leaq -0x90(%rbp), %rsi
movslq -0x94(%rbp), %rdx
callq 0x8070
cmpl $0x0, %eax
jne 0xbaf2
leaq 0x395d(%rip), %rdi      # 0xf446
movb $0x0, %al
callq 0x8050
jmp 0xbb00
leaq 0x395d(%rip), %rdi      # 0xf456
movb $0x0, %al
callq 0x8050
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0xbb2e
movq -0xa0(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x8030
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xbb07
movq -0x40(%rbp), %rax
movq %rax, %rsp
xorl %eax, %eax
movq %rbp, %rsp
popq %rbp
retq
nopl (%rax)