// File: /workspace/github_c_makefile_star2_O3/mjosaarinen[P]brutus/crypto_aead/deoxyseq256128v13/ref/tweakableBC.c
// Function: deoxysKeySetupEnc256
int deoxysKeySetupEnc256(uint32_t* rtweakey,
                         const uint8_t* TweakKey,
                         const int no_tweakeys)
{

  int r;
  uint8_t tweakey[3][16];
  uint8_t alpha[3];
  const uint32_t rcon_row1 = 0x01020408;
  int Nr;

  memcpy (tweakey[0], TweakKey +  0, 16);
  memcpy (tweakey[1], TweakKey + 16, 16);

  if( 2 == no_tweakeys ){
    alpha[0] = 2;
    alpha[1] = 1;

    /* Number of rounds is 14 */
    Nr=14;

  } else if( 3 == no_tweakeys ){
    memcpy (tweakey[2], TweakKey + 32, 16);
    alpha[0] = 4;
    alpha[1] = 2;
    alpha[2] = 1;

    /* Number of rounds is 16 */
    Nr=16;

  } else {
    printf("The #tweakeys is %d, and it should be either 2 or 3. Exiting...\n", no_tweakeys);
    exit(1);
  }

  /* For each rounds */
  for(r=0; r<=Nr; r++) {

    /* Produce the round tweakey */
    rtweakey[ 4*r + 0] = GETU32( tweakey[0] +  0 ) ^ GETU32( tweakey[1] +  0 ) ^ ((3==no_tweakeys)* GETU32( tweakey[2] +  0 )) ^ rcon_row1 ;
    rtweakey[ 4*r + 1] = GETU32( tweakey[0] +  4 ) ^ GETU32( tweakey[1] +  4 ) ^ ((3==no_tweakeys)* GETU32( tweakey[2] +  4 )) ^ GETRCON( r);
    rtweakey[ 4*r + 2] = GETU32( tweakey[0] +  8 ) ^ GETU32( tweakey[1] +  8 ) ^ ((3==no_tweakeys)* GETU32( tweakey[2] +  8 ));
    rtweakey[ 4*r + 3] = GETU32( tweakey[0] + 12 ) ^ GETU32( tweakey[1] + 12 ) ^ ((3==no_tweakeys)* GETU32( tweakey[2] + 12 ));

    /* Apply H and G functions */
    H (tweakey[0]);
    G (tweakey[0], alpha[0]);

    H (tweakey[1]);
    G (tweakey[1], alpha[1]);

    if (3 == no_tweakeys) {
      H (tweakey[2]);
      G (tweakey[2], alpha[2]);
    }

  }/*r*/

  return Nr;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
vmovups (%rsi), %xmm0
vmovaps %xmm0, (%rsp)
movl %edx, %ebx
movq %rdi, %r14
vmovdqu 0x10(%rsi), %xmm0
vmovdqa %xmm0, 0x10(%rsp)
cmpl $0x2, %edx
je 0x216a
cmpl $0x3, %ebx
jne 0x22d1
vmovdqu 0x20(%rsi), %xmm0
vmovdqa %xmm0, 0x20(%rsp)
movl $0x10, %edx
movb $0x4, %al
movb $0x2, %cl
jmp 0x2173
movl $0xe, %edx
movb $0x2, %al
movb $0x1, %cl
movl %edx, 0x3c(%rsp)
orl $0x1, %edx
movq %rdx, 0x40(%rsp)
movzbl %al, %r15d
movzbl %cl, %r12d
xorl %r13d, %r13d
cmpl $0x3, %ebx
movl (%rsp), %ecx
movbel 0x20(%rsp), %eax
movl $0x0, %r8d
cmovnel %r8d, %eax
xorl 0x10(%rsp), %ecx
bswapl %ecx
xorl %eax, %ecx
xorl $0x1020408, %ecx        # imm = 0x1020408
movq %r13, %rax
shlq $0x4, %rax
cmpl $0x3, %ebx
movl %ecx, (%r14,%rax)
movl 0x14(%rsp), %ecx
movbel 0x24(%rsp), %edx
cmovnel %r8d, %edx
xorl 0x4(%rsp), %ecx
bswapl %ecx
xorl %edx, %ecx
leaq 0x30c7(%rip), %rdx      # 0x52a0
movzbl (%r13,%rdx), %edx
movl %edx, %esi
shll $0x18, %esi
movl %edx, %edi
shll $0x10, %edi
orl %esi, %edi
movl %edx, %esi
shll $0x8, %esi
orl %edi, %esi
orl %edx, %esi
xorl %ecx, %esi
cmpl $0x3, %ebx
movl %esi, 0x4(%r14,%rax)
movl 0x18(%rsp), %ecx
movbel 0x28(%rsp), %edx
cmovnel %r8d, %edx
xorl 0x8(%rsp), %ecx
bswapl %ecx
xorl %edx, %ecx
cmpl $0x3, %ebx
movl %ecx, 0x8(%r14,%rax)
movl 0x1c(%rsp), %ecx
movbel 0x2c(%rsp), %edx
cmovnel %r8d, %edx
xorl 0xc(%rsp), %ecx
bswapl %ecx
xorl %edx, %ecx
movl %ecx, 0xc(%r14,%rax)
vmovdqa (%rsp), %xmm0
vpshufb 0x2ddb(%rip), %xmm0, %xmm0 # 0x5020
vmovdqa %xmm0, (%rsp)
xorl %ebp, %ebp
movzbl (%rsp,%rbp), %edi
movl %r15d, %esi
callq 0x10a0
movb %al, (%rsp,%rbp)
incq %rbp
cmpq $0x10, %rbp
jne 0x224c
vmovdqa 0x10(%rsp), %xmm0
vpshufb 0x2dad(%rip), %xmm0, %xmm0 # 0x5020
vmovdqa %xmm0, 0x10(%rsp)
movl $0x10, %ebp
movzbl (%rsp,%rbp), %edi
movl %r12d, %esi
callq 0x10a0
movb %al, (%rsp,%rbp)
incq %rbp
cmpq $0x20, %rbp
jne 0x227e
cmpl $0x3, %ebx
jne 0x22b0
vmovdqa 0x20(%rsp), %xmm0
vpshufb 0x2d76(%rip), %xmm0, %xmm0 # 0x5020
vmovdqa %xmm0, 0x20(%rsp)
incq %r13
cmpq 0x40(%rsp), %r13
jne 0x218a
movl 0x3c(%rsp), %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x583b(%rip), %rdi      # 0x7b13
movl %ebx, %esi
xorl %eax, %eax
callq 0x1030
movl $0x1, %edi
callq 0x1060