// File: bitwiseshiftleft[P]crandom/chacha.c
// Function: crandom_chacha_expand
extern_c void
crandom_chacha_expand(u_int64_t iv,
                      u_int64_t ctr,
                      int nr,
                      int output_size,
                      const unsigned char *key_,
                      unsigned char *output_) {
# if MIGHT_HAVE_SSE2
  if (HAVE(SSE2)) {
    ssereg *key = (ssereg *)key_;
    ssereg *output = (ssereg *)output_;
                     
    ssereg a1 = key[0], a2 = a1, aa = a1,
           b1 = key[1], b2 = b1, bb = b1,
           c1 = {iv, ctr}, c2 = {iv, ctr+1}, cc = c1,
           d1 = {0x3320646e61707865ull, 0x6b20657479622d32ull}, d2 = d1, dd = d1,
           p = {0, 1};
     
    int i,r;
#   if (NEED_XOP)
      if (HAVE(XOP)) {
        for (i=0; i<output_size; i+=128) {
          for (r=nr; r>0; r-=2)
            DOUBLE_ROUND(quarter_round_xop);
          OUTPUT_FUNCTION;
        }
        return;
      }
#   endif
#   if (NEED_SSSE3)
      if (HAVE(SSSE3)) {
        for (i=0; i<output_size; i+=128) {
          for (r=nr; r>0; r-=2)
            DOUBLE_ROUND(quarter_round_ssse3);
          OUTPUT_FUNCTION;
        }
        return;
      }
#   endif
#   if (NEED_SSE2)
      if (HAVE(SSE2)) {
        for (i=0; i<output_size; i+=128) {
          for (r=nr; r>0; r-=2)
            DOUBLE_ROUND(quarter_round_sse2);
          OUTPUT_FUNCTION;
        }
        return;
      }
#   endif
  }
# endif

# if NEED_CONV
  {
    const u_int32_t *key = (const u_int32_t *)key_;
    u_int32_t
      x[16],
      input[16] = {
        key[0], key[1], key[2], key[3],
        key[4], key[5], key[6], key[7],
        iv, iv>>32, ctr, ctr>>32,
        0x61707865, 0x3320646e, 0x79622d32, 0x6b206574
      },
      *output = (u_int32_t *)output_;
    int i, r;
  
    for (i=0; i<output_size; i+= 64) {
      for (r=0; r<16; r++) {
        x[r] = input[r];
      }
      for (r=nr; r>0; r-=2) {
        quarter_round(&x[0], &x[4],  &x[8], &x[12]);
        quarter_round(&x[1], &x[5],  &x[9], &x[13]);
        quarter_round(&x[2], &x[6], &x[10], &x[14]);
        quarter_round(&x[3], &x[7], &x[11], &x[15]);
        
        quarter_round(&x[0], &x[5], &x[10], &x[15]);
        quarter_round(&x[1], &x[6], &x[11], &x[12]);
        quarter_round(&x[2], &x[7],  &x[8], &x[13]);
        quarter_round(&x[3], &x[4],  &x[9], &x[14]);
      }
      for (r=0; r<16; r++) {
        output[r] = x[r] + input[r];
      }
      
      output += 16;
      input[11] ++;
      if (!input[11]) input[12]++;
    }
  }
  
#endif // NEED_CONV
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x370, %rsp            # imm = 0x370
movq %rdi, -0x188(%rbp)
movq %rsi, -0x190(%rbp)
movl %edx, -0x194(%rbp)
movl %ecx, -0x198(%rbp)
movq %r8, -0x1a0(%rbp)
movq %r9, -0x1a8(%rbp)
movl $0x2, %edi
callq 0x53a0
cmpl $0x0, %eax
je 0x4fe9
movq -0x1a0(%rbp), %rax
movq %rax, -0x1b0(%rbp)
movq -0x1a8(%rbp), %rax
movq %rax, -0x1b8(%rbp)
movq -0x1b0(%rbp), %rax
movaps (%rax), %xmm0
movaps %xmm0, -0x1d0(%rbp)
movaps -0x1d0(%rbp), %xmm0
movaps %xmm0, -0x1e0(%rbp)
movaps -0x1d0(%rbp), %xmm0
movaps %xmm0, -0x1f0(%rbp)
movq -0x1b0(%rbp), %rax
movaps 0x10(%rax), %xmm0
movaps %xmm0, -0x200(%rbp)
movaps -0x200(%rbp), %xmm0
movaps %xmm0, -0x210(%rbp)
movaps -0x200(%rbp), %xmm0
movaps %xmm0, -0x220(%rbp)
movq -0x190(%rbp), %xmm1
movq -0x188(%rbp), %xmm0
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movaps %xmm0, -0x230(%rbp)
movq -0x190(%rbp), %rax
incq %rax
movq %rax, %xmm1
movq -0x188(%rbp), %xmm0
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movaps %xmm0, -0x240(%rbp)
movaps -0x230(%rbp), %xmm0
movaps %xmm0, -0x250(%rbp)
movaps 0x2831(%rip), %xmm0     # 0x72d0
movaps %xmm0, -0x260(%rbp)
movaps -0x260(%rbp), %xmm0
movaps %xmm0, -0x270(%rbp)
movaps -0x260(%rbp), %xmm0
movaps %xmm0, -0x280(%rbp)
movaps 0x2817(%rip), %xmm0     # 0x72e0
movaps %xmm0, -0x290(%rbp)
movl $0x2, %edi
callq 0x53a0
cmpl $0x0, %eax
je 0x4fe7
movl $0x0, -0x294(%rbp)
movl -0x294(%rbp), %eax
cmpl -0x198(%rbp), %eax
jge 0x4fe2
movl -0x194(%rbp), %eax
movl %eax, -0x298(%rbp)
cmpl $0x0, -0x298(%rbp)
jle 0x4ccd
leaq -0x1d0(%rbp), %rdi
movq %rdi, -0x370(%rbp)
leaq -0x200(%rbp), %rsi
movq %rsi, -0x368(%rbp)
leaq -0x230(%rbp), %rdx
movq %rdx, -0x360(%rbp)
leaq -0x260(%rbp), %rcx
movq %rcx, -0x358(%rbp)
callq 0x5430
leaq -0x1e0(%rbp), %rdi
movq %rdi, -0x350(%rbp)
leaq -0x210(%rbp), %rsi
movq %rsi, -0x348(%rbp)
leaq -0x240(%rbp), %rdx
movq %rdx, -0x340(%rbp)
leaq -0x270(%rbp), %rcx
movq %rcx, -0x338(%rbp)
callq 0x5430
movq -0x370(%rbp), %rdi
movq -0x368(%rbp), %rsi
movq -0x360(%rbp), %rdx
movq -0x358(%rbp), %rcx
movaps -0x200(%rbp), %xmm0
pshufd $0x39, %xmm0, %xmm0     # xmm0 = xmm0[1,2,3,0]
movaps %xmm0, -0x200(%rbp)
movaps -0x230(%rbp), %xmm0
pshufd $0x4e, %xmm0, %xmm0     # xmm0 = xmm0[2,3,0,1]
movaps %xmm0, -0x230(%rbp)
movaps -0x260(%rbp), %xmm0
pshufd $0x93, %xmm0, %xmm0     # xmm0 = xmm0[3,0,1,2]
movaps %xmm0, -0x260(%rbp)
movaps -0x210(%rbp), %xmm0
pshufd $0x39, %xmm0, %xmm0     # xmm0 = xmm0[1,2,3,0]
movaps %xmm0, -0x210(%rbp)
movaps -0x240(%rbp), %xmm0
pshufd $0x4e, %xmm0, %xmm0     # xmm0 = xmm0[2,3,0,1]
movaps %xmm0, -0x240(%rbp)
movaps -0x270(%rbp), %xmm0
pshufd $0x93, %xmm0, %xmm0     # xmm0 = xmm0[3,0,1,2]
movaps %xmm0, -0x270(%rbp)
callq 0x5430
movq -0x350(%rbp), %rdi
movq -0x348(%rbp), %rsi
movq -0x340(%rbp), %rdx
movq -0x338(%rbp), %rcx
callq 0x5430
movaps -0x200(%rbp), %xmm0
pshufd $0x93, %xmm0, %xmm0     # xmm0 = xmm0[3,0,1,2]
movaps %xmm0, -0x200(%rbp)
movaps -0x230(%rbp), %xmm0
pshufd $0x4e, %xmm0, %xmm0     # xmm0 = xmm0[2,3,0,1]
movaps %xmm0, -0x230(%rbp)
movaps -0x260(%rbp), %xmm0
pshufd $0x39, %xmm0, %xmm0     # xmm0 = xmm0[1,2,3,0]
movaps %xmm0, -0x260(%rbp)
movaps -0x210(%rbp), %xmm0
pshufd $0x93, %xmm0, %xmm0     # xmm0 = xmm0[3,0,1,2]
movaps %xmm0, -0x210(%rbp)
movaps -0x240(%rbp), %xmm0
pshufd $0x4e, %xmm0, %xmm0     # xmm0 = xmm0[2,3,0,1]
movaps %xmm0, -0x240(%rbp)
movaps -0x270(%rbp), %xmm0
pshufd $0x39, %xmm0, %xmm0     # xmm0 = xmm0[1,2,3,0]
movdqa %xmm0, -0x270(%rbp)
movl -0x298(%rbp), %eax
subl $0x2, %eax
movl %eax, -0x298(%rbp)
jmp 0x4b0b
movdqa -0x1d0(%rbp), %xmm1
movdqa -0x1f0(%rbp), %xmm0
movdqa %xmm1, -0x70(%rbp)
movdqa %xmm0, -0x80(%rbp)
movdqa -0x70(%rbp), %xmm0
movdqa -0x80(%rbp), %xmm1
paddd %xmm1, %xmm0
movq -0x1b8(%rbp), %rax
movdqa %xmm0, (%rax)
movdqa -0x200(%rbp), %xmm1
movdqa -0x220(%rbp), %xmm0
movdqa %xmm1, -0x90(%rbp)
movdqa %xmm0, -0xa0(%rbp)
movdqa -0x90(%rbp), %xmm0
movdqa -0xa0(%rbp), %xmm1
paddd %xmm1, %xmm0
movq -0x1b8(%rbp), %rax
movdqa %xmm0, 0x10(%rax)
movdqa -0x230(%rbp), %xmm1
movdqa -0x250(%rbp), %xmm0
movdqa %xmm1, -0xb0(%rbp)
movdqa %xmm0, -0xc0(%rbp)
movdqa -0xb0(%rbp), %xmm0
movdqa -0xc0(%rbp), %xmm1
paddd %xmm1, %xmm0
movq -0x1b8(%rbp), %rax
movdqa %xmm0, 0x20(%rax)
movdqa -0x260(%rbp), %xmm1
movdqa -0x280(%rbp), %xmm0
movdqa %xmm1, -0xd0(%rbp)
movdqa %xmm0, -0xe0(%rbp)
movdqa -0xd0(%rbp), %xmm0
movdqa -0xe0(%rbp), %xmm1
paddd %xmm1, %xmm0
movq -0x1b8(%rbp), %rax
movdqa %xmm0, 0x30(%rax)
movdqa -0x1e0(%rbp), %xmm1
movdqa -0x1f0(%rbp), %xmm0
movdqa %xmm1, -0xf0(%rbp)
movdqa %xmm0, -0x100(%rbp)
movdqa -0xf0(%rbp), %xmm0
movdqa -0x100(%rbp), %xmm1
paddd %xmm1, %xmm0
movq -0x1b8(%rbp), %rax
movdqa %xmm0, 0x40(%rax)
movdqa -0x210(%rbp), %xmm1
movdqa -0x220(%rbp), %xmm0
movdqa %xmm1, -0x110(%rbp)
movdqa %xmm0, -0x120(%rbp)
movdqa -0x110(%rbp), %xmm0
movdqa -0x120(%rbp), %xmm1
paddd %xmm1, %xmm0
movq -0x1b8(%rbp), %rax
movdqa %xmm0, 0x50(%rax)
movdqa -0x240(%rbp), %xmm1
movdqa -0x250(%rbp), %xmm2
movdqa -0x290(%rbp), %xmm0
movdqa %xmm2, -0x130(%rbp)
movdqa %xmm0, -0x140(%rbp)
movdqa -0x130(%rbp), %xmm0
movdqa -0x140(%rbp), %xmm2
paddd %xmm2, %xmm0
movdqa %xmm1, -0x150(%rbp)
movdqa %xmm0, -0x160(%rbp)
movdqa -0x150(%rbp), %xmm0
movdqa -0x160(%rbp), %xmm1
paddd %xmm1, %xmm0
movq -0x1b8(%rbp), %rax
movdqa %xmm0, 0x60(%rax)
movdqa -0x270(%rbp), %xmm1
movdqa -0x280(%rbp), %xmm0
movdqa %xmm1, -0x170(%rbp)
movdqa %xmm0, -0x180(%rbp)
movdqa -0x170(%rbp), %xmm0
movdqa -0x180(%rbp), %xmm1
paddd %xmm1, %xmm0
movq -0x1b8(%rbp), %rax
movdqa %xmm0, 0x70(%rax)
movq -0x1b8(%rbp), %rax
addq $0x80, %rax
movq %rax, -0x1b8(%rbp)
movdqa -0x250(%rbp), %xmm1
movdqa -0x290(%rbp), %xmm0
movdqa %xmm1, -0x10(%rbp)
movdqa %xmm0, -0x20(%rbp)
movdqa -0x10(%rbp), %xmm1
paddq -0x20(%rbp), %xmm1
movdqa -0x290(%rbp), %xmm0
movdqa %xmm1, -0x30(%rbp)
movdqa %xmm0, -0x40(%rbp)
movdqa -0x30(%rbp), %xmm0
paddq -0x40(%rbp), %xmm0
movdqa %xmm0, -0x250(%rbp)
movdqa -0x1f0(%rbp), %xmm0
movdqa %xmm0, -0x1e0(%rbp)
movdqa %xmm0, -0x1d0(%rbp)
movdqa -0x220(%rbp), %xmm0
movdqa %xmm0, -0x210(%rbp)
movdqa %xmm0, -0x200(%rbp)
movdqa -0x250(%rbp), %xmm0
movdqa %xmm0, -0x230(%rbp)
movdqa -0x250(%rbp), %xmm1
movdqa -0x290(%rbp), %xmm0
movdqa %xmm1, -0x50(%rbp)
movdqa %xmm0, -0x60(%rbp)
movdqa -0x50(%rbp), %xmm0
paddq -0x60(%rbp), %xmm0
movdqa %xmm0, -0x240(%rbp)
movdqa -0x280(%rbp), %xmm0
movdqa %xmm0, -0x270(%rbp)
movdqa %xmm0, -0x260(%rbp)
movl -0x294(%rbp), %eax
addl $0x80, %eax
movl %eax, -0x294(%rbp)
jmp 0x4aed
jmp 0x5391
jmp 0x4fe9
movq -0x1a0(%rbp), %rax
movq %rax, -0x2a0(%rbp)
movq -0x2a0(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x320(%rbp)
movq -0x2a0(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x31c(%rbp)
movq -0x2a0(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x318(%rbp)
movq -0x2a0(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x314(%rbp)
movq -0x2a0(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x310(%rbp)
movq -0x2a0(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x30c(%rbp)
movq -0x2a0(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x308(%rbp)
movq -0x2a0(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x304(%rbp)
movq -0x188(%rbp), %rax
movl %eax, -0x300(%rbp)
movq -0x188(%rbp), %rax
shrq $0x20, %rax
movl %eax, -0x2fc(%rbp)
movq -0x190(%rbp), %rax
movl %eax, -0x2f8(%rbp)
movq -0x190(%rbp), %rax
shrq $0x20, %rax
movl %eax, -0x2f4(%rbp)
movl $0x61707865, -0x2f0(%rbp) # imm = 0x61707865
movl $0x3320646e, -0x2ec(%rbp) # imm = 0x3320646E
movl $0x79622d32, -0x2e8(%rbp) # imm = 0x79622D32
movl $0x6b206574, -0x2e4(%rbp) # imm = 0x6B206574
movq -0x1a8(%rbp), %rax
movq %rax, -0x328(%rbp)
movl $0x0, -0x32c(%rbp)
movl -0x32c(%rbp), %eax
cmpl -0x198(%rbp), %eax
jge 0x5391
movl $0x0, -0x330(%rbp)
cmpl $0x10, -0x330(%rbp)
jge 0x5144
movslq -0x330(%rbp), %rax
movl -0x320(%rbp,%rax,4), %ecx
movslq -0x330(%rbp), %rax
movl %ecx, -0x2e0(%rbp,%rax,4)
movl -0x330(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x330(%rbp)
jmp 0x510e
movl -0x194(%rbp), %eax
movl %eax, -0x330(%rbp)
cmpl $0x0, -0x330(%rbp)
jle 0x52f1
leaq -0x2e0(%rbp), %rdi
leaq -0x2e0(%rbp), %rsi
addq $0x10, %rsi
leaq -0x2e0(%rbp), %rdx
addq $0x20, %rdx
leaq -0x2e0(%rbp), %rcx
addq $0x30, %rcx
callq 0x57d0
leaq -0x2e0(%rbp), %rdi
addq $0x4, %rdi
leaq -0x2e0(%rbp), %rsi
addq $0x14, %rsi
leaq -0x2e0(%rbp), %rdx
addq $0x24, %rdx
leaq -0x2e0(%rbp), %rcx
addq $0x34, %rcx
callq 0x57d0
leaq -0x2e0(%rbp), %rdi
addq $0x8, %rdi
leaq -0x2e0(%rbp), %rsi
addq $0x18, %rsi
leaq -0x2e0(%rbp), %rdx
addq $0x28, %rdx
leaq -0x2e0(%rbp), %rcx
addq $0x38, %rcx
callq 0x57d0
leaq -0x2e0(%rbp), %rdi
addq $0xc, %rdi
leaq -0x2e0(%rbp), %rsi
addq $0x1c, %rsi
leaq -0x2e0(%rbp), %rdx
addq $0x2c, %rdx
leaq -0x2e0(%rbp), %rcx
addq $0x3c, %rcx
callq 0x57d0
leaq -0x2e0(%rbp), %rdi
leaq -0x2e0(%rbp), %rsi
addq $0x14, %rsi
leaq -0x2e0(%rbp), %rdx
addq $0x28, %rdx
leaq -0x2e0(%rbp), %rcx
addq $0x3c, %rcx
callq 0x57d0
leaq -0x2e0(%rbp), %rdi
addq $0x4, %rdi
leaq -0x2e0(%rbp), %rsi
addq $0x18, %rsi
leaq -0x2e0(%rbp), %rdx
addq $0x2c, %rdx
leaq -0x2e0(%rbp), %rcx
addq $0x30, %rcx
callq 0x57d0
leaq -0x2e0(%rbp), %rdi
addq $0x8, %rdi
leaq -0x2e0(%rbp), %rsi
addq $0x1c, %rsi
leaq -0x2e0(%rbp), %rdx
addq $0x20, %rdx
leaq -0x2e0(%rbp), %rcx
addq $0x34, %rcx
callq 0x57d0
leaq -0x2e0(%rbp), %rdi
addq $0xc, %rdi
leaq -0x2e0(%rbp), %rsi
addq $0x10, %rsi
leaq -0x2e0(%rbp), %rdx
addq $0x24, %rdx
leaq -0x2e0(%rbp), %rcx
addq $0x38, %rcx
callq 0x57d0
movl -0x330(%rbp), %eax
subl $0x2, %eax
movl %eax, -0x330(%rbp)
jmp 0x5150
movl $0x0, -0x330(%rbp)
cmpl $0x10, -0x330(%rbp)
jge 0x5342
movslq -0x330(%rbp), %rax
movl -0x2e0(%rbp,%rax,4), %edx
movslq -0x330(%rbp), %rax
addl -0x320(%rbp,%rax,4), %edx
movq -0x328(%rbp), %rax
movslq -0x330(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x330(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x330(%rbp)
jmp 0x52fb
movq -0x328(%rbp), %rax
addq $0x40, %rax
movq %rax, -0x328(%rbp)
movl -0x2f4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2f4(%rbp)
cmpl $0x0, -0x2f4(%rbp)
jne 0x537b
movl -0x2f0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2f0(%rbp)
jmp 0x537d
movl -0x32c(%rbp), %eax
addl $0x40, %eax
movl %eax, -0x32c(%rbp)
jmp 0x50f2
addq $0x370, %rsp            # imm = 0x370
popq %rbp
retq
nopw (%rax,%rax)