// File: /workspace/github_c_makefile_star2_O0/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 %rbx
subq $0x406f0, %rsp          # imm = 0x406F0
movq %rdi, 0x406e0(%rsp)
movl %esi, 0x406dc(%rsp)
leaq 0x2ba2(%rip), %rax      # 0x6110
cmpl $0x0, (%rax)
je 0x35c5
movq 0x406e0(%rsp), %rax
movq 0x8(%rax), %rsi
movl 0x406dc(%rsp), %edx
movq 0x406e0(%rsp), %rax
movl 0x10(%rax), %ecx
movq 0x406e0(%rsp), %rax
movl 0x14(%rax), %r8d
movq 0x406e0(%rsp), %rax
movl 0x18(%rax), %r9d
movq 0x406e0(%rsp), %rax
movl 0x1c(%rax), %eax
leaq 0x1398(%rip), %rdi      # 0x4953
movl %eax, (%rsp)
movb $0x0, %al
callq 0x10a0
movslq 0x406dc(%rsp), %rax
imulq $0xf4240, %rax, %rax    # imm = 0xF4240
movl %eax, 0x406dc(%rsp)
movq 0x406e0(%rsp), %rax
movslq 0x1c(%rax), %rax
cmpq $0x100, %rax            # imm = 0x100
ja 0x3627
movq 0x406e0(%rsp), %rax
movslq 0x10(%rax), %rax
cmpq $0x100, %rax            # imm = 0x100
ja 0x3627
movq 0x406e0(%rsp), %rax
movslq 0x14(%rax), %rax
cmpq $0x40, %rax
ja 0x3627
movq 0x406e0(%rsp), %rax
movslq 0x18(%rax), %rax
cmpq $0x40, %rax
jbe 0x362c
jmp 0x3dee
leaq 0x405b0(%rsp), %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x10b0
leaq 0x40570(%rsp), %rdi
xorl %esi, %esi
movl $0x40, %edx
callq 0x10b0
leaq 0x40530(%rsp), %rdi
xorl %esi, %esi
movl $0x40, %edx
callq 0x10b0
leaq 0x40430(%rsp), %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x10b0
leaq 0x40330(%rsp), %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x10b0
leaq 0x40230(%rsp), %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x10b0
leaq 0x40130(%rsp), %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x10b0
leaq 0x120(%rsp), %rdi
xorl %esi, %esi
movl $0x40000, %edx          # imm = 0x40000
callq 0x10b0
movq 0x406e0(%rsp), %rax
movslq 0x1c(%rax), %rcx
movl $0x100, %eax            # imm = 0x100
subq %rcx, %rax
movq %rax, 0x406c8(%rsp)
movq 0x406e0(%rsp), %rax
movq 0x28(%rax), %rax
leaq 0x40230(%rsp), %rdi
leaq 0x40430(%rsp), %rdx
movq 0x406c8(%rsp), %rcx
leaq 0x40430(%rsp), %r8
leaq 0x40530(%rsp), %rbx
leaq 0x40570(%rsp), %r11
leaq 0x405b0(%rsp), %r10
leaq 0x406c0(%rsp), %rsi
xorl %r9d, %r9d
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
callq *%rax
cmpl $0x0, %eax
je 0x3751
jmp 0x3dee
cmpq $0x100, 0x406c0(%rsp) # imm = 0x100
jbe 0x3764
jmp 0x3dee
callq 0x1080
movq %rax, 0x40128(%rsp)
movq $0x0, 0x406b8(%rsp)
leaq 0x405b0(%rsp), %rdi
movq 0x406e0(%rsp), %rax
movl 0x10(%rax), %esi
callq 0x1dd0
leaq 0x40570(%rsp), %rdi
movq 0x406e0(%rsp), %rax
movl 0x18(%rax), %esi
callq 0x1dd0
leaq 0x40530(%rsp), %rdi
movq 0x406e0(%rsp), %rax
movl 0x14(%rax), %esi
callq 0x1dd0
leaq 0x40430(%rsp), %rdi
movq 0x406c8(%rsp), %rax
movl %eax, %esi
callq 0x1dd0
movq 0x406e0(%rsp), %rax
movq 0x28(%rax), %rax
leaq 0x40230(%rsp), %rdi
leaq 0x40430(%rsp), %rdx
movq 0x406c8(%rsp), %rcx
leaq 0x40430(%rsp), %r8
leaq 0x40530(%rsp), %rbx
leaq 0x40570(%rsp), %r11
leaq 0x405b0(%rsp), %r10
leaq 0x406c0(%rsp), %rsi
xorl %r9d, %r9d
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
callq *%rax
cmpl $0x0, %eax
je 0x3845
jmp 0x3dee
movl $0x0, 0x406d8(%rsp)
movslq 0x406d8(%rsp), %rax
cmpq 0x406c8(%rsp), %rax
jae 0x39ae
leaq 0x40330(%rsp), %rdi
leaq 0x40430(%rsp), %rsi
movq 0x406c8(%rsp), %rdx
callq 0x1120
movb $0x0, %al
callq 0x1da0
movl $0xff, %ecx
xorl %edx, %edx
divl %ecx
addl $0x1, %edx
movslq 0x406d8(%rsp), %rax
movzbl 0x40330(%rsp,%rax), %ecx
addl %edx, %ecx
movb %cl, 0x40330(%rsp,%rax)
movq 0x406e0(%rsp), %rax
movq 0x28(%rax), %rax
leaq 0x40130(%rsp), %rdi
leaq 0x40330(%rsp), %rdx
movq 0x406c8(%rsp), %rcx
leaq 0x40430(%rsp), %r8
leaq 0x40530(%rsp), %rbx
leaq 0x40570(%rsp), %r11
leaq 0x405b0(%rsp), %r10
leaq 0x406c0(%rsp), %rsi
xorl %r9d, %r9d
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
callq *%rax
cmpl $0x0, %eax
je 0x3918
jmp 0x3dee
movl $0x0, 0x406d4(%rsp)
movslq 0x406d4(%rsp), %rax
cmpq 0x406c0(%rsp), %rax
jae 0x3996
movslq 0x406d4(%rsp), %rax
movzbl 0x40230(%rsp,%rax), %eax
movslq 0x406d4(%rsp), %rcx
movzbl 0x40130(%rsp,%rcx), %ecx
cmpl %ecx, %eax
je 0x3981
movslq 0x406d8(%rsp), %rcx
leaq 0x120(%rsp), %rax
shlq $0xa, %rcx
addq %rcx, %rax
movslq 0x406d4(%rsp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
jmp 0x3983
movl 0x406d4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x406d4(%rsp)
jmp 0x3923
jmp 0x3998
movl 0x406d8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x406d8(%rsp)
jmp 0x3850
movq 0x406b8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x406b8(%rsp)
callq 0x1080
subq 0x40128(%rsp), %rax
movq %rax, 0x40120(%rsp)
movq 0x40120(%rsp), %rax
movslq 0x406dc(%rsp), %rcx
cmpq %rcx, %rax
jl 0x377d
leaq 0x20(%rsp), %rdi
movq 0x406e0(%rsp), %rax
movq 0x8(%rax), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x1060
movl $0x0, 0x406d8(%rsp)
movslq 0x406d8(%rsp), %rax
cmpq $0x100, %rax            # imm = 0x100
jae 0x3a61
movslq 0x406d8(%rsp), %rax
movsbl 0x20(%rsp,%rax), %eax
cmpl $0x0, %eax
je 0x3a4a
movslq 0x406d8(%rsp), %rax
movsbl 0x20(%rsp,%rax), %eax
cmpl $0x2d, %eax
jne 0x3a4c
jmp 0x3a61
jmp 0x3a4e
movl 0x406d8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x406d8(%rsp)
jmp 0x3a16
movslq 0x406d8(%rsp), %rax
leaq 0x20(%rsp), %rdi
addq %rax, %rdi
movslq 0x406d8(%rsp), %rax
movl $0x100, %edx            # imm = 0x100
subq %rax, %rdx
leaq 0xf09(%rip), %rsi       # 0x4991
callq 0x1060
leaq 0x20(%rsp), %rdi
leaq 0xefd(%rip), %rsi       # 0x4996
callq 0x1180
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
jne 0x3ac5
leaq 0x20(%rsp), %rdi
callq 0x1190
movl $0x1, 0x406ec(%rsp)
jmp 0x3e13
movslq 0x406d8(%rsp), %rax
movb $0x0, 0x20(%rsp,%rax)
movq 0x18(%rsp), %rdi
leaq 0x20(%rsp), %rdx
movq 0x406e0(%rsp), %rax
movl 0x10(%rax), %ecx
shll $0x3, %ecx
movq 0x406e0(%rsp), %rax
movl 0x14(%rax), %r8d
shll $0x3, %r8d
movq 0x406e0(%rsp), %rax
movl 0x18(%rax), %r9d
shll $0x3, %r9d
movq 0x406e0(%rsp), %rax
movl 0x1c(%rax), %eax
shll $0x3, %eax
leaq 0xe79(%rip), %rsi       # 0x4998
movl %eax, (%rsp)
movb $0x0, %al
callq 0x1100
movq 0x18(%rsp), %rdi
callq 0x1090
movslq 0x406d8(%rsp), %rax
leaq 0x20(%rsp), %rdi
addq %rax, %rdi
movslq 0x406d8(%rsp), %rax
movl $0x100, %edx            # imm = 0x100
subq %rax, %rdx
leaq 0xe68(%rip), %rsi       # 0x49c2
callq 0x1060
leaq 0x20(%rsp), %rdi
leaq 0xe2b(%rip), %rsi       # 0x4996
callq 0x1180
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
jne 0x3b97
leaq 0x20(%rsp), %rdi
callq 0x1190
movl $0x1, 0x406ec(%rsp)
jmp 0x3e13
movq 0x18(%rsp), %rdi
leaq 0x20(%rsp), %rdx
movq 0x406c0(%rsp), %rax
movl %eax, %ecx
addl $0x2, %ecx
movq 0x406c8(%rsp), %rax
movl %eax, %r8d
addl $0x2, %r8d
leaq 0xe03(%rip), %rsi       # 0x49c7
movb $0x0, %al
callq 0x1100
movl $0x0, 0x406d8(%rsp)
movslq 0x406d8(%rsp), %rax
movq 0x406c0(%rsp), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jae 0x3c15
movq 0x18(%rsp), %rdi
leaq 0xde9(%rip), %rsi       # 0x49e4
movb $0x0, %al
callq 0x1100
movl 0x406d8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x406d8(%rsp)
jmp 0x3bd6
movq 0x18(%rsp), %rdi
leaq 0xdb9(%rip), %rsi       # 0x49da
movb $0x0, %al
callq 0x1100
movl $0x0, 0x406d8(%rsp)
movslq 0x406d8(%rsp), %rax
cmpq 0x406c8(%rsp), %rax
jae 0x3d7a
movq 0x18(%rsp), %rdi
leaq 0xd8f(%rip), %rsi       # 0x49e4
movb $0x0, %al
callq 0x1100
movl $0x0, 0x406d4(%rsp)
movslq 0x406d4(%rsp), %rax
cmpq 0x406c0(%rsp), %rax
jae 0x3d51
movl 0x406d8(%rsp), %eax
andl $0xf, %eax
cmpl $0x0, %eax
je 0x3c9b
movl 0x406d4(%rsp), %eax
andl $0xf, %eax
cmpl $0x0, %eax
jne 0x3cea
movslq 0x406d8(%rsp), %rcx
leaq 0x120(%rsp), %rax
shlq $0xa, %rcx
addq %rcx, %rax
movslq 0x406d4(%rsp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jbe 0x3cd5
movq 0x18(%rsp), %rdi
leaq 0xd12(%rip), %rsi       # 0x49de
movb $0x0, %al
callq 0x1100
jmp 0x3ce8
movq 0x18(%rsp), %rdi
leaq 0xcfc(%rip), %rsi       # 0x49dd
movb $0x0, %al
callq 0x1100
jmp 0x3d39
movslq 0x406d8(%rsp), %rcx
leaq 0x120(%rsp), %rax
shlq $0xa, %rcx
addq %rcx, %rax
movslq 0x406d4(%rsp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jbe 0x3d24
movq 0x18(%rsp), %rdi
leaq 0xcc9(%rip), %rsi       # 0x49e4
movb $0x0, %al
callq 0x1100
jmp 0x3d37
movq 0x18(%rsp), %rdi
leaq 0xcb2(%rip), %rsi       # 0x49e2
movb $0x0, %al
callq 0x1100
jmp 0x3d39
jmp 0x3d3b
movl 0x406d4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x406d4(%rsp)
jmp 0x3c67
movq 0x18(%rsp), %rdi
leaq 0xc7d(%rip), %rsi       # 0x49da
movb $0x0, %al
callq 0x1100
movl 0x406d8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x406d8(%rsp)
jmp 0x3c33
movl $0x0, 0x406d8(%rsp)
movslq 0x406d8(%rsp), %rax
movq 0x406c0(%rsp), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jae 0x3dc4
movq 0x18(%rsp), %rdi
leaq 0xc3a(%rip), %rsi       # 0x49e4
movb $0x0, %al
callq 0x1100
movl 0x406d8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x406d8(%rsp)
jmp 0x3d85
movq 0x18(%rsp), %rdi
leaq 0xc0a(%rip), %rsi       # 0x49da
movb $0x0, %al
callq 0x1100
movq 0x18(%rsp), %rdi
callq 0x1090
movl $0x0, 0x406ec(%rsp)
jmp 0x3e13
movq 0x406e0(%rsp), %rax
movq 0x8(%rax), %rsi
leaq 0xbe6(%rip), %rdi       # 0x49e7
movb $0x0, %al
callq 0x10a0
movl $0x1, 0x406ec(%rsp)
movl 0x406ec(%rsp), %eax
addq $0x406f0, %rsp          # imm = 0x406F0
popq %rbx
retq