// File: /workspace/github_c_makefile_star2_O2/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, 0x10(%rsp)
movl %edx, %ebx
movq %rdi, %r14
vmovups 0x10(%rsi), %xmm0
vmovaps %xmm0, 0x20(%rsp)
cmpl $0x2, %edx
je 0x1f09
cmpl $0x3, %ebx
jne 0x2044
vmovups 0x20(%rsi), %xmm0
vmovaps %xmm0, 0x30(%rsp)
pushq $0x10
popq %rdx
movb $0x4, %al
movb $0x2, %cl
jmp 0x1f10
pushq $0xe
popq %rdx
movb $0x2, %al
movb $0x1, %cl
movl %edx, 0x4(%rsp)
movl %edx, %r15d
orl $0x1, %r15d
addq $0xc, %r14
xorl %r13d, %r13d
movzbl %al, %eax
movl %eax, 0xc(%rsp)
movzbl %cl, %eax
movl %eax, 0x8(%rsp)
xorl %ebp, %ebp
cmpq %rbp, %r15
je 0x2031
cmpl $0x3, %ebx
movl 0x10(%rsp), %eax
movbel 0x30(%rsp), %ecx
cmovnel %r13d, %ecx
xorl 0x20(%rsp), %eax
bswapl %eax
xorl %ecx, %eax
xorl $0x1020408, %eax        # imm = 0x1020408
cmpl $0x3, %ebx
movl %eax, -0xc(%r14)
movl 0x24(%rsp), %eax
movbel 0x34(%rsp), %ecx
cmovnel %r13d, %ecx
xorl 0x14(%rsp), %eax
bswapl %eax
xorl %ecx, %eax
leaq 0x31c3(%rip), %rcx      # 0x5140
movzbl (%rbp,%rcx), %ecx
movl %ecx, %edx
shll $0x18, %edx
movl %ecx, %esi
shll $0x10, %esi
orl %edx, %esi
movl %ecx, %edx
shll $0x8, %edx
orl %esi, %edx
orl %ecx, %edx
xorl %eax, %edx
cmpl $0x3, %ebx
movl %edx, -0x8(%r14)
movl 0x28(%rsp), %eax
movbel 0x38(%rsp), %ecx
cmovnel %r13d, %ecx
xorl 0x18(%rsp), %eax
bswapl %eax
xorl %ecx, %eax
cmpl $0x3, %ebx
movl %eax, -0x4(%r14)
movl 0x2c(%rsp), %eax
movbel 0x3c(%rsp), %ecx
cmovnel %r13d, %ecx
xorl 0x1c(%rsp), %eax
bswapl %eax
xorl %ecx, %eax
movl %eax, (%r14)
leaq 0x10(%rsp), %r12
movq %r12, %rdi
callq 0x1080
movq %r12, %rdi
movl 0xc(%rsp), %esi
callq 0x1100
leaq 0x20(%rsp), %r12
movq %r12, %rdi
callq 0x1080
movq %r12, %rdi
movl 0x8(%rsp), %esi
callq 0x1100
cmpl $0x3, %ebx
jne 0x2025
leaq 0x30(%rsp), %r12
movq %r12, %rdi
callq 0x1080
movq %r12, %rdi
pushq $0x1
popq %rsi
callq 0x1100
incq %rbp
addq $0x10, %r14
jmp 0x1f32
movl 0x4(%rsp), %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5968(%rip), %rdi      # 0x79b3
movl %ebx, %esi
xorl %eax, %eax
callq 0x1040
pushq $0x1
popq %rdi
callq 0x1070