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

  memzero(key_pad, sizeof(key_pad));
  if (keylen > SHA256_BLOCK_LENGTH) {
    static CONFIDENTIAL SHA256_CTX context;
    sha256_Init(&context);
    sha256_Update(&context, key, keylen);
    sha256_Final(&context, (uint8_t *)key_pad);
  } else {
    memcpy(key_pad, key, keylen);
  }

  /* compute o_key_pad and its digest */
  for (int i = 0; i < SHA256_BLOCK_LENGTH / (int)sizeof(uint32_t); i++) {
    uint32_t data;
#if BYTE_ORDER == LITTLE_ENDIAN
    REVERSE32(key_pad[i], data);
#else
    data = key_pad[i];
#endif
    key_pad[i] = data ^ 0x5c5c5c5c;
  }
  sha256_Transform(sha256_initial_hash_value, key_pad, opad_digest);

  /* convert o_key_pad to i_key_pad and compute its digest */
  for (int i = 0; i < SHA256_BLOCK_LENGTH / (int)sizeof(uint32_t); i++) {
    key_pad[i] = key_pad[i] ^ 0x5c5c5c5c ^ 0x36363636;
  }
  sha256_Transform(sha256_initial_hash_value, key_pad, ipad_digest);
  memzero(key_pad, sizeof(key_pad));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
leaq 0xfc42(%rip), %rdi      # 0x1ae50
movl $0x40, %esi
callq 0x81c0
cmpl $0x40, -0xc(%rbp)
jbe 0xb254
leaq 0xfc6b(%rip), %rdi      # 0x1ae90
callq 0x9750
movq -0x8(%rbp), %rsi
movl -0xc(%rbp), %eax
movl %eax, %edx
leaq 0xfc56(%rip), %rdi      # 0x1ae90
callq 0x9bd0
leaq 0xfc4a(%rip), %rdi      # 0x1ae90
leaq 0xfc03(%rip), %rsi      # 0x1ae50
callq 0x9e60
jmp 0xb269
movq -0x8(%rbp), %rsi
movl -0xc(%rbp), %eax
movl %eax, %edx
leaq 0xfbec(%rip), %rdi      # 0x1ae50
callq 0x8090
movl $0x0, -0x24(%rbp)
cmpl $0x10, -0x24(%rbp)
jge 0xb2e2
movslq -0x24(%rbp), %rcx
leaq 0xfbcf(%rip), %rax      # 0x1ae50
movl (%rax,%rcx,4), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
shrl $0x10, %eax
movl -0x2c(%rbp), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movabsq $0xff00ff00, %rcx       # imm = 0xFF00FF00
andq %rcx, %rax
shrq $0x8, %rax
movl -0x2c(%rbp), %ecx
andq $0xff00ff, %rcx         # imm = 0xFF00FF
shlq $0x8, %rcx
orq %rcx, %rax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %edx
xorl $0x5c5c5c5c, %edx       # imm = 0x5C5C5C5C
movslq -0x24(%rbp), %rcx
leaq 0xfb7c(%rip), %rax      # 0x1ae50
movl %edx, (%rax,%rcx,4)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xb270
movq -0x18(%rbp), %rdx
leaq 0x3d43(%rip), %rdi      # 0xf030
leaq 0xfb5c(%rip), %rsi      # 0x1ae50
callq 0x97c0
movl $0x0, -0x30(%rbp)
cmpl $0x10, -0x30(%rbp)
jge 0xb339
movslq -0x30(%rbp), %rcx
leaq 0xfb3f(%rip), %rax      # 0x1ae50
movl (%rax,%rcx,4), %edx
xorl $0x5c5c5c5c, %edx       # imm = 0x5C5C5C5C
xorl $0x36363636, %edx       # imm = 0x36363636
movslq -0x30(%rbp), %rcx
leaq 0xfb25(%rip), %rax      # 0x1ae50
movl %edx, (%rax,%rcx,4)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xb300
movq -0x20(%rbp), %rdx
leaq 0x3cec(%rip), %rdi      # 0xf030
leaq 0xfb05(%rip), %rsi      # 0x1ae50
callq 0x97c0
leaq 0xfaf9(%rip), %rdi      # 0x1ae50
movl $0x40, %esi
callq 0x81c0
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)