// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/src/deark-font.c
// Function: de_font_bitmap_font_to_image
void de_font_bitmap_font_to_image(deark *c, struct de_bitmap_font *font1, de_finfo *fi,
	unsigned int createflags)
{
	struct font_render_ctx *fctx = NULL;
	i64 i, j, k;
	de_bitmap *img = NULL;
	i64 xpos, ypos;
	i64 img_leftmargin, img_topmargin;
	i64 img_rightmargin, img_bottommargin;
	i64 img_vpixelsperchar;
	i64 img_width, img_height;
	i64 num_table_rows_to_display;
	i64 num_table_rows_total;
	i64 last_valid_row;
	struct de_bitmap_font *dfont = NULL;
	i64 chars_per_row = 32;
	const char *s;
	struct row_info_struct *row_info = NULL;
	struct col_info_struct *col_info = NULL;
	int unicode_req = 0;
	i64 label_stride;
	i64 rownum, colnum;
	i64 curpos;
	unsigned int dnflags;

	fctx = de_malloc(c, sizeof(struct font_render_ctx));
	fctx->font = font1;

	if(fctx->font->num_chars<1) goto done;
	if(fctx->font->num_chars>17*65536) goto done;
	if(fctx->font->nominal_width>512 || fctx->font->nominal_height>512) {
		de_err(c, "Font size too big (%d"DE_CHAR_TIMES"%d). Not supported.",
			(int)fctx->font->nominal_width, (int)fctx->font->nominal_height);
		goto done;
	}

	// -1 = "no preference"
	unicode_req = de_get_ext_option_bool(c, "font:tounicode", -1);

	if(unicode_req==0 &&
		(fctx->font->has_nonunicode_codepoints || !fctx->font->has_unicode_codepoints))
	{
		; // Render as nonunicode.
	}
	else if(fctx->font->has_unicode_codepoints &&
		(unicode_req>0 || fctx->font->prefer_unicode || !fctx->font->has_nonunicode_codepoints))
	{
		fctx->render_as_unicode = 1;
	}

	s = de_get_ext_option(c, "font:charsperrow");
	if(s) {
		chars_per_row = de_atoi64(s);
		if(chars_per_row<1) chars_per_row=1;
	}

	dfont = make_digit_font(c);

	fctx->codepoint_tmp = de_mallocarray(c, fctx->font->num_chars, sizeof(i32));
	fixup_codepoints(c, fctx);

	get_min_max_codepoint(fctx);
	if(fctx->num_valid_chars<1) goto done;
	num_table_rows_total = fctx->max_codepoint/chars_per_row+1;

	// TODO: Clean up these margin calculations, and make it more general.
	if(fctx->render_as_unicode) {
		img_leftmargin = (i64)dfont->nominal_width * 5 + 6;
	}
	else {
		if(fctx->max_codepoint >= 1000)
			img_leftmargin = (i64)dfont->nominal_width * 5 + 6;
		else
			img_leftmargin = (i64)dfont->nominal_width * 3 + 6;
	}
	img_topmargin = (i64)dfont->nominal_height + 6;
	img_rightmargin = 1;
	img_bottommargin = 1;

	// Scan the characters, and record relevant information.
	row_info = de_mallocarray(c, num_table_rows_total, sizeof(struct row_info_struct));
	col_info = de_mallocarray(c, chars_per_row, sizeof(struct col_info_struct));
	for(i=0; i<chars_per_row; i++) {
#define MIN_CHAR_CELL_WIDTH 5
		col_info[i].display_width = MIN_CHAR_CELL_WIDTH;
	}

	for(k=0; k<fctx->font->num_chars; k++) {
		i64 char_display_width;

		if(fctx->codepoint_tmp[k] == DE_CODEPOINT_INVALID) continue;
		if(!is_valid_char(&fctx->font->char_array[k])) continue;
		rownum = fctx->codepoint_tmp[k] / chars_per_row;
		colnum = fctx->codepoint_tmp[k] % chars_per_row;
		if(rownum<0 || rownum>=num_table_rows_total) {
			de_internal_err_fatal(c, "bad rownum");
		}

		// Remember that there is at least one valid character in this character's row.
		row_info[rownum].is_visible = 1;

		// Track the maximum width of any character in this character's column.
		char_display_width = (i64)fctx->font->char_array[k].width +
				(i64)fctx->font->char_array[k].extraspace_l +
				(i64)fctx->font->char_array[k].extraspace_r;
		if(char_display_width > col_info[colnum].display_width) {
			col_info[colnum].display_width = char_display_width;
		}
	}

	img_vpixelsperchar = (i64)fctx->font->nominal_height + 1;

	// Figure out how many rows are used, and where to draw them.
	num_table_rows_to_display = 0;
	last_valid_row = -1;
	curpos = img_topmargin;
	for(j=0; j<num_table_rows_total; j++) {
		if(!row_info[j].is_visible) continue;

		// If we skipped one or more rows, leave some extra vertical space.
		if(num_table_rows_to_display>0 && !row_info[j-1].is_visible) curpos+=3;

		last_valid_row = j;
		row_info[j].display_pos = curpos;
		curpos += img_vpixelsperchar;
		num_table_rows_to_display++;
	}
	if(num_table_rows_to_display<1) goto done;

	// Figure out the positions of the columns.
	curpos = img_leftmargin;
	for(i=0; i<chars_per_row; i++) {
		col_info[i].display_pos = curpos;
		curpos += col_info[i].display_width + 1;
	}

	img_width = col_info[chars_per_row-1].display_pos +
		col_info[chars_per_row-1].display_width + img_rightmargin;
	img_height = row_info[last_valid_row].display_pos +
		img_vpixelsperchar -1 + img_bottommargin;

	img = de_bitmap_create(c, img_width, img_height, 3);

	// Clear the image
	de_bitmap_rect(img, 0, 0, img->width, img->height, DE_MAKE_RGB(32,32,144), 0);

	// Draw/clear the cell backgrounds
	for(j=0; j<num_table_rows_total; j++) {
		if(!row_info[j].is_visible) continue;
		ypos = row_info[j].display_pos;

		for(i=0; i<chars_per_row; i++) {
			xpos = col_info[i].display_pos;
			de_bitmap_rect(img, xpos, ypos,
				col_info[i].display_width, img_vpixelsperchar-1,
				DE_MAKE_RGB(112,112,160), 0);
		}
	}

	// Draw the labels in the top margin.

	// TODO: Better label spacing logic.
	if(fctx->font->nominal_width <= 12)
		label_stride = 2;
	else
		label_stride = 1;

	for(i=0; i<chars_per_row; i++) {
		if(i%label_stride != 0) continue;
		xpos = col_info[i].display_pos + col_info[i].display_width/2;
		ypos = img_topmargin - 3;

		dnflags = DNFLAG_HCENTER;
		if(fctx->render_as_unicode) dnflags |= DNFLAG_HEX;

		draw_number(c, img, dfont, i, xpos, ypos, dnflags);
	}

	// Draw the labels in the left margin.
	for(j=0; j<num_table_rows_total; j++) {
		if(!row_info[j].is_visible) continue;
		xpos = img_leftmargin - 3;
		ypos = row_info[j].display_pos + (img_vpixelsperchar + dfont->nominal_height + 1)/2;

		dnflags = 0;
		if(fctx->render_as_unicode) dnflags |= DNFLAG_HEX | DNFLAG_LEADING_ZEROES;

		draw_number(c, img, dfont, j*chars_per_row, xpos, ypos, dnflags);
	}

	// Render the glyphs.
	for(k=0; k<fctx->font->num_chars; k++) {
		if(fctx->codepoint_tmp[k] == DE_CODEPOINT_INVALID) continue;
		if(!is_valid_char(&fctx->font->char_array[k])) continue;

		rownum = fctx->codepoint_tmp[k] / chars_per_row;
		colnum = fctx->codepoint_tmp[k] % chars_per_row;
		if(rownum<0 || rownum>=num_table_rows_total) {
			de_internal_err_fatal(c, "bad rownum");
		}

		xpos = col_info[colnum].display_pos;
		ypos = row_info[rownum].display_pos;

		checkerboard_bkgd(img, xpos, ypos,
			col_info[colnum].display_width, img_vpixelsperchar-1);

		de_font_paint_character_idx(c, img, fctx->font, k, xpos, ypos,
			DE_STOCKCOLOR_BLACK, DE_STOCKCOLOR_WHITE, 0);
	}

	de_bitmap_write_to_file_finfo(img, fi, createflags);

done:
	if(dfont) {
		de_free(c, dfont->char_array);
		de_destroy_bitmap_font(c, dfont);
	}
	de_bitmap_destroy(img);
	de_free(c, row_info);
	de_free(c, col_info);
	if(fctx) {
		de_free(c, fctx->codepoint_tmp);
		de_free(c, fctx);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0xb0(%rbp)
movq $0x20, -0xb8(%rbp)
movq $0x0, -0xc8(%rbp)
movq $0x0, -0xd0(%rbp)
movl $0x0, -0xd4(%rbp)
movq -0x8(%rbp), %rdi
movl $0x28, %esi
callq 0x15b780
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movq (%rax), %rax
cmpq $0x1, 0x18(%rax)
jge 0x16ff10
jmp 0x1709d2
movq -0x28(%rbp), %rax
movq (%rax), %rax
cmpq $0x110000, 0x18(%rax)   # imm = 0x110000
jle 0x16ff26
jmp 0x1709d2
movq -0x28(%rbp), %rax
movq (%rax), %rax
cmpl $0x200, (%rax)          # imm = 0x200
jg 0x16ff45
movq -0x28(%rbp), %rax
movq (%rax), %rax
cmpl $0x200, 0x4(%rax)       # imm = 0x200
jle 0x16ff6f
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rax
movl (%rax), %edx
movq -0x28(%rbp), %rax
movq (%rax), %rax
movl 0x4(%rax), %ecx
leaq 0x659ad(%rip), %rsi     # 0x1d5910
movb $0x0, %al
callq 0x15bfb0
jmp 0x1709d2
movq -0x8(%rbp), %rdi
leaq 0x659c1(%rip), %rsi     # 0x1d593b
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x15cbc0
movl %eax, -0xd4(%rbp)
cmpl $0x0, -0xd4(%rbp)
jne 0x16ffb2
movq -0x28(%rbp), %rax
movq (%rax), %rax
movzbl 0x10(%rax), %eax
cmpl $0x0, %eax
jne 0x16ffb0
movq -0x28(%rbp), %rax
movq (%rax), %rax
cmpb $0x0, 0x11(%rax)
jne 0x16ffb2
jmp 0x16fff5
movq -0x28(%rbp), %rax
movq (%rax), %rax
movzbl 0x11(%rax), %eax
cmpl $0x0, %eax
je 0x16fff3
cmpl $0x0, -0xd4(%rbp)
jg 0x16ffe8
movq -0x28(%rbp), %rax
movq (%rax), %rax
movzbl 0x12(%rax), %eax
cmpl $0x0, %eax
jne 0x16ffe8
movq -0x28(%rbp), %rax
movq (%rax), %rax
cmpb $0x0, 0x10(%rax)
jne 0x16fff3
movq -0x28(%rbp), %rax
movl $0x1, 0x18(%rax)
jmp 0x16fff5
movq -0x8(%rbp), %rdi
leaq 0x6594a(%rip), %rsi     # 0x1d594a
callq 0x15cb30
movq %rax, -0xc0(%rbp)
cmpq $0x0, -0xc0(%rbp)
je 0x170040
movq -0xc0(%rbp), %rdi
callq 0x15ccc0
movq %rax, -0xb8(%rbp)
cmpq $0x1, -0xb8(%rbp)
jge 0x17003e
movq $0x1, -0xb8(%rbp)
jmp 0x170040
movq -0x8(%rbp), %rdi
callq 0x170a60
movq %rax, -0xb0(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rsi
movl $0x4, %edx
callq 0x15c450
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x170ba0
movq -0x28(%rbp), %rdi
callq 0x170dc0
movq -0x28(%rbp), %rax
cmpq $0x1, 0x10(%rax)
jge 0x17009a
jmp 0x1709d2
movq -0x28(%rbp), %rax
movslq 0xc(%rax), %rax
cqto
idivq -0xb8(%rbp)
addq $0x1, %rax
movq %rax, -0xa0(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x0, 0x18(%rax)
je 0x1700d8
movq -0xb0(%rbp), %rax
movslq (%rax), %rax
imulq $0x5, %rax, %rax
addq $0x6, %rax
movq %rax, -0x60(%rbp)
jmp 0x170115
movq -0x28(%rbp), %rax
cmpl $0x3e8, 0xc(%rax)       # imm = 0x3E8
jl 0x1700fd
movq -0xb0(%rbp), %rax
movslq (%rax), %rax
imulq $0x5, %rax, %rax
addq $0x6, %rax
movq %rax, -0x60(%rbp)
jmp 0x170113
movq -0xb0(%rbp), %rax
movslq (%rax), %rax
imulq $0x3, %rax, %rax
addq $0x6, %rax
movq %rax, -0x60(%rbp)
jmp 0x170115
movq -0xb0(%rbp), %rax
movslq 0x4(%rax), %rax
addq $0x6, %rax
movq %rax, -0x68(%rbp)
movq $0x1, -0x70(%rbp)
movq $0x1, -0x78(%rbp)
movq -0x8(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movl $0x10, %edx
callq 0x15c450
movq %rax, -0xc8(%rbp)
movq -0x8(%rbp), %rdi
movq -0xb8(%rbp), %rsi
movl $0x10, %edx
callq 0x15c450
movq %rax, -0xd0(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0xb8(%rbp), %rax
jge 0x1701ac
movq -0xd0(%rbp), %rax
movq -0x30(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq $0x5, (%rax)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x170178
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x28(%rbp), %rcx
movq (%rcx), %rcx
cmpq 0x18(%rcx), %rax
jge 0x170330
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x40(%rbp), %rcx
cmpl $0xfffffff, (%rax,%rcx,4) # imm = 0xFFFFFFF
jne 0x1701e3
jmp 0x17031f
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq 0x20(%rax), %rdi
imulq $0x28, -0x40(%rbp), %rax
addq %rax, %rdi
callq 0x16f9f0
cmpl $0x0, %eax
jne 0x170205
jmp 0x17031f
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x40(%rbp), %rcx
movslq (%rax,%rcx,4), %rax
cqto
idivq -0xb8(%rbp)
movq %rax, -0xe8(%rbp)
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x40(%rbp), %rcx
movslq (%rax,%rcx,4), %rax
cqto
idivq -0xb8(%rbp)
movq %rdx, -0xf0(%rbp)
cmpq $0x0, -0xe8(%rbp)
jl 0x17025f
movq -0xe8(%rbp), %rax
cmpq -0xa0(%rbp), %rax
jl 0x170271
movq -0x8(%rbp), %rdi
leaq 0x656f1(%rip), %rsi     # 0x1d595b
movb $0x0, %al
callq 0x15c2a0
movq -0xc8(%rbp), %rax
movq -0xe8(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movb $0x1, (%rax)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq 0x20(%rax), %rax
imulq $0x28, -0x40(%rbp), %rcx
addq %rcx, %rax
movslq 0x8(%rax), %rax
movq -0x28(%rbp), %rcx
movq (%rcx), %rcx
movq 0x20(%rcx), %rcx
imulq $0x28, -0x40(%rbp), %rdx
addq %rdx, %rcx
movswq 0x14(%rcx), %rcx
addq %rcx, %rax
movq -0x28(%rbp), %rcx
movq (%rcx), %rcx
movq 0x20(%rcx), %rcx
imulq $0x28, -0x40(%rbp), %rdx
addq %rdx, %rcx
movswq 0x16(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x108(%rbp)
movq -0x108(%rbp), %rax
movq -0xd0(%rbp), %rcx
movq -0xf0(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jle 0x17031d
movq -0x108(%rbp), %rcx
movq -0xd0(%rbp), %rax
movq -0xf0(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
jmp 0x17031f
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x1701b4
movq -0x28(%rbp), %rax
movq (%rax), %rax
movslq 0x4(%rax), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
movq $0x0, -0x98(%rbp)
movq $-0x1, -0xa8(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0xa0(%rbp), %rax
jge 0x17042d
movq -0xc8(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpb $0x0, (%rax)
jne 0x170399
jmp 0x17041c
cmpq $0x0, -0x98(%rbp)
jle 0x1703d0
movq -0xc8(%rbp), %rax
movq -0x38(%rbp), %rcx
subq $0x1, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpb $0x0, (%rax)
jne 0x1703d0
movq -0xf8(%rbp), %rax
addq $0x3, %rax
movq %rax, -0xf8(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xf8(%rbp), %rcx
movq -0xc8(%rbp), %rax
movq -0x38(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x80(%rbp), %rax
addq -0xf8(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0x98(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x17036c
cmpq $0x1, -0x98(%rbp)
jge 0x17043c
jmp 0x1709d2
movq -0x60(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0xb8(%rbp), %rax
jge 0x1704ae
movq -0xf8(%rbp), %rcx
movq -0xd0(%rbp), %rax
movq -0x30(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0xd0(%rbp), %rax
movq -0x30(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
addq $0x1, %rax
addq -0xf8(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x17044f
movq -0xd0(%rbp), %rax
movq -0xb8(%rbp), %rcx
subq $0x1, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq -0xd0(%rbp), %rcx
movq -0xb8(%rbp), %rdx
subq $0x1, %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
addq (%rcx), %rax
addq -0x70(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0xc8(%rbp), %rax
movq -0xa8(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
addq -0x80(%rbp), %rax
subq $0x1, %rax
addq -0x78(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x8(%rbp), %rdi
movq -0x88(%rbp), %rsi
movq -0x90(%rbp), %rdx
movl $0x3, %ecx
callq 0x16b750
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x48(%rbp), %rax
movq 0x10(%rax), %r8
xorl %eax, %eax
movl %eax, %edx
movl $0xff202090, %r9d       # imm = 0xFF202090
xorl %eax, %eax
movq %rdx, %rsi
movl $0x0, (%rsp)
callq 0x16cdc0
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0xa0(%rbp), %rax
jge 0x170649
movq -0xc8(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpb $0x0, (%rax)
jne 0x1705a2
jmp 0x170638
movq -0xc8(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x58(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0xb8(%rbp), %rax
jge 0x170636
movq -0xd0(%rbp), %rax
movq -0x30(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq -0xd0(%rbp), %rax
movq -0x30(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq -0x80(%rbp), %r8
subq $0x1, %r8
movl $0xff7070a0, %r9d       # imm = 0xFF7070A0
xorl %eax, %eax
movl $0x0, (%rsp)
callq 0x16cdc0
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x1705c4
jmp 0x170638
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x170575
movq -0x28(%rbp), %rax
movq (%rax), %rax
cmpl $0xc, (%rax)
jg 0x170662
movq $0x2, -0xe0(%rbp)
jmp 0x17066d
movq $0x1, -0xe0(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0xb8(%rbp), %rax
jge 0x170754
movq -0x30(%rbp), %rax
cqto
idivq -0xe0(%rbp)
cmpq $0x0, %rdx
je 0x17069e
jmp 0x170743
movq -0xd0(%rbp), %rax
movq -0x30(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x110(%rbp)
movq -0xd0(%rbp), %rax
movq -0x30(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl $0x2, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq -0x110(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x68(%rbp), %rax
subq $0x3, %rax
movq %rax, -0x58(%rbp)
movl $0x4, -0xfc(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x0, 0x18(%rax)
je 0x17071a
movl -0xfc(%rbp), %eax
orl $0x1, %eax
movl %eax, -0xfc(%rbp)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0xb0(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x50(%rbp), %r8
movq -0x58(%rbp), %r9
movl -0xfc(%rbp), %eax
movl %eax, (%rsp)
callq 0x170ed0
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x170675
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0xa0(%rbp), %rax
jge 0x170848
movq -0xc8(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpb $0x0, (%rax)
jne 0x170789
jmp 0x170837
movq -0x60(%rbp), %rax
subq $0x3, %rax
movq %rax, -0x50(%rbp)
movq -0xc8(%rbp), %rax
movq -0x38(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x118(%rbp)
movq -0x80(%rbp), %rax
movq -0xb0(%rbp), %rcx
movslq 0x4(%rcx), %rcx
addq %rcx, %rax
addq $0x1, %rax
movl $0x2, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq -0x118(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movl $0x0, -0xfc(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x0, 0x18(%rax)
je 0x170806
movl -0xfc(%rbp), %eax
orl $0x3, %eax
movl %eax, -0xfc(%rbp)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0xb0(%rbp), %rdx
movq -0x38(%rbp), %rcx
imulq -0xb8(%rbp), %rcx
movq -0x50(%rbp), %r8
movq -0x58(%rbp), %r9
movl -0xfc(%rbp), %eax
movl %eax, (%rsp)
callq 0x170ed0
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x17075c
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x28(%rbp), %rcx
movq (%rcx), %rcx
cmpq 0x18(%rcx), %rax
jge 0x1709c2
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x40(%rbp), %rcx
cmpl $0xfffffff, (%rax,%rcx,4) # imm = 0xFFFFFFF
jne 0x17087f
jmp 0x1709b1
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq 0x20(%rax), %rdi
imulq $0x28, -0x40(%rbp), %rax
addq %rax, %rdi
callq 0x16f9f0
cmpl $0x0, %eax
jne 0x1708a1
jmp 0x1709b1
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x40(%rbp), %rcx
movslq (%rax,%rcx,4), %rax
cqto
idivq -0xb8(%rbp)
movq %rax, -0xe8(%rbp)
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x40(%rbp), %rcx
movslq (%rax,%rcx,4), %rax
cqto
idivq -0xb8(%rbp)
movq %rdx, -0xf0(%rbp)
cmpq $0x0, -0xe8(%rbp)
jl 0x1708fb
movq -0xe8(%rbp), %rax
cmpq -0xa0(%rbp), %rax
jl 0x17090d
movq -0x8(%rbp), %rdi
leaq 0x65055(%rip), %rsi     # 0x1d595b
movb $0x0, %al
callq 0x15c2a0
movq -0xd0(%rbp), %rax
movq -0xf0(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0xc8(%rbp), %rax
movq -0xe8(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq -0xd0(%rbp), %rax
movq -0xf0(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq -0x80(%rbp), %r8
subq $0x1, %r8
callq 0x171090
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x28(%rbp), %rax
movq (%rax), %rdx
movq -0x40(%rbp), %rcx
movq -0x50(%rbp), %r8
movq -0x58(%rbp), %r9
xorl %eax, %eax
movl $0xff000000, (%rsp)     # imm = 0xFF000000
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
movl $0x0, 0x10(%rsp)
callq 0x16f760
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x170850
movq -0x48(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x16afa0
cmpq $0x0, -0xb0(%rbp)
je 0x170a00
movq -0x8(%rbp), %rdi
movq -0xb0(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movq -0xb0(%rbp), %rsi
callq 0x16f730
movq -0x48(%rbp), %rdi
callq 0x16af60
movq -0x8(%rbp), %rdi
movq -0xc8(%rbp), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movq -0xd0(%rbp), %rsi
callq 0x15b820
cmpq $0x0, -0x28(%rbp)
je 0x170a4e
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x15b820
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
nopw (%rax,%rax)