// File: /workspace/github_c_makefile_star2_O0/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
subq $0x520, %rsp            # imm = 0x520
movl %edi, -0xc(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x1, %edi
movl $0x400, %esi            # imm = 0x400
callq 0x3300
movq %rax, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
leaq -0x68(%rbp), %rdi
xorl %esi, %esi
movl $0x40, %edx
callq 0x3240
movl $0x8, %edi
movl $0x4, %esi
callq 0x3440
movq %rax, -0x30(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x78(%rbp)
movq $0x0, -0x80(%rbp)
movl $0x0, -0x84(%rbp)
movl -0xc(%rbp), %edi
leaq -0x20(%rbp), %rsi
leaq -0x80(%rbp), %rdx
callq 0x6bf0
movl %eax, -0x84(%rbp)
cmpl $0x0, -0x84(%rbp)
je 0x5c26
jmp 0x6b79
leaq -0x2e0(%rbp), %rdi
xorl %esi, %esi
movl $0x258, %edx            # imm = 0x258
callq 0x3240
movq -0x20(%rbp), %rdi
movq -0x80(%rbp), %rsi
leaq -0x2e0(%rbp), %rdx
callq 0x3270
movl %eax, -0x84(%rbp)
cmpl $0x0, -0x84(%rbp)
je 0x5c74
movl $0x3, %edi
leaq 0x65ee(%rip), %rsi      # 0xc256
movb $0x0, %al
callq 0x3580
jmp 0x6b79
movq -0xb0(%rbp), %rdi
movq -0xa8(%rbp), %rsi
leaq 0x65e6(%rip), %rdx      # 0xc26f
callq 0x3220
movq %rax, -0x2e8(%rbp)
movq $0x0, -0x2f0(%rbp)
cmpq $0x0, -0x2e8(%rbp)
jne 0x5cbf
movl $0x2, %edi
leaq 0x65c8(%rip), %rsi      # 0xc27e
movb $0x0, %al
callq 0x3580
jmp 0x5ce0
movq -0x2e8(%rbp), %rdi
callq 0x3560
cltq
movq %rax, -0x2f0(%rbp)
movq -0x2e8(%rbp), %rdi
callq 0x3050
movq -0x80(%rbp), %rax
subq -0xa8(%rbp), %rax
movq %rax, -0x2f8(%rbp)
cmpq $0x0, -0x2f8(%rbp)
ja 0x5d4c
cmpq $0x0, -0x2f0(%rbp)
jbe 0x5d4c
movl -0xc(%rbp), %edi
movq -0x2f0(%rbp), %rsi
movq -0x2f8(%rbp), %rdx
leaq -0x2e0(%rbp), %rcx
callq 0x6cf0
movl %eax, -0x84(%rbp)
cmpl $0x0, -0x84(%rbp)
je 0x5d4a
movl $0x3, %edi
leaq 0x6560(%rip), %rsi      # 0xc29e
movb $0x0, %al
callq 0x3580
jmp 0x6b79
jmp 0x5d93
movq -0x2f8(%rbp), %rdi
movq -0x2f0(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x2e0(%rbp), %rcx
callq 0x3450
movl %eax, -0x84(%rbp)
cmpl $0x0, -0x84(%rbp)
je 0x5d91
movl $0x3, %edi
leaq 0x6546(%rip), %rsi      # 0xc2cb
movb $0x0, %al
callq 0x3580
jmp 0x6b79
jmp 0x5d93
leaq -0x320(%rbp), %rdi
leaq 0x68cf(%rip), %rsi      # 0xc670
movl $0x22, %edx
callq 0x3370
movq $0x21, -0x328(%rbp)
leaq -0x2e0(%rbp), %rdi
leaq 0x651d(%rip), %rsi      # 0xc2e1
callq 0x3040
movq %rax, -0x330(%rbp)
cmpq $0x0, -0x330(%rbp)
je 0x5e3e
movq -0x330(%rbp), %rdi
callq 0x3140
cmpq $0x21, %rax
jb 0x5e3e
leaq -0x320(%rbp), %rdi
movq -0x330(%rbp), %rsi
movl $0x21, %edx
callq 0x30b0
cmpl $0x0, %eax
jne 0x5e3e
leaq -0x2e0(%rbp), %rdi
callq 0x3180
movl %eax, -0x84(%rbp)
cmpl $0x0, -0x84(%rbp)
je 0x5e3c
movl $0x3, %edi
leaq 0x64be(%rip), %rsi      # 0xc2ee
movb $0x0, %al
callq 0x3580
jmp 0x6b79
jmp 0x5e3e
movq $0x0, -0x338(%rbp)
movq -0x338(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq 0x18(%rcx), %rcx
cmpq %rcx, %rax
jge 0x6020
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x168, -0x338(%rbp), %rcx # imm = 0x168
addq %rcx, %rax
movq %rax, -0x340(%rbp)
movq -0x340(%rbp), %rdi
leaq -0x2e0(%rbp), %rsi
callq 0x3310
cmpl $0x0, %eax
je 0x5e9b
jmp 0x6009
movq -0x340(%rbp), %rax
cmpq $0x4, 0x150(%rax)
jae 0x5eae
jmp 0x5ecd
leaq 0x645f(%rip), %rdi      # 0xc314
leaq 0x6482(%rip), %rsi      # 0xc33e
movl $0x1cb, %edx            # imm = 0x1CB
leaq 0x6485(%rip), %rcx      # 0xc34d
callq 0x3210
movq -0x340(%rbp), %rsi
addq $0x50, %rsi
leaq -0x380(%rbp), %rdi
movl $0x1, %edx
callq 0x32e0
movl %eax, -0x384(%rbp)
cmpl $0x0, -0x384(%rbp)
je 0x5f5c
movl -0x384(%rbp), %edi
leaq -0x410(%rbp), %rdx
leaq -0x380(%rbp), %rsi
movl $0x80, %ecx
callq 0x3380
leaq -0x410(%rbp), %rdx
movl $0x3, %edi
leaq 0x666b(%rip), %rsi      # 0xc594
movb $0x0, %al
callq 0x3580
cmpl $0x0, -0x384(%rbp)
jne 0x5f3b
jmp 0x5f5a
leaq 0x6452(%rip), %rdi      # 0xc394
leaq 0x63f5(%rip), %rsi      # 0xc33e
movl $0x1d2, %edx            # imm = 0x1D2
leaq 0x63f8(%rip), %rcx      # 0xc34d
callq 0x3210
jmp 0x5f5c
movq -0x340(%rbp), %rax
cmpq $0x0, 0x150(%rax)
jbe 0x5faf
leaq -0x2e0(%rbp), %rsi
addq $0x10, %rsi
movq -0x340(%rbp), %rax
movq 0x150(%rax), %rdx
addq $0x1, %rdx
leaq -0x2e0(%rbp), %rcx
addq $0x210, %rcx            # imm = 0x210
leaq -0x380(%rbp), %rdi
xorl %r8d, %r8d
callq 0x3430
movl %eax, -0x384(%rbp)
jmp 0x5fd6
leaq -0x2e0(%rbp), %rsi
addq $0x10, %rsi
leaq -0x380(%rbp), %rdi
xorl %eax, %eax
movl %eax, %ecx
xorl %r8d, %r8d
movq %rcx, %rdx
callq 0x3430
movl %eax, -0x384(%rbp)
leaq -0x380(%rbp), %rdi
callq 0x3130
cmpl $0x0, -0x384(%rbp)
jne 0x6007
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x168, -0x338(%rbp), %rcx # imm = 0x168
addq %rcx, %rax
movq %rax, -0x78(%rbp)
jmp 0x6020
jmp 0x6009
movq -0x338(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x338(%rbp)
jmp 0x5e49
movq $0x0, -0x418(%rbp)
cmpq $0x0, -0x78(%rbp)
jne 0x6093
leaq 0xac47(%rip), %rax      # 0x10c80
movq %rax, -0x78(%rbp)
movq $0x194, -0x418(%rbp) # imm = 0x194
movq -0x18(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x6079
movq -0x78(%rbp), %rdx
addq $0x10, %rdx
xorl %edi, %edi
leaq 0x633a(%rip), %rsi      # 0xc39e
movb $0x0, %al
callq 0x3580
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x78(%rbp)
jmp 0x6091
movq -0x78(%rbp), %rdx
addq $0x10, %rdx
xorl %edi, %edi
leaq 0x6337(%rip), %rsi      # 0xc3c1
movb $0x0, %al
callq 0x3580
jmp 0x60c9
movq -0x78(%rbp), %rdx
addq $0x10, %rdx
xorl %edi, %edi
leaq 0x6340(%rip), %rsi      # 0xc3e4
movb $0x0, %al
callq 0x3580
movq -0x78(%rbp), %rax
leaq -0x2e0(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq *0x158(%rax)
cltq
movq %rax, -0x418(%rbp)
cmpq $0x194, -0x418(%rbp) # imm = 0x194
jne 0x61a3
cmpq $0x0, -0x60(%rbp)
je 0x60ec
cmpq $0x0, -0x68(%rbp)
jne 0x61a3
movq -0x78(%rbp), %rdx
addq $0x10, %rdx
xorl %edi, %edi
leaq 0x62ff(%rip), %rsi      # 0xc3fc
movb $0x0, %al
callq 0x3580
leaq 0xab75(%rip), %rax      # 0x10c80
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x6140
movq -0x78(%rbp), %rdx
addq $0x10, %rdx
xorl %edi, %edi
leaq 0x6273(%rip), %rsi      # 0xc39e
movb $0x0, %al
callq 0x3580
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x78(%rbp)
jmp 0x6158
movq -0x78(%rbp), %rdx
addq $0x10, %rdx
xorl %edi, %edi
leaq 0x6270(%rip), %rsi      # 0xc3c1
movb $0x0, %al
callq 0x3580
movq -0x78(%rbp), %rax
cmpq $0x0, 0x158(%rax)
je 0x6186
movq -0x78(%rbp), %rax
leaq -0x2e0(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq *0x158(%rax)
cltq
movq %rax, -0x418(%rbp)
jmp 0x61a1
movq -0x78(%rbp), %rdx
addq $0x10, %rdx
movl $0x3, %edi
leaq 0x628f(%rip), %rsi      # 0xc429
movb $0x0, %al
callq 0x3580
jmp 0x61a3
movq $0x0, -0x420(%rbp)
movq $0x0, -0x428(%rbp)
movq -0xb0(%rbp), %rdi
movq -0xa8(%rbp), %rsi
leaq 0x6274(%rip), %rdx      # 0xc442
callq 0x3220
movq %rax, -0x430(%rbp)
cmpq $0x0, -0x430(%rbp)
je 0x6209
cmpq $0xc8, -0x418(%rbp)
jl 0x6209
cmpq $0x190, -0x418(%rbp) # imm = 0x190
jge 0x6209
movq $0xce, -0x418(%rbp)
movq $0x0, -0x438(%rbp)
callq 0x33b0
movq %rax, -0x440(%rbp)
callq 0x31f0
movq %rax, -0x448(%rbp)
movq $0x0, -0x338(%rbp)
movq -0x338(%rbp), %rax
cmpq -0x448(%rbp), %rax
jge 0x62b5
movq -0x440(%rbp), %rax
movq -0x338(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x458(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x450(%rbp)
movslq -0x458(%rbp), %rax
cmpq -0x418(%rbp), %rax
jne 0x629f
movq -0x440(%rbp), %rax
movq -0x338(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x438(%rbp)
jmp 0x62b5
jmp 0x62a1
movq -0x338(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x338(%rbp)
jmp 0x6237
cmpq $0x0, -0x438(%rbp)
je 0x62c1
jmp 0x62e0
leaq 0x6180(%rip), %rdi      # 0xc448
leaq 0x606f(%rip), %rsi      # 0xc33e
movl $0x21e, %edx            # imm = 0x21E
leaq 0x6072(%rip), %rcx      # 0xc34d
callq 0x3210
cmpq $0xc8, -0x418(%rbp)
je 0x633f
cmpq $0x194, -0x418(%rbp) # imm = 0x194
je 0x633f
cmpq $0x12d, -0x418(%rbp) # imm = 0x12D
je 0x633f
cmpq $0x12e, -0x418(%rbp) # imm = 0x12E
je 0x633f
cmpq $0x190, -0x418(%rbp) # imm = 0x190
je 0x633f
cmpq $0x193, -0x418(%rbp) # imm = 0x193
je 0x633f
cmpq $0x1f4, -0x418(%rbp) # imm = 0x1F4
jne 0x6657
cmpq $0x0, -0x60(%rbp)
jne 0x6358
movsd 0x5d92(%rip), %xmm0     # 0xc0e0
movsd %xmm0, -0x4d8(%rbp)
jmp 0x639d
movaps 0x5d91(%rip), %xmm1     # 0xc0f0
movq -0x60(%rbp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x5d90(%rip), %xmm1     # 0xc100
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
callq 0x3330
callq 0x3550
movsd 0x5d4f(%rip), %xmm1     # 0xc0e0
addsd %xmm1, %xmm0
movsd %xmm0, -0x4d8(%rbp)
movsd -0x4d8(%rbp), %xmm0
movsd 0x5d3b(%rip), %xmm2     # 0xc0e8
movaps %xmm0, %xmm1
subsd %xmm2, %xmm1
cvttsd2si %xmm1, %rcx
cvttsd2si %xmm0, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x460(%rbp)
movsbl -0x58(%rbp), %eax
cmpl $0x0, %eax
jne 0x63ef
movq 0x5d62(%rip), %rax      # 0xc144
movq %rax, -0x58(%rbp)
movb 0x5d60(%rip), %al       # 0xc14c
movb %al, -0x50(%rbp)
leaq -0x68(%rbp), %rdi
addq $0x10, %rdi
callq 0x3140
movq %rax, -0x4e0(%rbp)
movq -0x438(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x3140
movq %rax, %rcx
movq -0x4e0(%rbp), %rax
addq %rcx, %rax
addq -0x460(%rbp), %rax
subq $0x2, %rax
subq $0x3, %rax
addq $0x14, %rax
movq %rax, -0x420(%rbp)
movq $0x0, -0x468(%rbp)
movq $0x0, -0x468(%rbp)
movq -0x468(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x64c0
movq -0x30(%rbp), %rdi
movq -0x468(%rbp), %rax
movl %eax, %esi
callq 0x3160
movq %rax, -0x470(%rbp)
movq -0x470(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
addq $0x2, %rax
movq -0x470(%rbp), %rcx
movq (%rcx), %rcx
addq 0x18(%rcx), %rax
addq $0x2, %rax
addq -0x420(%rbp), %rax
movq %rax, -0x420(%rbp)
movq -0x468(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x468(%rbp)
jmp 0x6450
movq -0x60(%rbp), %rax
addq -0x420(%rbp), %rax
movq %rax, -0x428(%rbp)
movq -0x428(%rbp), %rdi
addq $0x1, %rdi
callq 0x33d0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movq -0x428(%rbp), %rdx
xorl %esi, %esi
callq 0x3240
movq -0x28(%rbp), %rax
movq -0x428(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x28(%rbp), %rdi
movq -0x428(%rbp), %rsi
movq -0x438(%rbp), %rax
movq 0x8(%rax), %rdx
leaq -0x68(%rbp), %rcx
addq $0x10, %rcx
movq -0x60(%rbp), %r8
movb $0x0, %al
callq 0x31e0
movq $0x0, -0x468(%rbp)
movq -0x468(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x662a
movq -0x30(%rbp), %rdi
movl -0x468(%rbp), %esi
callq 0x3160
movq %rax, -0x478(%rbp)
movq -0x478(%rbp), %rax
movq (%rax), %rcx
movq 0x8(%rcx), %rax
movq 0x18(%rcx), %rcx
leaq 0x5(%rax,%rcx), %rax
movq %rax, -0x480(%rbp)
movq -0x480(%rbp), %rax
movq %rsp, %rcx
movq %rcx, -0x488(%rbp)
movq %rax, %rcx
addq $0xf, %rcx
andq $-0x10, %rcx
movq %rsp, %rdi
subq %rcx, %rdi
movq %rdi, -0x4e8(%rbp)
movq %rdi, %rsp
movq %rax, -0x490(%rbp)
movq -0x480(%rbp), %rax
movb $0x0, (%rdi,%rax)
movq -0x428(%rbp), %rsi
movq -0x478(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rcx
movq -0x478(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %r8
leaq 0x5e76(%rip), %rdx      # 0xc461
movb $0x0, %al
callq 0x31e0
movq -0x4e8(%rbp), %rsi
movq -0x28(%rbp), %rdi
movq -0x480(%rbp), %rdx
callq 0x3290
movq -0x488(%rbp), %rax
movq %rax, %rsp
movq -0x468(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x468(%rbp)
jmp 0x653b
movq -0x28(%rbp), %rdi
leaq 0x606b(%rip), %rsi      # 0xc6a0
callq 0x3570
movq -0x28(%rbp), %rdi
addq -0x420(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
callq 0x3370
jmp 0x6ab9
cmpq $0xce, -0x418(%rbp)
jne 0x6ab7
movq -0x430(%rbp), %rdi
callq 0x35c0
movq %rax, -0x4a0(%rbp)
movq %rdx, -0x498(%rbp)
movq -0x430(%rbp), %rdx
movq -0x4a0(%rbp), %rcx
movq -0x498(%rbp), %r8
xorl %edi, %edi
leaq 0x5dca(%rip), %rsi      # 0xc46a
movb $0x0, %al
callq 0x3580
movq -0x430(%rbp), %rdi
callq 0x3050
movq $0x0, -0x4a8(%rbp)
cmpq $0x0, -0x4a0(%rbp)
jne 0x66d9
movq -0x60(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x4a8(%rbp)
jmp 0x66ef
movq -0x60(%rbp), %rax
subq -0x4a0(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x4a8(%rbp)
movq -0x4a8(%rbp), %rax
cmpq -0x60(%rbp), %rax
jb 0x670b
movq -0x60(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x4a8(%rbp)
movq -0x498(%rbp), %rax
cmpq -0x60(%rbp), %rax
jae 0x6728
movq -0x498(%rbp), %rax
movq %rax, -0x4f0(%rbp)
jmp 0x6733
xorl %eax, %eax
movq %rax, -0x4f0(%rbp)
jmp 0x6733
movq -0x4f0(%rbp), %rax
movq %rax, -0x4b0(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x4b8(%rbp)
cmpq $0x0, -0x4b8(%rbp)
jne 0x6768
movsd 0x5982(%rip), %xmm0     # 0xc0e0
movsd %xmm0, -0x4f8(%rbp)
jmp 0x67b0
movaps 0x5981(%rip), %xmm1     # 0xc0f0
movq -0x4b8(%rbp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x597d(%rip), %xmm1     # 0xc100
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
callq 0x3330
callq 0x3550
movsd 0x593c(%rip), %xmm1     # 0xc0e0
addsd %xmm1, %xmm0
movsd %xmm0, -0x4f8(%rbp)
movsd -0x4f8(%rbp), %xmm0
movsd 0x5928(%rip), %xmm2     # 0xc0e8
movaps %xmm0, %xmm1
subsd %xmm2, %xmm1
cvttsd2si %xmm1, %rcx
cvttsd2si %xmm0, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x4c0(%rbp)
cmpq $0x0, -0x4b0(%rbp)
jne 0x6801
movsd 0x58e9(%rip), %xmm0     # 0xc0e0
movsd %xmm0, -0x500(%rbp)
jmp 0x6875
cmpq $0x0, -0x4b0(%rbp)
jne 0x681d
movsd 0x58cd(%rip), %xmm0     # 0xc0e0
movsd %xmm0, -0x508(%rbp)
jmp 0x6865
movaps 0x58cc(%rip), %xmm1     # 0xc0f0
movq -0x4b0(%rbp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x58c8(%rip), %xmm1     # 0xc100
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
callq 0x3330
callq 0x3550
movsd 0x5887(%rip), %xmm1     # 0xc0e0
addsd %xmm1, %xmm0
movsd %xmm0, -0x508(%rbp)
movsd -0x508(%rbp), %xmm0
movsd %xmm0, -0x500(%rbp)
movsd -0x500(%rbp), %xmm0
movsd 0x5863(%rip), %xmm2     # 0xc0e8
movaps %xmm0, %xmm1
subsd %xmm2, %xmm1
cvttsd2si %xmm1, %rcx
cvttsd2si %xmm0, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x4c8(%rbp)
cmpq $0x0, -0x4a8(%rbp)
jne 0x68c6
movsd 0x5824(%rip), %xmm0     # 0xc0e0
movsd %xmm0, -0x510(%rbp)
jmp 0x693a
cmpq $0x0, -0x4a8(%rbp)
jne 0x68e2
movsd 0x5808(%rip), %xmm0     # 0xc0e0
movsd %xmm0, -0x518(%rbp)
jmp 0x692a
movaps 0x5807(%rip), %xmm1     # 0xc0f0
movq -0x4a8(%rbp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x5803(%rip), %xmm1     # 0xc100
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
callq 0x3330
callq 0x3550
movsd 0x57c2(%rip), %xmm1     # 0xc0e0
addsd %xmm1, %xmm0
movsd %xmm0, -0x518(%rbp)
movsd -0x518(%rbp), %xmm0
movsd %xmm0, -0x510(%rbp)
movsd -0x510(%rbp), %xmm0
movsd 0x579e(%rip), %xmm2     # 0xc0e8
movaps %xmm0, %xmm1
subsd %xmm2, %xmm1
cvttsd2si %xmm1, %rcx
cvttsd2si %xmm0, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x4d0(%rbp)
leaq -0x68(%rbp), %rdi
addq $0x10, %rdi
callq 0x3140
movq %rax, -0x520(%rbp)
movq -0x438(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x3140
movq %rax, %rcx
movq -0x520(%rbp), %rax
addq %rcx, %rax
addq $0x14, %rax
addq -0x4c0(%rbp), %rax
addq -0x4c8(%rbp), %rax
addq -0x4d0(%rbp), %rax
addq -0x4c0(%rbp), %rax
subq $0x2, %rax
subq $0xc, %rax
movq %rax, -0x420(%rbp)
movq -0x4b8(%rbp), %rax
addq -0x420(%rbp), %rax
movq %rax, -0x428(%rbp)
movq -0x428(%rbp), %rdi
addq $0x1, %rdi
callq 0x33d0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x428(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x28(%rbp), %rdi
movq -0x428(%rbp), %rsi
movq -0x438(%rbp), %rax
movq 0x8(%rax), %rdx
leaq -0x68(%rbp), %rcx
addq $0x10, %rcx
movq -0x4b8(%rbp), %r8
movq -0x4b0(%rbp), %r9
movq -0x4a8(%rbp), %r10
movq -0x4b8(%rbp), %rax
subq $0x10, %rsp
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x31e0
addq $0x10, %rsp
movq -0x4b0(%rbp), %rdx
movq -0x4a8(%rbp), %rcx
movq -0x4b8(%rbp), %r8
xorl %edi, %edi
leaq 0x5a27(%rip), %rsi      # 0xc49e
movb $0x0, %al
callq 0x3580
movq -0x28(%rbp), %rdi
leaq 0x5c17(%rip), %rsi      # 0xc6a0
callq 0x3570
movq -0x28(%rbp), %rdi
addq -0x420(%rbp), %rdi
movq -0x68(%rbp), %rsi
addq -0x4b0(%rbp), %rsi
movq -0x4a8(%rbp), %rdx
subq -0x4b0(%rbp), %rdx
callq 0x3370
jmp 0x6ab9
movq -0x418(%rbp), %rax
movl %eax, %edx
leaq -0x2e0(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x6de0
movl $0x68, %edi
callq 0x33d0
movq %rax, -0x70(%rbp)
movq -0x28(%rbp), %rcx
movq -0x70(%rbp), %rax
movq %rcx, (%rax)
movq -0x428(%rbp), %rcx
movq -0x70(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x418(%rbp), %rax
movl %eax, %ecx
movq -0x70(%rbp), %rax
movl %ecx, 0x14(%rax)
movl -0xc(%rbp), %ecx
movq -0x70(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x70(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x78(%rbp), %rcx
movq -0x70(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x70(%rbp), %rdi
addq $0x28, %rdi
leaq -0x68(%rbp), %rsi
movl $0x40, %edx
callq 0x3370
movq -0x20(%rbp), %rdi
callq 0x3050
movq -0xb0(%rbp), %rdi
callq 0x3050
movq -0xa0(%rbp), %rdi
callq 0x3050
movq -0x90(%rbp), %rdi
callq 0x3050
movq -0x70(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x6bdf
cmpq $0x0, -0x78(%rbp)
je 0x6ba1
movq -0x78(%rbp), %rax
cmpq $0x0, 0x160(%rax)
je 0x6ba1
movq -0x78(%rbp), %rax
movl $0x1f4, %edi            # imm = 0x1F4
leaq -0x68(%rbp), %rsi
callq *0x160(%rax)
movq -0x28(%rbp), %rdi
callq 0x3050
movq -0x20(%rbp), %rdi
callq 0x3050
movq -0xb0(%rbp), %rdi
callq 0x3050
movq -0xa0(%rbp), %rdi
callq 0x3050
movq -0x90(%rbp), %rdi
callq 0x3050
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rbp, %rsp
popq %rbp
retq
nopl (%rax,%rax)