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

  hmac_sha512_prepare(pass, passlen, pctx->odig, pctx->idig);
  memzero(pctx->g, sizeof(pctx->g));
  pctx->g[8] = 0x8000000000000000;
  pctx->g[15] = (SHA512_BLOCK_LENGTH + SHA512_DIGEST_LENGTH) * 8;

  memcpy(ctx.state, pctx->idig, sizeof(pctx->idig));
  ctx.bitcount[0] = SHA512_BLOCK_LENGTH * 8;
  ctx.bitcount[1] = 0;
  sha512_Update(&ctx, salt, saltlen);
  sha512_Update(&ctx, (uint8_t *)&blocknr, sizeof(blocknr));
  sha512_Final(&ctx, (uint8_t *)pctx->g);
#if BYTE_ORDER == LITTLE_ENDIAN
  for (uint32_t k = 0; k < SHA512_DIGEST_LENGTH / sizeof(uint64_t); k++) {
    REVERSE64(pctx->g[k], pctx->g[k]);
  }
#endif
  sha512_Transform(pctx->odig, pctx->g, pctx->g);
  memcpy(pctx->f, pctx->g, SHA512_DIGEST_LENGTH);
  pctx->first = 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
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, -0xfc(%rbp)
movl -0xfc(%rbp), %eax
shrl $0x10, %eax
movl -0xfc(%rbp), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movl %eax, -0xfc(%rbp)
movl -0xfc(%rbp), %eax
movabsq $0xff00ff00, %rcx       # imm = 0xFF00FF00
andq %rcx, %rax
shrq $0x8, %rax
movl -0xfc(%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 $0x40, %rcx
callq 0xb5a0
movq -0x8(%rbp), %rdi
addq $0xc0, %rdi
movl $0x80, %esi
callq 0x81c0
movq -0x8(%rbp), %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
movq %rcx, 0x100(%rax)
movq -0x8(%rbp), %rax
movq $0x600, 0x138(%rax) # imm = 0x600
leaq -0xf8(%rbp), %rdi
movq -0x8(%rbp), %rsi
addq $0x40, %rsi
movl $0x40, %edx
callq 0x8090
movq $0x400, -0xb8(%rbp) # imm = 0x400
movq $0x0, -0xb0(%rbp)
movq -0x20(%rbp), %rsi
movslq -0x24(%rbp), %rdx
leaq -0xf8(%rbp), %rdi
callq 0xa7b0
leaq -0xf8(%rbp), %rdi
leaq -0x28(%rbp), %rsi
movl $0x4, %edx
callq 0xa7b0
movq -0x8(%rbp), %rsi
addq $0xc0, %rsi
leaq -0xf8(%rbp), %rdi
callq 0xab50
movl $0x0, -0x100(%rbp)
movl -0x100(%rbp), %eax
cmpq $0x8, %rax
jae 0x88bd
movq -0x8(%rbp), %rax
movl -0x100(%rbp), %ecx
movq 0xc0(%rax,%rcx,8), %rax
movq %rax, -0x108(%rbp)
movq -0x108(%rbp), %rax
shrq $0x20, %rax
movq -0x108(%rbp), %rcx
shlq $0x20, %rcx
orq %rcx, %rax
movq %rax, -0x108(%rbp)
movabsq $-0xff00ff00ff0100, %rax # imm = 0xFF00FF00FF00FF00
andq -0x108(%rbp), %rax
shrq $0x8, %rax
movabsq $0xff00ff00ff00ff, %rcx # imm = 0xFF00FF00FF00FF
andq -0x108(%rbp), %rcx
shlq $0x8, %rcx
orq %rcx, %rax
movq %rax, -0x108(%rbp)
movabsq $-0xffff00010000, %rdx  # imm = 0xFFFF0000FFFF0000
andq -0x108(%rbp), %rdx
shrq $0x10, %rdx
movabsq $0xffff0000ffff, %rax   # imm = 0xFFFF0000FFFF
andq -0x108(%rbp), %rax
shlq $0x10, %rax
orq %rax, %rdx
movq -0x8(%rbp), %rax
movl -0x100(%rbp), %ecx
movq %rdx, 0xc0(%rax,%rcx,8)
movl -0x100(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x100(%rbp)
jmp 0x87ed
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rsi
addq $0xc0, %rsi
movq -0x8(%rbp), %rdx
addq $0xc0, %rdx
callq 0xa2b0
movq -0x8(%rbp), %rdi
addq $0x80, %rdi
movq -0x8(%rbp), %rsi
addq $0xc0, %rsi
movl $0x40, %edx
callq 0x8090
movq -0x8(%rbp), %rax
movb $0x1, 0x140(%rax)
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq