// File: /workspace/github_c_makefile_star2_O0/qpfiffer[P]38-Moths/src/grengine.c
// Function: m38_send_response
m38_handled_request *m38_send_response(m38_handled_request *hreq) {
	/* Send that shit over the wire: */
	const m38_route *matching_route = hreq->matching_route;

	const size_t bytes_left = hreq->response_len - hreq->sent;
	const size_t to_send = bytes_left < 4096 ? bytes_left : 4096;
	int rc = send(hreq->accept_fd, hreq->response_bytes + hreq->sent, to_send, MSG_NOSIGNAL);
	if (rc <= 0) {
		m38_log_msg(LOG_ERR, "Could not send response.");
		goto error;
	}

	hreq->sent += to_send;

	if (hreq->response_len - hreq->sent <= 0) {
		if (matching_route->cleanup != NULL) {
			m38_log_msg(LOG_INFO, "Calling cleanup for %s.", matching_route->name);
			matching_route->cleanup(hreq->response_code, &hreq->response);
		}
		_clean_up_extra_headers(&hreq->response);
		close(hreq->accept_fd);
		free(hreq->response_bytes);
		free(hreq);

		return NULL;
	}

	return hreq;

error:
	if (matching_route != NULL && matching_route->cleanup != NULL)
		matching_route->cleanup(500, &hreq->response);
	_clean_up_extra_headers(&hreq->response);
	close(hreq->accept_fd);
	free(hreq->response_bytes);
	free(hreq);

	return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
subq 0x18(%rcx), %rax
movq %rax, -0x20(%rbp)
cmpq $0x1000, -0x20(%rbp)    # imm = 0x1000
jae 0x6f40
movq -0x20(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x6f4b
movl $0x1000, %eax           # imm = 0x1000
movq %rax, -0x38(%rbp)
jmp 0x6f4b
movq -0x38(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %edi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
addq 0x18(%rax), %rsi
movq -0x28(%rbp), %rdx
movl $0x4000, %ecx           # imm = 0x4000
callq 0x31a0
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jg 0x6f98
movl $0x3, %edi
leaq 0x553b(%rip), %rsi      # 0xc4c7
movb $0x0, %al
callq 0x3580
jmp 0x7042
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
addq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
subq 0x18(%rcx), %rax
cmpq $0x0, %rax
ja 0x7038
movq -0x18(%rbp), %rax
cmpq $0x0, 0x160(%rax)
je 0x7000
movq -0x18(%rbp), %rdx
addq $0x10, %rdx
xorl %edi, %edi
leaq 0x5503(%rip), %rsi      # 0xc4e0
movb $0x0, %al
callq 0x3580
movq -0x18(%rbp), %rax
movq 0x160(%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x14(%rcx), %edi
movq -0x10(%rbp), %rsi
addq $0x28, %rsi
callq *%rax
movq -0x10(%rbp), %rdi
addq $0x28, %rdi
callq 0x70c0
movq -0x10(%rbp), %rax
movl 0x10(%rax), %edi
callq 0x32a0
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x3050
movq -0x10(%rbp), %rdi
callq 0x3050
movq $0x0, -0x8(%rbp)
jmp 0x70a7
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x70a7
cmpq $0x0, -0x18(%rbp)
je 0x7071
movq -0x18(%rbp), %rax
cmpq $0x0, 0x160(%rax)
je 0x7071
movq -0x18(%rbp), %rax
movq 0x160(%rax), %rax
movq -0x10(%rbp), %rsi
addq $0x28, %rsi
movl $0x1f4, %edi            # imm = 0x1F4
callq *%rax
movq -0x10(%rbp), %rdi
addq $0x28, %rdi
callq 0x70c0
movq -0x10(%rbp), %rax
movl 0x10(%rax), %edi
callq 0x32a0
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x3050
movq -0x10(%rbp), %rdi
callq 0x3050
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)