// File: /workspace/github_c_makefile_star2_O0/Seclabs-htc[P]slip39/trezor-crypto/hmac.c
// Function: hmac_sha512_prepare
void hmac_sha512_prepare(const uint8_t *key, const uint32_t keylen,
                         uint64_t *opad_digest, uint64_t *ipad_digest) {
  static CONFIDENTIAL uint64_t key_pad[SHA512_BLOCK_LENGTH / sizeof(uint64_t)];

  memzero(key_pad, sizeof(key_pad));
  if (keylen > SHA512_BLOCK_LENGTH) {
    static CONFIDENTIAL SHA512_CTX context;
    sha512_Init(&context);
    sha512_Update(&context, key, keylen);
    sha512_Final(&context, (uint8_t *)key_pad);
  } else {
    memcpy(key_pad, key, keylen);
  }

  /* compute o_key_pad and its digest */
  for (int i = 0; i < SHA512_BLOCK_LENGTH / (int)sizeof(uint64_t); i++) {
    uint64_t data;
#if BYTE_ORDER == LITTLE_ENDIAN
    REVERSE64(key_pad[i], data);
#else
    data = key_pad[i];
#endif
    key_pad[i] = data ^ 0x5c5c5c5c5c5c5c5c;
  }
  sha512_Transform(sha512_initial_hash_value, key_pad, opad_digest);

  /* convert o_key_pad to i_key_pad and compute its digest */
  for (int i = 0; i < SHA512_BLOCK_LENGTH / (int)sizeof(uint64_t); i++) {
    key_pad[i] = key_pad[i] ^ 0x5c5c5c5c5c5c5c5c ^ 0x3636363636363636;
  }
  sha512_Transform(sha512_initial_hash_value, key_pad, ipad_digest);
  memzero(key_pad, sizeof(key_pad));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
leaq 0xf9c2(%rip), %rdi      # 0x1af80
movl $0x80, %esi
callq 0x81c0
cmpl $0x80, -0xc(%rbp)
jbe 0xb607
leaq 0xfa28(%rip), %rdi      # 0x1b000
callq 0xa250
movq -0x8(%rbp), %rsi
movl -0xc(%rbp), %eax
movl %eax, %edx
leaq 0xfa13(%rip), %rdi      # 0x1b000
callq 0xa7b0
leaq 0xfa07(%rip), %rdi      # 0x1b000
leaq 0xf980(%rip), %rsi      # 0x1af80
callq 0xab50
jmp 0xb61c
movq -0x8(%rbp), %rsi
movl -0xc(%rbp), %eax
movl %eax, %edx
leaq 0xf969(%rip), %rdi      # 0x1af80
callq 0x8090
movl $0x0, -0x24(%rbp)
cmpl $0x10, -0x24(%rbp)
jge 0xb6d8
movslq -0x24(%rbp), %rcx
leaq 0xf948(%rip), %rax      # 0x1af80
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
shrq $0x20, %rax
movq -0x38(%rbp), %rcx
shlq $0x20, %rcx
orq %rcx, %rax
movq %rax, -0x38(%rbp)
movabsq $-0xff00ff00ff0100, %rax # imm = 0xFF00FF00FF00FF00
andq -0x38(%rbp), %rax
shrq $0x8, %rax
movabsq $0xff00ff00ff00ff, %rcx # imm = 0xFF00FF00FF00FF
andq -0x38(%rbp), %rcx
shlq $0x8, %rcx
orq %rcx, %rax
movq %rax, -0x38(%rbp)
movabsq $-0xffff00010000, %rax  # imm = 0xFFFF0000FFFF0000
andq -0x38(%rbp), %rax
shrq $0x10, %rax
movabsq $0xffff0000ffff, %rcx   # imm = 0xFFFF0000FFFF
andq -0x38(%rbp), %rcx
shlq $0x10, %rcx
orq %rcx, %rax
movq %rax, -0x30(%rbp)
movabsq $0x5c5c5c5c5c5c5c5c, %rdx # imm = 0x5C5C5C5C5C5C5C5C
xorq -0x30(%rbp), %rdx
movslq -0x24(%rbp), %rcx
leaq 0xf8ba(%rip), %rax      # 0x1af80
movq %rdx, (%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xb623
movq -0x18(%rbp), %rdx
leaq 0x396d(%rip), %rdi      # 0xf050
leaq 0xf896(%rip), %rsi      # 0x1af80
callq 0xa2b0
movl $0x0, -0x3c(%rbp)
cmpl $0x10, -0x3c(%rbp)
jge 0xb73c
movslq -0x3c(%rbp), %rcx
leaq 0xf879(%rip), %rax      # 0x1af80
movabsq $0x5c5c5c5c5c5c5c5c, %rdx # imm = 0x5C5C5C5C5C5C5C5C
xorq (%rax,%rcx,8), %rdx
movabsq $0x3636363636363636, %rax # imm = 0x3636363636363636
xorq %rax, %rdx
movslq -0x3c(%rbp), %rcx
leaq 0xf853(%rip), %rax      # 0x1af80
movq %rdx, (%rax,%rcx,8)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xb6f6
movq -0x20(%rbp), %rdx
leaq 0x3909(%rip), %rdi      # 0xf050
leaq 0xf832(%rip), %rsi      # 0x1af80
callq 0xa2b0
leaq 0xf826(%rip), %rdi      # 0x1af80
movl $0x80, %esi
callq 0x81c0
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)