// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/aezv3/ref/aez_ref.c
// Function: AEZtiny
static void AEZtiny(byte *K, unsigned kbytes, byte delta[16],
                        byte *in, unsigned inbytes, unsigned d, byte *out) {
    unsigned rounds,i,j=7,k;
    int step;
    byte mask=0x00, pad=0x80, L[16], R[16], buf[32];
    if      (inbytes==1) rounds=24;
    else if (inbytes==2) rounds=16;
    else if (inbytes<16) rounds=10;
    else {          j=6; rounds=8; }
    /* Split (inbytes*8)/2 bits into L and R. Beware: May end in nibble. */
    memcpy(L, in,           (inbytes+1)/2);
    memcpy(R, in+inbytes/2, (inbytes+1)/2);
    if (inbytes&1) {                     /* Must shift R left by half a byte */
        for (i=0; i<inbytes/2; i++)
            R[i] = (byte)((R[i] << 4) | (R[i+1] >> 4));
        R[inbytes/2] = (byte)(R[inbytes/2] << 4);
        pad = 0x08; mask = 0xf0;
    }
    if (d) {
        if (inbytes < 16) {
            memset(buf,0,16); memcpy(buf,in,inbytes); buf[0] |= 0x80;
            xor_bytes(delta, buf, 16, buf);
            E(K, kbytes,0,3,buf,buf);
            L[0] ^= (buf[0] & 0x80);
        }
        i = rounds-1; step = -1;
    } else {
        i = 0; step = 1;
    }
    for (k=0; k<rounds/2; k++,i=(unsigned)((int)i+2*step)) {
        memset(buf, 0, 16);
        memcpy(buf,R,(inbytes+1)/2);
        buf[inbytes/2] = (buf[inbytes/2] & mask) | pad;
        xor_bytes(buf, delta, 16, buf);
        buf[15] ^= (byte)i;
        E(K, kbytes,0,j,buf,buf);
        xor_bytes(L, buf, 16, L);

        memset(buf, 0, 16);
        memcpy(buf,L,(inbytes+1)/2);
        buf[inbytes/2] = (buf[inbytes/2] & mask) | pad;
        xor_bytes(buf, delta, 16, buf);
        buf[15] ^= (byte)((int)i+step);
        E(K, kbytes,0,j,buf,buf);
        xor_bytes(R, buf, 16, R);
    }
    memcpy(buf,           R, inbytes/2);
    memcpy(buf+inbytes/2, L, (inbytes+1)/2);
    if (inbytes&1) {
        for (i=inbytes-1; i>inbytes/2; i--)
            buf[i] = (byte)((buf[i] >> 4) | (buf[i-1] << 4));
        buf[inbytes/2] = (byte)((L[0] >> 4) | (R[inbytes/2] & 0xf0));
    }
    memcpy(out,buf,inbytes);
    if ((inbytes < 16) && !d) {
        memset(buf+inbytes,0,16-inbytes); buf[0] |= 0x80;
        xor_bytes(delta, buf, 16, buf);
        E(K, kbytes,0,3,buf,buf);
        out[0] ^= (buf[0] & 0x80);
    }
}

// Assembly:
subq $0x88, %rsp
movq 0x90(%rsp), %rax
movq %rdi, 0x80(%rsp)
movl %esi, 0x7c(%rsp)
movq %rdx, 0x70(%rsp)
movq %rcx, 0x68(%rsp)
movl %r8d, 0x64(%rsp)
movl %r9d, 0x60(%rsp)
movl $0x7, 0x54(%rsp)
movb $0x0, 0x4b(%rsp)
movb $-0x80, 0x4a(%rsp)
cmpl $0x1, 0x64(%rsp)
jne 0x2792
movl $0x18, 0x5c(%rsp)
jmp 0x27c8
cmpl $0x2, 0x64(%rsp)
jne 0x27a3
movl $0x10, 0x5c(%rsp)
jmp 0x27c6
cmpl $0x10, 0x64(%rsp)
jae 0x27b4
movl $0xa, 0x5c(%rsp)
jmp 0x27c4
movl $0x6, 0x54(%rsp)
movl $0x8, 0x5c(%rsp)
jmp 0x27c6
jmp 0x27c8
leaq 0x30(%rsp), %rdi
movq 0x68(%rsp), %rsi
movl 0x64(%rsp), %eax
addl $0x1, %eax
shrl %eax
movl %eax, %eax
movl %eax, %edx
callq 0x10d0
leaq 0x20(%rsp), %rdi
movq 0x68(%rsp), %rsi
movl 0x64(%rsp), %eax
shrl %eax
movl %eax, %eax
addq %rax, %rsi
movl 0x64(%rsp), %eax
addl $0x1, %eax
shrl %eax
movl %eax, %eax
movl %eax, %edx
callq 0x10d0
movl 0x64(%rsp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x288b
movl $0x0, 0x58(%rsp)
movl 0x58(%rsp), %eax
movl 0x64(%rsp), %ecx
shrl %ecx
cmpl %ecx, %eax
jae 0x2863
movl 0x58(%rsp), %eax
movzbl 0x20(%rsp,%rax), %eax
shll $0x4, %eax
movl 0x58(%rsp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movzbl 0x20(%rsp,%rcx), %ecx
sarl $0x4, %ecx
orl %ecx, %eax
movb %al, %cl
movl 0x58(%rsp), %eax
movb %cl, 0x20(%rsp,%rax)
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0x281f
movl 0x64(%rsp), %eax
shrl %eax
movl %eax, %eax
movzbl 0x20(%rsp,%rax), %eax
shll $0x4, %eax
movb %al, %cl
movl 0x64(%rsp), %eax
shrl %eax
movl %eax, %eax
movb %cl, 0x20(%rsp,%rax)
movb $0x8, 0x4a(%rsp)
movb $-0x10, 0x4b(%rsp)
cmpl $0x0, 0x60(%rsp)
je 0x2928
cmpl $0x10, 0x64(%rsp)
jae 0x2913
movq %rsp, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1040
movq %rsp, %rdi
movq 0x68(%rsp), %rsi
movl 0x64(%rsp), %eax
movl %eax, %edx
callq 0x10d0
movzbl (%rsp), %eax
orl $0x80, %eax
movb %al, (%rsp)
movq 0x70(%rsp), %rdi
movq %rsp, %rsi
movq %rsp, %rcx
movl $0x10, %edx
callq 0x2170
movq 0x80(%rsp), %rdi
movl 0x7c(%rsp), %esi
movq %rsp, %r8
movq %rsp, %r9
xorl %edx, %edx
movl $0x3, %ecx
callq 0x1c40
movzbl (%rsp), %ecx
andl $0x80, %ecx
movzbl 0x30(%rsp), %eax
xorl %ecx, %eax
movb %al, 0x30(%rsp)
movl 0x5c(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x58(%rsp)
movl $0xffffffff, 0x4c(%rsp) # imm = 0xFFFFFFFF
jmp 0x2938
movl $0x0, 0x58(%rsp)
movl $0x1, 0x4c(%rsp)
movl $0x0, 0x50(%rsp)
movl 0x50(%rsp), %eax
movl 0x5c(%rsp), %ecx
shrl %ecx
cmpl %ecx, %eax
jae 0x2acc
movq %rsp, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1040
movq %rsp, %rdi
leaq 0x20(%rsp), %rsi
movl 0x64(%rsp), %eax
addl $0x1, %eax
shrl %eax
movl %eax, %eax
movl %eax, %edx
callq 0x10d0
movl 0x64(%rsp), %eax
shrl %eax
movl %eax, %eax
movzbl (%rsp,%rax), %eax
movzbl 0x4b(%rsp), %ecx
andl %ecx, %eax
movzbl 0x4a(%rsp), %ecx
orl %ecx, %eax
movb %al, %cl
movl 0x64(%rsp), %eax
shrl %eax
movl %eax, %eax
movb %cl, (%rsp,%rax)
movq %rsp, %rdi
movq 0x70(%rsp), %rsi
movq %rsp, %rcx
movl $0x10, %edx
callq 0x2170
movl 0x58(%rsp), %eax
movzbl %al, %ecx
movzbl 0xf(%rsp), %eax
xorl %ecx, %eax
movb %al, 0xf(%rsp)
movq 0x80(%rsp), %rdi
movl 0x7c(%rsp), %esi
movl 0x54(%rsp), %ecx
movq %rsp, %r8
movq %rsp, %r9
xorl %edx, %edx
callq 0x1c40
leaq 0x30(%rsp), %rdi
movq %rsp, %rsi
leaq 0x30(%rsp), %rcx
movl $0x10, %edx
callq 0x2170
movq %rsp, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1040
movq %rsp, %rdi
leaq 0x30(%rsp), %rsi
movl 0x64(%rsp), %eax
addl $0x1, %eax
shrl %eax
movl %eax, %eax
movl %eax, %edx
callq 0x10d0
movl 0x64(%rsp), %eax
shrl %eax
movl %eax, %eax
movzbl (%rsp,%rax), %eax
movzbl 0x4b(%rsp), %ecx
andl %ecx, %eax
movzbl 0x4a(%rsp), %ecx
orl %ecx, %eax
movb %al, %cl
movl 0x64(%rsp), %eax
shrl %eax
movl %eax, %eax
movb %cl, (%rsp,%rax)
movq %rsp, %rdi
movq 0x70(%rsp), %rsi
movq %rsp, %rcx
movl $0x10, %edx
callq 0x2170
movl 0x58(%rsp), %eax
addl 0x4c(%rsp), %eax
movzbl %al, %ecx
movzbl 0xf(%rsp), %eax
xorl %ecx, %eax
movb %al, 0xf(%rsp)
movq 0x80(%rsp), %rdi
movl 0x7c(%rsp), %esi
movl 0x54(%rsp), %ecx
movq %rsp, %r8
movq %rsp, %r9
xorl %edx, %edx
callq 0x1c40
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
leaq 0x20(%rsp), %rcx
movl $0x10, %edx
callq 0x2170
movl 0x50(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x50(%rsp)
movl 0x58(%rsp), %eax
movl 0x4c(%rsp), %ecx
shll %ecx
addl %ecx, %eax
movl %eax, 0x58(%rsp)
jmp 0x2940
movq %rsp, %rdi
leaq 0x20(%rsp), %rsi
movl 0x64(%rsp), %eax
shrl %eax
movl %eax, %eax
movl %eax, %edx
callq 0x10d0
movq %rsp, %rdi
movl 0x64(%rsp), %eax
shrl %eax
movl %eax, %eax
addq %rax, %rdi
leaq 0x30(%rsp), %rsi
movl 0x64(%rsp), %eax
addl $0x1, %eax
shrl %eax
movl %eax, %eax
movl %eax, %edx
callq 0x10d0
movl 0x64(%rsp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2b8a
movl 0x64(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x58(%rsp)
movl 0x58(%rsp), %eax
movl 0x64(%rsp), %ecx
shrl %ecx
cmpl %ecx, %eax
jbe 0x2b60
movl 0x58(%rsp), %eax
movzbl (%rsp,%rax), %eax
sarl $0x4, %eax
movl 0x58(%rsp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movzbl (%rsp,%rcx), %ecx
shll $0x4, %ecx
orl %ecx, %eax
movb %al, %cl
movl 0x58(%rsp), %eax
movb %cl, (%rsp,%rax)
movl 0x58(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0x2b1f
movzbl 0x30(%rsp), %eax
sarl $0x4, %eax
movl 0x64(%rsp), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl 0x20(%rsp,%rcx), %ecx
andl $0xf0, %ecx
orl %ecx, %eax
movb %al, %cl
movl 0x64(%rsp), %eax
shrl %eax
movl %eax, %eax
movb %cl, (%rsp,%rax)
movq 0x90(%rsp), %rdi
movq %rsp, %rsi
movl 0x64(%rsp), %eax
movl %eax, %edx
callq 0x10d0
cmpl $0x10, 0x64(%rsp)
jae 0x2c24
cmpl $0x0, 0x60(%rsp)
jne 0x2c24
movq %rsp, %rdi
movl 0x64(%rsp), %eax
addq %rax, %rdi
movl $0x10, %eax
subl 0x64(%rsp), %eax
movl %eax, %eax
movl %eax, %edx
xorl %esi, %esi
callq 0x1040
movzbl (%rsp), %eax
orl $0x80, %eax
movb %al, (%rsp)
movq 0x70(%rsp), %rdi
movq %rsp, %rsi
movq %rsp, %rcx
movl $0x10, %edx
callq 0x2170
movq 0x80(%rsp), %rdi
movl 0x7c(%rsp), %esi
movq %rsp, %r8
movq %rsp, %r9
xorl %edx, %edx
movl $0x3, %ecx
callq 0x1c40
movzbl (%rsp), %edx
andl $0x80, %edx
movq 0x90(%rsp), %rax
movzbl (%rax), %ecx
xorl %edx, %ecx
movb %cl, (%rax)
addq $0x88, %rsp
retq
nopl (%rax)