// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/lib/net.c
// Function: netHttpGetMultiple
int netHttpGetMultiple(char *url, struct slName *queries, void *userData,
		       void (*responseCB)(void *userData, char *req,
					  char *hdr, struct dyString *body))
/* Given an URL which is the base of all requests to be made, and a 
 * linked list of queries to be appended to that base and sent in as 
 * requests, send the requests as a batch and read the HTTP response 
 * headers and bodies.  If not all the requests get responses (i.e. if 
 * the server is ignoring Keep-Alive or is imposing a limit), try again 
 * until we can't connect or until all requests have been served. 
 * For each HTTP response, do a callback. */
{
  struct slName *qStart;
  struct slName *qPtr;
  struct lineFile *lf;
  struct netParsedUrl *npu;
  struct dyString *dyQ    = newDyString(512);
  struct dyString *body;
  char *base;
  char *hdr;
  int qCount;
  int qTotal;
  int numParseFailures;
  int contentLength;
  boolean chunked;
  boolean done;
  boolean keepAlive;

  /* Find out how many queries we'll need to do so we know how many times 
   * it's OK to run into end of file in case server ignores Keep-Alive. */
  qTotal = 0;
  for (qPtr = queries;  qPtr != NULL;  qPtr = qPtr->next)
    {
      qTotal++;
    }

  done = FALSE;
  qCount = 0;
  numParseFailures = 0;
  qStart = queries;
  while ((! done) && (qStart != NULL))
    {
      lf = netHttpLineFileMayOpen(url, &npu);
      if (lf == NULL)
	{
	  done = TRUE;
	  break;
	}
      base = cloneString(npu->file);
      /* Send all remaining requests with keep-alive. */
      for (qPtr = qStart;  qPtr != NULL;  qPtr = qPtr->next)
	{
	  dyStringClear(dyQ);
	  dyStringAppend(dyQ, base);
	  dyStringAppend(dyQ, qPtr->name);
	  strcpy(npu->file, dyQ->string);
	  keepAlive = (qPtr->next == NULL) ? FALSE : TRUE;
	  netHttpGet(lf, npu, keepAlive);
	}
      /* Get as many responses as we can; call responseCB() and 
       * advance qStart for each. */
      for (qPtr = qStart;  qPtr != NULL;  qPtr = qPtr->next)
        {
	  if (lineFileParseHttpHeader(lf, &hdr, &chunked, &contentLength))
	    {
	      body = lineFileSlurpHttpBody(lf, chunked, contentLength);
	      dyStringClear(dyQ);
	      dyStringAppend(dyQ, base);
	      dyStringAppend(dyQ, qPtr->name);
	      responseCB(userData, dyQ->string, hdr, body);
	      qStart = qStart->next;
	      qCount++;
	    }
	  else
	    {
	      if (numParseFailures++ > qTotal) {
		done = TRUE;
	      }
	      break;
	    }
	}
    }

  return qCount;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl $0x200, %edi            # imm = 0x200
callq 0x35020
movq %rax, -0x48(%rbp)
movl $0x0, -0x68(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x45a55
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0x45a38
movl $0x0, -0x78(%rbp)
movl $0x0, -0x64(%rbp)
movl $0x0, -0x6c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x78(%rbp)
movb %al, -0x7d(%rbp)
jne 0x45a88
cmpq $0x0, -0x28(%rbp)
setne %al
movb %al, -0x7d(%rbp)
movb -0x7d(%rbp), %al
testb $0x1, %al
jne 0x45a94
jmp 0x45c37
movq -0x8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x45780
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x45ab8
movl $0x1, -0x78(%rbp)
jmp 0x45c37
movq -0x40(%rbp), %rdi
addq $0x1820, %rdi           # imm = 0x1820
callq 0x2a450
movq %rax, -0x58(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x45b63
movq -0x48(%rbp), %rax
movl $0x0, 0x14(%rax)
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movb $0x0, (%rax)
movq -0x48(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x353b0
movq -0x48(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x8, %rsi
callq 0x353b0
movq -0x40(%rbp), %rdi
addq $0x1820, %rdi           # imm = 0x1820
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x6680
movq -0x30(%rbp), %rax
movq (%rax), %rdx
movl $0x1, %eax
xorl %ecx, %ecx
cmpq $0x0, %rdx
cmovel %ecx, %eax
movl %eax, -0x7c(%rbp)
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl -0x7c(%rbp), %edx
callq 0x45850
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0x45ad4
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x45c32
movq -0x38(%rbp), %rdi
leaq -0x60(%rbp), %rsi
leaq -0x74(%rbp), %rdx
leaq -0x70(%rbp), %rcx
callq 0x3d540
cmpl $0x0, %eax
je 0x45c07
movq -0x38(%rbp), %rdi
movl -0x74(%rbp), %esi
movl -0x70(%rbp), %edx
callq 0x3d850
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
movl $0x0, 0x14(%rax)
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movb $0x0, (%rax)
movq -0x48(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x353b0
movq -0x48(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x8, %rsi
callq 0x353b0
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rdi
movq -0x48(%rbp), %rcx
movq 0x8(%rcx), %rsi
movq -0x60(%rbp), %rdx
movq -0x50(%rbp), %rcx
callq *%rax
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x45c20
movl -0x6c(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x6c(%rbp)
cmpl -0x68(%rbp), %eax
jle 0x45c1e
movl $0x1, -0x78(%rbp)
jmp 0x45c32
jmp 0x45c22
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0x45b6b
jmp 0x45a72
movl -0x64(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)