// File: /workspace/github_c_makefile_star2_O3/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 $0x10010, %eax          # imm = 0x10010
jle 0x42a3
cmpl $0x10011, %eax          # imm = 0x10011
je 0x431a
cmpl $0x10020, %eax          # imm = 0x10020
je 0x4349
cmpl $0x10030, %eax          # imm = 0x10030
je 0x4305
jmp 0x4400
cmpl $0x10000, %eax          # imm = 0x10000
je 0x4305
cmpl $0x10010, %eax          # imm = 0x10010
jne 0x4400
cmpq $0x0, 0x20(%r15)
je 0x42c8
movq %r15, %rdi
callq 0xb80c
testl %eax, %eax
jne 0x42cf
movl $0x0, (%r15)
movq 0x18(%r15), %rcx
leaq 0x1(%rcx), %rax
movabsq $0x100000001, %rdx      # imm = 0x100000001
cmpq %rdx, %rax
jb 0x4335
leaq 0xd277(%rip), %rdi      # 0x11564
leaq 0xd085(%rip), %rsi      # 0x11379
leaq 0xd2a6(%rip), %rcx      # 0x115a1
movl $0x111, %edx            # imm = 0x111
callq 0x21e0
movq 0x20(%r14), %rdi
movq 0x18(%rbx), %rsi
movl (%r15), %edx
callq 0xae73
jmp 0x43e1
movq 0x18(%r15), %rcx
leaq 0x1(%rcx), %rax
movabsq $0x100000001, %rdx      # imm = 0x100000001
cmpq %rdx, %rax
jae 0x4430
movq 0x20(%r14), %rdi
movq 0x18(%rbx), %rsi
movl (%r15), %edx
movq 0x20(%r15), %r8
jmp 0x43dc
movq 0x8(%r15), %rsi
movq 0x10(%r15), %rdi
leaq 0xd27f(%rip), %rdx      # 0x115d7
callq 0x5f99
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x43ce
movq %rax, %r12
callq 0x20a0
movq %rax, %r13
movl $0x0, (%rax)
movq %rsp, %rbp
movq %r12, %rdi
movq %rbp, %rsi
movl $0xa, %edx
callq 0x2400
movq (%rbp), %rdx
movl $0x16, %ecx
cmpq %r12, %rdx
je 0x43ac
cmpb $0x0, (%rdx)
jne 0x43ac
movq %rax, %rcx
shrq $0x20, %rcx
movl $0x22, %ecx
je 0x4425
movl %ecx, (%r13)
leaq 0xd22f(%rip), %rdi      # 0x115e6
movq %r12, %rsi
xorl %eax, %eax
callq 0xa33c
movl $0x0, (%r13)
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq 0x20(%r14), %rdi
movq 0x18(%rbx), %rsi
movl (%r15), %edx
xorl %r8d, %r8d
callq 0xaef5
testl %eax, %eax
je 0x4400
movq 0x20(%r15), %rdi
callq 0x2040
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4135
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x4416
movq 0x20(%r15), %rdi
callq 0x2040
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4135
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x0, (%r13)
jne 0x43b0
movl %eax, %ecx
jmp 0x43ce
leaq 0xd12d(%rip), %rdi      # 0x11564
leaq 0xcf3b(%rip), %rsi      # 0x11379
leaq 0xd15c(%rip), %rcx      # 0x115a1
movl $0x11b, %edx            # imm = 0x11B
callq 0x21e0
nop