// File: /workspace/github_c_makefile_star2_O2/JimKent[P]linearSat/lib/linefile.c
// Function: lineFileParseHttpHeader
boolean lineFileParseHttpHeader(struct lineFile *lf, char **hdr,
				boolean *chunked, int *contentLength)
/* Extract HTTP response header from lf into hdr, tell if it's
 * "Transfer-Encoding: chunked" or if it has a contentLength. */
{
  struct dyString *header = newDyString(1024);
  char *line;
  int lineSize;

  if (chunked != NULL)
    *chunked = FALSE;
  if (contentLength != NULL)
    *contentLength = -1;
  dyStringClear(header);
  if (lineFileNext(lf, &line, &lineSize))
    {
      if (startsWith("HTTP/", line))
	{
	char *version, *code;
	dyStringAppendN(header, line, lineSize-1);
	dyStringAppendC(header, '\n');
	version = nextWord(&line);
	code = nextWord(&line);
	if (code == NULL)
	    {
	    warn("%s: Expecting HTTP/<version> <code> header line, got this: %s\n", lf->fileName, header->string);
	    *hdr = cloneString(header->string);
	    dyStringFree(&header);
	    return FALSE;
	    }
	if (!sameString(code, "200"))
	    {
	    warn("%s: Errored HTTP response header: %s %s %s\n", lf->fileName, version, code, line);
	    *hdr = cloneString(header->string);
	    dyStringFree(&header);
	    return FALSE;
	    }
	while (lineFileNext(lf, &line, &lineSize))
	    {
	    /* blank line means end of HTTP header */
	    if ((line[0] == '\r' && line[1] == 0) || line[0] == 0)
	        break;
	    if (strstr(line, "Transfer-Encoding: chunked") && chunked != NULL)
	        *chunked = TRUE;
	    dyStringAppendN(header, line, lineSize-1);
	    dyStringAppendC(header, '\n');
	    if (strstr(line, "Content-Length:"))
	      {
		code = nextWord(&line);
		code = nextWord(&line);
		if (contentLength != NULL)
		    *contentLength = atoi(code);
	      }
	    }
	}
      else
	{
	  /* put the line back, don't put it in header/hdr */
	  lineFileReuse(lf);
	  warn("%s: Expecting HTTP/<version> <code> header line, got this: %s\n", lf->fileName, header->string);
	  *hdr = cloneString(header->string);
	  dyStringFree(&header);
	  return FALSE;
	}
    }
  else
    {
      *hdr = cloneString(header->string);
      dyStringFree(&header);
      return FALSE;
    }

  *hdr = cloneString(header->string);
  dyStringFree(&header);
  return TRUE;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, %r14
movl $0x400, %edi            # imm = 0x400
callq 0x9df0
movq %rax, %r13
movq %rax, 0x8(%rsp)
testq %r12, %r12
je 0xcdad
andl $0x0, (%r12)
testq %r15, %r15
je 0xcdb6
orl $-0x1, (%r15)
andl $0x0, 0x14(%r13)
movq 0x8(%r13), %rax
movb $0x0, (%rax)
leaq 0x18(%rsp), %rsi
leaq 0x14(%rsp), %rdx
movq %r14, %rdi
callq 0xbcea
testl %eax, %eax
je 0xce72
movq 0x18(%rsp), %rsi
leaq 0xb46d(%rip), %rdi      # 0x18255
callq 0x76a5
testl %eax, %eax
je 0xce7d
movq %rbx, 0x20(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rbx
movq (%rbx), %rsi
movl 0x14(%rsp), %edx
decl %edx
callq 0x9eec
movq 0x8(%rsp), %rdi
pushq $0xa
popq %rsi
callq 0x9f5e
movq %rbx, %rdi
callq 0x6b8e
movq %rax, %r13
movq %rbx, %rdi
callq 0x6b8e
testq %rax, %rax
je 0xcead
movq %rax, %rbx
leaq 0xb459(%rip), %rsi      # 0x1829a
movq %rax, %rdi
callq 0x3440
testl %eax, %eax
je 0xcedd
movq 0x8(%r14), %rsi
movq 0x18(%rsp), %r8
leaq 0xb43d(%rip), %rdi      # 0x1829e
xorl %ebp, %ebp
movq %r13, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0xa3aa
jmp 0xceca
addq $0x8, %r13
xorl %ebp, %ebp
jmp 0xcfb0
movb $0x1, 0x3c(%r14)
movq 0x8(%r14), %rsi
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdx
leaq 0xb3c5(%rip), %rdi      # 0x1825b
xorl %ebp, %ebp
xorl %eax, %eax
callq 0xa3aa
movq 0x8(%rsp), %r13
addq $0x8, %r13
jmp 0xcfb0
movq 0x8(%r14), %rsi
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdx
leaq 0xb39a(%rip), %rdi      # 0x1825b
xorl %ebp, %ebp
xorl %eax, %eax
callq 0xa3aa
movq 0x8(%rsp), %r13
addq $0x8, %r13
movq 0x20(%rsp), %rbx
jmp 0xcfb0
leaq 0x18(%rsp), %r13
movq 0x20(%rsp), %rbx
movq %r14, %rdi
movq %r13, %rsi
leaq 0x14(%rsp), %rdx
callq 0xbcea
testl %eax, %eax
je 0xcfa4
movq 0x18(%rsp), %rbp
movzbl (%rbp), %eax
cmpl $0xd, %eax
je 0xcf16
testl %eax, %eax
jne 0xcf20
jmp 0xcfa4
cmpb $0x0, 0x1(%rbp)
je 0xcfa4
movq %rbp, %rdi
leaq 0xb3a0(%rip), %rsi      # 0x182ca
callq 0x3760
testq %r12, %r12
je 0xcf41
testq %rax, %rax
je 0xcf41
movl $0x1, (%r12)
movq 0x8(%rsp), %rdi
movl 0x14(%rsp), %edx
decl %edx
movq %rbp, %rsi
callq 0x9eec
movq 0x8(%rsp), %rdi
pushq $0xa
popq %rsi
callq 0x9f5e
movq 0x18(%rsp), %rdi
leaq 0xb378(%rip), %rsi      # 0x182e5
callq 0x3760
testq %rax, %rax
je 0xcee7
movq %r13, %rdi
callq 0x6b8e
movq %r13, %rdi
callq 0x6b8e
testq %r15, %r15
je 0xcee7
movq %rax, %rdi
callq 0x36a0
movl %eax, (%r15)
jmp 0xcee7
movq 0x8(%rsp), %r13
addq $0x8, %r13
pushq $0x1
popq %rbp
movq (%r13), %rdi
callq 0x5ede
movq %rax, (%rbx)
leaq 0x8(%rsp), %rdi
callq 0x9e2b
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq