// File: /workspace/github_c_makefile_star2_O3/mjosaarinen[P]brutus/crypto_aead/joltikeq6464v13/ref/tweakableBC.c
// Function: joltikKeySetupEnc128
int joltikKeySetupEnc128(uint64_t* rtweakey,
                        const uint8_t* Tweakey,
                        const int no_tweakeys)
{

  int r;
  uint64_t tweakey[3];
  uint8_t alpha[3];
  int Nr;

  tweakey[0]=GETU64(Tweakey+0);
  tweakey[1]=GETU64(Tweakey+8);
  tweakey[2]=0;

  if( 2 == no_tweakeys ){
    alpha[0] = 1; /* key   */
    alpha[1] = 2; /* tweak */

    /* Number of rounds is 24 for Joltik-BC-128 */
    Nr=24;

  } else if( 3 == no_tweakeys ){

    tweakey[2]=GETU64(Tweakey+16);
    alpha[0] = 1; /* key 1 */
    alpha[1] = 2; /* key 2 */
    alpha[2] = 4; /* tweak */

    /* Number of rounds is 36 for Joltik-BC-192 */
    Nr=32;

  } 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[r] = tweakey[0] ^ tweakey[1] ^ tweakey[2] ^ rcon[r];

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

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

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

  }/*r*/

  return Nr;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movzbl (%rsi), %eax
movq %rax, 0x10(%rsp)
movzbl 0x1(%rsi), %eax
movzbl 0x2(%rsi), %r10d
movzbl 0x3(%rsi), %ebp
movzbl 0x4(%rsi), %r14d
movzbl 0x5(%rsi), %ebx
movzbl 0x6(%rsi), %r11d
movzbl 0x7(%rsi), %r15d
movzbl 0x8(%rsi), %ecx
movq %rcx, 0x18(%rsp)
movzbl 0x9(%rsi), %r9d
movzbl 0xa(%rsi), %r8d
movzbl 0xb(%rsi), %edi
movzbl 0xc(%rsi), %ecx
movq %rcx, 0x20(%rsp)
movzbl 0xd(%rsi), %ecx
movq %rcx, 0x28(%rsp)
movzbl 0xe(%rsi), %ecx
movq %rcx, 0x8(%rsp)
movzbl 0xf(%rsi), %r12d
cmpl $0x2, %edx
movl %edx, 0x4(%rsp)
je 0x1dda
cmpl $0x3, %edx
jne 0x2084
movzbl 0x10(%rsi), %r13d
shlq $0x38, %r13
movzbl 0x11(%rsi), %ecx
shlq $0x30, %rcx
orq %r13, %rcx
movzbl 0x12(%rsi), %r13d
shlq $0x28, %r13
orq %rcx, %r13
movzbl 0x13(%rsi), %ecx
shlq $0x20, %rcx
orq %r13, %rcx
movzbl 0x14(%rsi), %r13d
shll $0x18, %r13d
orq %rcx, %r13
movzbl 0x15(%rsi), %ecx
shll $0x10, %ecx
orq %r13, %rcx
movzbl 0x16(%rsi), %edx
shll $0x8, %edx
orq %rcx, %rdx
movzbl 0x17(%rsi), %r13d
xorq %rdx, %r13
movl $0x20, %ecx
jmp 0x1de2
movl $0x18, %ecx
xorl %r13d, %r13d
movq 0x10(%rsp), %rdx
shlq $0x38, %rdx
shlq $0x30, %rax
orq %rdx, %rax
shlq $0x28, %r10
orq %rax, %r10
shlq $0x20, %rbp
orq %r10, %rbp
shll $0x18, %r14d
orq %rbp, %r14
shll $0x10, %ebx
orq %r14, %rbx
shll $0x8, %r11d
orq %rbx, %r11
xorq %r11, %r15
movq 0x18(%rsp), %rax
shlq $0x38, %rax
shlq $0x30, %r9
orq %rax, %r9
shlq $0x28, %r8
orq %r9, %r8
shlq $0x20, %rdi
orq %r8, %rdi
movq 0x20(%rsp), %rax
shll $0x18, %eax
orq %rdi, %rax
movq 0x28(%rsp), %rdx
shll $0x10, %edx
orq %rax, %rdx
movq 0x8(%rsp), %rax
shll $0x8, %eax
orq %rdx, %rax
xorq %rax, %r12
movl %ecx, 0x8(%rsp)
movl %ecx, %ebp
orl $0x1, %ebp
xorl %r14d, %r14d
vpbroadcastq 0x13f2(%rip), %ymm5 # 0x3260
leaq 0x143b(%rip), %rbx      # 0x32b0
vpbroadcastq 0x13ea(%rip), %ymm6 # 0x3268
vpbroadcastq 0x13e9(%rip), %ymm7 # 0x3270
leaq 0x14d2(%rip), %rax      # 0x3360
movq (%rax,%r14,8), %rax
xorq %r13, %rax
movq %r12, %rcx
xorq %r15, %rcx
xorq %rax, %rcx
movq 0x30(%rsp), %rax
movq %rcx, (%rax,%r14,8)
vpbroadcastq %r15, %ymm1
vpxor %xmm0, %xmm0, %xmm0
xorl %eax, %eax
vpmovsxbq 0x12a0(%rip), %ymm2 # 0x315c
vpsllq $0x2, %ymm2, %ymm3
vpsubq %ymm3, %ymm5, %ymm3
vpsrlvq %ymm3, %ymm1, %ymm3
vpmovzxbq (%rax,%rbx), %ymm4
vpsllq $0x2, %ymm4, %ymm4
vpsubq %ymm4, %ymm5, %ymm4
vpand %ymm6, %ymm3, %ymm3
vpsllvq %ymm4, %ymm3, %ymm3
vpxor %ymm0, %ymm3, %ymm0
addq $0x4, %rax
vpaddq %ymm7, %ymm2, %ymm2
cmpq $0x10, %rax
jne 0x1ebc
vextracti128 $0x1, %ymm0, %xmm1
vpxor %xmm1, %xmm0, %xmm0
vpshufd $0xee, %xmm0, %xmm1     # xmm1 = xmm0[2,3,2,3]
vpxor %xmm1, %xmm0, %xmm0
vmovq %xmm0, %rdi
movl $0x1, %esi
vzeroupper
callq 0x10f0
vpbroadcastq 0x134e(%rip), %ymm7 # 0x3270
vpbroadcastq 0x133d(%rip), %ymm6 # 0x3268
vpbroadcastq 0x132c(%rip), %ymm5 # 0x3260
movq %rax, %r15
vpbroadcastq %r12, %ymm1
vpxor %xmm0, %xmm0, %xmm0
xorl %eax, %eax
vpmovsxbq 0x1210(%rip), %ymm2 # 0x315c
vpsllq $0x2, %ymm2, %ymm3
vpsubq %ymm3, %ymm5, %ymm3
vpsrlvq %ymm3, %ymm1, %ymm3
vpmovzxbq (%rax,%rbx), %ymm4
vpsllq $0x2, %ymm4, %ymm4
vpsubq %ymm4, %ymm5, %ymm4
vpand %ymm6, %ymm3, %ymm3
vpsllvq %ymm4, %ymm3, %ymm3
vpxor %ymm0, %ymm3, %ymm0
addq $0x4, %rax
vpaddq %ymm7, %ymm2, %ymm2
cmpq $0x10, %rax
jne 0x1f4c
vextracti128 $0x1, %ymm0, %xmm1
vpxor %xmm1, %xmm0, %xmm0
vpshufd $0xee, %xmm0, %xmm1     # xmm1 = xmm0[2,3,2,3]
vpxor %xmm1, %xmm0, %xmm0
vmovq %xmm0, %rdi
movl $0x2, %esi
vzeroupper
callq 0x10f0
movq %rax, %r12
cmpl $0x3, 0x4(%rsp)
jne 0x2047
vpbroadcastq %r13, %ymm1
vpxor %xmm0, %xmm0, %xmm0
xorl %eax, %eax
vpmovsxbq 0x1190(%rip), %ymm2 # 0x315c
vpbroadcastq 0x128b(%rip), %ymm5 # 0x3260
vpbroadcastq 0x128a(%rip), %ymm6 # 0x3268
vpbroadcastq 0x1289(%rip), %ymm7 # 0x3270
vpsllq $0x2, %ymm2, %ymm3
vpsubq %ymm3, %ymm5, %ymm3
vpsrlvq %ymm3, %ymm1, %ymm3
vpmovzxbq (%rax,%rbx), %ymm4
vpsllq $0x2, %ymm4, %ymm4
vpsubq %ymm4, %ymm5, %ymm4
vpand %ymm6, %ymm3, %ymm3
vpsllvq %ymm4, %ymm3, %ymm3
vpxor %ymm0, %ymm3, %ymm0
addq $0x4, %rax
vpaddq %ymm7, %ymm2, %ymm2
cmpq $0x10, %rax
jne 0x1fe7
vextracti128 $0x1, %ymm0, %xmm1
vpxor %xmm1, %xmm0, %xmm0
vpshufd $0xee, %xmm0, %xmm1     # xmm1 = xmm0[2,3,2,3]
vpxor %xmm1, %xmm0, %xmm0
vmovq %xmm0, %rdi
movl $0x4, %esi
vzeroupper
callq 0x10f0
movq %rax, %r13
incq %r14
cmpq %rbp, %r14
vpbroadcastq 0x120a(%rip), %ymm5 # 0x3260
vpbroadcastq 0x1209(%rip), %ymm6 # 0x3268
vpbroadcastq 0x1208(%rip), %ymm7 # 0x3270
jne 0x1e87
movl 0x8(%rsp), %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
vzeroupper
retq
leaq 0x1288(%rip), %rdi      # 0x3313
movl 0x4(%rsp), %esi
xorl %eax, %eax
callq 0x1030
movl $0x1, %edi
callq 0x1060