// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movl %edx, 0x34(%rsp)
movq 0x38(%rsp), %rax
movzbl (%rax), %eax
shlq $0x38, %rax
movq 0x38(%rsp), %rcx
movzbl 0x1(%rcx), %ecx
shlq $0x30, %rcx
xorq %rcx, %rax
movq 0x38(%rsp), %rcx
movzbl 0x2(%rcx), %ecx
shlq $0x28, %rcx
xorq %rcx, %rax
movq 0x38(%rsp), %rcx
movzbl 0x3(%rcx), %ecx
shlq $0x20, %rcx
xorq %rcx, %rax
movq 0x38(%rsp), %rcx
movzbl 0x4(%rcx), %ecx
shlq $0x18, %rcx
xorq %rcx, %rax
movq 0x38(%rsp), %rcx
movzbl 0x5(%rcx), %ecx
shlq $0x10, %rcx
xorq %rcx, %rax
movq 0x38(%rsp), %rcx
movzbl 0x6(%rcx), %ecx
shlq $0x8, %rcx
xorq %rcx, %rax
movq 0x38(%rsp), %rcx
movzbl 0x7(%rcx), %ecx
xorq %rcx, %rax
movq %rax, 0x10(%rsp)
movq 0x38(%rsp), %rax
movzbl 0x8(%rax), %eax
shlq $0x38, %rax
movq 0x38(%rsp), %rcx
movzbl 0x9(%rcx), %ecx
shlq $0x30, %rcx
xorq %rcx, %rax
movq 0x38(%rsp), %rcx
movzbl 0xa(%rcx), %ecx
shlq $0x28, %rcx
xorq %rcx, %rax
movq 0x38(%rsp), %rcx
movzbl 0xb(%rcx), %ecx
shlq $0x20, %rcx
xorq %rcx, %rax
movq 0x38(%rsp), %rcx
movzbl 0xc(%rcx), %ecx
shlq $0x18, %rcx
xorq %rcx, %rax
movq 0x38(%rsp), %rcx
movzbl 0xd(%rcx), %ecx
shlq $0x10, %rcx
xorq %rcx, %rax
movq 0x38(%rsp), %rcx
movzbl 0xe(%rcx), %ecx
shlq $0x8, %rcx
xorq %rcx, %rax
movq 0x38(%rsp), %rcx
movzbl 0xf(%rcx), %ecx
xorq %rcx, %rax
movq %rax, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
movl $0x2, %eax
cmpl 0x34(%rsp), %eax
jne 0x2648
movb $0x1, 0xd(%rsp)
movb $0x2, 0xe(%rsp)
movl $0x18, 0x8(%rsp)
jmp 0x270c
movl $0x3, %eax
cmpl 0x34(%rsp), %eax
jne 0x26ee
movq 0x38(%rsp), %rax
movzbl 0x10(%rax), %eax
shlq $0x38, %rax
movq 0x38(%rsp), %rcx
movzbl 0x11(%rcx), %ecx
shlq $0x30, %rcx
xorq %rcx, %rax
movq 0x38(%rsp), %rcx
movzbl 0x12(%rcx), %ecx
shlq $0x28, %rcx
xorq %rcx, %rax
movq 0x38(%rsp), %rcx
movzbl 0x13(%rcx), %ecx
shlq $0x20, %rcx
xorq %rcx, %rax
movq 0x38(%rsp), %rcx
movzbl 0x14(%rcx), %ecx
shlq $0x18, %rcx
xorq %rcx, %rax
movq 0x38(%rsp), %rcx
movzbl 0x15(%rcx), %ecx
shlq $0x10, %rcx
xorq %rcx, %rax
movq 0x38(%rsp), %rcx
movzbl 0x16(%rcx), %ecx
shlq $0x8, %rcx
xorq %rcx, %rax
movq 0x38(%rsp), %rcx
movzbl 0x17(%rcx), %ecx
xorq %rcx, %rax
movq %rax, 0x20(%rsp)
movb $0x1, 0xd(%rsp)
movb $0x2, 0xe(%rsp)
movb $0x4, 0xf(%rsp)
movl $0x20, 0x8(%rsp)
jmp 0x270a
movl 0x34(%rsp), %esi
leaq 0x329a(%rip), %rdi      # 0x5993
movb $0x0, %al
callq 0x1040
movl $0x1, %edi
callq 0x1070
jmp 0x270c
movl $0x0, 0x30(%rsp)
movl 0x30(%rsp), %eax
cmpl 0x8(%rsp), %eax
jg 0x27d5
movq 0x10(%rsp), %rdx
xorq 0x18(%rsp), %rdx
xorq 0x20(%rsp), %rdx
movslq 0x30(%rsp), %rcx
leaq 0x18f3(%rip), %rax      # 0x4030
xorq (%rax,%rcx,8), %rdx
movq 0x40(%rsp), %rax
movslq 0x30(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x10(%rsp), %rdi
callq 0x1080
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rdi
movzbl 0xd(%rsp), %esi
callq 0x1120
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rdi
callq 0x1080
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rdi
movzbl 0xe(%rsp), %esi
callq 0x1120
movq %rax, 0x18(%rsp)
movl $0x3, %eax
cmpl 0x34(%rsp), %eax
jne 0x27c3
movq 0x20(%rsp), %rdi
callq 0x1080
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rdi
movzbl 0xf(%rsp), %esi
callq 0x1120
movq %rax, 0x20(%rsp)
jmp 0x27c5
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0x2714
movl 0x8(%rsp), %eax
addq $0x48, %rsp
retq
nop