// File: /workspace/github_c_makefile_star2_O2/otrtool[P]otrtool/src/main.c
// Function: decryptFileWorker
void *decryptFileWorker(void *w_) {
  struct worker_info *w = w_;
  char buffer[65536];
  unsigned long long length = w->length;
  unsigned long long position;
  size_t readsize, writesize;

  waitSemaphore(&w->read_sema);
  while ((position = *w->pposition) < length) {
    showProgress(position, length);
    readsize = MIN(length - position, sizeof(buffer));
    if (fread(buffer, 1, readsize, w->file) < readsize) {
      if (feof(w->file))
        ERROR("Input file is too short");
      PERROR("Error reading input file");
    }
    *w->pposition = position + readsize;
    postSemaphore(&w->next->read_sema);

    waitSemaphore(&w->ivfy_sema);
    verifyFile_data(w->vfy_inp, buffer, readsize);
    postSemaphore(&w->next->ivfy_sema);

    /* If the payload length is not a multiple of eight,
     * the last few bytes are stored unencrypted */
    bf_ecb_decrypt(w->blowfishp, buffer, readsize - readsize % 8);

    waitSemaphore(&w->ovfy_sema);
    verifyFile_data(w->vfy_outp, buffer, readsize);
    postSemaphore(&w->next->ovfy_sema);

    waitSemaphore(&w->write_sema);
    writesize = fwrite(buffer, 1, readsize, w->destfile);
    if (writesize != readsize)
      PERROR("Error writing to destination file");
    postSemaphore(&w->next->write_sema);

    waitSemaphore(&w->read_sema);
  }
  postSemaphore(&w->next->read_sema);

  return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10028, %rsp          # imm = 0x10028
movq %rdi, %rbx
movq 0x88(%rdi), %r13
addq $0x8, %rdi
movq %rdi, (%rsp)
callq 0x4030
leaq 0x28(%rbx), %rax
movq %rax, 0x18(%rsp)
leaq 0x48(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x68(%rbx), %rax
movq %rax, 0x8(%rsp)
leaq 0x20(%rsp), %r15
pushq $0x1
popq %r12
movq 0x90(%rbx), %rax
movq (%rax), %rbp
movq %r13, %r14
subq %rbp, %r14
jbe 0x5a69
movq %rbp, %rdi
movq %r13, %rsi
callq 0x3cee
movl $0x10000, %eax          # imm = 0x10000
cmpq %rax, %r14
cmovaeq %rax, %r14
movq 0x98(%rbx), %rcx
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x2370
cmpq %r14, %rax
jb 0x5a89
addq %r14, %rbp
movq 0x90(%rbx), %rax
movq %rbp, (%rax)
movq (%rbx), %rdi
addq $0x8, %rdi
callq 0x40a8
movq 0x18(%rsp), %rdi
callq 0x4030
movq 0xa8(%rbx), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x25a5
movq (%rbx), %rdi
addq $0x28, %rdi
callq 0x40a8
movq 0xb8(%rbx), %rdi
movl %r14d, %edx
andl $0x1fff8, %edx          # imm = 0x1FFF8
movq %r15, %rsi
callq 0x3230
movq 0x10(%rsp), %rdi
callq 0x4030
movq 0xb0(%rbx), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x25a5
movq (%rbx), %rdi
addq $0x48, %rdi
callq 0x40a8
movq 0x8(%rsp), %rdi
callq 0x4030
movq 0xa0(%rbx), %rcx
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x2480
cmpq %r14, %rax
jne 0x5abb
movq (%rbx), %rdi
addq $0x68, %rdi
callq 0x40a8
movq (%rsp), %rdi
callq 0x4030
jmp 0x595f
movq (%rbx), %rdi
addq $0x8, %rdi
callq 0x40a8
xorl %eax, %eax
addq $0x10028, %rsp          # imm = 0x10028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x98(%rbx), %rdi
callq 0x2380
movl %eax, %ebx
movq 0x653a(%rip), %r14      # 0xbfd8
movq (%r14), %rsi
pushq $0xa
popq %rdi
callq 0x22d0
movq (%r14), %rcx
testl %ebx, %ebx
jne 0x5b03
leaq 0x2f4f(%rip), %rdi      # 0x8a06
pushq $0x18
jmp 0x5ad9
movq 0x6516(%rip), %r14      # 0xbfd8
movq (%r14), %rsi
pushq $0xa
popq %rdi
callq 0x22d0
movq (%r14), %rcx
leaq 0x2f48(%rip), %rdi      # 0x8a1f
pushq $0x21
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x2480
movq (%r14), %rcx
leaq 0x2c48(%rip), %rdi      # 0x8737
pushq $0x2
popq %rsi
movq %rbx, %rdx
callq 0x2480
xorl %edi, %edi
callq 0x2180
jmp 0x5b20
leaq 0x2ee4(%rip), %rdi      # 0x89ee
pushq $0x17
popq %rsi
pushq $0x1
popq %rdx
callq 0x2480
movq (%r14), %rsi
pushq $0xa
popq %rdi
callq 0x22d0
pushq $0x1
popq %rdi
callq 0x22a0