// File: /workspace/github_c_makefile_star2_O1/mjosaarinen[P]brutus/src/kat.c
// Function: do_kat
void do_kat(caesar_t *aead, int mlen, int adlen)
{
    int ret;
    unsigned long long clen;

    uint8_t key[80], nsec[64], osec[64], npub[64];
    // that 524304 ABYTES factor comes from Trivia. Don't ask.
    uint8_t pt[KAT_LIMIT], ad[KAT_LIMIT], ct[KAT_LIMIT + 524304];

    if (aead->name == NULL ||
        aead->abytes + sizeof(pt) > sizeof(ct) ||
        aead->keybytes > sizeof(key) || aead->nsecbytes > sizeof(nsec) ||
        aead->nsecbytes > sizeof(osec) || aead->npubbytes > sizeof(npub)) {
        fprintf(stderr, "do_kat(): invalid parameters\n");
    }

    memset(pt, 0x00, sizeof(pt));
    memset(ad, 0x00, sizeof(ad));
    memset(ct, 0x00, sizeof(ct));
    memset(key, 0x00, sizeof(key));
    memset(nsec, 0x00, sizeof(nsec));
    memset(npub, 0x00, sizeof(npub));

    detseq_fill(key, aead->keybytes);
    detseq_fill(pt, mlen);
    detseq_fill(ad, adlen);
    detseq_fill(npub, aead->npubbytes);
    detseq_fill(nsec, aead->nsecbytes);

    kat_vec(key, aead->keybytes, "key");
    kat_vec(nsec, aead->nsecbytes, "nsec");
    kat_vec(npub, aead->npubbytes, "npub");
    kat_vec(pt, mlen, "m");
    kat_vec(ad, adlen, "ad");

    ret = aead->encrypt(ct, &clen, pt, mlen,
        ad, adlen, nsec, npub, key);
    if (ret != 0) {
        printf("[%s] encrypt failed with code %d\n", aead->name, ret);
        return;
    }
    kat_vec(ct, clen, "c");
    printf("\n");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb00f8, %rsp          # imm = 0xB00F8
movl %edx, %ebp
movl %esi, %r14d
movq %rdi, %rbx
cmpq $0x0, 0x8(%rdi)
je 0x2732
movslq 0x1c(%rbx), %rax
addq $-0x80011, %rax         # imm = 0xFFF7FFEF
cmpq $-0x90011, %rax         # imm = 0xFFF6FFEF
jb 0x2732
cmpl $0x50, 0x10(%rbx)
ja 0x2732
cmpl $0x40, 0x14(%rbx)
ja 0x2732
cmpl $0x41, 0x18(%rbx)
jb 0x2737
callq 0x129c
leaq 0x100e0(%rsp), %rdi
movl $0x10000, %edx          # imm = 0x10000
xorl %esi, %esi
callq 0x10d0
leaq 0xe0(%rsp), %rdi
movl $0x10000, %edx          # imm = 0x10000
xorl %esi, %esi
callq 0x10d0
leaq 0x200e0(%rsp), %rdi
movl $0x90010, %edx          # imm = 0x90010
xorl %esi, %esi
callq 0x10d0
vxorps %xmm0, %xmm0, %xmm0
leaq 0x90(%rsp), %r13
vmovups %ymm0, (%r13)
vmovups %ymm0, 0x20(%r13)
vmovups %ymm0, 0x30(%r13)
leaq 0x50(%rsp), %r15
vmovups %ymm0, (%r15)
vmovups %ymm0, 0x20(%r15)
leaq 0x10(%rsp), %r12
vmovups %ymm0, (%r12)
vmovups %ymm0, 0x20(%r12)
movl 0x10(%rbx), %esi
movq %r13, %rdi
vzeroupper
callq 0x1a4a
leaq 0x100e0(%rsp), %rdi
movl %r14d, %esi
callq 0x1a4a
leaq 0xe0(%rsp), %rdi
movl %ebp, %esi
callq 0x1a4a
movl 0x18(%rbx), %esi
movq %r12, %rdi
callq 0x1a4a
movl 0x14(%rbx), %esi
movq %r15, %rdi
callq 0x1a4a
movl 0x10(%rbx), %esi
leaq 0x2034(%rip), %rdx      # 0x4834
movq %r13, %rdi
callq 0x2694
movl 0x14(%rbx), %esi
leaq 0x21fc(%rip), %rdx      # 0x4a0e
movq %r15, %rdi
callq 0x2694
movl 0x18(%rbx), %esi
leaq 0x2014(%rip), %rdx      # 0x4838
movq %r12, %rdi
callq 0x2694
leaq 0x2327(%rip), %rdx      # 0x4b5a
leaq 0x100e0(%rsp), %rdi
movl %r14d, %esi
callq 0x2694
leaq 0x1ff3(%rip), %rdx      # 0x483d
leaq 0xe0(%rsp), %rdi
movl %ebp, %esi
callq 0x2694
movslq %r14d, %rcx
movslq %ebp, %r9
subq $0x8, %rsp
leaq 0x10(%rsp), %rsi
leaq 0x200e8(%rsp), %rdi
leaq 0x100e8(%rsp), %rdx
leaq 0xe8(%rsp), %r8
pushq %r13
pushq %r12
pushq %r15
callq *0x28(%rbx)
addq $0x20, %rsp
testl %eax, %eax
je 0x28a7
movq 0x8(%rbx), %rsi
leaq 0x2177(%rip), %rdi      # 0x4a13
movl %eax, %edx
xorl %eax, %eax
callq 0x10b0
jmp 0x28c9
movl 0x8(%rsp), %esi
leaq 0x215f(%rip), %rdx      # 0x4a11
leaq 0x200e0(%rsp), %rdi
callq 0x2694
movl $0xa, %edi
callq 0x1050
addq $0xb00f8, %rsp          # imm = 0xB00F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq