// File: /workspace/github_cpp_makefile_star2_O1/gpertea[P]gclib/GStr.cpp
// Function: GStr::read(_IO_FILE*, char const*, unsigned long)
size_t GStr::read(FILE* stream, const char* delimiter, size_t bufsize) {
//read up to (and including) the given delimiter string
//if delimiter is NULL or zero length, it will read the whole file
 if (readbuf==NULL) {
    GMALLOC(readbuf, bufsize);
    readbufsize=bufsize;
    }
  else if (bufsize!=readbufsize) {
            GFREE(readbuf);
            if (bufsize>0) {
              GMALLOC(readbuf, bufsize);
              }
            readbufsize=bufsize;
            }
 if (bufsize==0) {
    prep_data(0);
    return 0; //clear the string and free the buffer
    }
 size_t numread;
 size_t acc_len=0; //accumulated length
 int dlen=0;
 if (delimiter!=NULL && delimiter[0]!=0)
	 dlen=strlen(delimiter);
 void* p=NULL;
 Data* data = &null_data;
 do {
   numread=fread(readbuf, 1, bufsize, stream);
   if (numread) {
	 if (dlen>0)
       p=Gmemscan(readbuf, bufsize, (void*) delimiter, dlen);
     if (p!=NULL) {//found the delimiter
           //position the stream after it
           int l = (char*)p-(char*)readbuf;
           fseek(stream, l+dlen-numread, SEEK_CUR);
           numread=l+dlen;
      } else {//not found, go back if not eof
          if (numread==bufsize) {
              if (dlen>0) {
                 fseek(stream, -dlen, SEEK_CUR); //check if this works!
                 numread-=dlen;
              }
          }
      }
      if (data==&null_data) {
        data=new_data(numread);
        ::memcpy(data->chars, readbuf, numread);
        acc_len+=numread;
        }
       else {
        GREALLOC(data, sizeof(Data)+acc_len+numread);
        memcpy(&data->chars[acc_len], readbuf, numread);
        acc_len+=numread;
        data->length=acc_len;
        data->chars[acc_len]='\0';
        }
      } //if something read
   } while (p==NULL && numread!=0);
  replace_data(data);
  return acc_len;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, 0x18(%rsp)
movq %rdi, %rbx
movq 0x10(%rdi), %rdi
testq %rdi, %rdi
je 0x79d6
cmpq %r15, 0x18(%rbx)
je 0x7a0b
leaq 0x18(%rbx), %r14
callq 0x22e0
movq $0x0, 0x10(%rbx)
testq %r15, %r15
je 0x7a08
movq $0x0, 0x10(%rbx)
movq %r15, %rdi
callq 0x2330
movq %rax, 0x10(%rbx)
testq %rax, %rax
jne 0x7a08
leaq 0x6653(%rip), %rdi      # 0xe020
xorl %eax, %eax
callq 0x289c
jmp 0x7a08
movq $0x0, 0x10(%rbx)
testq %r15, %r15
je 0x79ef
movq %r15, %rdi
callq 0x2330
movq %rax, 0x10(%rbx)
cmpq $0x0, 0x10(%rbx)
jne 0x7a04
leaq 0x6623(%rip), %rdi      # 0xe020
xorl %eax, %eax
callq 0x289c
leaq 0x18(%rbx), %r14
movq %r15, (%r14)
testq %r15, %r15
movq %rbx, 0x8(%rsp)
je 0x7bc9
xorl %eax, %eax
testq %r12, %r12
movq %r15, 0x30(%rsp)
je 0x7a34
cmpb $0x0, (%r12)
je 0x7a34
movq %r12, %rdi
callq 0x2140
movq %r12, 0x28(%rsp)
movl %eax, %ecx
movq %rcx, 0x10(%rsp)
negl %eax
cltq
movq %rax, 0x20(%rsp)
leaq 0xc800(%rip), %rbp      # 0x14250
xorl %r14d, %r14d
movq 0x10(%rbx), %rdi
movl $0x1, %esi
movq 0x30(%rsp), %r13
movq %r13, %rdx
movq 0x18(%rsp), %rcx
callq 0x2390
testq %rax, %rax
je 0x7a95
movq %rax, %r15
movq 0x10(%rsp), %rcx
testl %ecx, %ecx
jle 0x7aa3
movq 0x10(%rbx), %rdi
movl %r13d, %esi
movq 0x28(%rsp), %rdx
callq 0x3416
movq %rax, %r12
jmp 0x7aa6
xorl %r15d, %r15d
movq %r14, %r13
xorl %r12d, %r12d
jmp 0x7bab
xorl %r12d, %r12d
testq %r12, %r12
je 0x7ad4
movl 0x10(%rbx), %eax
movl %r12d, %ecx
subl %eax, %ecx
addl 0x10(%rsp), %ecx
movslq %ecx, %rbx
movq %rbx, %rsi
subq %r15, %rsi
movq 0x18(%rsp), %rdi
movl $0x1, %edx
callq 0x2290
movq %rbx, %r15
jmp 0x7aff
cmpl $0x0, 0x10(%rsp)
setle %al
cmpq %r13, %r15
setne %cl
orb %al, %cl
jne 0x7aff
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
movl $0x1, %edx
callq 0x2290
subq 0x10(%rsp), %r15
leaq 0xc74a(%rip), %rax      # 0x14250
cmpq %rax, %rbp
je 0x7b27
leaq (%r14,%r15), %r13
movq %r13, %rsi
addq $0x10, %rsi
je 0x7b51
testq %rbp, %rbp
je 0x7b64
movq %rbp, %rdi
callq 0x23d0
jmp 0x7b6c
movl %r15d, %edi
xorl %esi, %esi
callq 0x4928
movq %rax, %rbp
leaq 0xc(%rax), %rdi
movq 0x8(%rsp), %rbx
movq 0x10(%rbx), %rsi
movq %r15, %rdx
callq 0x21e0
addq %r15, %r14
movq %r14, %r13
jmp 0x7bab
movb $0x1, %bl
testq %rbp, %rbp
je 0x7b60
movq %rbp, %rdi
callq 0x22e0
xorl %ebp, %ebp
jmp 0x7b76
movq %rsi, %rdi
callq 0x2330
testq %rax, %rax
setne %bl
cmovneq %rax, %rbp
testb %bl, %bl
jne 0x7b88
leaq 0x649f(%rip), %rdi      # 0xe020
xorl %eax, %eax
callq 0x289c
leaq (%r14,%rbp), %rdi
addq $0xc, %rdi
movq 0x8(%rsp), %rbx
movq 0x10(%rbx), %rsi
movq %r15, %rdx
callq 0x21e0
movl %r13d, 0x8(%rbp)
movb $0x0, 0xc(%rbp,%r13)
testq %r12, %r12
jne 0x7bbc
movq %r13, %r14
testq %r15, %r15
jne 0x7a53
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x4b54
jmp 0x7bfb
movq 0x20(%rbx), %rdi
leaq 0xc67c(%rip), %rbx      # 0x14250
cmpq %rbx, %rdi
je 0x7bef
decl (%rdi)
jne 0x7bef
callq 0x22e0
movq 0x8(%rsp), %rax
movq $0x0, 0x20(%rax)
movq 0x8(%rsp), %rax
movq %rbx, 0x20(%rax)
xorl %r13d, %r13d
movq %r13, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop