// File: /workspace/github_cpp_makefile_star2_O2/tsfn[P]doc2txt/src/doc_text.cpp
// Function: doc_text_file(Storage const&, _IO_FILE*)
bool doc_text_file(const Storage &storage, FILE *text_file) {
  const uchar *wds;
  uint wds_size;
  if (!storage.stream("WordDocument", &wds, &wds_size)) {
    return false;
  }

  const uchar *pt = get_piece_table(storage);
  if (pt == NULL) {
    return false;
  }

  fputc(0xFF, text_file);
  fputc(0xFE, text_file);
  uint lcb = *(const uint *)(pt + 1);
  uint n = (lcb - 4) / 12;
  const uchar *pcd = pt + 5;
  for (uint i = 0; i < n; ++i) {
    uint start = *(const uint *)(pcd + i * 4);
    uint end = *(const uint *)(pcd + i * 4 + 4);
    if (start >= end) return false;
    uint fcCompressed = *(const uint *)(pcd + (n + 1) * 4 + i * 8 + 2);
    bool fCompressed = (fcCompressed >> 30) & 1;
    if (fCompressed) {
      uint fc = (fcCompressed & ~(1U << 30)) / 2;
      uint cb = end - start;
      for (uint i = 0; i < cb; ++i) {
        if (fc + i < wds_size) {
          fputc(wds[fc + i], text_file);
          fputc(0, text_file);
        }
      }
    } else {
      uint fc = fcCompressed;
      uint cb = (end - start) * 2;
      for (uint i = 0; i < cb; i += 2) {
        if (fc + i + 1 < wds_size) {
          uchar low = wds[fc + i], high = wds[fc + i + 1];
          ushort ch = ((ushort)high << 8) + low;
          if (ch >= 0x000A) {
            fputc(wds[fc + i], text_file);
            fputc(wds[fc + i + 1], text_file);
          }
        }
      }
    }
  }
  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x10fa(%rip), %rsi      # 0x3044
leaq -0x38(%rbp), %rdx
leaq -0x2c(%rbp), %rcx
callq 0x1998
testb %al, %al
je 0x2084
movq %r14, %rdi
callq 0x1e79
testq %rax, %rax
je 0x2084
movq %rax, %r14
movl $0xff, %edi
movq %rbx, %rsi
callq 0x1170
movl $0xfe, %edi
movq %rbx, %rsi
callq 0x1170
movl 0x1(%r14), %eax
addl $-0x4, %eax
xorl %esi, %esi
pushq $0xc
popq %rcx
xorl %edx, %edx
divl %ecx
movq %rax, -0x50(%rbp)
leaq (%r14,%rax,4), %rax
addq $0xb, %rax
movq %rax, -0x40(%rbp)
addq $0x5, %r14
movq %r14, -0x48(%rbp)
cmpq -0x50(%rbp), %rsi
sete %al
je 0x2086
movl 0x4(%r14,%rsi,4), %r13d
subl (%r14,%rsi,4), %r13d
jbe 0x2086
movq %rsi, -0x58(%rbp)
movq -0x40(%rbp), %rax
movl (%rax,%rsi,8), %r15d
btl $0x1e, %r15d
jb 0x203c
addl %r13d, %r13d
xorl %r14d, %r14d
cmpq %r13, %r14
jae 0x2074
leal 0x1(%r15), %eax
cmpl -0x2c(%rbp), %eax
jae 0x2032
movq -0x38(%rbp), %rcx
movl %r15d, %edx
movzbl (%rcx,%rdx), %edi
movl %eax, %r12d
movzbl (%rcx,%r12), %eax
shll $0x8, %eax
orl %edi, %eax
cmpl $0xa, %eax
jb 0x2032
movq %rbx, %rsi
callq 0x1170
movq -0x38(%rbp), %rax
movzbl (%rax,%r12), %edi
movq %rbx, %rsi
callq 0x1170
addq $0x2, %r14
addl $0x2, %r15d
jmp 0x1fea
shrl %r15d
andl $0x5fffffff, %r15d      # imm = 0x5FFFFFFF
subq $0x1, %r13
jb 0x2074
cmpl -0x2c(%rbp), %r15d
jae 0x206f
movq -0x38(%rbp), %rax
movl %r15d, %ecx
movzbl (%rax,%rcx), %edi
movq %rbx, %rsi
callq 0x1170
xorl %edi, %edi
movq %rbx, %rsi
callq 0x1170
incl %r15d
jmp 0x2046
movq -0x58(%rbp), %rsi
incq %rsi
movq -0x48(%rbp), %r14
jmp 0x1fb5
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)