// File: twekkel[P]mzpq/libzpaq.cpp
// Function: libzpaq::AES_CTR::encrypt(unsigned int, unsigned int, unsigned int, unsigned int, unsigned char*)
void AES_CTR::encrypt(U32 s0, U32 s1, U32 s2, U32 s3, unsigned char* ct) {
  int r = Nr >> 1;
  U32 *rk = &ek[0];
  U32 t0=0, t1=0, t2=0, t3=0;
  s0 ^= rk[0];
  s1 ^= rk[1];
  s2 ^= rk[2];
  s3 ^= rk[3];
  for (;;) {
    t0 =
      Te0[byte(s0, 3)] ^
      Te1[byte(s1, 2)] ^
      Te2[byte(s2, 1)] ^
      Te3[byte(s3, 0)] ^
      rk[4];
    t1 =
      Te0[byte(s1, 3)] ^
      Te1[byte(s2, 2)] ^
      Te2[byte(s3, 1)] ^
      Te3[byte(s0, 0)] ^
      rk[5];
    t2 =
      Te0[byte(s2, 3)] ^
      Te1[byte(s3, 2)] ^
      Te2[byte(s0, 1)] ^
      Te3[byte(s1, 0)] ^
      rk[6];
    t3 =
      Te0[byte(s3, 3)] ^
      Te1[byte(s0, 2)] ^
      Te2[byte(s1, 1)] ^
      Te3[byte(s2, 0)] ^
      rk[7];

    rk += 8;
    if (--r == 0) {
      break;
    }

    s0 =
      Te0[byte(t0, 3)] ^
      Te1[byte(t1, 2)] ^
      Te2[byte(t2, 1)] ^
      Te3[byte(t3, 0)] ^
      rk[0];
    s1 =
      Te0[byte(t1, 3)] ^
      Te1[byte(t2, 2)] ^
      Te2[byte(t3, 1)] ^
      Te3[byte(t0, 0)] ^
      rk[1];
    s2 =
      Te0[byte(t2, 3)] ^
      Te1[byte(t3, 2)] ^
      Te2[byte(t0, 1)] ^
      Te3[byte(t1, 0)] ^
      rk[2];
    s3 =
      Te0[byte(t3, 3)] ^
      Te1[byte(t0, 2)] ^
      Te2[byte(t1, 1)] ^
      Te3[byte(t2, 0)] ^
      rk[3];
  }

  // apply last round and map cipher state to byte array block:
  s0 =
    (Te4_3[byte(t0, 3)]) ^
    (Te4_2[byte(t1, 2)]) ^
    (Te4_1[byte(t2, 1)]) ^
    (Te4_0[byte(t3, 0)]) ^
    rk[0];
  STORE32H(s0, ct);
  s1 =
    (Te4_3[byte(t1, 3)]) ^
    (Te4_2[byte(t2, 2)]) ^
    (Te4_1[byte(t3, 1)]) ^
    (Te4_0[byte(t0, 0)]) ^
    rk[1];
  STORE32H(s1, ct+4);
  s2 =
    (Te4_3[byte(t2, 3)]) ^
    (Te4_2[byte(t3, 2)]) ^
    (Te4_1[byte(t0, 1)]) ^
    (Te4_0[byte(t1, 0)]) ^
    rk[2];
  STORE32H(s2, ct+8);
  s3 =
    (Te4_3[byte(t3, 3)]) ^
    (Te4_2[byte(t0, 2)]) ^
    (Te4_1[byte(t1, 1)]) ^
    (Te4_0[byte(t2, 0)]) ^ 
    rk[3];
  STORE32H(s3, ct+12);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl %r8d, -0x18(%rbp)
movq %r9, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movl 0x14f0(%rax), %ecx
sarl %ecx
movl %ecx, -0x24(%rbp)
addq $0x1400, %rax           # imm = 0x1400
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movq -0x30(%rbp), %rax
movl (%rax), %eax
xorl -0xc(%rbp), %eax
movl %eax, -0xc(%rbp)
movq -0x30(%rbp), %rax
movl 0x4(%rax), %eax
xorl -0x10(%rbp), %eax
movl %eax, -0x10(%rbp)
movq -0x30(%rbp), %rax
movl 0x8(%rax), %eax
xorl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
movq -0x30(%rbp), %rax
movl 0xc(%rax), %eax
xorl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
movl -0xc(%rbp), %edi
movl $0x3, %esi
callq 0xd410
movl %eax, %ecx
movq -0x48(%rbp), %rax
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x78(%rbp)
movl -0x10(%rbp), %edi
movl $0x2, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0x78(%rbp), %eax
movl %edx, %edx
xorl 0x400(%rcx,%rdx,4), %eax
movl %eax, -0x74(%rbp)
movl -0x14(%rbp), %edi
movl $0x1, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0x74(%rbp), %eax
movl %edx, %edx
xorl 0x800(%rcx,%rdx,4), %eax
movl %eax, -0x70(%rbp)
movl -0x18(%rbp), %edi
xorl %esi, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0x70(%rbp), %eax
movl %edx, %edx
xorl 0xc00(%rcx,%rdx,4), %eax
movq -0x30(%rbp), %rcx
xorl 0x10(%rcx), %eax
movl %eax, -0x34(%rbp)
movl -0x10(%rbp), %edi
movl $0x3, %esi
callq 0xd410
movl %eax, %ecx
movq -0x48(%rbp), %rax
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x6c(%rbp)
movl -0x14(%rbp), %edi
movl $0x2, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0x6c(%rbp), %eax
movl %edx, %edx
xorl 0x400(%rcx,%rdx,4), %eax
movl %eax, -0x68(%rbp)
movl -0x18(%rbp), %edi
movl $0x1, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0x68(%rbp), %eax
movl %edx, %edx
xorl 0x800(%rcx,%rdx,4), %eax
movl %eax, -0x64(%rbp)
movl -0xc(%rbp), %edi
xorl %esi, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0x64(%rbp), %eax
movl %edx, %edx
xorl 0xc00(%rcx,%rdx,4), %eax
movq -0x30(%rbp), %rcx
xorl 0x14(%rcx), %eax
movl %eax, -0x38(%rbp)
movl -0x14(%rbp), %edi
movl $0x3, %esi
callq 0xd410
movl %eax, %ecx
movq -0x48(%rbp), %rax
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x60(%rbp)
movl -0x18(%rbp), %edi
movl $0x2, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0x60(%rbp), %eax
movl %edx, %edx
xorl 0x400(%rcx,%rdx,4), %eax
movl %eax, -0x5c(%rbp)
movl -0xc(%rbp), %edi
movl $0x1, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0x5c(%rbp), %eax
movl %edx, %edx
xorl 0x800(%rcx,%rdx,4), %eax
movl %eax, -0x58(%rbp)
movl -0x10(%rbp), %edi
xorl %esi, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0x58(%rbp), %eax
movl %edx, %edx
xorl 0xc00(%rcx,%rdx,4), %eax
movq -0x30(%rbp), %rcx
xorl 0x18(%rcx), %eax
movl %eax, -0x3c(%rbp)
movl -0x18(%rbp), %edi
movl $0x3, %esi
callq 0xd410
movl %eax, %ecx
movq -0x48(%rbp), %rax
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x54(%rbp)
movl -0xc(%rbp), %edi
movl $0x2, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0x54(%rbp), %eax
movl %edx, %edx
xorl 0x400(%rcx,%rdx,4), %eax
movl %eax, -0x50(%rbp)
movl -0x10(%rbp), %edi
movl $0x1, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0x50(%rbp), %eax
movl %edx, %edx
xorl 0x800(%rcx,%rdx,4), %eax
movl %eax, -0x4c(%rbp)
movl -0x14(%rbp), %edi
xorl %esi, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0x4c(%rbp), %eax
movl %edx, %edx
xorl 0xc00(%rcx,%rdx,4), %eax
movq -0x30(%rbp), %rcx
xorl 0x1c(%rcx), %eax
movl %eax, -0x40(%rbp)
movq -0x30(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x30(%rbp)
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, %eax
jne 0xd6ef
jmp 0xd943
movl -0x34(%rbp), %edi
movl $0x3, %esi
callq 0xd410
movl %eax, %ecx
movq -0x48(%rbp), %rax
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0xa8(%rbp)
movl -0x38(%rbp), %edi
movl $0x2, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0xa8(%rbp), %eax
movl %edx, %edx
xorl 0x400(%rcx,%rdx,4), %eax
movl %eax, -0xa4(%rbp)
movl -0x3c(%rbp), %edi
movl $0x1, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0xa4(%rbp), %eax
movl %edx, %edx
xorl 0x800(%rcx,%rdx,4), %eax
movl %eax, -0xa0(%rbp)
movl -0x40(%rbp), %edi
xorl %esi, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0xa0(%rbp), %eax
movl %edx, %edx
xorl 0xc00(%rcx,%rdx,4), %eax
movq -0x30(%rbp), %rcx
xorl (%rcx), %eax
movl %eax, -0xc(%rbp)
movl -0x38(%rbp), %edi
movl $0x3, %esi
callq 0xd410
movl %eax, %ecx
movq -0x48(%rbp), %rax
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x9c(%rbp)
movl -0x3c(%rbp), %edi
movl $0x2, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0x9c(%rbp), %eax
movl %edx, %edx
xorl 0x400(%rcx,%rdx,4), %eax
movl %eax, -0x98(%rbp)
movl -0x40(%rbp), %edi
movl $0x1, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0x98(%rbp), %eax
movl %edx, %edx
xorl 0x800(%rcx,%rdx,4), %eax
movl %eax, -0x94(%rbp)
movl -0x34(%rbp), %edi
xorl %esi, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0x94(%rbp), %eax
movl %edx, %edx
xorl 0xc00(%rcx,%rdx,4), %eax
movq -0x30(%rbp), %rcx
xorl 0x4(%rcx), %eax
movl %eax, -0x10(%rbp)
movl -0x3c(%rbp), %edi
movl $0x3, %esi
callq 0xd410
movl %eax, %ecx
movq -0x48(%rbp), %rax
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x90(%rbp)
movl -0x40(%rbp), %edi
movl $0x2, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0x90(%rbp), %eax
movl %edx, %edx
xorl 0x400(%rcx,%rdx,4), %eax
movl %eax, -0x8c(%rbp)
movl -0x34(%rbp), %edi
movl $0x1, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0x8c(%rbp), %eax
movl %edx, %edx
xorl 0x800(%rcx,%rdx,4), %eax
movl %eax, -0x88(%rbp)
movl -0x38(%rbp), %edi
xorl %esi, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0x88(%rbp), %eax
movl %edx, %edx
xorl 0xc00(%rcx,%rdx,4), %eax
movq -0x30(%rbp), %rcx
xorl 0x8(%rcx), %eax
movl %eax, -0x14(%rbp)
movl -0x40(%rbp), %edi
movl $0x3, %esi
callq 0xd410
movl %eax, %ecx
movq -0x48(%rbp), %rax
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x84(%rbp)
movl -0x34(%rbp), %edi
movl $0x2, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0x84(%rbp), %eax
movl %edx, %edx
xorl 0x400(%rcx,%rdx,4), %eax
movl %eax, -0x80(%rbp)
movl -0x38(%rbp), %edi
movl $0x1, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0x80(%rbp), %eax
movl %edx, %edx
xorl 0x800(%rcx,%rdx,4), %eax
movl %eax, -0x7c(%rbp)
movl -0x3c(%rbp), %edi
xorl %esi, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0x7c(%rbp), %eax
movl %edx, %edx
xorl 0xc00(%rcx,%rdx,4), %eax
movq -0x30(%rbp), %rcx
xorl 0xc(%rcx), %eax
movl %eax, -0x18(%rbp)
jmp 0xd4bc
movl -0x34(%rbp), %edi
movl $0x3, %esi
callq 0xd410
movl %eax, %ecx
movq -0x48(%rbp), %rax
movl %ecx, %ecx
movl 0x1000(%rax,%rcx,4), %eax
andl $0xff000000, %eax       # imm = 0xFF000000
movl %eax, -0xd8(%rbp)
movl -0x38(%rbp), %edi
movl $0x2, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0xd8(%rbp), %eax
movl %edx, %edx
movl 0x1000(%rcx,%rdx,4), %ecx
andl $0xff0000, %ecx         # imm = 0xFF0000
xorl %ecx, %eax
movl %eax, -0xd4(%rbp)
movl -0x3c(%rbp), %edi
movl $0x1, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0xd4(%rbp), %eax
movl %edx, %edx
movl 0x1000(%rcx,%rdx,4), %ecx
andl $0xff00, %ecx           # imm = 0xFF00
xorl %ecx, %eax
movl %eax, -0xd0(%rbp)
movl -0x40(%rbp), %edi
xorl %esi, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0xd0(%rbp), %eax
movl %edx, %edx
movl 0x1000(%rcx,%rdx,4), %ecx
andl $0xff, %ecx
xorl %ecx, %eax
movq -0x30(%rbp), %rcx
xorl (%rcx), %eax
movl %eax, -0xc(%rbp)
movq -0x20(%rbp), %rsi
leaq -0xc(%rbp), %rdi
callq 0xdc70
movl -0x38(%rbp), %edi
movl $0x3, %esi
callq 0xd410
movl %eax, %ecx
movq -0x48(%rbp), %rax
movl %ecx, %ecx
movl 0x1000(%rax,%rcx,4), %eax
andl $0xff000000, %eax       # imm = 0xFF000000
movl %eax, -0xcc(%rbp)
movl -0x3c(%rbp), %edi
movl $0x2, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0xcc(%rbp), %eax
movl %edx, %edx
movl 0x1000(%rcx,%rdx,4), %ecx
andl $0xff0000, %ecx         # imm = 0xFF0000
xorl %ecx, %eax
movl %eax, -0xc8(%rbp)
movl -0x40(%rbp), %edi
movl $0x1, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0xc8(%rbp), %eax
movl %edx, %edx
movl 0x1000(%rcx,%rdx,4), %ecx
andl $0xff00, %ecx           # imm = 0xFF00
xorl %ecx, %eax
movl %eax, -0xc4(%rbp)
movl -0x34(%rbp), %edi
xorl %esi, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0xc4(%rbp), %eax
movl %edx, %edx
movl 0x1000(%rcx,%rdx,4), %ecx
andl $0xff, %ecx
xorl %ecx, %eax
movq -0x30(%rbp), %rcx
xorl 0x4(%rcx), %eax
movl %eax, -0x10(%rbp)
movq -0x20(%rbp), %rsi
addq $0x4, %rsi
leaq -0x10(%rbp), %rdi
callq 0xdc70
movl -0x3c(%rbp), %edi
movl $0x3, %esi
callq 0xd410
movl %eax, %ecx
movq -0x48(%rbp), %rax
movl %ecx, %ecx
movl 0x1000(%rax,%rcx,4), %eax
andl $0xff000000, %eax       # imm = 0xFF000000
movl %eax, -0xc0(%rbp)
movl -0x40(%rbp), %edi
movl $0x2, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0xc0(%rbp), %eax
movl %edx, %edx
movl 0x1000(%rcx,%rdx,4), %ecx
andl $0xff0000, %ecx         # imm = 0xFF0000
xorl %ecx, %eax
movl %eax, -0xbc(%rbp)
movl -0x34(%rbp), %edi
movl $0x1, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0xbc(%rbp), %eax
movl %edx, %edx
movl 0x1000(%rcx,%rdx,4), %ecx
andl $0xff00, %ecx           # imm = 0xFF00
xorl %ecx, %eax
movl %eax, -0xb8(%rbp)
movl -0x38(%rbp), %edi
xorl %esi, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0xb8(%rbp), %eax
movl %edx, %edx
movl 0x1000(%rcx,%rdx,4), %ecx
andl $0xff, %ecx
xorl %ecx, %eax
movq -0x30(%rbp), %rcx
xorl 0x8(%rcx), %eax
movl %eax, -0x14(%rbp)
movq -0x20(%rbp), %rsi
addq $0x8, %rsi
leaq -0x14(%rbp), %rdi
callq 0xdc70
movl -0x40(%rbp), %edi
movl $0x3, %esi
callq 0xd410
movl %eax, %ecx
movq -0x48(%rbp), %rax
movl %ecx, %ecx
movl 0x1000(%rax,%rcx,4), %eax
andl $0xff000000, %eax       # imm = 0xFF000000
movl %eax, -0xb4(%rbp)
movl -0x34(%rbp), %edi
movl $0x2, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0xb4(%rbp), %eax
movl %edx, %edx
movl 0x1000(%rcx,%rdx,4), %ecx
andl $0xff0000, %ecx         # imm = 0xFF0000
xorl %ecx, %eax
movl %eax, -0xb0(%rbp)
movl -0x38(%rbp), %edi
movl $0x1, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0xb0(%rbp), %eax
movl %edx, %edx
movl 0x1000(%rcx,%rdx,4), %ecx
andl $0xff00, %ecx           # imm = 0xFF00
xorl %ecx, %eax
movl %eax, -0xac(%rbp)
movl -0x3c(%rbp), %edi
xorl %esi, %esi
callq 0xd410
movq -0x48(%rbp), %rcx
movl %eax, %edx
movl -0xac(%rbp), %eax
movl %edx, %edx
movl 0x1000(%rcx,%rdx,4), %ecx
andl $0xff, %ecx
xorl %ecx, %eax
movq -0x30(%rbp), %rcx
xorl 0xc(%rcx), %eax
movl %eax, -0x18(%rbp)
movq -0x20(%rbp), %rsi
addq $0xc, %rsi
leaq -0x18(%rbp), %rdi
callq 0xdc70
addq $0xe0, %rsp
popq %rbp
retq
nopl (%rax,%rax)