// File: /workspace/github_c_makefile_star2_O0/otrtool[P]otrtool/src/blowfish.c
// Function: bf_init
void bf_init(bf_state_t *st, void *key_, size_t keylen)
{
  uint8_t *key = key_;
  int i, j;
  size_t ki;
  uint32_t k;
  uint32_t xL, xR;

  if (keylen < 1 || keylen > 56)
    return;

  /* step 1 */
  memcpy(st->S, S0, sizeof(S0));
  memcpy(st->P, P0, sizeof(P0));

  /* step 2 */
  ki = 0;
  for (i=0; i<18; i++) {
    k = 0;
    for (j=0; j<4; j++) {
      k = (k << 8) | key[ki];
      if (++ki >= keylen) ki = 0;
    }
    st->P[i] ^= k;
  }

  /* steps 3 to 7 */
  xL = xR = 0;
  for (i=0; i<18; i+=2) {
    BF_ENCRYPT(st, xL, xR);
    st->P[i] = xL;
    st->P[i+1] = xR;
  }
  for (i=0; i<4; i++) {
    for (j=0; j<256; j+=2) {
      BF_ENCRYPT(st, xL, xR);
      st->S[i][j] = xL;
      st->S[i][j+1] = xR;
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpq $0x1, -0x18(%rbp)
jb 0x3a7a
cmpq $0x38, -0x18(%rbp)
jbe 0x3a7f
jmp 0x3d1d
movq -0x8(%rbp), %rdi
leaq 0x5586(%rip), %rsi      # 0x9010
movl $0x1000, %edx           # imm = 0x1000
callq 0x2170
movq -0x8(%rbp), %rdi
addq $0x1000, %rdi           # imm = 0x1000
leaq 0x656a(%rip), %rsi      # 0xa010
movl $0x48, %edx
callq 0x2170
movq $0x0, -0x30(%rbp)
movl $0x0, -0x24(%rbp)
cmpl $0x12, -0x24(%rbp)
jge 0x3b3b
movl $0x0, -0x34(%rbp)
movl $0x0, -0x28(%rbp)
cmpl $0x4, -0x28(%rbp)
jge 0x3b17
movl -0x34(%rbp), %eax
shll $0x8, %eax
movq -0x20(%rbp), %rcx
movq -0x30(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
orl %ecx, %eax
movl %eax, -0x34(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
cmpq -0x18(%rbp), %rax
jb 0x3b0a
movq $0x0, -0x30(%rbp)
jmp 0x3b0c
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x3ad3
movl -0x34(%rbp), %edx
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rcx
xorl 0x1000(%rax,%rcx,4), %edx
movl %edx, 0x1000(%rax,%rcx,4)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x3abf
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x24(%rbp)
cmpl $0x12, -0x24(%rbp)
jge 0x3c1a
jmp 0x3b5c
movl $0x0, -0x44(%rbp)
cmpl $0x10, -0x44(%rbp)
jge 0x3baf
movl -0x38(%rbp), %eax
movq -0x8(%rbp), %rcx
movslq -0x44(%rbp), %rdx
xorl 0x1000(%rcx,%rdx,4), %eax
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movl -0x38(%rbp), %esi
callq 0x3d30
xorl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0x3ba4
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x3b63
jmp 0x3bb1
movl -0x38(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x8(%rbp), %rcx
xorl 0x1040(%rcx), %eax
movl %eax, -0x3c(%rbp)
movl -0x38(%rbp), %eax
movq -0x8(%rbp), %rcx
xorl 0x1044(%rcx), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %edx
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl %edx, 0x1000(%rax,%rcx,4)
movl -0x3c(%rbp), %edx
movq -0x8(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, 0x1000(%rax,%rcx,4)
movl -0x24(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x24(%rbp)
jmp 0x3b50
movl $0x0, -0x24(%rbp)
cmpl $0x4, -0x24(%rbp)
jge 0x3d1d
movl $0x0, -0x28(%rbp)
cmpl $0x100, -0x28(%rbp)     # imm = 0x100
jge 0x3d0d
jmp 0x3c41
movl $0x0, -0x4c(%rbp)
cmpl $0x10, -0x4c(%rbp)
jge 0x3c94
movl -0x38(%rbp), %eax
movq -0x8(%rbp), %rcx
movslq -0x4c(%rbp), %rdx
xorl 0x1000(%rcx,%rdx,4), %eax
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movl -0x38(%rbp), %esi
callq 0x3d30
xorl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0x3c89
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x3c48
jmp 0x3c96
movl -0x38(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x8(%rbp), %rcx
xorl 0x1040(%rcx), %eax
movl %eax, -0x3c(%rbp)
movl -0x38(%rbp), %eax
movq -0x8(%rbp), %rcx
xorl 0x1044(%rcx), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %edx
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rcx
shlq $0xa, %rcx
addq %rcx, %rax
movslq -0x28(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x3c(%rbp), %edx
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rcx
shlq $0xa, %rcx
addq %rcx, %rax
movl -0x28(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x28(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x28(%rbp)
jmp 0x3c32
jmp 0x3d0f
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x3c21
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)