// File: /workspace/github_c_makefile_star2_O0/JimKent[P]linearSat/lib/linefile.c
// Function: lineFileSlurpHttpBody
struct dyString *lineFileSlurpHttpBody(struct lineFile *lf,
				       boolean chunked, int contentLength)
/* Return a dyString that contains the http response body in lf.  Handle
 * chunk-encoding and content-length. */
{
  struct dyString *body = newDyString(64*1024);
  char *line;
  int lineSize;

  dyStringClear(body);
  if (chunked)
    {
      /* Handle "Transfer-Encoding: chunked" body */
      /* Procedure from RFC2068 section 19.4.6 */
      char *csword;
      unsigned chunkSize = 0;
      unsigned size;
      do
	{
	  /* Read line that has chunk size (in hex) as first word. */
	  if (lineFileNext(lf, &line, NULL))
	    csword = nextWord(&line);
	  else break;
	  if (sscanf(csword, "%x", &chunkSize) < 1)
	    {
	      warn("%s: chunked transfer-encoding chunk size parse error.\n",
		   lf->fileName);
	      break;
	    }
	  /* If chunk size is 0, read in a blank line & then we're done. */
	  if (chunkSize == 0)
	    {
	      lineFileNext(lf, &line, NULL);
	      if (line == NULL || (line[0] != '\r' && line[0] != 0))
		warn("%s: chunked transfer-encoding: expected blank line, got %s\n",
		     lf->fileName, line);

	      break;
	    }
	  /* Read (and save) lines until we have read in chunk. */
	  for (size = 0;  size < chunkSize;  size += lineSize)
	    {
	      if (! lineFileNext(lf, &line, &lineSize))
		break;
	      dyStringAppendN(body, line, lineSize-1);
	      dyStringAppendC(body, '\n');
	    }
	  /* Read blank line - or extra CRLF inserted in the middle of the
	   * current line, in which case we need to trim it. */
	  if (size > chunkSize)
	    {
	      body->stringSize -= (size - chunkSize);
	      body->string[body->stringSize] = 0;
	    }
	  else if (size == chunkSize)
	    {
	      lineFileNext(lf, &line, NULL);
	      if (line == NULL || (line[0] != '\r' && line[0] != 0))
		warn("%s: chunked transfer-encoding: expected blank line, got %s\n",
		     lf->fileName, line);
	    }
	} while (chunkSize > 0);
      /* Try to read in next line.  If it's an HTTP header, put it back. */
      /* If there is a next line but it's not an HTTP header, it's a footer. */
      if (lineFileNext(lf, &line, NULL))
	{
	  if (startsWith("HTTP/", line))
	    lineFileReuse(lf);
	  else
	    {
	      /* Got a footer -- keep reading until blank line */
	      warn("%s: chunked transfer-encoding: got footer %s, discarding it.\n",
		   lf->fileName, line);
	      while (lineFileNext(lf, &line, NULL))
		{
		  if ((line[0] == '\r' && line[1] == 0) || line[0] == 0)
		    break;
		  warn("discarding footer line: %s\n", line);
		}
	    }
	}
    }
  else if (contentLength >= 0)
    {
      /* Read in known length */
      int size;
      for (size = 0;  size < contentLength;  size += lineSize)
	{
	  if (! lineFileNext(lf, &line, &lineSize))
	    break;
	  dyStringAppendN(body, line, lineSize-1);
	  dyStringAppendC(body, '\n');
	}
    }
  else
    {
      /* Read in to end of file (assume it's not a persistent connection) */
      while (lineFileNext(lf, &line, &lineSize))
	{
	  dyStringAppendN(body, line, lineSize-1);
	  dyStringAppendC(body, '\n');
	}
    }

  return(body);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl $0x10000, %edi          # imm = 0x10000
callq 0xf030
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl $0x0, 0x14(%rax)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movb $0x0, (%rax)
cmpl $0x0, -0xc(%rbp)
je 0x147af
movl $0x0, -0x34(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x20(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x12650
cmpl $0x0, %eax
je 0x1458c
leaq -0x20(%rbp), %rdi
callq 0x9050
movq %rax, -0x30(%rbp)
jmp 0x14591
jmp 0x14701
movq -0x30(%rbp), %rdi
leaq 0x1190a(%rip), %rsi     # 0x25ea6
leaq -0x34(%rbp), %rdx
movb $0x0, %al
callq 0x3510
cmpl $0x1, %eax
jge 0x145c7
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x10d62(%rip), %rdi     # 0x2531d
movb $0x0, %al
callq 0xf8f0
jmp 0x14701
cmpl $0x0, -0x34(%rbp)
jne 0x1461c
movq -0x8(%rbp), %rdi
leaq -0x20(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x12650
cmpq $0x0, -0x20(%rbp)
je 0x145fd
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0xd, %eax
je 0x14617
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x14617
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x20(%rbp), %rdx
leaq 0x10d44(%rip), %rdi     # 0x25354
movb $0x0, %al
callq 0xf8f0
jmp 0x14701
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
jae 0x1466f
movq -0x8(%rbp), %rdi
leaq -0x20(%rbp), %rsi
leaq -0x24(%rbp), %rdx
callq 0x12650
cmpl $0x0, %eax
jne 0x14643
jmp 0x1466f
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0x24(%rbp), %edx
subl $0x1, %edx
callq 0xf200
movq -0x18(%rbp), %rdi
movl $0xa, %esi
callq 0xf2b0
movl -0x24(%rbp), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x14623
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
jbe 0x1469f
movl -0x38(%rbp), %edx
subl -0x34(%rbp), %edx
movq -0x18(%rbp), %rax
movl 0x14(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x14(%rax)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
movslq 0x14(%rcx), %rcx
movb $0x0, (%rax,%rcx)
jmp 0x146f5
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
jne 0x146f3
movq -0x8(%rbp), %rdi
leaq -0x20(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x12650
cmpq $0x0, -0x20(%rbp)
je 0x146d7
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0xd, %eax
je 0x146f1
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x146f1
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x20(%rbp), %rdx
leaq 0x10c6a(%rip), %rdi     # 0x25354
movb $0x0, %al
callq 0xf8f0
jmp 0x146f3
jmp 0x146f5
jmp 0x146f7
cmpl $0x0, -0x34(%rbp)
ja 0x14567
movq -0x8(%rbp), %rdi
leaq -0x20(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x12650
cmpl $0x0, %eax
je 0x147aa
movq -0x20(%rbp), %rsi
leaq 0x10b57(%rip), %rdi     # 0x2527d
callq 0xa4b0
cmpl $0x0, %eax
je 0x1473b
movq -0x8(%rbp), %rdi
callq 0x12460
jmp 0x147a8
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x20(%rbp), %rdx
leaq 0x10c42(%rip), %rdi     # 0x25390
movb $0x0, %al
callq 0xf8f0
movq -0x8(%rbp), %rdi
leaq -0x20(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x12650
cmpl $0x0, %eax
je 0x147a6
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0xd, %eax
jne 0x14784
movq -0x20(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
je 0x14790
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x14792
jmp 0x147a6
movq -0x20(%rbp), %rsi
leaq 0x10c31(%rip), %rdi     # 0x253ce
movb $0x0, %al
callq 0xf8f0
jmp 0x14755
jmp 0x147a8
jmp 0x147aa
jmp 0x14849
cmpl $0x0, -0x10(%rbp)
jl 0x1480a
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x14808
movq -0x8(%rbp), %rdi
leaq -0x20(%rbp), %rsi
leaq -0x24(%rbp), %rdx
callq 0x12650
cmpl $0x0, %eax
jne 0x147dc
jmp 0x14808
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0x24(%rbp), %edx
subl $0x1, %edx
callq 0xf200
movq -0x18(%rbp), %rdi
movl $0xa, %esi
callq 0xf2b0
movl -0x24(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0x147bc
jmp 0x14847
jmp 0x1480c
movq -0x8(%rbp), %rdi
leaq -0x20(%rbp), %rsi
leaq -0x24(%rbp), %rdx
callq 0x12650
cmpl $0x0, %eax
je 0x14845
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0x24(%rbp), %edx
subl $0x1, %edx
callq 0xf200
movq -0x18(%rbp), %rdi
movl $0xa, %esi
callq 0xf2b0
jmp 0x1480c
jmp 0x14847
jmp 0x14849
movq -0x18(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)