// File: /workspace/github_c_makefile_star2_O2/skeeto[P]enchive/src/chacha.c
// Function: chacha_encrypt
void
chacha_encrypt(chacha_ctx *x, const uint8_t *m, uint8_t *c, uint32_t bytes)
{
  uint8_t output[64];
  uint32_t i;

  if (!bytes) return;
  for (;;) {
    salsa20_wordtobyte(output,x->input);
    x->input[12] = PLUSONE(x->input[12]);
    if (!x->input[12]) {
      x->input[13] = PLUSONE(x->input[13]);
      /* stopping at 2^70 bytes per nonce is user's responsibility */
    }
    if (bytes <= 64) {
      for (i = 0;i < bytes;++i) c[i] = m[i] ^ output[i];
      return;
    }
    for (i = 0;i < 64;++i) c[i] = m[i] ^ output[i];
    bytes -= 64;
    c += 64;
    m += 64;
  }
}

// Assembly:
testl %ecx, %ecx
je 0x524e
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, -0x18(%rsp)
xorl %eax, %eax
cmpq $0x10, %rax
je 0x4f8b
movl (%rdi,%rax,4), %r8d
movl %r8d, -0x70(%rsp,%rax,4)
incq %rax
jmp 0x4f77
movl %ecx, -0x24(%rsp)
movq %rsi, -0x10(%rsp)
movq %rdx, -0x8(%rsp)
movl -0x70(%rsp), %eax
movl %eax, -0x74(%rsp)
movl -0x6c(%rsp), %r12d
movl -0x60(%rsp), %edi
movl -0x40(%rsp), %esi
movl -0x50(%rsp), %edx
movl -0x5c(%rsp), %r8d
movl -0x3c(%rsp), %eax
movl -0x4c(%rsp), %r13d
movl -0x68(%rsp), %ebp
movl -0x58(%rsp), %r15d
movl -0x38(%rsp), %r14d
movl -0x48(%rsp), %ecx
movl %ecx, -0x7c(%rsp)
movl -0x64(%rsp), %ebx
movl -0x54(%rsp), %r11d
movl -0x34(%rsp), %r10d
movl -0x44(%rsp), %ecx
movl %ecx, -0x78(%rsp)
movl $0xfffffff8, %r9d       # imm = 0xFFFFFFF8
movl %r12d, %ecx
testl %r9d, %r9d
je 0x515d
movl %r9d, -0x20(%rsp)
movl -0x74(%rsp), %r9d
addl %edi, %r9d
xorl %r9d, %esi
roll $0x10, %esi
addl %esi, %edx
xorl %edx, %edi
roll $0xc, %edi
addl %edi, %r9d
xorl %r9d, %esi
roll $0x8, %esi
addl %esi, %edx
xorl %edx, %edi
roll $0x7, %edi
addl %r8d, %ecx
xorl %ecx, %eax
roll $0x10, %eax
addl %eax, %r13d
xorl %r13d, %r8d
roll $0xc, %r8d
addl %r8d, %ecx
xorl %ecx, %eax
roll $0x8, %eax
addl %eax, %r13d
xorl %r13d, %r8d
roll $0x7, %r8d
addl %r15d, %ebp
xorl %ebp, %r14d
roll $0x10, %r14d
movl -0x7c(%rsp), %r12d
addl %r14d, %r12d
xorl %r12d, %r15d
roll $0xc, %r15d
addl %r15d, %ebp
movl %ebp, -0x1c(%rsp)
xorl %ebp, %r14d
roll $0x8, %r14d
addl %r14d, %r12d
xorl %r12d, %r15d
roll $0x7, %r15d
addl %r11d, %ebx
xorl %ebx, %r10d
roll $0x10, %r10d
movl %ebx, %ebp
movl -0x78(%rsp), %ebx
addl %r10d, %ebx
xorl %ebx, %r11d
roll $0xc, %r11d
addl %r11d, %ebp
xorl %ebp, %r10d
roll $0x8, %r10d
addl %r10d, %ebx
xorl %ebx, %r11d
roll $0x7, %r11d
addl %r8d, %r9d
xorl %r9d, %r10d
roll $0x10, %r10d
addl %r10d, %r12d
xorl %r12d, %r8d
roll $0xc, %r8d
addl %r8d, %r9d
movl %r9d, -0x74(%rsp)
xorl %r9d, %r10d
movl -0x20(%rsp), %r9d
roll $0x8, %r10d
addl %r10d, %r12d
movl %r12d, -0x7c(%rsp)
xorl %r12d, %r8d
roll $0x7, %r8d
addl %r15d, %ecx
xorl %ecx, %esi
roll $0x10, %esi
addl %esi, %ebx
xorl %ebx, %r15d
roll $0xc, %r15d
addl %r15d, %ecx
xorl %ecx, %esi
roll $0x8, %esi
addl %esi, %ebx
movl %ebx, -0x78(%rsp)
xorl %ebx, %r15d
movl %ebp, %ebx
movl -0x1c(%rsp), %ebp
roll $0x7, %r15d
addl %r11d, %ebp
xorl %ebp, %eax
roll $0x10, %eax
addl %eax, %edx
xorl %edx, %r11d
roll $0xc, %r11d
addl %r11d, %ebp
xorl %ebp, %eax
roll $0x8, %eax
addl %eax, %edx
xorl %edx, %r11d
roll $0x7, %r11d
addl %edi, %ebx
xorl %ebx, %r14d
roll $0x10, %r14d
addl %r14d, %r13d
xorl %r13d, %edi
roll $0xc, %edi
addl %edi, %ebx
xorl %ebx, %r14d
roll $0x8, %r14d
addl %r14d, %r13d
xorl %r13d, %edi
roll $0x7, %edi
addl $0x2, %r9d
jmp 0x4ff5
movl -0x74(%rsp), %r9d
movl %r9d, -0x70(%rsp)
movl %edi, -0x60(%rsp)
movl %esi, -0x40(%rsp)
movl %edx, -0x50(%rsp)
movl %ecx, -0x6c(%rsp)
movl %r8d, -0x5c(%rsp)
movl %eax, -0x3c(%rsp)
movl %r13d, -0x4c(%rsp)
movl %ebp, -0x68(%rsp)
movl %r15d, -0x58(%rsp)
movl %r14d, -0x38(%rsp)
movl -0x7c(%rsp), %eax
movl %eax, -0x48(%rsp)
movl %ebx, -0x64(%rsp)
movl %r11d, -0x54(%rsp)
movl %r10d, -0x34(%rsp)
movl -0x78(%rsp), %eax
movl %eax, -0x44(%rsp)
xorl %eax, %eax
movq -0x8(%rsp), %rdx
movq -0x10(%rsp), %rsi
movl -0x24(%rsp), %ecx
movq -0x18(%rsp), %rdi
cmpq $0x10, %rax
je 0x51da
movl (%rdi,%rax,4), %r8d
addl %r8d, -0x70(%rsp,%rax,4)
incq %rax
jmp 0x51c6
xorl %eax, %eax
cmpq $0x10, %rax
je 0x51f0
movl -0x70(%rsp,%rax,4), %r8d
movl %r8d, (%rsp,%rax,4)
incq %rax
jmp 0x51dc
incl 0x30(%rdi)
jne 0x51f8
incl 0x34(%rdi)
cmpl $0x41, %ecx
jb 0x5226
xorl %eax, %eax
cmpq $0x40, %rax
je 0x5216
movb (%rsp,%rax), %r8b
xorb (%rsi,%rax), %r8b
movb %r8b, (%rdx,%rax)
incq %rax
jmp 0x51ff
addl $-0x40, %ecx
addq $0x40, %rdx
addq $0x40, %rsi
jmp 0x4f75
movl %ecx, %eax
xorl %ecx, %ecx
cmpq %rax, %rcx
jae 0x5240
movb (%rsp,%rcx), %dil
xorb (%rsi,%rcx), %dil
movb %dil, (%rdx,%rcx)
incq %rcx
jmp 0x522a
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop