// File: /workspace/github_c_makefile_star2_O0/Seclabs-htc[P]slip39/trezor-crypto/pbkdf2.c
// Function: pbkdf2_hmac_sha256_Init
void pbkdf2_hmac_sha256_Init(PBKDF2_HMAC_SHA256_CTX *pctx, const uint8_t *pass,
                             int passlen, const uint8_t *salt, int saltlen,
                             uint32_t blocknr) {
  SHA256_CTX ctx;
#if BYTE_ORDER == LITTLE_ENDIAN
  REVERSE32(blocknr, blocknr);
#endif

  hmac_sha256_prepare(pass, passlen, pctx->odig, pctx->idig);
  memzero(pctx->g, sizeof(pctx->g));
  pctx->g[8] = 0x80000000;
  pctx->g[15] = (SHA256_BLOCK_LENGTH + SHA256_DIGEST_LENGTH) * 8;

  memcpy(ctx.state, pctx->idig, sizeof(pctx->idig));
  ctx.bitcount = SHA256_BLOCK_LENGTH * 8;
  sha256_Update(&ctx, salt, saltlen);
  sha256_Update(&ctx, (uint8_t *)&blocknr, sizeof(blocknr));
  sha256_Final(&ctx, (uint8_t *)pctx->g);
#if BYTE_ORDER == LITTLE_ENDIAN
  for (uint32_t k = 0; k < SHA256_DIGEST_LENGTH / sizeof(uint32_t); k++) {
    REVERSE32(pctx->g[k], pctx->g[k]);
  }
#endif
  sha256_Transform(pctx->odig, pctx->g, pctx->g);
  memcpy(pctx->f, pctx->g, SHA256_DIGEST_LENGTH);
  pctx->first = 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movl %r9d, -0x28(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x94(%rbp)
movl -0x94(%rbp), %eax
shrl $0x10, %eax
movl -0x94(%rbp), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movl %eax, -0x94(%rbp)
movl -0x94(%rbp), %eax
movabsq $0xff00ff00, %rcx       # imm = 0xFF00FF00
andq %rcx, %rax
shrq $0x8, %rax
movl -0x94(%rbp), %ecx
andq $0xff00ff, %rcx         # imm = 0xFF00FF
shlq $0x8, %rcx
orq %rcx, %rax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movq -0x8(%rbp), %rdx
movq -0x8(%rbp), %rcx
addq $0x20, %rcx
callq 0xb1f0
movq -0x8(%rbp), %rdi
addq $0x60, %rdi
movl $0x40, %esi
callq 0x81c0
movq -0x8(%rbp), %rax
movl $0x80000000, 0x80(%rax) # imm = 0x80000000
movq -0x8(%rbp), %rax
movl $0x300, 0x9c(%rax)      # imm = 0x300
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rcx
movq %rcx, -0x90(%rbp)
movq 0x28(%rax), %rcx
movq %rcx, -0x88(%rbp)
movq 0x30(%rax), %rcx
movq %rcx, -0x80(%rbp)
movq 0x38(%rax), %rax
movq %rax, -0x78(%rbp)
movq $0x200, -0x70(%rbp)     # imm = 0x200
movq -0x20(%rbp), %rsi
movslq -0x24(%rbp), %rdx
leaq -0x90(%rbp), %rdi
callq 0x9bd0
leaq -0x90(%rbp), %rdi
leaq -0x28(%rbp), %rsi
movl $0x4, %edx
callq 0x9bd0
movq -0x8(%rbp), %rsi
addq $0x60, %rsi
leaq -0x90(%rbp), %rdi
callq 0x9e60
movl $0x0, -0x98(%rbp)
movl -0x98(%rbp), %eax
cmpq $0x8, %rax
jae 0x83ab
movq -0x8(%rbp), %rax
movl -0x98(%rbp), %ecx
movl 0x60(%rax,%rcx,4), %eax
movl %eax, -0x9c(%rbp)
movl -0x9c(%rbp), %eax
shrl $0x10, %eax
movl -0x9c(%rbp), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movl %eax, -0x9c(%rbp)
movl -0x9c(%rbp), %eax
movabsq $0xff00ff00, %rcx       # imm = 0xFF00FF00
andq %rcx, %rax
shrq $0x8, %rax
movl -0x9c(%rbp), %ecx
andq $0xff00ff, %rcx         # imm = 0xFF00FF
shlq $0x8, %rcx
orq %rcx, %rax
movl %eax, %edx
movq -0x8(%rbp), %rax
movl -0x98(%rbp), %ecx
movl %edx, 0x60(%rax,%rcx,4)
movl -0x98(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x98(%rbp)
jmp 0x8322
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rsi
addq $0x60, %rsi
movq -0x8(%rbp), %rdx
addq $0x60, %rdx
callq 0x97c0
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x60(%rcx), %rdx
movq %rdx, 0x40(%rax)
movq 0x68(%rcx), %rdx
movq %rdx, 0x48(%rax)
movq 0x70(%rcx), %rdx
movq %rdx, 0x50(%rax)
movq 0x78(%rcx), %rcx
movq %rcx, 0x58(%rax)
movq -0x8(%rbp), %rax
movb $0x1, 0xa0(%rax)
addq $0xa0, %rsp
popq %rbp
retq