// File: /workspace/github_c_makefile_star2_O1/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, %r13
movq %rdi, %r14
movl $0x400, %edi            # imm = 0x400
callq 0xaf38
movq %rax, 0x20(%rsp)
testq %r12, %r12
je 0xe525
movl $0x0, (%r12)
testq %r15, %r15
je 0xe531
movl $0xffffffff, (%r15)     # imm = 0xFFFFFFFF
movl $0x0, 0x14(%rax)
movq 0x8(%rax), %rax
movb $0x0, (%rax)
leaq 0x18(%rsp), %rsi
leaq 0xc(%rsp), %rdx
movq %r14, %rdi
callq 0xd274
testl %eax, %eax
je 0xe5f2
movq 0x18(%rsp), %rsi
leaq 0xbce0(%rip), %rdi      # 0x1a245
callq 0x8214
testl %eax, %eax
je 0xe5f6
movq %r13, 0x10(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %r13
movq (%r13), %rsi
movl 0xc(%rsp), %edx
decl %edx
callq 0xb042
movq 0x20(%rsp), %rdi
movl $0xa, %esi
callq 0xb0c7
movq %r13, %rdi
callq 0x7371
movq %rax, %rbx
movq %r13, %rdi
callq 0x7371
testq %rax, %rax
je 0xe61a
movq %rax, %r13
leaq 0xbcc9(%rip), %rsi      # 0x1a28a
movq %rax, %rdi
callq 0x3440
testl %eax, %eax
je 0xe66a
movq 0x8(%r14), %rsi
movq 0x18(%rsp), %r8
leaq 0xbcad(%rip), %rdi      # 0x1a28e
xorl %ebp, %ebp
movq %rbx, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0xb632
jmp 0xe637
xorl %ebp, %ebp
jmp 0xe63c
movb $0x1, 0x3c(%r14)
movq 0x8(%r14), %rsi
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rdx
leaq 0xbc3c(%rip), %rdi      # 0x1a24b
xorl %ebp, %ebp
xorl %eax, %eax
callq 0xb632
jmp 0xe63c
movq 0x8(%r14), %rsi
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rdx
leaq 0xbc1d(%rip), %rdi      # 0x1a24b
xorl %ebp, %ebp
xorl %eax, %eax
callq 0xb632
movq 0x10(%rsp), %r13
leaq 0x20(%rsp), %rbx
movq (%rbx), %rax
movq 0x8(%rax), %rdi
callq 0x647e
movq %rax, (%r13)
movq %rbx, %rdi
callq 0xaf75
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x18(%rsp), %rsi
leaq 0xc(%rsp), %rdx
movq %r14, %rdi
callq 0xd274
movl $0x1, %ebp
testl %eax, %eax
je 0xe637
leaq 0x18(%rsp), %r13
movq 0x18(%rsp), %rbx
movzbl (%rbx), %eax
cmpl $0xd, %eax
je 0xe69d
testl %eax, %eax
jne 0xe6a7
jmp 0xe637
testb %al, %al
je 0xe637
cmpb $0x0, 0x1(%rbx)
je 0xe637
movq %rbx, %rdi
leaq 0xbc09(%rip), %rsi      # 0x1a2ba
callq 0x3760
testq %r12, %r12
je 0xe6c8
testq %rax, %rax
je 0xe6c8
movl $0x1, (%r12)
movq 0x20(%rsp), %rdi
movl 0xc(%rsp), %edx
decl %edx
movq %rbx, %rsi
callq 0xb042
movq 0x20(%rsp), %rdi
movl $0xa, %esi
callq 0xb0c7
movq 0x18(%rsp), %rdi
leaq 0xbbdf(%rip), %rsi      # 0x1a2d5
callq 0x3760
testq %rax, %rax
je 0xe720
movq %r13, %rdi
callq 0x7371
movq %r13, %rdi
callq 0x7371
testq %r15, %r15
je 0xe720
movq %rax, %rdi
callq 0x36a0
movl %eax, (%r15)
movq %r14, %rdi
movq %r13, %rsi
leaq 0xc(%rsp), %rdx
callq 0xd274
testl %eax, %eax
jne 0xe68a
jmp 0xe637