// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/aezv4/ref/encrypt.c
// Function: AEZtiny
static void AEZtiny(byte *K, unsigned kbytes, byte delta[16],
                        byte *in, unsigned inbytes, unsigned d, byte *out) {
    unsigned rounds,i=7,j,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 {          i=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 (k=0; k<inbytes/2; k++)
            R[k] = (byte)((R[k] << 4) | (R[k+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);
        }
        j = rounds-1; step = -1;
    } else {
        j = 0; step = 1;
    }
    for (k=0; k<rounds/2; k++,j=(unsigned)((int)j+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)j;
        E(K, kbytes,0,i,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)j+step);
        E(K, kbytes,0,i,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 (k=inbytes-1; k>inbytes/2; k--)
            buf[k] = (byte)((buf[k] >> 4) | (buf[k-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, 0x58(%rsp)
movb $0x0, 0x4b(%rsp)
movb $-0x80, 0x4a(%rsp)
cmpl $0x1, 0x64(%rsp)
jne 0x3762
movl $0x18, 0x5c(%rsp)
jmp 0x3798
cmpl $0x2, 0x64(%rsp)
jne 0x3773
movl $0x10, 0x5c(%rsp)
jmp 0x3796
cmpl $0x10, 0x64(%rsp)
jae 0x3784
movl $0xa, 0x5c(%rsp)
jmp 0x3794
movl $0x6, 0x58(%rsp)
movl $0x8, 0x5c(%rsp)
jmp 0x3796
jmp 0x3798
leaq 0x30(%rsp), %rdi
movq 0x68(%rsp), %rsi
movl 0x64(%rsp), %eax
addl $0x1, %eax
shrl %eax
movl %eax, %eax
movl %eax, %edx
callq 0x1110
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 0x1110
movl 0x64(%rsp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x385b
movl $0x0, 0x50(%rsp)
movl 0x50(%rsp), %eax
movl 0x64(%rsp), %ecx
shrl %ecx
cmpl %ecx, %eax
jae 0x3833
movl 0x50(%rsp), %eax
movzbl 0x20(%rsp,%rax), %eax
shll $0x4, %eax
movl 0x50(%rsp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movzbl 0x20(%rsp,%rcx), %ecx
sarl $0x4, %ecx
orl %ecx, %eax
movb %al, %cl
movl 0x50(%rsp), %eax
movb %cl, 0x20(%rsp,%rax)
movl 0x50(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x50(%rsp)
jmp 0x37ef
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 0x38f8
cmpl $0x10, 0x64(%rsp)
jae 0x38e3
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 0x1110
movzbl (%rsp), %eax
orl $0x80, %eax
movb %al, (%rsp)
movq 0x70(%rsp), %rdi
movq %rsp, %rsi
movq %rsp, %rcx
movl $0x10, %edx
callq 0x34d0
movq 0x80(%rsp), %rdi
movl 0x7c(%rsp), %esi
movq %rsp, %r8
movq %rsp, %r9
xorl %edx, %edx
movl $0x3, %ecx
callq 0x2ed0
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, 0x54(%rsp)
movl $0xffffffff, 0x4c(%rsp) # imm = 0xFFFFFFFF
jmp 0x3908
movl $0x0, 0x54(%rsp)
movl $0x1, 0x4c(%rsp)
movl $0x0, 0x50(%rsp)
movl 0x50(%rsp), %eax
movl 0x5c(%rsp), %ecx
shrl %ecx
cmpl %ecx, %eax
jae 0x3a9c
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 0x1110
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 0x34d0
movl 0x54(%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 0x58(%rsp), %ecx
movq %rsp, %r8
movq %rsp, %r9
xorl %edx, %edx
callq 0x2ed0
leaq 0x30(%rsp), %rdi
movq %rsp, %rsi
leaq 0x30(%rsp), %rcx
movl $0x10, %edx
callq 0x34d0
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 0x1110
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 0x34d0
movl 0x54(%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 0x58(%rsp), %ecx
movq %rsp, %r8
movq %rsp, %r9
xorl %edx, %edx
callq 0x2ed0
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
leaq 0x20(%rsp), %rcx
movl $0x10, %edx
callq 0x34d0
movl 0x50(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x50(%rsp)
movl 0x54(%rsp), %eax
movl 0x4c(%rsp), %ecx
shll %ecx
addl %ecx, %eax
movl %eax, 0x54(%rsp)
jmp 0x3910
movq %rsp, %rdi
leaq 0x20(%rsp), %rsi
movl 0x64(%rsp), %eax
shrl %eax
movl %eax, %eax
movl %eax, %edx
callq 0x1110
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 0x1110
movl 0x64(%rsp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x3b5a
movl 0x64(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x50(%rsp)
movl 0x50(%rsp), %eax
movl 0x64(%rsp), %ecx
shrl %ecx
cmpl %ecx, %eax
jbe 0x3b30
movl 0x50(%rsp), %eax
movzbl (%rsp,%rax), %eax
sarl $0x4, %eax
movl 0x50(%rsp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movzbl (%rsp,%rcx), %ecx
shll $0x4, %ecx
orl %ecx, %eax
movb %al, %cl
movl 0x50(%rsp), %eax
movb %cl, (%rsp,%rax)
movl 0x50(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x50(%rsp)
jmp 0x3aef
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 0x1110
cmpl $0x10, 0x64(%rsp)
jae 0x3bf4
cmpl $0x0, 0x60(%rsp)
jne 0x3bf4
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 0x34d0
movq 0x80(%rsp), %rdi
movl 0x7c(%rsp), %esi
movq %rsp, %r8
movq %rsp, %r9
xorl %edx, %edx
movl $0x3, %ecx
callq 0x2ed0
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)