// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/acorn128v2/ref/encrypt.c
// Function: crypto_aead_decrypt
int crypto_aead_decrypt(
	unsigned char *m,unsigned long long *mlen,
	unsigned char *nsec,
	const unsigned char *c,unsigned long long clen,
	const unsigned char *ad,unsigned long long adlen,
	const unsigned char *npub,
	const unsigned char *k
	)
{
    unsigned long long i;
    unsigned char plaintextbyte, ciphertextbyte, ksbyte;
    unsigned char state[293];
    unsigned char tag[16];
    unsigned char check = 0;
    unsigned char ca, cb;

    if (clen < 16) return -1;

    //initialization stage
    acorn128_initialization(k, npub, state);

    //process the associated data
    for (i = 0; i < adlen; i++)
    {
        acorn128_enc_onebyte(state, ad[i], &ciphertextbyte, &ksbyte, 0xff, 0xff);
    }

    for (i = 0; i < 256/8; i++)
    {
        if ( i == 0 ) plaintextbyte = 0x1;
        else plaintextbyte = 0;

        if ( i < 128/8)   ca = 0xff;
        else ca = 0;

        cb = 0xff;

        acorn128_enc_onebyte(state, plaintextbyte, &ciphertextbyte, &ksbyte, ca, cb);
    }

    //process the ciphertext
    *mlen = clen - 16;

    for (i = 0; i < *mlen; i++)
    {
        acorn128_dec_onebyte(state, &m[i], c[i], &ksbyte, 0xff, 0);
    }

    for (i = 0; i < 256/8; i++)
    {
        if ( i == 0 ) plaintextbyte = 0x1;
        else plaintextbyte = 0;

        if ( i < 128/8)   ca = 0xff;
        else ca = 0;

        cb = 0;

        acorn128_enc_onebyte(state, plaintextbyte, &ciphertextbyte, &ksbyte, ca, cb);
    }

    //finalization stage, we assume that the tag length is a multiple of bytes
    acorn128_tag_generation(*mlen, adlen, 16, tag, state);

    for (i = 0; i  < 16; i++) check |= (tag[i] ^ c[clen - 16 + i]);
    if (check == 0) return 0;
    else return -1;
}

// Assembly:
subq $0x188, %rsp            # imm = 0x188
movq 0x1a0(%rsp), %rax
movq 0x198(%rsp), %rax
movq 0x190(%rsp), %rax
movq %rdi, 0x178(%rsp)
movq %rsi, 0x170(%rsp)
movq %rdx, 0x168(%rsp)
movq %rcx, 0x160(%rsp)
movq %r8, 0x158(%rsp)
movq %r9, 0x150(%rsp)
movb $0x0, 0xf(%rsp)
cmpq $0x10, 0x158(%rsp)
jae 0x1ecf
movl $0xffffffff, 0x184(%rsp) # imm = 0xFFFFFFFF
jmp 0x21d3
movq 0x1a0(%rsp), %rdi
movq 0x198(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x10c0
movq $0x0, 0x148(%rsp)
movq 0x148(%rsp), %rax
cmpq 0x190(%rsp), %rax
jae 0x1f54
leaq 0x20(%rsp), %rdi
movq 0x150(%rsp), %rax
movq 0x148(%rsp), %rsi
leaq 0x146(%rsp), %rdx
leaq 0x145(%rsp), %rcx
movl $0xff, %r9d
movzbl (%rax,%rsi), %esi
movl %r9d, %r8d
callq 0x10d0
movq 0x148(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x148(%rsp)
jmp 0x1ef5
movq $0x0, 0x148(%rsp)
cmpq $0x20, 0x148(%rsp)
jae 0x1ff5
cmpq $0x0, 0x148(%rsp)
jne 0x1f84
movb $0x1, 0x147(%rsp)
jmp 0x1f8c
movb $0x0, 0x147(%rsp)
cmpq $0x10, 0x148(%rsp)
jae 0x1f9e
movb $-0x1, 0xe(%rsp)
jmp 0x1fa3
movb $0x0, 0xe(%rsp)
movb $-0x1, 0xd(%rsp)
leaq 0x20(%rsp), %rdi
movb 0x147(%rsp), %sil
movb 0xe(%rsp), %al
leaq 0x146(%rsp), %rdx
leaq 0x145(%rsp), %rcx
movzbl %sil, %esi
movzbl %al, %r8d
movzbl 0xd(%rsp), %r9d
callq 0x10d0
movq 0x148(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x148(%rsp)
jmp 0x1f60
movq 0x158(%rsp), %rcx
subq $0x10, %rcx
movq 0x170(%rsp), %rax
movq %rcx, (%rax)
movq $0x0, 0x148(%rsp)
movq 0x148(%rsp), %rax
movq 0x170(%rsp), %rcx
cmpq (%rcx), %rax
jae 0x2082
leaq 0x20(%rsp), %rdi
movq 0x178(%rsp), %rsi
addq 0x148(%rsp), %rsi
movq 0x160(%rsp), %rax
movq 0x148(%rsp), %rdx
leaq 0x145(%rsp), %rcx
movl $0xff, %r8d
xorl %r9d, %r9d
movzbl (%rax,%rdx), %edx
callq 0x10b0
movq 0x148(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x148(%rsp)
jmp 0x2018
movq $0x0, 0x148(%rsp)
cmpq $0x20, 0x148(%rsp)
jae 0x2123
cmpq $0x0, 0x148(%rsp)
jne 0x20b2
movb $0x1, 0x147(%rsp)
jmp 0x20ba
movb $0x0, 0x147(%rsp)
cmpq $0x10, 0x148(%rsp)
jae 0x20cc
movb $-0x1, 0xe(%rsp)
jmp 0x20d1
movb $0x0, 0xe(%rsp)
movb $0x0, 0xd(%rsp)
leaq 0x20(%rsp), %rdi
movb 0x147(%rsp), %sil
movb 0xe(%rsp), %al
leaq 0x146(%rsp), %rdx
leaq 0x145(%rsp), %rcx
movzbl %sil, %esi
movzbl %al, %r8d
movzbl 0xd(%rsp), %r9d
callq 0x10d0
movq 0x148(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x148(%rsp)
jmp 0x208e
movq 0x170(%rsp), %rax
movq (%rax), %rdi
movq 0x190(%rsp), %rsi
leaq 0x10(%rsp), %rcx
leaq 0x20(%rsp), %r8
movl $0x10, %edx
callq 0x1090
movq $0x0, 0x148(%rsp)
cmpq $0x10, 0x148(%rsp)
jae 0x21b1
movq 0x148(%rsp), %rax
movzbl 0x10(%rsp,%rax), %ecx
movq 0x160(%rsp), %rax
movq 0x158(%rsp), %rdx
subq $0x10, %rdx
addq 0x148(%rsp), %rdx
movzbl (%rax,%rdx), %eax
xorl %eax, %ecx
movzbl 0xf(%rsp), %eax
orl %ecx, %eax
movb %al, 0xf(%rsp)
movq 0x148(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x148(%rsp)
jmp 0x2156
movzbl 0xf(%rsp), %eax
cmpl $0x0, %eax
jne 0x21c8
movl $0x0, 0x184(%rsp)
jmp 0x21d3
movl $0xffffffff, 0x184(%rsp) # imm = 0xFFFFFFFF
movl 0x184(%rsp), %eax
addq $0x188, %rsp            # imm = 0x188
retq
nopw %cs:(%rax,%rax)
nopl (%rax)