// File: /workspace/github_c_makefile_star2_O1/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
xorl %r12d, %r12d
cmpl $0x10010, %eax          # imm = 0x10010
jle 0x42ef
cmpl $0x10011, %eax          # imm = 0x10011
je 0x4366
cmpl $0x10020, %eax          # imm = 0x10020
je 0x4395
cmpl $0x10030, %eax          # imm = 0x10030
je 0x4351
jmp 0x4445
cmpl $0x10000, %eax          # imm = 0x10000
je 0x4351
cmpl $0x10010, %eax          # imm = 0x10010
jne 0x4445
cmpq $0x0, 0x20(%r15)
je 0x4314
movq %r15, %rdi
callq 0xb7dc
testl %eax, %eax
jne 0x431b
movl $0x0, (%r15)
movq 0x18(%r15), %rcx
leaq 0x1(%rcx), %rax
movabsq $0x100000001, %rdx      # imm = 0x100000001
cmpq %rdx, %rax
jb 0x4381
leaq 0xd29f(%rip), %rdi      # 0x115d8
leaq 0xd0ad(%rip), %rsi      # 0x113ed
leaq 0xd2ce(%rip), %rcx      # 0x11615
movl $0x111, %edx            # imm = 0x111
callq 0x21e0
movq 0x20(%r14), %rdi
movq 0x18(%rbx), %rsi
movl (%r15), %edx
callq 0xae37
jmp 0x443b
movq 0x18(%r15), %rcx
leaq 0x1(%rcx), %rax
movabsq $0x100000001, %rdx      # imm = 0x100000001
cmpq %rdx, %rax
jae 0x446b
movq 0x20(%r14), %rdi
movq 0x18(%rbx), %rsi
movl (%r15), %edx
movq 0x20(%r15), %r8
jmp 0x4436
movq 0x8(%r15), %rsi
movq 0x10(%r15), %rdi
leaq 0xd2a7(%rip), %rdx      # 0x1164b
callq 0x5fa7
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x4425
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 0x43f8
cmpb $0x0, (%rdx)
jne 0x43f8
movq %rax, %rcx
shrq $0x20, %rcx
movl $0x22, %ecx
je 0x43fc
movl %ecx, (%r13)
cmpl $0x0, (%r13)
je 0x4423
leaq 0xd250(%rip), %rdi      # 0x1165a
movq %r12, %rsi
xorl %eax, %eax
callq 0xa2f4
movl $0x0, (%r13)
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
jmp 0x4425
movl %eax, %ecx
movq 0x20(%r14), %rdi
movq 0x18(%rbx), %rsi
movl (%r15), %edx
xorl %r12d, %r12d
xorl %r8d, %r8d
callq 0xaeb9
testl %eax, %eax
je 0x4445
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movq 0x20(%r15), %rdi
callq 0x2040
movq %r14, %rdi
movq %rbx, %rsi
callq 0x417a
movl %r12d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd166(%rip), %rdi      # 0x115d8
leaq 0xcf74(%rip), %rsi      # 0x113ed
leaq 0xd195(%rip), %rcx      # 0x11615
movl $0x11b, %edx            # imm = 0x11B
callq 0x21e0
nop