// File: /workspace/github_c_makefile_star2_O2/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, 0x18(%rsp)
movzbl 0x1(%rsi), %ecx
movzbl 0x2(%rsi), %eax
movzbl 0x3(%rsi), %r10d
movzbl 0x4(%rsi), %ebp
movzbl 0x5(%rsi), %r14d
movzbl 0x6(%rsi), %r11d
movzbl 0x7(%rsi), %r15d
movzbl 0x8(%rsi), %edi
movq %rdi, 0x20(%rsp)
movzbl 0x9(%rsi), %r9d
movzbl 0xa(%rsi), %r8d
movzbl 0xb(%rsi), %edi
movzbl 0xc(%rsi), %ebx
movq %rbx, 0x28(%rsp)
movzbl 0xd(%rsi), %ebx
movq %rbx, 0x8(%rsp)
movzbl 0xe(%rsi), %ebx
movzbl 0xf(%rsi), %r12d
cmpl $0x2, %edx
movl %edx, 0x4(%rsp)
je 0x1b39
movq %rbx, 0x10(%rsp)
cmpl $0x3, %edx
jne 0x1c4d
movzbl 0x10(%rsi), %ebx
shlq $0x38, %rbx
movzbl 0x11(%rsi), %r13d
shlq $0x30, %r13
orq %rbx, %r13
movzbl 0x12(%rsi), %ebx
shlq $0x28, %rbx
orq %r13, %rbx
movzbl 0x13(%rsi), %r13d
shlq $0x20, %r13
orq %rbx, %r13
movzbl 0x14(%rsi), %ebx
shll $0x18, %ebx
orq %r13, %rbx
movzbl 0x15(%rsi), %r13d
shll $0x10, %r13d
orq %rbx, %r13
movzbl 0x16(%rsi), %ebx
shll $0x8, %ebx
orq %r13, %rbx
movzbl 0x17(%rsi), %r13d
xorq %rbx, %r13
pushq $0x20
popq %rdx
movq 0x10(%rsp), %rbx
jmp 0x1b3f
pushq $0x18
popq %rdx
xorl %r13d, %r13d
movq 0x18(%rsp), %rsi
shlq $0x38, %rsi
shlq $0x30, %rcx
orq %rsi, %rcx
shlq $0x28, %rax
orq %rcx, %rax
shlq $0x20, %r10
orq %rax, %r10
shll $0x18, %ebp
orq %r10, %rbp
shll $0x10, %r14d
orq %rbp, %r14
shll $0x8, %r11d
orq %r14, %r11
xorq %r11, %r15
movq 0x20(%rsp), %rax
shlq $0x38, %rax
shlq $0x30, %r9
orq %rax, %r9
shlq $0x28, %r8
orq %r9, %r8
shlq $0x20, %rdi
orq %r8, %rdi
movq 0x28(%rsp), %rcx
shll $0x18, %ecx
orq %rdi, %rcx
movq 0x8(%rsp), %rax
shll $0x10, %eax
orq %rcx, %rax
shll $0x8, %ebx
orq %rax, %rbx
xorq %rbx, %r12
movl %edx, 0x8(%rsp)
movl %edx, %eax
leaq 0x8(,%rax,8), %rbx
xorl %ebp, %ebp
pushq $0x2
popq %r14
cmpq %rbp, %rbx
je 0x1c3a
leaq 0x151f(%rip), %rax      # 0x30f0
movq (%rbp,%rax), %rax
xorq %r13, %rax
movq %r12, %rcx
xorq %r15, %rcx
xorq %rax, %rcx
movq 0x30(%rsp), %rax
movq %rcx, (%rax,%rbp)
movq %r15, %rdi
callq 0x1080
movq %rax, %rdi
pushq $0x1
popq %rsi
callq 0x1120
movq %rax, %r15
movq %r12, %rdi
callq 0x1080
movq %rax, %rdi
movl %r14d, %esi
callq 0x1120
movq %rax, %r12
cmpl $0x3, 0x4(%rsp)
jne 0x1c34
movq %r13, %rdi
callq 0x1080
movq %rax, %rdi
pushq $0x4
popq %rsi
callq 0x1120
movq %rax, %r13
addq $0x8, %rbp
jmp 0x1bc5
movl 0x8(%rsp), %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x144f(%rip), %rdi      # 0x30a3
movl 0x4(%rsp), %esi
xorl %eax, %eax
callq 0x1040
pushq $0x1
popq %rdi
callq 0x1070