// File: SYZYGYfpga[P]syzygy-tools/dna-tools/dna-writer.cpp
// Function: main
int main(int argc, char *argv[])
{
	std::vector<uint8_t> dna_header(SZG_DNA_HEADER_LENGTH_V1);
	uint8_t min_ver_major, min_ver_minor;

	// Print usage if there are not enough or too many arguments
	if ((argc < 3) || (argc > 4)) {
		std::cout << "USAGE: " << argv[0];
		std::cout << " in_file out_file [serial]\n";
		std::cout << "  If no serial is provided it will be ";
		std::cout << "extracted from the JSON input file\n";
		return 0;
	}

	std::ifstream input_file(argv[1]);
	std::ofstream output_file(argv[2], std::ios::out | std::ios::binary);

	json dna_json;

	// Parse the input data
	input_file >> dna_json;

	dna_header[SZG_DNA_PTR_HEADER_LENGTH] = SZG_DNA_HEADER_LENGTH_V1 & 0xFF;
	dna_header[SZG_DNA_PTR_HEADER_LENGTH + 1] =
	    (SZG_DNA_HEADER_LENGTH_V1 & 0xFF00) >> 8;

	dna_header[SZG_DNA_PTR_DNA_MAJOR] = DNA_SPEC_MAJOR;
	dna_header[SZG_DNA_PTR_DNA_MINOR] = DNA_SPEC_MINOR;

	// By default the DNA should be compatible with any version of the spec.
	min_ver_major = 0;
	min_ver_minor = 0;

	// TXR4 peripherals require version > 1.1
	if (dna_json["is_txr4"].get<bool>() == true) {
		if (min_ver_major < 1) {
			min_ver_major = 1;
			min_ver_minor = 1;
		} else if ((min_ver_major == 1) &&
		           (min_ver_minor < 1)) {
			min_ver_minor = 1;
		}
	}

	dna_header[SZG_DNA_PTR_DNA_REQUIRED_MAJOR] = min_ver_major;
	dna_header[SZG_DNA_PTR_DNA_REQUIRED_MINOR] = min_ver_minor;

	dna_header[SZG_DNA_PTR_MAX_5V_LOAD] = dna_json["max_5v_load"].get<uint16_t>() & 0xFF;
	dna_header[SZG_DNA_PTR_MAX_5V_LOAD + 1] = dna_json["max_5v_load"].get<uint16_t>() >> 8;
	dna_header[SZG_DNA_PTR_MAX_33V_LOAD] = dna_json["max_3v3_load"].get<uint16_t>() & 0xFF;
	dna_header[SZG_DNA_PTR_MAX_33V_LOAD + 1] = dna_json["max_3v3_load"].get<uint16_t>() >> 8;
	dna_header[SZG_DNA_PTR_MAX_VIO_LOAD] = dna_json["max_vio_load"].get<uint16_t>() & 0xFF;
	dna_header[SZG_DNA_PTR_MAX_VIO_LOAD + 1] = dna_json["max_vio_load"].get<uint16_t>() >> 8;

	dna_header[SZG_DNA_PTR_ATTRIBUTES] |= dna_json["is_lvds"].get<bool>() ?
	    SZG_ATTR_LVDS : 0;
	dna_header[SZG_DNA_PTR_ATTRIBUTES] |= dna_json["is_doublewide"].get<bool>() ?
	    SZG_ATTR_DOUBLEWIDE : 0;
	dna_header[SZG_DNA_PTR_ATTRIBUTES] |= dna_json["is_txr4"].get<bool>() ?
	    SZG_ATTR_TXR4 : 0;

	// Run through each range and set the values accordingly
	for (int i = 0; i < SZG_MAX_DNA_RANGES - 1; i++) {
		uint16_t vio;
		vio = dna_json["vio"][i]["min"].get<uint16_t>();
		dna_header[SZG_DNA_MIN_VIO_RANGE0 + 4*i] = vio & 0xFF;
		dna_header[SZG_DNA_MIN_VIO_RANGE0 + (4*i) + 1] = (vio & 0xFF00) >> 8;

		vio = dna_json["vio"][i]["max"].get<uint16_t>();
		dna_header[SZG_DNA_MAX_VIO_RANGE0 + 4*i] = vio & 0xFF;
		dna_header[SZG_DNA_MAX_VIO_RANGE0 + (4*i) + 1] = (vio & 0xFF00) >> 8;
	}

	uint8_t manuf_len =
	    dna_json["manufacturer_name"].get<std::string>().length();

	uint8_t name_len =
	    dna_json["product_name"].get<std::string>().length();

	uint8_t model_len =
	    dna_json["product_model"].get<std::string>().length();

	uint8_t version_len =
	    dna_json["product_version"].get<std::string>().length();

	uint8_t serial_len = 0;

	if (argc == 4) {
		serial_len = strlen(argv[3]);
	} else {
		serial_len = dna_json["serial"].get<std::string>().length();
	}

	dna_header[SZG_DNA_MANUFACTURER_NAME_LENGTH] = manuf_len;

	dna_header[SZG_DNA_PRODUCT_NAME_LENGTH] = name_len;

	dna_header[SZG_DNA_PRODUCT_MODEL_LENGTH] = model_len;

	dna_header[SZG_DNA_PRODUCT_VERSION_LENGTH] = version_len;

	dna_header[SZG_DNA_SERIAL_NUMBER_LENGTH] = serial_len;

	uint16_t dna_length = SZG_DNA_HEADER_LENGTH_V1 + manuf_len + name_len +
	                      model_len + version_len + serial_len;

	dna_header[SZG_DNA_PTR_FULL_LENGTH] = dna_length & 0xFF;
	dna_header[SZG_DNA_PTR_FULL_LENGTH + 1] = (dna_length & 0xFF00) >> 8;

	// Calculate and insert the CRC once all data has been gathered
	uint16_t crc = szgComputeCRC(&dna_header[0], SZG_DNA_HEADER_LENGTH_V1 - 2);

	dna_header[SZG_DNA_CRC16_HIGH] = (crc & 0xFF00) >> 8;
	dna_header[SZG_DNA_CRC16_LOW] = crc & 0xFF;

	for (int i = 0; i < SZG_DNA_HEADER_LENGTH_V1; i++) {
		output_file << dna_header[i];
	}

	output_file << dna_json["manufacturer_name"].get<std::string>();
	output_file << dna_json["product_name"].get<std::string>();
	output_file << dna_json["product_model"].get<std::string>();
	output_file << dna_json["product_version"].get<std::string>();

	if (argc == 4) {
		output_file << argv[3];
	} else {
		output_file << dna_json["serial"].get<std::string>();
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x7c0, %rsp            # imm = 0x7C0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x29(%rbp), %rdi
movq %rdi, -0x5d8(%rbp)
callq 0x4560
movq -0x5d8(%rbp), %rdx
leaq -0x28(%rbp), %rdi
movl $0x28, %esi
callq 0x4580
jmp 0x36f0
leaq -0x29(%rbp), %rdi
callq 0x45f0
cmpl $0x3, -0x8(%rbp)
jl 0x3709
cmpl $0x4, -0x8(%rbp)
jle 0x37b7
movq 0x1e8c8(%rip), %rdi     # 0x21fd8
leaq 0x121dd(%rip), %rsi     # 0x158f4
callq 0x32f0
movq %rax, -0x5e0(%rbp)
jmp 0x3725
movq -0x5e0(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0x32f0
jmp 0x373a
movq 0x1e897(%rip), %rdi     # 0x21fd8
leaq 0x121b4(%rip), %rsi     # 0x158fc
callq 0x32f0
jmp 0x374f
movq 0x1e882(%rip), %rdi     # 0x21fd8
leaq 0x121bb(%rip), %rsi     # 0x15918
callq 0x32f0
jmp 0x3764
movq 0x1e86d(%rip), %rdi     # 0x21fd8
leaq 0x121cd(%rip), %rsi     # 0x1593f
callq 0x32f0
jmp 0x3779
movl $0x0, -0x4(%rbp)
movl $0x1, -0x44(%rbp)
jmp 0x4535
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x29(%rbp), %rdi
callq 0x45f0
jmp 0x4553
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x454a
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq -0x250(%rbp), %rdi
movl $0x8, %edx
callq 0x3500
jmp 0x37d2
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x5f0(%rbp)
movl $0x10, %edi
movl $0x4, %esi
callq 0x4610
movl %eax, -0x5e4(%rbp)
jmp 0x37f8
movl -0x5e4(%rbp), %edx
movq -0x5f0(%rbp), %rsi
leaq -0x450(%rbp), %rdi
callq 0x3340
jmp 0x3813
xorl %eax, %eax
movl %eax, %esi
leaq -0x460(%rbp), %rdi
movq %rdi, -0x5f8(%rbp)
callq 0x4630
movq -0x5f8(%rbp), %rsi
leaq -0x250(%rbp), %rdi
callq 0x4670
jmp 0x383f
leaq -0x28(%rbp), %rdi
movq %rdi, -0x608(%rbp)
movl $0x2, %esi
callq 0x47b0
movq -0x608(%rbp), %rdi
movb $0x28, (%rax)
movl $0x3, %esi
callq 0x47b0
movq -0x608(%rbp), %rdi
movb $0x0, (%rax)
movl $0x4, %esi
callq 0x47b0
movq -0x608(%rbp), %rdi
movb $0x1, (%rax)
movl $0x5, %esi
callq 0x47b0
movb $0x1, (%rax)
movb $0x0, -0x3d(%rbp)
movb $0x0, -0x3e(%rbp)
leaq 0x120c1(%rip), %rsi     # 0x15963
leaq -0x460(%rbp), %rdi
callq 0x47d0
movq %rax, -0x600(%rbp)
jmp 0x38b7
movq -0x600(%rbp), %rdi
callq 0x4a10
movb %al, -0x609(%rbp)
jmp 0x38cb
movb -0x609(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x392a
movzbl -0x3d(%rbp), %eax
cmpl $0x1, %eax
jge 0x3910
movb $0x1, -0x3d(%rbp)
movb $0x1, -0x3e(%rbp)
jmp 0x3928
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x4527
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x450f
movzbl -0x3d(%rbp), %eax
cmpl $0x1, %eax
jne 0x3926
movzbl -0x3e(%rbp), %eax
cmpl $0x1, %eax
jge 0x3926
movb $0x1, -0x3e(%rbp)
jmp 0x3928
jmp 0x392a
movb -0x3d(%rbp), %al
movb %al, -0x629(%rbp)
leaq -0x28(%rbp), %rdi
movq %rdi, -0x628(%rbp)
movl $0x6, %esi
callq 0x47b0
movb -0x629(%rbp), %cl
movq -0x628(%rbp), %rdi
movb %cl, (%rax)
movb -0x3e(%rbp), %al
movb %al, -0x619(%rbp)
movl $0x7, %esi
callq 0x47b0
movb -0x619(%rbp), %cl
movb %cl, (%rax)
leaq 0x11ff2(%rip), %rsi     # 0x1596b
leaq -0x460(%rbp), %rdi
callq 0x47d0
movq %rax, -0x618(%rbp)
jmp 0x398e
movq -0x618(%rbp), %rdi
callq 0x4a40
movw %ax, -0x62c(%rbp)
jmp 0x39a3
movw -0x62c(%rbp), %ax
movb %al, -0x639(%rbp)
leaq -0x28(%rbp), %rdi
movl $0x8, %esi
callq 0x47b0
movb -0x639(%rbp), %cl
movb %cl, (%rax)
leaq 0x11f9e(%rip), %rsi     # 0x1596b
leaq -0x460(%rbp), %rdi
callq 0x47d0
movq %rax, -0x638(%rbp)
jmp 0x39e2
movq -0x638(%rbp), %rdi
callq 0x4a40
movw %ax, -0x63c(%rbp)
jmp 0x39f7
movw -0x63c(%rbp), %cx
movw %cx, %ax
movl %eax, -0x64c(%rbp)
leaq -0x28(%rbp), %rdi
movl $0x9, %esi
callq 0x47b0
movl -0x64c(%rbp), %ecx
movb %ch, %cl
movb %cl, (%rax)
leaq 0x11f51(%rip), %rsi     # 0x15977
leaq -0x460(%rbp), %rdi
callq 0x47d0
movq %rax, -0x648(%rbp)
jmp 0x3a3b
movq -0x648(%rbp), %rdi
callq 0x4a40
movw %ax, -0x64e(%rbp)
jmp 0x3a50
movw -0x64e(%rbp), %ax
movb %al, -0x659(%rbp)
leaq -0x28(%rbp), %rdi
movl $0xa, %esi
callq 0x47b0
movb -0x659(%rbp), %cl
movb %cl, (%rax)
leaq 0x11efd(%rip), %rsi     # 0x15977
leaq -0x460(%rbp), %rdi
callq 0x47d0
movq %rax, -0x658(%rbp)
jmp 0x3a8f
movq -0x658(%rbp), %rdi
callq 0x4a40
movw %ax, -0x65c(%rbp)
jmp 0x3aa4
movw -0x65c(%rbp), %cx
movw %cx, %ax
movl %eax, -0x66c(%rbp)
leaq -0x28(%rbp), %rdi
movl $0xb, %esi
callq 0x47b0
movl -0x66c(%rbp), %ecx
movb %ch, %cl
movb %cl, (%rax)
leaq 0x11eb1(%rip), %rsi     # 0x15984
leaq -0x460(%rbp), %rdi
callq 0x47d0
movq %rax, -0x668(%rbp)
jmp 0x3ae8
movq -0x668(%rbp), %rdi
callq 0x4a40
movw %ax, -0x66e(%rbp)
jmp 0x3afd
movw -0x66e(%rbp), %ax
movb %al, -0x679(%rbp)
leaq -0x28(%rbp), %rdi
movl $0xc, %esi
callq 0x47b0
movb -0x679(%rbp), %cl
movb %cl, (%rax)
leaq 0x11e5d(%rip), %rsi     # 0x15984
leaq -0x460(%rbp), %rdi
callq 0x47d0
movq %rax, -0x678(%rbp)
jmp 0x3b3c
movq -0x678(%rbp), %rdi
callq 0x4a40
movw %ax, -0x67c(%rbp)
jmp 0x3b51
movw -0x67c(%rbp), %cx
movw %cx, %ax
movl %eax, -0x68c(%rbp)
leaq -0x28(%rbp), %rdi
movl $0xd, %esi
callq 0x47b0
movl -0x68c(%rbp), %ecx
movb %ch, %cl
movb %cl, (%rax)
leaq 0x11e11(%rip), %rsi     # 0x15991
leaq -0x460(%rbp), %rdi
callq 0x47d0
movq %rax, -0x688(%rbp)
jmp 0x3b95
movq -0x688(%rbp), %rdi
callq 0x4a10
movb %al, -0x68d(%rbp)
jmp 0x3ba9
movb -0x68d(%rbp), %al
movzbl %al, %eax
andl $0x1, %eax
movl %eax, -0x69c(%rbp)
leaq -0x28(%rbp), %rdi
movl $0xe, %esi
callq 0x47b0
movl -0x69c(%rbp), %edx
movzbl (%rax), %ecx
orl %edx, %ecx
movb %cl, (%rax)
leaq 0x11dbc(%rip), %rsi     # 0x15999
leaq -0x460(%rbp), %rdi
callq 0x47d0
movq %rax, -0x698(%rbp)
jmp 0x3bf2
movq -0x698(%rbp), %rdi
callq 0x4a10
movb %al, -0x69d(%rbp)
jmp 0x3c06
movb -0x69d(%rbp), %al
movzbl %al, %eax
andl $0x1, %eax
addl %eax, %eax
movl %eax, -0x6ac(%rbp)
leaq -0x28(%rbp), %rdi
movl $0xe, %esi
callq 0x47b0
movl -0x6ac(%rbp), %edx
movzbl (%rax), %ecx
orl %edx, %ecx
movb %cl, (%rax)
leaq 0x11d27(%rip), %rsi     # 0x15963
leaq -0x460(%rbp), %rdi
callq 0x47d0
movq %rax, -0x6a8(%rbp)
jmp 0x3c51
movq -0x6a8(%rbp), %rdi
callq 0x4a10
movb %al, -0x6ad(%rbp)
jmp 0x3c65
movb -0x6ad(%rbp), %dl
xorl %eax, %eax
movl $0x4, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x6b4(%rbp)
leaq -0x28(%rbp), %rdi
movl $0xe, %esi
callq 0x47b0
movl -0x6b4(%rbp), %edx
movzbl (%rax), %ecx
orl %edx, %ecx
movb %cl, (%rax)
movl $0x0, -0x464(%rbp)
cmpl $0x3, -0x464(%rbp)
jge 0x3e84
leaq 0x11cf0(%rip), %rsi     # 0x159a7
leaq -0x460(%rbp), %rdi
callq 0x47d0
movq %rax, -0x6c0(%rbp)
jmp 0x3ccc
movq -0x6c0(%rbp), %rdi
movslq -0x464(%rbp), %rsi
callq 0x4a70
movq %rax, -0x6c8(%rbp)
jmp 0x3ce8
movq -0x6c8(%rbp), %rdi
leaq 0x11cb5(%rip), %rsi     # 0x159ab
callq 0x47d0
movq %rax, -0x6d0(%rbp)
jmp 0x3d04
movq -0x6d0(%rbp), %rdi
callq 0x4a40
movw %ax, -0x6d2(%rbp)
jmp 0x3d19
movw -0x6d2(%rbp), %ax
movw %ax, -0x466(%rbp)
movb -0x466(%rbp), %al
movb %al, -0x6f1(%rbp)
movl -0x464(%rbp), %ecx
movl %ecx, %eax
leal 0x10(,%rax,4), %eax
movslq %eax, %rsi
leaq -0x28(%rbp), %rdi
movq %rdi, -0x6f0(%rbp)
callq 0x47b0
movb -0x6f1(%rbp), %cl
movq -0x6f0(%rbp), %rdi
movb %cl, (%rax)
movb -0x465(%rbp), %al
movb %al, -0x6e1(%rbp)
movl -0x464(%rbp), %ecx
movl %ecx, %eax
leal 0x11(,%rax,4), %eax
movslq %eax, %rsi
callq 0x47b0
movb -0x6e1(%rbp), %cl
movb %cl, (%rax)
leaq 0x11c11(%rip), %rsi     # 0x159a7
leaq -0x460(%rbp), %rdi
callq 0x47d0
movq %rax, -0x6e0(%rbp)
jmp 0x3dab
movq -0x6e0(%rbp), %rdi
movslq -0x464(%rbp), %rsi
callq 0x4a70
movq %rax, -0x700(%rbp)
jmp 0x3dc7
movq -0x700(%rbp), %rdi
leaq 0x11bda(%rip), %rsi     # 0x159af
callq 0x47d0
movq %rax, -0x708(%rbp)
jmp 0x3de3
movq -0x708(%rbp), %rdi
callq 0x4a40
movw %ax, -0x70a(%rbp)
jmp 0x3df8
movw -0x70a(%rbp), %ax
movw %ax, -0x466(%rbp)
movzwl -0x466(%rbp), %eax
andl $0xff, %eax
movb %al, -0x70c(%rbp)
movl -0x464(%rbp), %eax
shll $0x2, %eax
addl $0x12, %eax
movslq %eax, %rsi
leaq -0x28(%rbp), %rdi
callq 0x47b0
movb -0x70c(%rbp), %cl
movb %cl, (%rax)
movzwl -0x466(%rbp), %eax
andl $0xff00, %eax           # imm = 0xFF00
sarl $0x8, %eax
movb %al, -0x70b(%rbp)
movl -0x464(%rbp), %eax
shll $0x2, %eax
addl $0x12, %eax
addl $0x1, %eax
movslq %eax, %rsi
leaq -0x28(%rbp), %rdi
callq 0x47b0
movb -0x70b(%rbp), %cl
movb %cl, (%rax)
movl -0x464(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x464(%rbp)
jmp 0x3ca3
leaq 0x11b28(%rip), %rsi     # 0x159b3
leaq -0x460(%rbp), %rdi
callq 0x47d0
movq %rax, -0x718(%rbp)
jmp 0x3ea0
movq -0x718(%rbp), %rsi
leaq -0x488(%rbp), %rdi
callq 0x4d00
jmp 0x3eb5
leaq -0x488(%rbp), %rdi
movq %rdi, -0x730(%rbp)
callq 0x3410
movq -0x730(%rbp), %rdi
movb %al, -0x721(%rbp)
callq 0x3200
movb -0x721(%rbp), %al
movb %al, -0x467(%rbp)
leaq 0x11ad8(%rip), %rsi     # 0x159c5
leaq -0x460(%rbp), %rdi
callq 0x47d0
movq %rax, -0x720(%rbp)
jmp 0x3f02
movq -0x720(%rbp), %rsi
leaq -0x4b0(%rbp), %rdi
callq 0x4d00
jmp 0x3f17
leaq -0x4b0(%rbp), %rdi
movq %rdi, -0x748(%rbp)
callq 0x3410
movq -0x748(%rbp), %rdi
movb %al, -0x739(%rbp)
callq 0x3200
movb -0x739(%rbp), %al
movb %al, -0x489(%rbp)
leaq 0x11a83(%rip), %rsi     # 0x159d2
leaq -0x460(%rbp), %rdi
callq 0x47d0
movq %rax, -0x738(%rbp)
jmp 0x3f64
movq -0x738(%rbp), %rsi
leaq -0x4d8(%rbp), %rdi
callq 0x4d00
jmp 0x3f79
leaq -0x4d8(%rbp), %rdi
movq %rdi, -0x760(%rbp)
callq 0x3410
movq -0x760(%rbp), %rdi
movb %al, -0x751(%rbp)
callq 0x3200
movb -0x751(%rbp), %al
movb %al, -0x4b1(%rbp)
leaq 0x11a2f(%rip), %rsi     # 0x159e0
leaq -0x460(%rbp), %rdi
callq 0x47d0
movq %rax, -0x750(%rbp)
jmp 0x3fc6
movq -0x750(%rbp), %rsi
leaq -0x500(%rbp), %rdi
callq 0x4d00
jmp 0x3fdb
leaq -0x500(%rbp), %rdi
callq 0x3410
movb %al, -0x761(%rbp)
leaq -0x500(%rbp), %rdi
callq 0x3200
movb -0x761(%rbp), %al
movb %al, -0x4d9(%rbp)
movb $0x0, -0x501(%rbp)
cmpl $0x4, -0x8(%rbp)
jne 0x4027
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x3170
movb %al, -0x501(%rbp)
jmp 0x4076
leaq 0x119c2(%rip), %rsi     # 0x159f0
leaq -0x460(%rbp), %rdi
callq 0x47d0
movq %rax, -0x770(%rbp)
jmp 0x4043
movq -0x770(%rbp), %rsi
leaq -0x528(%rbp), %rdi
callq 0x4d00
jmp 0x4058
leaq -0x528(%rbp), %rdi
callq 0x3410
movb %al, -0x501(%rbp)
leaq -0x528(%rbp), %rdi
callq 0x3200
movb -0x467(%rbp), %al
movb %al, -0x78f(%rbp)
leaq -0x28(%rbp), %rdi
movq %rdi, -0x788(%rbp)
movl $0x20, %esi
callq 0x47b0
movb -0x78f(%rbp), %cl
movq -0x788(%rbp), %rdi
movb %cl, (%rax)
movb -0x489(%rbp), %al
movb %al, -0x78e(%rbp)
movl $0x21, %esi
callq 0x47b0
movb -0x78e(%rbp), %cl
movq -0x788(%rbp), %rdi
movb %cl, (%rax)
movb -0x4b1(%rbp), %al
movb %al, -0x78d(%rbp)
movl $0x22, %esi
callq 0x47b0
movb -0x78d(%rbp), %cl
movq -0x788(%rbp), %rdi
movb %cl, (%rax)
movb -0x4d9(%rbp), %al
movb %al, -0x78c(%rbp)
movl $0x23, %esi
callq 0x47b0
movb -0x78c(%rbp), %cl
movq -0x788(%rbp), %rdi
movb %cl, (%rax)
movb -0x501(%rbp), %al
movb %al, -0x78b(%rbp)
movl $0x24, %esi
callq 0x47b0
movb -0x78b(%rbp), %cl
movq -0x788(%rbp), %rdi
movb %cl, (%rax)
movzbl -0x467(%rbp), %edx
movzbl -0x489(%rbp), %eax
addl %eax, %edx
movzbl -0x4b1(%rbp), %eax
addl %eax, %edx
movzbl -0x4d9(%rbp), %eax
addl %eax, %edx
movzbl -0x501(%rbp), %ecx
movl %ecx, %eax
movl %edx, %ecx
leal 0x28(%rax,%rcx), %eax
movw %ax, -0x52a(%rbp)
movb -0x52a(%rbp), %al
movb %al, -0x78a(%rbp)
xorl %eax, %eax
movl %eax, %esi
movq %rsi, -0x780(%rbp)
callq 0x47b0
movb -0x78a(%rbp), %cl
movq -0x788(%rbp), %rdi
movb %cl, (%rax)
movb -0x529(%rbp), %al
movb %al, -0x789(%rbp)
movl $0x1, %esi
callq 0x47b0
movb -0x789(%rbp), %cl
movq -0x788(%rbp), %rdi
movq -0x780(%rbp), %rsi
movb %cl, (%rax)
callq 0x47b0
movq %rax, %rdi
movl $0x26, %esi
callq 0x14070
movw %ax, -0x772(%rbp)
jmp 0x41e4
movw -0x772(%rbp), %ax
movw %ax, -0x52c(%rbp)
movzwl -0x52c(%rbp), %eax
andl $0xff00, %eax           # imm = 0xFF00
sarl $0x8, %eax
movb %al, -0x791(%rbp)
leaq -0x28(%rbp), %rdi
movl $0x26, %esi
callq 0x47b0
movb -0x791(%rbp), %cl
movb %cl, (%rax)
movzwl -0x52c(%rbp), %eax
andl $0xff, %eax
movb %al, -0x790(%rbp)
leaq -0x28(%rbp), %rdi
movl $0x27, %esi
callq 0x47b0
movb -0x790(%rbp), %cl
movb %cl, (%rax)
movl $0x0, -0x530(%rbp)
cmpl $0x28, -0x530(%rbp)
jge 0x428c
movslq -0x530(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0x47b0
movzbl (%rax), %esi
leaq -0x450(%rbp), %rdi
callq 0x3420
jmp 0x4279
jmp 0x427b
movl -0x530(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x530(%rbp)
jmp 0x424f
leaq 0x11720(%rip), %rsi     # 0x159b3
leaq -0x460(%rbp), %rdi
callq 0x47d0
movq %rax, -0x7a0(%rbp)
jmp 0x42a8
movq -0x7a0(%rbp), %rsi
leaq -0x550(%rbp), %rdi
callq 0x4d00
jmp 0x42bd
leaq -0x450(%rbp), %rdi
leaq -0x550(%rbp), %rsi
callq 0x32c0
jmp 0x42d2
leaq -0x550(%rbp), %rdi
callq 0x3200
leaq 0x116e0(%rip), %rsi     # 0x159c5
leaq -0x460(%rbp), %rdi
callq 0x47d0
movq %rax, -0x7a8(%rbp)
jmp 0x42fa
movq -0x7a8(%rbp), %rsi
leaq -0x570(%rbp), %rdi
callq 0x4d00
jmp 0x430f
leaq -0x450(%rbp), %rdi
leaq -0x570(%rbp), %rsi
callq 0x32c0
jmp 0x4324
leaq -0x570(%rbp), %rdi
callq 0x3200
leaq 0x1169b(%rip), %rsi     # 0x159d2
leaq -0x460(%rbp), %rdi
callq 0x47d0
movq %rax, -0x7b0(%rbp)
jmp 0x434c
movq -0x7b0(%rbp), %rsi
leaq -0x590(%rbp), %rdi
callq 0x4d00
jmp 0x4361
leaq -0x450(%rbp), %rdi
leaq -0x590(%rbp), %rsi
callq 0x32c0
jmp 0x4376
leaq -0x590(%rbp), %rdi
callq 0x3200
leaq 0x11657(%rip), %rsi     # 0x159e0
leaq -0x460(%rbp), %rdi
callq 0x47d0
movq %rax, -0x7b8(%rbp)
jmp 0x439e
movq -0x7b8(%rbp), %rsi
leaq -0x5b0(%rbp), %rdi
callq 0x4d00
jmp 0x43b3
leaq -0x450(%rbp), %rdi
leaq -0x5b0(%rbp), %rsi
callq 0x32c0
jmp 0x43c8
leaq -0x5b0(%rbp), %rdi
callq 0x3200
cmpl $0x4, -0x8(%rbp)
jne 0x446d
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
leaq -0x450(%rbp), %rdi
callq 0x32f0
jmp 0x43f4
jmp 0x44db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x550(%rbp), %rdi
callq 0x3200
jmp 0x450f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x570(%rbp), %rdi
callq 0x3200
jmp 0x450f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x590(%rbp), %rdi
callq 0x3200
jmp 0x450f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x5b0(%rbp), %rdi
callq 0x3200
jmp 0x450f
leaq 0x1157c(%rip), %rsi     # 0x159f0
leaq -0x460(%rbp), %rdi
callq 0x47d0
movq %rax, -0x7c0(%rbp)
jmp 0x4489
movq -0x7c0(%rbp), %rsi
leaq -0x5d0(%rbp), %rdi
callq 0x4d00
jmp 0x449e
leaq -0x450(%rbp), %rdi
leaq -0x5d0(%rbp), %rsi
callq 0x32c0
jmp 0x44b3
leaq -0x5d0(%rbp), %rdi
callq 0x3200
jmp 0x44db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x5d0(%rbp), %rdi
callq 0x3200
jmp 0x450f
movl $0x0, -0x4(%rbp)
movl $0x1, -0x44(%rbp)
leaq -0x460(%rbp), %rdi
callq 0x4d80
leaq -0x450(%rbp), %rdi
callq 0x3400
leaq -0x250(%rbp), %rdi
callq 0x30c0
jmp 0x4535
leaq -0x460(%rbp), %rdi
callq 0x4d80
leaq -0x450(%rbp), %rdi
callq 0x3400
leaq -0x250(%rbp), %rdi
callq 0x30c0
jmp 0x454a
leaq -0x28(%rbp), %rdi
callq 0x4dc0
movl -0x4(%rbp), %eax
addq $0x7c0, %rsp            # imm = 0x7C0
popq %rbp
retq
leaq -0x28(%rbp), %rdi
callq 0x4dc0
movq -0x38(%rbp), %rdi
callq 0x34e0
nopl (%rax)