// File: /workspace/github_c_makefile_star2_O2/qpfiffer[P]38-Moths/src/grengine.c
// Function: m38_generate_response
m38_handled_request *m38_generate_response(const int accept_fd, const m38_app *app) {
	unsigned char *to_read = calloc(1, MAX_READ_LEN);
	char *actual_response = NULL;
	m38_http_response response = {
		.mimetype = {0},
		0
	};
	response.extra_headers = vector_new(sizeof(m38_header_pair *), 4);

	m38_handled_request *hreq = NULL;
	const m38_route *matching_route = NULL;
	size_t num_read = 0;
	int rc = 0;

	rc = read_max_bytes_from_socket(accept_fd, &to_read, &num_read);
	if (rc != 0)
		goto error;

	m38_http_request request = {
		.verb = {0},
		.resource = {0},
		.matches = {{0}},
		.header_len = 0,
		.full_header = NULL,
		.body_len = 0,
		.full_body = NULL
	};

	rc = m38_parse_request(to_read, num_read, &request);
	if (rc != 0) {
		m38_log_msg(LOG_ERR, "Could not parse request.");
		goto error;
	}

	char *clength = m38_get_header_value_raw(request.full_header, request.header_len, "Content-Length");
	size_t clength_num = 0;
	if (clength == NULL) {
		m38_log_msg(LOG_WARN, "Could not parse content length.");
	} else {
		clength_num = atoi(clength);
		free(clength);
	}

	/* Do we have a POST body or something? */
	const size_t post_body_len = num_read - request.header_len;
	if (post_body_len <= 0 && clength_num > 0) {
		/* re-read will just copy into the m38_http_request. */
		rc = attempt_reread_from_socket(accept_fd, clength_num, post_body_len, &request);
		if (rc != 0) {
			m38_log_msg(LOG_ERR, "Could not reread from socket and parse body.");
			goto error;
		}
	} else {
		rc = m38_parse_body(post_body_len, clength_num, to_read, &request);
		if (rc != 0) {
			m38_log_msg(LOG_ERR, "Could not parse body.");
			goto error;
		}
	}

	/* Parses form encoding, if applicable: */
	const char form_encoding[] = "application/x-www-form-urlencoded";
	const size_t form_encoding_siz = strlen(form_encoding);
	char *content_type = m38_get_header_value_request(&request, "Content-Type");

	if (content_type &&
			strlen(content_type) >= form_encoding_siz &&
			strncmp(form_encoding, content_type, form_encoding_siz) == 0) {
		rc = m38_parse_form_encoded_body(&request);
		if (rc != 0) {
			/* application/x-www-form-urlencoded */
			m38_log_msg(LOG_ERR, "Could not parse form-urlencoded body.");
			goto error;
		}
	
	}

	/* Find our matching route: */
	int64_t i;
	for (i = 0; i < app->num_routes; i++) {
		const m38_route *cur_route = &app->routes[i];
		if (strcmp(cur_route->verb, request.verb) != 0)
			continue;

		assert(cur_route->expected_matches < MAX_MATCHES);
		regex_t regex;
		int reti = regcomp(&regex, cur_route->route_match, REG_EXTENDED);
		if (reti != 0) {
			char errbuf[128];
			regerror(reti, &regex, errbuf, sizeof(errbuf));
			m38_log_msg(LOG_ERR, "%s", errbuf);
			assert(reti == 0);
		}

		if (cur_route->expected_matches > 0)
			reti = regexec(&regex, request.resource, cur_route->expected_matches + 1, request.matches, 0);
		else
			reti = regexec(&regex, request.resource, 0, NULL, 0);
		regfree(&regex);
		if (reti == 0) {
			matching_route = &app->routes[i];
			break;
		}
	}

	/* If we didn't find one just use the 404 route: */
	int64_t response_code = 0;
	if (matching_route == NULL) {
		matching_route = &r_404_route;
		response_code = 404;
		if (app->r_404_route) {
			m38_log_msg(LOG_INFO, "Setting custom 404 handler for %s.", matching_route->name);
			matching_route = app->r_404_route;
		} else {
			m38_log_msg(LOG_INFO, "Using internal 404 handler for %s.", matching_route->name);
		}
	} else {
		/* Run the handler through with the data we have: */
		m38_log_msg(LOG_INFO, "Calling handler for %s.", matching_route->name);
		response_code = matching_route->handler(&request, &response);
	}

	/* It doesn't seem like you actually need the response.outsize and .out checks here,
	 * but this makes it so that a view function can return a 404 and the 404 handler will
	 * be called. Very nifty.
	 */
	if (response_code == 404 && (response.outsize == 0 || response.out == NULL)) {
		m38_log_msg(LOG_INFO, "No response gen: Calling 404 handler for %s.", matching_route->name);
		matching_route = &r_404_route;

		if (app->r_404_route) {
			m38_log_msg(LOG_INFO, "Setting custom 404 handler for %s.", matching_route->name);
			matching_route = app->r_404_route;
		} else {
			m38_log_msg(LOG_INFO, "Using internal 404 handler for %s.", matching_route->name);
		}

		if (matching_route->handler) {
			response_code = matching_route->handler(&request, &response);
		} else {
			m38_log_msg(LOG_ERR, "No handler for route %s.", matching_route->name);
		}
	}

	/* Embed the handler's text into the header: */
	size_t header_size = 0;
	size_t actual_response_siz = 0;

	/* Figure out if this thing needs to be partial */
	char *range_header_value = m38_get_header_value_raw(request.full_header, request.header_len, "Range");
	if (range_header_value && RESPONSE_OK(response_code)) {
		response_code = 206;
	}

	/* Figure out what header we need to use: */
	const code_to_message *matched_response = NULL;
	const code_to_message *response_headers = get_response_headers();
	const int64_t num_elements = get_response_headers_num_elements();
	for (i = 0; i < num_elements; i++) {
		code_to_message current_response = response_headers[i];
		if (current_response.code == response_code) {
			matched_response = &response_headers[i];
			break;
		}
	}
	/* Blow up if we don't have that code. We should have them all at
	 * compile time. */
	assert(matched_response != NULL);

	if (response_code == 200 || response_code == 404 || response_code == 301 ||
			response_code == 302 ||response_code == 400 || response_code == 403 ||
			response_code == 500) {
		const size_t integer_length = UINT_LEN(response.outsize);
		if (response.mimetype[0] == '\0')
			memcpy(response.mimetype, "text/html", strlen("text/html"));

		header_size = strlen(response.mimetype) + strlen(matched_response->message)
			+ integer_length - strlen("%s") - strlen("%zu") + strlen(r_final);

		size_t i = 0;
		for (i = 0; i < response.extra_headers->count; i++) {
			m38_header_pair **pair = (m38_header_pair **)vector_get(response.extra_headers, i);
			header_size += (*pair)->header_len + strlen(": ") + (*pair)->value_len
								    + strlen("\r\n");
		}
		actual_response_siz = response.outsize + header_size;
		actual_response = malloc(actual_response_siz + 1);
		memset(actual_response, '\0', actual_response_siz);
		actual_response[actual_response_siz] = '\0';

		/* snprintf the header because it's just a string: */
		snprintf(actual_response, actual_response_siz, matched_response->message, response.mimetype, response.outsize);
		for (i = 0; i < response.extra_headers->count; i++) {
			m38_header_pair **pair = (m38_header_pair **)vector_get(response.extra_headers, i);
			const size_t siz = (*pair)->header_len + strlen(": ") + (*pair)->value_len
								    + strlen("\r\n") + 1;
			char buf[siz];
			buf[siz] = '\0';
			snprintf(buf, actual_response_siz, "%s: %s\r\n", (*pair)->header, (*pair)->value);
			strncat(actual_response, buf, siz);
		}
		strcat(actual_response, r_final);

		/* memcpy the rest because it could be anything: */
		memcpy(actual_response + header_size, response.out, response.outsize);
	} else if (response_code == 206) {
		/* Byte range queries have some extra shit. */
		m38_range_header byte_range = m38_parse_range_header(range_header_value);
		/* TODO: Add the custom header stuff here (for 206), too. */

		m38_log_msg(LOG_INFO, "Range header parsed: Raw: %s Limit: %zu Offset: %zu", range_header_value, byte_range.limit, byte_range.offset);
		free(range_header_value);

		size_t end_byte = 0;
		if (byte_range.limit == 0) {
			end_byte = response.outsize - 1;
		} else {
			end_byte = (response.outsize - byte_range.limit) - 1;
		}

		if (end_byte >= response.outsize)
			end_byte = response.outsize - 1;
		const size_t start_byte = byte_range.offset < response.outsize ? byte_range.offset : 0;
		const size_t max_size = response.outsize; /* Should be the same as file size. */
		const size_t integer_length = UINT_LEN(max_size);

		const size_t minb_len = start_byte == 0 ? 1 : UINT_LEN(start_byte);
		const size_t maxb_len = end_byte == 0 ? 1 : UINT_LEN(end_byte);
		/* Compute the size of the header */
		header_size = strlen(response.mimetype) + strlen(matched_response->message) + strlen(r_final)
			+ integer_length + minb_len + maxb_len + integer_length
			- strlen("%s") - (strlen("%zu") * 4);
		actual_response_siz = max_size + header_size;
		/* malloc the full response */
		actual_response = malloc(actual_response_siz + 1);
		actual_response[actual_response_siz] = '\0';

		/* snprintf the header because it's just a string: */
		snprintf(actual_response, actual_response_siz, matched_response->message,
			response.mimetype, max_size,
			start_byte, end_byte, max_size);
		m38_log_msg(LOG_INFO, "Sending back: Content-Range: %zu-%zu/%zu", start_byte, end_byte, max_size);

		strcat(actual_response, r_final);

		/* memcpy the rest because it could be anything: */
		memcpy(actual_response + header_size, response.out + start_byte, end_byte - start_byte);
	}

	log_request(&request, &response, response_code);

	hreq = malloc(sizeof(m38_handled_request));
	hreq->response_bytes = actual_response;
	hreq->response_len = actual_response_siz;
	hreq->response_code = response_code;
	hreq->accept_fd = accept_fd;
	hreq->sent = 0;
	hreq->matching_route = matching_route;
	memcpy(&hreq->response, &response, sizeof(response));

	free(to_read);
	free(request.full_header);
	free(request.full_body);
	free(request.form_elements);
	return hreq;

error:
	if (matching_route != NULL && matching_route->cleanup != NULL)
		matching_route->cleanup(500, &response);
	free(actual_response);
	free(to_read);
	free(request.full_header);
	free(request.full_body);
	free(request.form_elements);
	return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3b8, %rsp            # imm = 0x3B8
movq %rsi, %r14
movl %edi, %r12d
pushq $0x1
popq %r15
movl $0x400, %esi            # imm = 0x400
movq %r15, %rdi
callq 0x32e0
leaq -0xc0(%rbp), %rbx
movq %rax, (%rbx)
xorpd %xmm0, %xmm0
movapd %xmm0, -0x70(%rbp)
movapd %xmm0, -0x80(%rbp)
movapd %xmm0, -0x90(%rbp)
andq $0x0, -0x60(%rbp)
pushq $0x8
popq %rdi
pushq $0x4
popq %rsi
callq 0x3410
movq %rax, -0x58(%rbp)
leaq -0xb8(%rbp), %rdx
andq $0x0, (%rdx)
movl %r12d, %edi
movq %rbx, %rsi
callq 0x559b
movq (%rbx), %r13
testl %eax, %eax
jne 0x4b53
movq %r15, -0x30(%rbp)
leaq -0x358(%rbp), %r15
movl $0x258, %edx            # imm = 0x258
movq %r15, %rdi
xorl %esi, %esi
callq 0x3220
movq -0xb8(%rbp), %rbx
movq %r13, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x3250
testl %eax, %eax
je 0x4b93
leaq 0x46ed(%rip), %rsi      # 0x9236
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x3540
movq %r13, %rdi
callq 0x3050
xorl %ebx, %ebx
movq -0x128(%rbp), %rdi
callq 0x3050
movq -0x118(%rbp), %rdi
callq 0x3050
movq -0x108(%rbp), %rdi
callq 0x3050
movq %rbx, %rax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r12d, -0x34(%rbp)
movq -0x128(%rbp), %rdi
movq -0x120(%rbp), %rsi
leaq 0x46a3(%rip), %rdx      # 0x924f
callq 0x3210
testq %rax, %rax
je 0x4bce
movq %rax, %r12
movq %rax, %rdi
callq 0x3530
movslq %eax, %r15
movq %r12, %rdi
callq 0x3050
jmp 0x4be2
leaq 0x4689(%rip), %rsi      # 0x925e
xorl %r15d, %r15d
pushq $0x2
popq %rdi
xorl %eax, %eax
callq 0x3540
subq -0x120(%rbp), %rbx
jne 0x4c70
testq %r15, %r15
je 0x4c70
leaq -0x100(%rbp), %rax
andq $0x0, (%rax)
pushq $0x1
popq %rdi
movl $0x400, %esi            # imm = 0x400
callq 0x32e0
leaq -0x3e0(%rbp), %rbx
movq %rax, (%rbx)
leaq 0x4996(%rip), %rsi      # 0x95b3
pushq $0x2
popq %r12
movl %r12d, %edi
movq %r15, %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x3540
leaq 0x49b3(%rip), %rsi      # 0x95ea
movl %r12d, %edi
movq %r15, %rdx
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x3540
movl -0x34(%rbp), %edi
movq %rbx, %rsi
leaq -0x100(%rbp), %rdx
callq 0x559b
movq (%rbx), %rdi
testl %eax, %eax
je 0x4c95
callq 0x3050
leaq 0x4613(%rip), %rsi      # 0x927e
jmp 0x4b49
leaq -0x358(%rbp), %rcx
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x3420
testl %eax, %eax
je 0x4caa
leaq 0x461b(%rip), %rsi      # 0x92ab
jmp 0x4b49
movq -0x100(%rbp), %rax
movq %rdi, -0x118(%rbp)
movq %rax, -0x110(%rbp)
leaq 0x4610(%rip), %rsi      # 0x92c1
leaq -0x358(%rbp), %rdi
callq 0x3040
testq %rax, %rax
je 0x4ced
movq %rax, %rbx
movq %rax, %rdi
callq 0x3150
cmpq $0x21, %rax
jb 0x4ced
leaq 0x4976(%rip), %rdi      # 0x9650
pushq $0x21
popq %rdx
movq %rbx, %rsi
callq 0x30b0
testl %eax, %eax
je 0x5272
xorl %r12d, %r12d
leaq -0x100(%rbp), %rbx
xorl %r13d, %r13d
movslq 0x18(%r14), %rax
cmpq %rax, %r13
jge 0x4de9
movq 0x10(%r14), %r15
leaq (%r15,%r12), %rdi
leaq -0x358(%rbp), %rsi
callq 0x32f0
testl %eax, %eax
jne 0x4d92
cmpq $0x4, 0x150(%r15,%r12)
jae 0x557c
leaq (%r15,%r12), %rsi
addq $0x50, %rsi
movq %rbx, %rdi
pushq $0x1
popq %rdx
callq 0x32c0
testl %eax, %eax
jne 0x552c
movq 0x150(%r15,%r12), %rdx
testq %rdx, %rdx
je 0x4d6c
incq %rdx
movq %rbx, %rdi
leaq -0x348(%rbp), %rsi
leaq -0x148(%rbp), %rcx
jmp 0x4d7a
movq %rbx, %rdi
leaq -0x348(%rbp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3400
movl %eax, %r15d
movq %rbx, %rdi
callq 0x3140
testl %r15d, %r15d
je 0x4da1
incq %r13
addq $0x168, %r12            # imm = 0x168
jmp 0x4cfa
movq 0x10(%r14), %rax
testq %rax, %rax
je 0x4de9
leaq (%rax,%r12), %r13
leaq (%rax,%r12), %rbx
addq $0x10, %rbx
leaq 0x4607(%rip), %rsi      # 0x93c4
xorl %edi, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3540
leaq -0x358(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq *0x148(%rbx)
cmpl $0x194, %eax            # imm = 0x194
je 0x4e2b
jmp 0x4ebe
cmpq $0x0, 0x20(%r14)
je 0x4e0d
leaq 0x4587(%rip), %rsi      # 0x937e
leaq 0x8e92(%rip), %rdx      # 0xdc90
xorl %edi, %edi
xorl %eax, %eax
callq 0x3540
movq 0x20(%r14), %r13
jmp 0x4e2b
leaq 0x458d(%rip), %rsi      # 0x93a1
leaq 0x8e75(%rip), %rdx      # 0xdc90
xorl %edi, %edi
xorl %eax, %eax
callq 0x3540
leaq 0x8e55(%rip), %r13      # 0xdc80
cmpq $0x0, -0x88(%rbp)
movl $0x194, %r15d           # imm = 0x194
je 0x4e49
cmpq $0x0, -0x90(%rbp)
jne 0x4ed8
addq $0x10, %r13
leaq 0x4588(%rip), %rsi      # 0x93dc
xorl %edi, %edi
movq %r13, %rdx
xorl %eax, %eax
callq 0x3540
cmpq $0x0, 0x20(%r14)
je 0x4e84
leaq 0x4510(%rip), %rsi      # 0x937e
leaq 0x8e1b(%rip), %rdx      # 0xdc90
xorl %edi, %edi
xorl %eax, %eax
callq 0x3540
movq 0x20(%r14), %r13
jmp 0x4ea2
leaq 0x4516(%rip), %rsi      # 0x93a1
leaq 0x8dfe(%rip), %rdx      # 0xdc90
xorl %edi, %edi
xorl %eax, %eax
callq 0x3540
leaq 0x8dde(%rip), %r13      # 0xdc80
movq 0x158(%r13), %rax
testq %rax, %rax
je 0x4ec3
leaq -0x358(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq *%rax
movslq %eax, %r15
jmp 0x4ed8
leaq 0x10(%r13), %rdx
leaq 0x453b(%rip), %rsi      # 0x9409
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x3540
movq -0x128(%rbp), %rdi
movq -0x120(%rbp), %rsi
leaq 0x4535(%rip), %rdx      # 0x9422
callq 0x3210
movq %rax, %rbx
leaq -0xc8(%r15), %rax
cmpq $0xc8, %rax
movl $0xce, %r8d
cmovaeq %r15, %r8
testq %rbx, %rbx
cmoveq %r15, %r8
pushq $-0x8
popq %rax
leaq 0x8ce3(%rip), %r12      # 0xdc00
leaq 0x10(%rax), %r14
cmpq $0x88, %r14
je 0x550d
movslq 0x8(%rax,%r12), %rcx
movq %r14, %rax
cmpq %rcx, %r8
jne 0x4f1d
leaq -0x190(%r8), %rax
cmpq $0x4, %rax
jbe 0x4f87
leaq -0x12d(%r8), %rax
cmpq $0x2, %rax
jb 0x4f90
cmpq $0x1f4, %r8             # imm = 0x1F4
je 0x4f90
cmpq $0xce, %r8
je 0x5292
movq $0x0, -0x30(%rbp)
movl $0x0, %r15d
cmpq $0xc8, %r8
je 0x4f90
jmp 0x5174
pushq $0x19
popq %rcx
btq %rax, %rcx
jae 0x4f48
movq %r8, -0x48(%rbp)
movq %r13, -0x50(%rbp)
movq -0x88(%rbp), %rax
testq %rax, %rax
je 0x4ffc
movq %rax, %xmm1
punpckldq 0x410f(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x4117(%rip), %xmm1     # 0x90d0
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
callq 0x3310
callq 0x3520
addsd 0x4109(%rip), %xmm0     # 0x90e0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
subsd 0x4101(%rip), %xmm0     # 0x90e8
cvttsd2si %xmm0, %r13
sarq $0x3f, %rcx
andq %rcx, %r13
orq %rax, %r13
addq $0xf, %r13
jmp 0x5000
pushq $0x10
popq %r13
leaq -0x80(%rbp), %rdi
cmpb $0x0, (%rdi)
jne 0x501a
movabsq $0x6d74682f74786574, %rax # imm = 0x6D74682F74786574
movq %rax, (%rdi)
movb $0x6c, 0x8(%rdi)
callq 0x3150
movq %rax, %r15
movq (%r14,%r12), %rdi
callq 0x3150
addq %r15, %r13
addq %rax, %r13
xorl %r15d, %r15d
movq -0x58(%rbp), %rdi
cmpq 0x10(%rdi), %r15
jae 0x505d
movl %r15d, %esi
callq 0x3170
movq (%rax), %rax
movq 0x18(%rax), %rcx
addq 0x8(%rax), %r13
addq %rcx, %r13
addq $0x4, %r13
incq %r15
jmp 0x5034
movq -0x88(%rbp), %r15
leaq (%r15,%r13), %rbx
leaq (%r15,%r13), %rdi
incq %rdi
callq 0x33a0
movq %rax, %r12
movq %rax, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x3220
movb $0x0, (%r12,%rbx)
leaq 0x8b70(%rip), %rax      # 0xdc00
movq (%r14,%rax), %rdx
movq %r12, -0x40(%rbp)
movq %r12, %rdi
movq %rbx, -0x30(%rbp)
movq %rbx, %rsi
leaq -0x80(%rbp), %rcx
movq %r15, %r8
xorl %eax, %eax
callq 0x31e0
xorl %r15d, %r15d
movq -0x58(%rbp), %rdi
cmpq 0x10(%rdi), %r15
jae 0x512a
movl %r15d, %esi
callq 0x3170
movq %rsp, %rbx
movq (%rax), %rcx
movq 0x8(%rcx), %rdx
movq 0x18(%rcx), %rcx
leaq (%rdx,%rcx), %r14
addq $0x5, %r14
addq %rdx, %rcx
addq $0x14, %rcx
andq $-0x10, %rcx
movq %rsp, %r12
subq %rcx, %r12
movq %r12, %rsp
movb $0x0, (%r12,%r14)
movq (%rax), %rax
movq (%rax), %rcx
movq 0x10(%rax), %r8
movq %r12, %rdi
movq -0x30(%rbp), %rsi
leaq 0x4335(%rip), %rdx      # 0x9441
xorl %eax, %eax
callq 0x31e0
movq -0x40(%rbp), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x3270
movq %rbx, %rsp
incq %r15
jmp 0x50b3
movq -0x40(%rbp), %r15
movq %r15, %rdi
callq 0x3150
movabsq $0xa0d0a0d736874, %rcx  # imm = 0xA0D0A0D736874
movq %rcx, 0xd(%r15,%rax)
movapd 0x4533(%rip), %xmm0     # 0x9680
movupd %xmm0, (%r15,%rax)
movq %r15, %rdi
addq %r13, %rdi
movq -0x90(%rbp), %rsi
movq -0x88(%rbp), %rdx
callq 0x3350
movq -0x50(%rbp), %r13
movq -0x48(%rbp), %r8
leaq -0x358(%rbp), %rbx
movq 0x230(%rbx), %rdi
movq 0x238(%rbx), %rsi
leaq 0x447d(%rip), %rdx      # 0x960d
movq %r8, %r14
callq 0x3210
movq %r15, %r12
movq %rax, %r15
movq 0x230(%rbx), %rdi
movq 0x238(%rbx), %rsi
leaq 0x4464(%rip), %rdx      # 0x9617
callq 0x3210
movq %rax, %rbx
testq %r15, %r15
leaq 0x4473(%rip), %rdx      # 0x9638
cmovneq %r15, %rdx
testq %rax, %rax
leaq 0x446a(%rip), %r10      # 0x963d
cmovneq %rax, %r10
leaq 0x4444(%rip), %rsi      # 0x9622
pushq $0x4
popq %rdi
leaq -0x358(%rbp), %rcx
leaq -0x348(%rbp), %r8
movl %r14d, %r9d
xorl %eax, %eax
pushq %r10
pushq -0x88(%rbp)
callq 0x3540
popq %rax
popq %rcx
movq %r15, %rdi
callq 0x3050
movq %rbx, %rdi
callq 0x3050
pushq $0x68
popq %rdi
callq 0x33a0
movq %rax, %rbx
movq %r12, (%rax)
movq -0x30(%rbp), %rax
movq %rax, 0x8(%rbx)
movl %r14d, 0x14(%rbx)
movl -0x34(%rbp), %eax
movl %eax, 0x10(%rbx)
andq $0x0, 0x18(%rbx)
movq %r13, 0x20(%rbx)
movapd -0x90(%rbp), %xmm0
movaps -0x80(%rbp), %xmm1
movaps -0x70(%rbp), %xmm2
movaps -0x60(%rbp), %xmm3
movupd %xmm0, 0x28(%rbx)
movups %xmm1, 0x38(%rbx)
movups %xmm2, 0x48(%rbx)
movups %xmm3, 0x58(%rbx)
movq -0xc0(%rbp), %rdi
callq 0x3050
jmp 0x4b5d
leaq -0x358(%rbp), %rdi
callq 0x3190
testl %eax, %eax
je 0x4ced
leaq 0x4041(%rip), %rsi      # 0x92ce
jmp 0x4b49
movq %r8, -0x48(%rbp)
movq %r13, -0x50(%rbp)
movq %rbx, %rdi
callq 0x3580
movq %rax, %r13
movq %rdx, %r15
leaq 0x419b(%rip), %rsi      # 0x944a
xorl %edi, %edi
movq %rbx, %rdx
movq %rax, %rcx
movq %r15, %r8
xorl %eax, %eax
callq 0x3540
movq %rbx, %rdi
callq 0x3050
movq -0x88(%rbp), %rbx
movq %r13, %rdx
notq %rdx
addq %rbx, %rdx
leaq -0x1(%rbx), %rax
leaq -0x1(%rbx), %rcx
testq %r13, %r13
movl $0x0, %r13d
cmoveq %rcx, %rax
cmoveq %rcx, %rdx
cmpq %rbx, %rdx
cmovaeq %rax, %rdx
movq %rdx, -0xa8(%rbp)
cmpq %rbx, %r15
cmovbq %r15, %r13
cmpq $0x1, %rbx
pushq $0x8
popq %r15
jb 0x536b
movq %rbx, %xmm1
punpckldq 0x3da2(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3daa(%rip), %xmm1     # 0x90d0
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
callq 0x3310
callq 0x3520
addsd 0x3d9c(%rip), %xmm0     # 0x90e0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
subsd 0x3d94(%rip), %xmm0     # 0x90e8
cvttsd2si %xmm0, %rdx
sarq $0x3f, %rcx
andq %rcx, %rdx
orq %rax, %rdx
leaq 0x6(,%rdx,2), %r15
movq %rbx, -0xa0(%rbp)
pushq $0x1
popq %rbx
testq %r13, %r13
je 0x53cc
movq %r13, %xmm1
punpckldq 0x3d39(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3d41(%rip), %xmm1     # 0x90d0
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
callq 0x3310
callq 0x3520
addsd 0x3d33(%rip), %xmm0     # 0x90e0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x3d27(%rip), %xmm0     # 0x90e8
cvttsd2si %xmm0, %rbx
andq %rcx, %rbx
orq %rax, %rbx
movq %r13, -0xb0(%rbp)
movq %r15, -0x40(%rbp)
movq -0xa8(%rbp), %r13
testq %r13, %r13
je 0x5439
movq %r13, %xmm1
punpckldq 0x3cd0(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x3cd8(%rip), %xmm1     # 0x90d0
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
callq 0x3310
callq 0x3520
addsd 0x3cca(%rip), %xmm0     # 0x90e0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x3cbe(%rip), %xmm0     # 0x90e8
cvttsd2si %xmm0, %rdx
andq %rcx, %rdx
orq %rax, %rdx
movq %rdx, -0x30(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x3150
movq %rax, -0x98(%rbp)
movq (%r14,%r12), %r15
movq %r15, %rdi
callq 0x3150
movq -0x40(%rbp), %r14
addq %rbx, %r14
addq -0x30(%rbp), %r14
addq -0x98(%rbp), %r14
addq %rax, %r14
movq -0xa0(%rbp), %r12
leaq (%r14,%r12), %rbx
leaq (%r12,%r14), %rdi
incq %rdi
callq 0x33a0
movb $0x0, (%rax,%rbx)
movq %rax, %rdi
movq %rbx, -0x30(%rbp)
movq %rbx, %rsi
movq %r15, %rdx
movq %rax, %r15
leaq -0x80(%rbp), %rcx
movq %r12, %r8
movq -0xb0(%rbp), %rbx
movq %rbx, %r9
xorl %eax, %eax
pushq %r12
pushq %r13
callq 0x31e0
popq %rcx
popq %rdx
leaq 0x3fc4(%rip), %rsi      # 0x947e
xorl %edi, %edi
movq %rbx, %rdx
movq %r13, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0x3540
movq %r15, %rdi
callq 0x3150
movabsq $0xa0d0a0d736874, %rcx  # imm = 0xA0D0A0D736874
movq %rcx, 0xd(%r15,%rax)
movapd 0x4195(%rip), %xmm0     # 0x9680
movupd %xmm0, (%r15,%rax)
addq %r15, %r14
subq %rbx, %r13
leaq -0x80(%rbp), %rax
addq -0x10(%rax), %rbx
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
jmp 0x5167
leaq 0x3f14(%rip), %rdi      # 0x9428
leaq 0x3e03(%rip), %rsi      # 0x931e
leaq 0x3e0b(%rip), %rcx      # 0x932d
movl $0x21e, %edx            # imm = 0x21E
callq 0x3200
leaq -0x100(%rbp), %rsi
leaq -0x3e0(%rbp), %rbx
movl $0x80, %ecx
movl %eax, %edi
movq %rbx, %rdx
callq 0x3360
leaq 0x4024(%rip), %rsi      # 0x9574
pushq $0x3
popq %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3540
leaq 0x3e10(%rip), %rdi      # 0x9374
leaq 0x3db3(%rip), %rsi      # 0x931e
leaq 0x3dbb(%rip), %rcx      # 0x932d
movl $0x1d2, %edx            # imm = 0x1D2
callq 0x3200
leaq 0x3d71(%rip), %rdi      # 0x92f4
leaq 0x3d94(%rip), %rsi      # 0x931e
leaq 0x3d9c(%rip), %rcx      # 0x932d
movl $0x1cb, %edx            # imm = 0x1CB
callq 0x3200