// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/external/md5-1.2/src/ldes56.c
// Function: des56_crypt
static int des56_crypt( lua_State *L )
{
  char *cypheredText;
  keysched KS;
  int rel_index, pad, abs_index;
  size_t plainlen;
  const char *plainText = luaL_checklstring( L, 1, &plainlen );
  const char *key = luaL_optstring( L, 2, NULL );

  cypheredText = (char *) malloc( (plainlen+8) * sizeof(char));
  if(cypheredText == NULL) {
    lua_pushstring(L, "Error encrypting file. Not enough memory."); 
    lua_error(L);
  }

  if (key && strlen(key) >= 8)
  {
    char k[8];
    int i;

    for (i=0; i<8; i++)
      k[i] = (unsigned char)key[i];
    fsetkey(k, &KS);
  } else {
    lua_pushstring(L, "Error encrypting file. Invalid key.");
    lua_error(L);
  }

  rel_index = 0;
  abs_index = 0;
  while (abs_index < (int) plainlen) {
    cypheredText[abs_index] = plainText[abs_index];
    abs_index++;
    rel_index++;
    if( rel_index == 8 ) {
      rel_index = 0;
      fencrypt(&(cypheredText[abs_index - 8]), 0, &KS);
    }
  }

  pad = 0;
  if(rel_index != 0) { /* Pads remaining bytes with zeroes */
    while(rel_index < 8)
    {
      pad++;
      cypheredText[abs_index++] = 0;
      rel_index++;
    }
    fencrypt(&(cypheredText[abs_index - 8]), 0, &KS);
  }
  cypheredText[abs_index] = pad;

  lua_pushlstring( L, cypheredText, abs_index+1 );
  free( cypheredText );
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rdi, %rbx
leaq 0x8(%rsp), %r14
movl $0x1, %esi
movq %r14, %rdx
callq 0x22708d
movq %rax, %r15
movq %rbx, %rdi
movl $0x2, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x227029
movq %rax, %r12
movq (%r14), %rdi
addq $0x8, %rdi
callq 0x17ff0
movq %rax, %r14
testq %rax, %rax
jne 0x23c524
leaq 0x18cbbf(%rip), %rsi    # 0x3c90d3
movq %rbx, %rdi
callq 0x2243ba
movq %rbx, %rdi
callq 0x225800
testq %r12, %r12
je 0x23c55b
movq %r12, %rdi
callq 0x172f0
cmpq $0x8, %rax
jb 0x23c55b
xorl %eax, %eax
movb (%r12,%rax), %cl
movb %cl, 0x10(%rsp,%rax)
incq %rax
cmpq $0x8, %rax
jne 0x23c539
leaq 0x10(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x332f78
jmp 0x23c572
leaq 0x18cb9b(%rip), %rsi    # 0x3c90fd
movq %rbx, %rdi
callq 0x2243ba
movq %rbx, %rdi
callq 0x225800
movq 0x8(%rsp), %rax
testl %eax, %eax
jle 0x23c61c
xorl %ecx, %ecx
leaq 0x18(%rsp), %r12
movq %rcx, %r13
cltq
addq %r14, %rcx
leaq (%r15,%r13), %rdx
xorl %ebp, %ebp
movb (%rdx,%rbp), %sil
movb %sil, (%rcx,%rbp)
cmpl $0x7, %ebp
je 0x23c5b6
leaq 0x1(,%rbp), %rsi
addq %r13, %rsi
incq %rbp
cmpq %rax, %rsi
jl 0x23c594
jmp 0x23c5ee
movq %r13, %rax
addq %rbp, %rax
leaq (%r14,%rax), %rdi
addq $-0x7, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x3335a6
movq 0x8(%rsp), %rax
movslq %eax, %rdx
leaq 0x1(,%rbp), %rcx
addq %r13, %rcx
cmpq %rdx, %rcx
jl 0x23c586
addl %ebp, %r13d
incl %r13d
jmp 0x23c61f
addq %rbp, %r13
leal -0x1(%rbp), %eax
cmpl $0x7, %eax
jae 0x23c623
movl %r13d, %edi
addq %r14, %rdi
negq %rbp
leal 0x7(%rbp), %edx
incq %rdx
xorl %esi, %esi
callq 0x173a0
addl %ebp, %r13d
addl $0x8, %r13d
addb $0x8, %bpl
jmp 0x23c625
xorl %r13d, %r13d
xorl %ebp, %ebp
jmp 0x23c63c
xorl %ebp, %ebp
movl %r13d, %eax
leaq (%r14,%rax), %rdi
addq $-0x8, %rdi
leaq 0x18(%rsp), %rdx
xorl %esi, %esi
callq 0x3335a6
movslq %r13d, %rax
movb %bpl, (%r14,%rax)
incl %eax
movslq %eax, %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2241f7
movq %r14, %rdi
callq 0x17fe8
movl $0x1, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq