// File: twekkel[P]mzpq/libzpaq.cpp
// Function: libzpaq::pbkdf2(char const*, int, char const*, int, int, char*, int)
static void pbkdf2(const char* pw, int pwLen, const char* salt, int saltLen,
                   int c, char* buf, int dkLen) {
  assert(c==1);
  assert(dkLen%32==0);
  assert(pwLen<=64);

  libzpaq::SHA256 sha256;
  char b[32];
  for (int i=1; i*32<=dkLen; ++i) {
    for (int j=0; j<pwLen; ++j) sha256.put(pw[j]^0x36);
    for (int j=pwLen; j<64; ++j) sha256.put(0x36);
    for (int j=0; j<saltLen; ++j) sha256.put(salt[j]);
    for (int j=24; j>=0; j-=8) sha256.put(i>>j);
    memcpy(b, sha256.result(), 32);
    for (int j=0; j<pwLen; ++j) sha256.put(pw[j]^0x5c);
    for (int j=pwLen; j<64; ++j) sha256.put(0x5c);
    for (int j=0; j<32; ++j) sha256.put(b[j]);
    memcpy(buf+i*32-32, sha256.result(), 32);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movq %r9, -0x28(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x31ee0
movl $0x1, -0xd4(%rbp)
movl -0xd4(%rbp), %eax
shll $0x5, %eax
cmpl 0x10(%rbp), %eax
jg 0xe202
movl $0x0, -0xd8(%rbp)
movl -0xd8(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0xdff0
movq -0x8(%rbp), %rax
movslq -0xd8(%rbp), %rcx
movsbl (%rax,%rcx), %esi
xorl $0x36, %esi
leaq -0xb0(%rbp), %rdi
callq 0x30100
movl -0xd8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd8(%rbp)
jmp 0xdfb6
movl -0xc(%rbp), %eax
movl %eax, -0xdc(%rbp)
cmpl $0x40, -0xdc(%rbp)
jge 0xe024
leaq -0xb0(%rbp), %rdi
movl $0x36, %esi
callq 0x30100
movl -0xdc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xdc(%rbp)
jmp 0xdff9
movl $0x0, -0xe0(%rbp)
movl -0xe0(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0xe065
movq -0x18(%rbp), %rax
movslq -0xe0(%rbp), %rcx
movsbl (%rax,%rcx), %esi
leaq -0xb0(%rbp), %rdi
callq 0x30100
movl -0xe0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe0(%rbp)
jmp 0xe02e
movl $0x18, -0xe4(%rbp)
cmpl $0x0, -0xe4(%rbp)
jl 0xe0a3
movl -0xd4(%rbp), %esi
movl -0xe4(%rbp), %ecx
sarl %cl, %esi
leaq -0xb0(%rbp), %rdi
callq 0x30100
movl -0xe4(%rbp), %eax
subl $0x8, %eax
movl %eax, -0xe4(%rbp)
jmp 0xe06f
leaq -0xb0(%rbp), %rdi
callq 0xcab0
movq (%rax), %rcx
movq %rcx, -0xd0(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0xc8(%rbp)
movq 0x10(%rax), %rcx
movq %rcx, -0xc0(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0xb8(%rbp)
movl $0x0, -0xe8(%rbp)
movl -0xe8(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0xe11e
movq -0x8(%rbp), %rax
movslq -0xe8(%rbp), %rcx
movsbl (%rax,%rcx), %esi
xorl $0x5c, %esi
leaq -0xb0(%rbp), %rdi
callq 0x30100
movl -0xe8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe8(%rbp)
jmp 0xe0e4
movl -0xc(%rbp), %eax
movl %eax, -0xec(%rbp)
cmpl $0x40, -0xec(%rbp)
jge 0xe152
leaq -0xb0(%rbp), %rdi
movl $0x5c, %esi
callq 0x30100
movl -0xec(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xec(%rbp)
jmp 0xe127
movl $0x0, -0xf0(%rbp)
cmpl $0x20, -0xf0(%rbp)
jge 0xe191
movslq -0xf0(%rbp), %rax
movsbl -0xd0(%rbp,%rax), %esi
leaq -0xb0(%rbp), %rdi
callq 0x30100
movl -0xf0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf0(%rbp)
jmp 0xe15c
movq -0x28(%rbp), %rax
movq %rax, -0xf8(%rbp)
movl -0xd4(%rbp), %eax
shll $0x5, %eax
cltq
movq %rax, -0x100(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0xcab0
movq -0x100(%rbp), %rcx
movq %rax, %rdx
movq -0xf8(%rbp), %rax
movq (%rdx), %rsi
movq %rsi, -0x20(%rax,%rcx)
movq 0x8(%rdx), %rsi
movq %rsi, -0x18(%rax,%rcx)
movq 0x10(%rdx), %rsi
movq %rsi, -0x10(%rax,%rcx)
movq 0x18(%rdx), %rdx
movq %rdx, -0x8(%rax,%rcx)
movl -0xd4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd4(%rbp)
jmp 0xdf9a
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nopl (%rax,%rax)