// File: /workspace/github_c_makefile_star2_O1/mjosaarinen[P]brutus/src/xprmnt.c
// Function: test_xprmnt
int test_xprmnt(caesar_t *aead, int limit)
{
    int i, j;
    unsigned long long mlen, clen, steps;
    uint8_t key[256], npub[64], nsec[64],
        mx[XBLOCK], my[XBLOCK], cx[XBLOCK], cy[XBLOCK];
    clock_t stim, etim;
    uint32_t cnt[XBLOCK][XBLOCK];
    char fn[256];
    FILE *f;

    if (brutus_verbose) {
        printf("[%s] feedback (limit=%d sec) "
            " key=%d  nsec=%d  npub=%d  a=%d\n",
            aead->name, limit,
            aead->keybytes, aead->nsecbytes,
            aead->npubbytes, aead->abytes);
    }

    limit *= CLOCKS_PER_SEC;

    if (aead->abytes > sizeof(cx) || aead->keybytes > sizeof(key) ||
        aead->nsecbytes > sizeof(nsec) || aead->npubbytes > sizeof(npub))
        goto fail;

    memset(key, 0x00, sizeof(key));
    memset(npub, 0x00, sizeof(npub));
    memset(nsec, 0x00, sizeof(nsec));
    memset(mx, 0x00, sizeof(mx));
    memset(my, 0x00, sizeof(my));
    memset(cx, 0x00, sizeof(cx));
    memset(cy, 0x00, sizeof(cy));

    memset(cnt, 0x00, sizeof(cnt));

    mlen = sizeof(cx) - aead->abytes;
    if (aead->encrypt(cx, &clen, mx, mlen, mx, 0, nsec, npub, key) != 0)
        goto fail;
    if (clen > sizeof(cx))
        goto fail;

    stim = clock();
    steps = 0;
    do {
        detseq_fill(key, aead->keybytes);
        detseq_fill(npub, aead->npubbytes);
        detseq_fill(nsec, aead->nsecbytes);
        detseq_fill(mx, mlen);

        if (aead->encrypt(cx, &clen, mx, mlen, mx, 0, nsec, npub, key) != 0)
            goto fail;

        for (i = 0; i < mlen; i++) {
            memcpy(my, mx, mlen);
            my[i] += (detseq32() % 255) + 1;
            if (aead->encrypt(cy, &clen, my, mlen, mx, 0,
                nsec, npub, key) != 0)
                goto fail;
            for (j = 0; j < clen; j++) {
                if (cx[j] != cy[j])
                    cnt[i][j]++;
            }
        }
        steps++;
        etim = clock() - stim;
    } while (etim < limit);

    strncpy(fn, aead->name, sizeof(fn));
    for (i = 0; i < sizeof(fn); i++) {
        if (fn[i] == 0 || fn[i] == '-')
            break;
    }

    strncpy(&fn[i], ".def", sizeof(fn) - i);
    f = fopen(fn, "w");
    if (f == NULL) {
        perror(fn);
        return 1;
    }
    fn[i] = 0;
    fprintf(f, "[%s]<br>key:%d  nsec:%d  npub:%d  pad:%d\n",
            fn, 8 * aead->keybytes, 8 * aead->nsecbytes,
            8 * aead->npubbytes, 8 * aead->abytes);
    fclose(f);

    strncpy(&fn[i], ".pgm", sizeof(fn) - i);
    f = fopen(fn, "w");
    if (f == NULL) {
        perror(fn);
        return 1;
    }

    // output the file

    fprintf(f, "P2\n# %s\n%d %d\n255\n",
        fn, (int) clen + 2, (int) mlen + 2);

    for (i = 0; i < clen + 1; i++)
        fprintf(f, "0 ");
    fprintf(f, "0\n");

    for (i = 0; i < mlen; i++) {
        fprintf(f, "0 ");
        for (j = 0; j < clen; j++) {

            if ((i & 0xF) == 0 || (j & 0xF) == 0) {

                if (cnt[i][j] > 0)
                    fprintf(f, "55 ");
                else
                    fprintf(f, "255 ");
         
            } else {

                if (cnt[i][j] > 0)
                    fprintf(f, "0 ");
                else
                    fprintf(f, "200 ");

            }
        }
        fprintf(f, "0\n");
    }

    for (i = 0; i < clen + 1; i++)
        fprintf(f, "0 ");
    fprintf(f, "0\n");

    fclose(f);

    return 0;

fail:
    printf("[%s] Incompatible parameters, bailing out.\n",
        aead->name);

    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x406a8, %rsp          # imm = 0x406A8
movl %esi, %ebp
movq %rdi, %r14
leaq 0x4763(%rip), %rax      # 0x7128
cmpl $0x0, (%rax)
je 0x29f8
movq 0x8(%r14), %rsi
movl 0x10(%r14), %ecx
movl 0x14(%r14), %r8d
movl 0x18(%r14), %r9d
movl 0x1c(%r14), %r10d
subq $0x8, %rsp
leaq 0x20ff(%rip), %rdi      # 0x4ae8
movl %ebp, %edx
xorl %eax, %eax
pushq %r10
callq 0x10b0
addq $0x10, %rsp
movl 0x1c(%r14), %eax
movq %rax, 0x8(%rsp)
cmpq $0x100, %rax            # imm = 0x100
ja 0x2a21
cmpl $0x100, 0x10(%r14)      # imm = 0x100
ja 0x2a21
cmpl $0x40, 0x14(%r14)
ja 0x2a21
cmpl $0x40, 0x18(%r14)
jbe 0x2a4a
movq 0x8(%r14), %rsi
leaq 0x2150(%rip), %rdi      # 0x4b7c
xorl %eax, %eax
callq 0x10b0
movl $0x1, %eax
addq $0x406a8, %rsp          # imm = 0x406A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
vpxor %xmm0, %xmm0, %xmm0
leaq 0x4a0(%rsp), %r15
vmovdqu %ymm0, 0xe0(%r15)
vmovdqu %ymm0, 0xc0(%r15)
vmovdqu %ymm0, 0xa0(%r15)
vmovdqu %ymm0, 0x80(%r15)
vmovdqu %ymm0, 0x60(%r15)
vmovdqu %ymm0, 0x40(%r15)
vmovdqu %ymm0, 0x20(%r15)
vmovdqu %ymm0, (%r15)
leaq 0x60(%rsp), %rax
vmovdqu %ymm0, (%rax)
vmovdqu %ymm0, 0x20(%rax)
leaq 0x20(%rsp), %rax
vmovdqu %ymm0, (%rax)
vmovdqu %ymm0, 0x20(%rax)
leaq 0x5a0(%rsp), %r12
vmovdqu %ymm0, (%r12)
vmovdqu %ymm0, 0x20(%r12)
vmovdqu %ymm0, 0x40(%r12)
vmovdqu %ymm0, 0x60(%r12)
vmovdqu %ymm0, 0x80(%r12)
vmovdqu %ymm0, 0xa0(%r12)
vmovdqu %ymm0, 0xc0(%r12)
vmovdqu %ymm0, 0xe0(%r12)
vmovdqu %ymm0, 0x180(%rsp)
vmovdqu %ymm0, 0x160(%rsp)
vmovdqu %ymm0, 0x140(%rsp)
vmovdqu %ymm0, 0x120(%rsp)
vmovdqu %ymm0, 0x100(%rsp)
vmovdqu %ymm0, 0xe0(%rsp)
vmovdqu %ymm0, 0xc0(%rsp)
vmovdqu %ymm0, 0xa0(%rsp)
leaq 0x3a0(%rsp), %r13
vmovdqu %ymm0, (%r13)
vmovdqu %ymm0, 0x20(%r13)
vmovdqu %ymm0, 0x40(%r13)
vmovdqu %ymm0, 0x60(%r13)
vmovdqu %ymm0, 0x80(%r13)
vmovdqu %ymm0, 0xa0(%r13)
vmovdqu %ymm0, 0xc0(%r13)
vmovdqu %ymm0, 0xe0(%r13)
vmovdqu %ymm0, 0x1a0(%rsp)
vmovdqu %ymm0, 0x1c0(%rsp)
vmovdqu %ymm0, 0x1e0(%rsp)
vmovdqu %ymm0, 0x200(%rsp)
vmovdqu %ymm0, 0x220(%rsp)
vmovdqu %ymm0, 0x240(%rsp)
vmovdqu %ymm0, 0x260(%rsp)
vmovdqu %ymm0, 0x280(%rsp)
leaq 0x6a0(%rsp), %rdi
movl $0x40000, %edx          # imm = 0x40000
xorl %esi, %esi
vzeroupper
callq 0x10d0
movl $0x100, %ebx            # imm = 0x100
subq 0x8(%rsp), %rbx
subq $0x8, %rsp
leaq 0x8(%rsp), %rsi
movq %r13, %rdi
movq %r12, %rdx
movq %rbx, %rcx
movq %r12, %r8
xorl %r9d, %r9d
pushq %r15
leaq 0x70(%rsp), %rax
pushq %rax
leaq 0x38(%rsp), %rax
pushq %rax
callq *0x28(%r14)
addq $0x20, %rsp
testl %eax, %eax
jne 0x2a21
cmpq $0x100, (%rsp)          # imm = 0x100
ja 0x2a21
imull $0xf4240, %ebp, %ebp    # imm = 0xF4240
callq 0x1090
movq %rax, 0x18(%rsp)
movslq %ebp, %rax
movq %rax, 0x10(%rsp)
leaq 0x5a0(%rsp), %rbp
movl 0x10(%r14), %esi
leaq 0x4a0(%rsp), %r15
movq %r15, %rdi
callq 0x1a4a
movl 0x18(%r14), %esi
leaq 0x60(%rsp), %r13
movq %r13, %rdi
callq 0x1a4a
movl 0x14(%r14), %esi
leaq 0x20(%rsp), %r12
movq %r12, %rdi
callq 0x1a4a
movq %rbp, %rdi
movl %ebx, %esi
callq 0x1a4a
subq $0x8, %rsp
leaq 0x3a8(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movq %rbp, %rdx
movq %rbx, %rcx
movq %rbp, %r8
xorl %r9d, %r9d
pushq %r15
pushq %r13
pushq %r12
callq *0x28(%r14)
addq $0x20, %rsp
testl %eax, %eax
jne 0x2a21
cmpl $0x100, 0x8(%rsp)       # imm = 0x100
je 0x2e07
leaq 0x6a0(%rsp), %r12
xorl %r13d, %r13d
leaq 0xa0(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
vzeroupper
callq 0x1130
xorl %eax, %eax
callq 0x1a2f
movl %eax, %ecx
movl $0x80808081, %edx       # imm = 0x80808081
imulq %rdx, %rcx
shrq $0x27, %rcx
addl %eax, %ecx
addb 0xa0(%rsp,%r13), %cl
incb %cl
movb %cl, 0xa0(%rsp,%r13)
subq $0x8, %rsp
leaq 0x1a8(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movq %r15, %rdx
movq %rbx, %rcx
movq %rbp, %r8
xorl %r9d, %r9d
leaq 0x4a8(%rsp), %rax
pushq %rax
leaq 0x70(%rsp), %rax
pushq %rax
leaq 0x38(%rsp), %rax
pushq %rax
callq *0x28(%r14)
addq $0x20, %rsp
testl %eax, %eax
jne 0x2a21
movq (%rsp), %rcx
testq %rcx, %rcx
vpmovsxbq 0x1d6e(%rip), %ymm3 # 0x4ae0
vpmovsxbq 0x1d69(%rip), %ymm4 # 0x4ae4
vpcmpeqd %ymm5, %ymm5, %ymm5
je 0x2df4
leaq 0x7(%rcx), %rax
andq $-0x8, %rax
decq %rcx
vpbroadcastq %rcx, %ymm0
xorl %ecx, %ecx
vpbroadcastq %rcx, %ymm1
vpor %ymm3, %ymm1, %ymm2
vpor %ymm4, %ymm1, %ymm1
vpcmpleuq %ymm0, %ymm1, %k0
vpcmpleuq %ymm0, %ymm2, %k1
kshiftlb $0x4, %k1, %k1
korb %k1, %k0, %k0
kmovb %k0, %k1
vmovdqu8 0x3a0(%rsp,%rcx), %xmm1 {%k1} {z}
vmovdqu8 0x1a0(%rsp,%rcx), %xmm2 {%k1} {z}
vpcmpneqb %xmm2, %xmm1, %k1
kandb %k1, %k0, %k1
vmovdqu32 (%r12,%rcx,4), %ymm1 {%k1} {z}
vpsubd %ymm5, %ymm1, %ymm1
vmovdqu32 %ymm1, (%r12,%rcx,4) {%k1}
addq $0x8, %rcx
cmpq %rcx, %rax
jne 0x2d94
incq %r13
addq $0x400, %r12            # imm = 0x400
cmpq %rbx, %r13
jne 0x2cdd
vzeroupper
callq 0x1090
subq 0x18(%rsp), %rax
cmpq 0x10(%rsp), %rax
jl 0x2c51
movq 0x8(%r14), %rsi
leaq 0x2a0(%rsp), %rdi
movl $0x100, %edx            # imm = 0x100
callq 0x1060
xorl %eax, %eax
movzbl 0x2a0(%rsp,%rax), %ecx
testl %ecx, %ecx
je 0x2e58
cmpl $0x2d, %ecx
je 0x2e58
incq %rax
cmpq $0x100, %rax            # imm = 0x100
jne 0x2e37
movl $0x100, %eax            # imm = 0x100
leaq (%rsp,%rax), %r12
addq $0x2a0, %r12            # imm = 0x2A0
movl $0x100, %ebp            # imm = 0x100
subq %rax, %rbp
leaq 0x1cb4(%rip), %rsi      # 0x4b26
movq %r12, %rdi
movq %rbp, %rdx
callq 0x1060
leaq 0x1ca7(%rip), %rsi      # 0x4b2b
leaq 0x2a0(%rsp), %rdi
callq 0x11a0
testq %rax, %rax
je 0x30ca
movq %rax, %r13
movb $0x0, (%r12)
movl 0x10(%r14), %ecx
movl 0x14(%r14), %r8d
shll $0x3, %ecx
shll $0x3, %r8d
movl 0x18(%r14), %r9d
shll $0x3, %r9d
movl 0x1c(%r14), %r10d
shll $0x3, %r10d
subq $0x8, %rsp
leaq 0x1c61(%rip), %rsi      # 0x4b2d
leaq 0x2a8(%rsp), %r14
movq %rax, %rdi
movq %r14, %rdx
xorl %eax, %eax
pushq %r10
callq 0x1110
addq $0x10, %rsp
movq %r13, %rdi
callq 0x10a0
leaq 0x1c61(%rip), %rsi      # 0x4b57
movq %r12, %rdi
movq %rbp, %rdx
callq 0x1060
leaq 0x1c23(%rip), %rsi      # 0x4b2b
movq %r14, %rdi
callq 0x11a0
testq %rax, %rax
je 0x30ca
movq %rax, %r14
movl (%rsp), %ecx
addl $0x2, %ecx
leal 0x2(%rbx), %r8d
leaq 0x1c2f(%rip), %rsi      # 0x4b5c
leaq 0x2a0(%rsp), %rdx
movq %rax, %rdi
xorl %eax, %eax
callq 0x1110
cmpq $-0x1, (%rsp)
je 0x2f74
xorl %r13d, %r13d
leaq 0x1c29(%rip), %r12      # 0x4b79
movl $0x2, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %r14, %rcx
callq 0x11f0
incq %r13
movq (%rsp), %rax
incq %rax
cmpq %r13, %rax
ja 0x2f50
leaq 0x1bf4(%rip), %rdi      # 0x4b6f
movl $0x2, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x11f0
cmpl $0x100, 0x8(%rsp)       # imm = 0x100
je 0x306d
leaq 0x6a0(%rsp), %r13
xorl %r12d, %r12d
leaq 0x1bcc(%rip), %r15      # 0x4b79
movl $0x2, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %r14, %rcx
callq 0x11f0
cmpq $0x0, (%rsp)
je 0x3041
xorl %ebp, %ebp
testb $0xf, %r12b
setne %cl
testb $0xf, %bpl
setne %dl
movl (%r13,%rbp,4), %eax
testb %dl, %cl
jne 0x2ff9
testl %eax, %eax
je 0x300c
movl $0x3, %esi
movl $0x1, %edx
leaq 0x1b7c(%rip), %rdi      # 0x4b73
jmp 0x3030
testl %eax, %eax
je 0x301f
movl $0x2, %esi
movl $0x1, %edx
movq %r15, %rdi
jmp 0x3030
movl $0x4, %esi
movl $0x1, %edx
leaq 0x1b55(%rip), %rdi      # 0x4b72
jmp 0x3030
movl $0x4, %esi
movl $0x1, %edx
leaq 0x1b47(%rip), %rdi      # 0x4b77
movq %r14, %rcx
callq 0x11f0
incq %rbp
cmpq %rbp, (%rsp)
ja 0x2fcb
movl $0x2, %esi
movl $0x1, %edx
leaq 0x1b1d(%rip), %rdi      # 0x4b6f
movq %r14, %rcx
callq 0x11f0
incq %r12
addq $0x400, %r13            # imm = 0x400
cmpq %rbx, %r12
jne 0x2fad
cmpq $-0x1, (%rsp)
je 0x30a2
xorl %r15d, %r15d
leaq 0x1afb(%rip), %rbx      # 0x4b79
movl $0x2, %esi
movl $0x1, %edx
movq %rbx, %rdi
movq %r14, %rcx
callq 0x11f0
incq %r15
movq (%rsp), %rax
incq %rax
cmpq %r15, %rax
ja 0x307e
leaq 0x1ac6(%rip), %rdi      # 0x4b6f
movl $0x2, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x11f0
movq %r14, %rdi
callq 0x10a0
xorl %eax, %eax
jmp 0x2a38
leaq 0x2a0(%rsp), %rdi
callq 0x11b0
jmp 0x2a33