// File: /workspace/github_c_makefile_star2_O2/Tarsnap[P]kivaloo/s3/dispatch.c
// Function: callback_response
static int
callback_response(void * cookie, struct http_response * res)
{
	struct request * R = cookie;
	struct dispatch_state * D = R->D;
	const char * s_clen;
	uint32_t clen;

	/* Send appropriate response back to the client. */
	switch (R->R.type) {
	case PROTO_S3_PUT:
		if (proto_s3_response_put(D->writeq, R->R.ID, res->status))
			goto err1;
		break;
	case PROTO_S3_GET:
		/* Verify that we have a body and the ETag is correct. */
		if ((res->body == NULL) || (s3_verifyetag(res) == 0))
			res->status = 0;

		/* Sanity check. */
		assert((res->bodylen == (size_t)-1) ||
		    (res->bodylen <= UINT32_MAX));

		/* Send the response. */
		if (proto_s3_response_get(D->writeq, R->R.ID, res->status,
		    (uint32_t)res->bodylen, res->body))
			goto err1;
		break;
	case PROTO_S3_RANGE:
		/* Sanity check. */
		assert((res->bodylen == (size_t)-1) ||
		    (res->bodylen <= UINT32_MAX));

		/* Send the response. */
		if (proto_s3_response_range(D->writeq, R->R.ID, res->status,
		    (uint32_t)res->bodylen, res->body))
			goto err1;
		break;
	case PROTO_S3_HEAD:
		/* Look for a Content-Length header. */
		if ((s_clen = http_findheader(res->headers,
		    res->nheaders, "Content-Length")) == NULL) {
			/* We have no Content-Length header. */
			clen = (uint32_t)(-1);
		} else {
			/* Parse in base 10, no trailing characters. */
			if (PARSENUM_EX(&clen, s_clen, 10, 0)) {
				warnp("Invalid Content-Length: %s", s_clen);
				clen = (uint32_t)(-1);
			}
		}

		/* Send the response. */
		if (proto_s3_response_head(D->writeq, R->R.ID, res->status,
		    clen))
			goto err1;
		break;
	case PROTO_S3_DELETE:
		if (proto_s3_response_delete(D->writeq, R->R.ID, res->status))
			goto err1;
	}

	/* Free the response body buffer. */
	free(res->body);

	/* Remove this request from the in-progress list. */
	request_dequeue(D, R);

	/* Success! */
	return (0);

err1:
	free(res->body);
	request_dequeue(D, R);

	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r15
movq %rdi, %rbx
movq (%rdi), %r14
movl 0x20(%rdi), %eax
cmpl $0x10030, %eax          # imm = 0x10030
je 0x3c83
cmpl $0x10010, %eax          # imm = 0x10010
je 0x3c98
cmpl $0x10011, %eax          # imm = 0x10011
je 0x3d74
cmpl $0x10020, %eax          # imm = 0x10020
je 0x3ce9
cmpl $0x10000, %eax          # imm = 0x10000
jne 0x3dbc
movq 0x20(%r14), %rdi
movq 0x18(%rbx), %rsi
movl (%r15), %edx
callq 0xa034
jmp 0x3d9f
cmpq $0x0, 0x20(%r15)
je 0x3cab
movq %r15, %rdi
callq 0xa92c
testl %eax, %eax
jne 0x3caf
andl $0x0, (%r15)
movq 0x18(%r15), %rcx
leaq 0x1(%rcx), %rax
movabsq $0x100000001, %rdx      # imm = 0x100000001
cmpq %rdx, %rax
jb 0x3d8b
leaq 0xc893(%rip), %rdi      # 0x10564
leaq 0xc6a1(%rip), %rsi      # 0x10379
leaq 0xc8c2(%rip), %rcx      # 0x105a1
movl $0x111, %edx            # imm = 0x111
callq 0x21e0
pushq $-0x1
popq %rbp
movq 0x8(%r15), %rsi
movq 0x10(%r15), %rdi
leaq 0xc8dc(%rip), %rdx      # 0x105d7
callq 0x56ac
testq %rax, %rax
je 0x3d62
movq %rax, %r12
callq 0x20a0
movq %rax, %r13
andl $0x0, (%rax)
movq %rsp, %rbp
pushq $0xa
popq %rdx
movq %r12, %rdi
movq %rbp, %rsi
callq 0x2410
movq (%rbp), %rdx
pushq $0x16
popq %rcx
cmpq %r12, %rdx
je 0x3d45
cmpb $0x0, (%rdx)
jne 0x3d45
movq %rax, %rcx
shrq $0x20, %rcx
je 0x3de1
pushq $0x22
popq %rcx
movl %ecx, (%r13)
leaq 0xc896(%rip), %rdi      # 0x105e6
movq %r12, %rsi
xorl %eax, %eax
callq 0x945d
andl $0x0, (%r13)
pushq $-0x1
popq %rbp
movq 0x20(%r14), %rdi
movq 0x18(%rbx), %rsi
movl (%r15), %edx
movl %ebp, %ecx
xorl %r8d, %r8d
jmp 0x3d9a
movq 0x18(%r15), %rcx
leaq 0x1(%rcx), %rax
movabsq $0x100000001, %rdx      # imm = 0x100000001
cmpq %rdx, %rax
jae 0x3df3
movq 0x20(%r14), %rdi
movq 0x18(%rbx), %rsi
movl (%r15), %edx
movq 0x20(%r15), %r8
callq 0xa0af
testl %eax, %eax
je 0x3dbc
movq 0x20(%r15), %rdi
callq 0x2040
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3b31
pushq $-0x1
popq %rax
jmp 0x3dd2
movq 0x20(%r15), %rdi
callq 0x2040
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3b31
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x0, (%r13)
jne 0x3d49
movl %eax, %ebp
jmp 0x3d62
leaq 0xc76a(%rip), %rdi      # 0x10564
leaq 0xc578(%rip), %rsi      # 0x10379
leaq 0xc799(%rip), %rcx      # 0x105a1
movl $0x11b, %edx            # imm = 0x11B
callq 0x21e0
nop