// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/liball/../libcperciva/http/http.c
// Function: gotheaders
static int
gotheaders(struct http_cookie * H, uint8_t * buf, size_t buflen)
{
	size_t bufpos;
	size_t linelen;
	size_t i;
	char * s;
	int major, minor;
	size_t len;
	const char * te;
	const char * clen;
	size_t cpos;
	size_t s_len;

	/* Suck the headers into a separate buffer. */
	H->res_headlen = buflen;
	if ((H->res_head = malloc(H->res_headlen)) == NULL)
		return (die(H));
	memcpy(H->res_head, buf, H->res_headlen);

	/* Consume the headers from the buffered reader. */
	netbuf_read_consume(H->R, H->res_headlen);

	/* Count header lines. */
	for (H->res.nheaders = 0, bufpos = 0;
	    bufpos < H->res_headlen;
	    H->res.nheaders++, bufpos += linelen + 2) {
		/* Find an EOL. */
		linelen = findeol(&H->res_head[bufpos],
		    H->res_headlen - bufpos);
	}

	/*
	 * We only call gotheaders() if we've found "\r\n\r\n", so we must have
	 * at least two EOLs.
	 */
	assert(H->res.nheaders >= 2);

	/* # headers = # lines - 1 (status-line) - 1 (blank line). */
	H->res.nheaders -= 2;

	/* Allocate header structures. */
	if (IMALLOC(H->res.headers, H->res.nheaders, struct http_header))
		return (die(H));

	/* Go back to the start of the buffer for the parsing pass. */
	bufpos = 0;

	/* Find the status-line and check for premature NULs. */
	s = sgetline(H->res_head, H->res_headlen, &bufpos, &linelen);
	if (strlen(s) < linelen) {
		warn0("Status line contains NUL byte");
		return (fail(H));
	}

	/* Parse "HTTP/X.Y Z " from status-line and sanity-check. */
	if (sscanf(s, "HTTP/%d.%d %d ", &major, &minor, &H->res.status) < 3) {
		warn0("Invalid HTTP status-line: %s", s);
		return (fail(H));
	}
	if (major != 1) {
		warn0("HTTP response with major version > 1!");
		return (fail(H));
	}
	if ((H->res.status < 100) || (H->res.status > 599)) {
		warn0("Invalid HTTP status code: %d", H->res.status);
		return (fail(H));
	}

	/* Parse headers. */
	for (i = 0; i < H->res.nheaders; i++) {
		/* Grab a line. */
		s = sgetline(H->res_head, H->res_headlen, &bufpos, &linelen);
		s_len = strlen(s);
		if (s_len < linelen) {
			warn0("Header contains NUL byte");
			return (fail(H));
		}

		/* Remove trailing optional whitespace (OWS). */
		while (s_len > 0) {
			if ((s[s_len - 1] == ' ') || (s[s_len - 1] == '\t'))
				s[--s_len] = '\0';
			else
				break;
		}

		/* Split into header and value. */
		cpos = strcspn(s, ":");
		H->res.headers[i].header = s;
		H->res.headers[i].value = s[cpos] ? &s[cpos + 1] : &s[cpos];
		s[cpos] = '\0';

		/* Strip leading optional whitespace (OWS) from the value. */
		H->res.headers[i].value += strspn(H->res.headers[i].value,
		    " \t");
	}

	/* We should be 2 bytes (\r\n) away from the end of the buffer. */
	assert(bufpos + 2 == H->res_headlen);

	/*
	 * If we received a 1xx response, we need to throw all the headers
	 * away and read a completely new response.  RFC 2616 says that a
	 * server can send a 1xx response whenever it likes and we must be
	 * prepared to accept it (but we may ignore it).
	 */
	if ((H->res.status >= 100) && (H->res.status <= 199)) {
		/* Free the headers. */
		free(H->res_head);
		free(H->res.headers);

		/* We don't want to try to free these again later. */
		H->res_head = NULL;
		H->res.headers = NULL;

		/* Go back to reading headers. */
		return (callback_read_header(H, 0));
	}

	/* If we don't expect any body, we can perform the callback now. */
	if ((H->req_ishead != 0) ||
	    (H->res.status == 204) || (H->res.status == 304)) {
		H->res.bodylen = 0;
		H->res.body = NULL;
		return (docallback(H));
	}

	/*
	 * If we have a "Transfer-Encoding: chunked" header, read the response
	 * body that way.
	 */
	if ((te = http_findheader(H->res.headers, H->res.nheaders,
	    "Transfer-Encoding")) != NULL) {
		if (strstr(te, "chunked") != NULL) {
			/* We're using chunked transfer-encoding. */
			H->chunked = 1;

			/* Read the first chunked header line. */
			return (callback_chunkedheader(H, 0));
		}
	}

	/*
	 * If we have a Content-Length header, parse the value; then read the
	 * specified number of bytes of body.
	 */
	if ((clen = http_findheader(H->res.headers, H->res.nheaders,
	    "Content-Length")) != NULL) {
		/* Parse in base 10, no trailing characters. */
		if (PARSENUM_EX(&len, clen, 10, 0)) {
			warnp("Invalid Content-Length: %s", clen);
			return (fail(H));
		}

		/* Read the body as a single blob. */
		return (get_body_gotclen(H, len));
	}

	/* Otherwise we need to just read until the connection is closed. */
	return (callback_read_toeof(H, 0));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x78(%rax)
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rdi
callq 0x34c0
movq -0x10(%rbp), %rcx
movq %rax, 0x80(%rcx)
cmpq $0x0, %rax
jne 0xce02
movq -0x10(%rbp), %rdi
callq 0xcc50
movl %eax, -0x4(%rbp)
jmp 0xd4f0
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rdx
callq 0x32c0
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rsi
callq 0xe600
movq -0x10(%rbp), %rax
movq $0x0, 0xb0(%rax)
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x78(%rcx), %rax
jae 0xcea4
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rdi
addq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rsi
subq -0x28(%rbp), %rsi
callq 0xd500
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0xb0(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0xb0(%rax)
movq -0x30(%rbp), %rax
addq $0x2, %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0xce4a
movq -0x10(%rbp), %rax
cmpq $0x2, 0xb0(%rax)
jb 0xceb4
jmp 0xced3
leaq 0x12194(%rip), %rdi     # 0x1f04f
leaq 0x1204b(%rip), %rsi     # 0x1ef0d
movl $0x1d8, %edx            # imm = 0x1D8
leaq 0x12196(%rip), %rcx     # 0x1f064
callq 0x3240
movq -0x10(%rbp), %rax
movq 0xb0(%rax), %rcx
subq $0x2, %rcx
movq %rcx, 0xb0(%rax)
movq -0x10(%rbp), %rax
movq 0xb0(%rax), %rdi
movl $0x10, %esi
callq 0xd570
movq -0x10(%rbp), %rcx
movq %rax, 0xb8(%rcx)
cmpq $0x0, %rax
jne 0xcf2e
movq -0x10(%rbp), %rax
cmpq $0x0, 0xb0(%rax)
jbe 0xcf2e
movq -0x10(%rbp), %rdi
callq 0xcc50
movl %eax, -0x4(%rbp)
jmp 0xd4f0
movq $0x0, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rsi
leaq -0x28(%rbp), %rdx
leaq -0x30(%rbp), %rcx
callq 0xd610
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x31a0
cmpq -0x30(%rbp), %rax
jae 0xcf95
jmp 0xcf6b
leaq 0x1212a(%rip), %rdi     # 0x1f09c
movb $0x0, %al
callq 0x6930
callq 0x3040
movl $0x0, (%rax)
movq -0x10(%rbp), %rdi
callq 0xcc10
movl %eax, -0x4(%rbp)
jmp 0xd4f0
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %r8
addq $0xa8, %r8
leaq 0x1210f(%rip), %rsi     # 0x1f0ba
leaq -0x44(%rbp), %rdx
leaq -0x48(%rbp), %rcx
movb $0x0, %al
callq 0x3390
cmpl $0x3, %eax
jge 0xcfef
jmp 0xcfc1
movq -0x40(%rbp), %rsi
leaq 0x120fd(%rip), %rdi     # 0x1f0c9
movb $0x0, %al
callq 0x6930
callq 0x3040
movl $0x0, (%rax)
movq -0x10(%rbp), %rdi
callq 0xcc10
movl %eax, -0x4(%rbp)
jmp 0xd4f0
cmpl $0x1, -0x44(%rbp)
je 0xd021
jmp 0xcff7
leaq 0x120e8(%rip), %rdi     # 0x1f0e6
movb $0x0, %al
callq 0x6930
callq 0x3040
movl $0x0, (%rax)
movq -0x10(%rbp), %rdi
callq 0xcc10
movl %eax, -0x4(%rbp)
jmp 0xd4f0
movq -0x10(%rbp), %rax
cmpl $0x64, 0xa8(%rax)
jl 0xd03e
movq -0x10(%rbp), %rax
cmpl $0x257, 0xa8(%rax)      # imm = 0x257
jle 0xd074
jmp 0xd040
movq -0x10(%rbp), %rax
movl 0xa8(%rax), %esi
leaq 0x120bb(%rip), %rdi     # 0x1f10c
movb $0x0, %al
callq 0x6930
callq 0x3040
movl $0x0, (%rax)
movq -0x10(%rbp), %rdi
callq 0xcc10
movl %eax, -0x4(%rbp)
jmp 0xd4f0
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0xb0(%rcx), %rax
jae 0xd22e
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rsi
leaq -0x28(%rbp), %rdx
leaq -0x30(%rbp), %rcx
callq 0xd610
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x31a0
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
cmpq -0x30(%rbp), %rax
jae 0xd0f8
jmp 0xd0ce
leaq 0x12054(%rip), %rdi     # 0x1f129
movb $0x0, %al
callq 0x6930
callq 0x3040
movl $0x0, (%rax)
movq -0x10(%rbp), %rdi
callq 0xcc10
movl %eax, -0x4(%rbp)
jmp 0xd4f0
jmp 0xd0fa
cmpq $0x0, -0x70(%rbp)
jbe 0xd149
movq -0x40(%rbp), %rax
movq -0x70(%rbp), %rcx
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x20, %eax
je 0xd12b
movq -0x40(%rbp), %rax
movq -0x70(%rbp), %rcx
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x9, %eax
jne 0xd145
movq -0x40(%rbp), %rax
movq -0x70(%rbp), %rcx
movq %rcx, %rdx
addq $-0x1, %rdx
movq %rdx, -0x70(%rbp)
movb $0x0, -0x1(%rax,%rcx)
jmp 0xd147
jmp 0xd149
jmp 0xd0fa
movq -0x40(%rbp), %rdi
leaq 0x11fee(%rip), %rsi     # 0x1f142
callq 0x3080
movq %rax, -0x68(%rbp)
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0xb8(%rax), %rax
movq -0x38(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rax
movq -0x68(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0xd1a0
movq -0x40(%rbp), %rax
movq -0x68(%rbp), %rcx
addq $0x1, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
jmp 0xd1ac
movq -0x40(%rbp), %rax
addq -0x68(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0xb8(%rax), %rax
movq -0x38(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x40(%rbp), %rax
movq -0x68(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x10(%rbp), %rax
movq 0xb8(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdi
leaq 0x11f4d(%rip), %rsi     # 0x1f144
callq 0x3190
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq 0xb8(%rax), %rax
movq -0x38(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xd07c
movq -0x28(%rbp), %rax
addq $0x2, %rax
movq -0x10(%rbp), %rcx
cmpq 0x78(%rcx), %rax
jne 0xd242
jmp 0xd261
leaq 0x11efe(%rip), %rdi     # 0x1f147
leaq 0x11cbd(%rip), %rsi     # 0x1ef0d
movl $0x217, %edx            # imm = 0x217
leaq 0x11e08(%rip), %rcx     # 0x1f064
callq 0x3240
movq -0x10(%rbp), %rax
cmpl $0x64, 0xa8(%rax)
jl 0xd2cf
movq -0x10(%rbp), %rax
cmpl $0xc7, 0xa8(%rax)
jg 0xd2cf
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rdi
callq 0x3460
movq -0x10(%rbp), %rax
movq 0xb8(%rax), %rdi
callq 0x3460
movq -0x10(%rbp), %rax
movq $0x0, 0x80(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0xb8(%rax)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0xcc70
movl %eax, -0x4(%rbp)
jmp 0xd4f0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x30(%rax)
jne 0xd2f9
movq -0x10(%rbp), %rax
cmpl $0xcc, 0xa8(%rax)
je 0xd2f9
movq -0x10(%rbp), %rax
cmpl $0x130, 0xa8(%rax)      # imm = 0x130
jne 0xd328
movq -0x10(%rbp), %rax
movq $0x0, 0xc0(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0xc8(%rax)
movq -0x10(%rbp), %rdi
callq 0xd6c0
movl %eax, -0x4(%rbp)
jmp 0xd4f0
movq -0x10(%rbp), %rax
movq 0xb8(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0xb0(%rax), %rsi
leaq 0x11e1f(%rip), %rdx     # 0x1f164
callq 0xcb60
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
je 0xd38d
movq -0x58(%rbp), %rdi
leaq 0x11e17(%rip), %rsi     # 0x1f176
callq 0x30d0
cmpq $0x0, %rax
je 0xd38b
movq -0x10(%rbp), %rax
movl $0x1, 0x88(%rax)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0xd710
movl %eax, -0x4(%rbp)
jmp 0xd4f0
jmp 0xd38d
movq -0x10(%rbp), %rax
movq 0xb8(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0xb0(%rax), %rsi
leaq 0x11dd4(%rip), %rdx     # 0x1f17e
callq 0xcb60
movq %rax, -0x60(%rbp)
cmpq $0x0, %rax
je 0xd4e2
callq 0x3040
movl $0x0, (%rax)
movq $0x1, -0x50(%rbp)
movq -0x50(%rbp), %rax
shrq %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, %rax
jbe 0xd412
movq 0x18bf8(%rip), %rax     # 0x25fe0
movq (%rax), %rdi
leaq 0x11d9b(%rip), %rsi     # 0x1f18d
leaq 0x11df2(%rip), %rdx     # 0x1f1eb
leaq 0x11b0d(%rip), %rcx     # 0x1ef0d
movl $0x24a, %r8d            # imm = 0x24A
movb $0x0, %al
callq 0x3530
callq 0x31f0
movq $-0x1, -0x50(%rbp)
movb $0x1, %al
testb $0x1, %al
jne 0xd422
jmp 0xd446
movq -0x60(%rbp), %rdi
movq -0x50(%rbp), %rdx
movq -0x50(%rbp), %rcx
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %r8d
xorl %r9d, %r9d
callq 0xda00
movq %rax, -0x50(%rbp)
jmp 0xd477
movq 0x18b93(%rip), %rax     # 0x25fe0
movq (%rax), %rdi
leaq 0x11d9f(%rip), %rsi     # 0x1f1f6
leaq 0x11d8d(%rip), %rdx     # 0x1f1eb
leaq 0x11aa8(%rip), %rcx     # 0x1ef0d
movl $0x24a, %r8d            # imm = 0x24A
movb $0x0, %al
callq 0x3530
callq 0x31f0
jmp 0xd479
callq 0x3040
cmpl $0x0, (%rax)
je 0xd4d0
jmp 0xd485
callq 0x3040
cmpl $0x0, (%rax)
je 0xd4ae
movq -0x60(%rbp), %rsi
leaq 0x11dcd(%rip), %rdi     # 0x1f267
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0xd4c0
movq -0x60(%rbp), %rsi
leaq 0x11dae(%rip), %rdi     # 0x1f267
movb $0x0, %al
callq 0x6930
jmp 0xd4c2
movq -0x10(%rbp), %rdi
callq 0xcc10
movl %eax, -0x4(%rbp)
jmp 0xd4f0
movq -0x10(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0xdac0
movl %eax, -0x4(%rbp)
jmp 0xd4f0
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0xdb30
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)