// File: /workspace/github_cpp_makefile_star2_O1/SYZYGYfpga[P]syzygy-tools/smartvio/syzygy.c
// Function: szgParsePortDNA
int
szgParsePortDNA(int n, szgSmartVIOConfig *svio, unsigned char *dnaBuf, int length)
{
	int i;
	int vmin, vmax;
	unsigned int offset;


	// Bounds check for input buffer.
	if (length < SZG_DNA_HEADER_LENGTH_V1) {
		return(-1);
	}

	// Validate the DNA CRC.
	if (0 != szgComputeCRC(dnaBuf, SZG_DNA_HEADER_LENGTH_V1)) {
		return(-1);
	}

	svio->ports[n].present = 1;
	svio->ports[n].req_ver_major = dnaBuf[SZG_DNA_PTR_DNA_REQUIRED_MAJOR];
	svio->ports[n].req_ver_minor = dnaBuf[SZG_DNA_PTR_DNA_REQUIRED_MINOR];
	svio->ports[n].attr = (dnaBuf[SZG_DNA_PTR_ATTRIBUTES + 1] << 8) | (dnaBuf[SZG_DNA_PTR_ATTRIBUTES]);
	for (i=0; i<SZG_MAX_DNA_RANGES; i++) {
		vmin = (dnaBuf[SZG_DNA_MIN_VIO_RANGE0 + i*4 + 1] << 8) | (dnaBuf[SZG_DNA_MIN_VIO_RANGE0 + i*4]);
		vmax = (dnaBuf[SZG_DNA_MAX_VIO_RANGE0 + i*4 + 1] << 8) | (dnaBuf[SZG_DNA_MAX_VIO_RANGE0 + i*4]);
		if ((vmin == 0) && (vmin == 0)) {
			break;
		} else {
			svio->ports[n].ranges[i].min = vmin;
			svio->ports[n].ranges[i].max = vmax;
			svio->ports[n].range_count++;
		}
	}

	// If the DOUBLEWIDE attribute is set, we need to add the mating group to the dependents.
	// We also need to create the reciprocal relationship so that the mating group includes
	// the present port.
	if (svio->ports[n].attr & SZG_ATTR_DOUBLEWIDE) {
		svio->group_masks[svio->ports[n].group] |= (1 << svio->ports[n].doublewide_mate);
		svio->group_masks[svio->ports[n].doublewide_mate] |= (1 << svio->ports[n].group);
	}

	offset = SZG_DNA_HEADER_LENGTH_V1;
	svio->ports[n].mfr_offset = offset;
	svio->ports[n].mfr_length = dnaBuf[SZG_DNA_MANUFACTURER_NAME_LENGTH];

	offset += svio->ports[n].mfr_length;
	svio->ports[n].product_name_offset = offset;
	svio->ports[n].product_name_length = dnaBuf[SZG_DNA_PRODUCT_NAME_LENGTH];

	offset += svio->ports[n].product_name_length;
	svio->ports[n].product_model_offset = offset;
	svio->ports[n].product_model_length = dnaBuf[SZG_DNA_PRODUCT_MODEL_LENGTH];

	offset += svio->ports[n].product_model_length;
	svio->ports[n].product_version_offset = offset;
	svio->ports[n].product_version_length = dnaBuf[SZG_DNA_PRODUCT_VERSION_LENGTH];

	offset += svio->ports[n].product_version_length;
	svio->ports[n].serial_number_offset = offset;
	svio->ports[n].serial_number_length = dnaBuf[SZG_DNA_SERIAL_NUMBER_LENGTH];

	return(0);
}

// Assembly:
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $0x28, %ecx
jl 0x8832
movw $0xffff, %r8w           # imm = 0xFFFF
xorl %ecx, %ecx
movzwl %r8w, %r9d
shrl $0x8, %r9d
movzbl (%rdx,%rcx), %r10d
xorl %r9d, %r10d
movl %r10d, %r11d
shrl $0x4, %r11d
xorl %r10d, %r11d
shll $0x8, %r8d
movl %r11d, %r9d
orl %r11d, %r8d
shll $0xc, %r11d
shll $0x5, %r9d
movl %r8d, %r10d
xorl %r11d, %r10d
movl %r10d, %r8d
xorl %r9d, %r8d
incq %rcx
cmpl $0x28, %ecx
jne 0x871d
cmpw %r9w, %r10w
jne 0x8832
movslq %edi, %rax
imulq $0x6c, %rax, %rax
addq %rsi, %rax
addq $0x20, %rax
movl $0x1, 0x4(%rax)
movzbl 0x6(%rdx), %ecx
movl %ecx, 0xc(%rax)
movzbl 0x7(%rdx), %ecx
movl %ecx, 0x10(%rax)
movzbl 0xf(%rdx), %edi
shll $0x8, %edi
movzbl 0xe(%rdx), %ecx
orl %ecx, %edi
movl %edi, 0x14(%rax)
xorl %edi, %edi
movzwl 0x10(%rdx,%rdi,4), %r8d
testl %r8d, %r8d
je 0x87c3
movzwl 0x12(%rdx,%rdi,4), %r9d
movl %r8d, 0x24(%rax,%rdi,8)
movl %r9d, 0x28(%rax,%rdi,8)
incl 0x20(%rax)
incq %rdi
cmpq $0x4, %rdi
jne 0x879c
testb $0x2, %cl
je 0x87ef
movb 0x1c(%rax), %cl
movl $0x1, %edi
movl $0x1, %r8d
shll %cl, %r8d
movslq 0x8(%rax), %rcx
orl %r8d, 0x14(%rsi,%rcx,4)
movb 0x8(%rax), %cl
shll %cl, %edi
movslq 0x1c(%rax), %rcx
orl %edi, 0x14(%rsi,%rcx,4)
movl $0x28, 0x44(%rax)
movzbl 0x20(%rdx), %ecx
movl %ecx, 0x48(%rax)
leal 0x28(%rcx), %esi
movl %esi, 0x4c(%rax)
movzbl 0x21(%rdx), %esi
movl %esi, 0x50(%rax)
leal 0x28(%rcx,%rsi), %ecx
movl %ecx, 0x54(%rax)
movzbl 0x22(%rdx), %esi
movl %esi, 0x58(%rax)
addl %esi, %ecx
movl %ecx, 0x5c(%rax)
movzbl 0x23(%rdx), %esi
movl %esi, 0x60(%rax)
addl %esi, %ecx
movl %ecx, 0x64(%rax)
movzbl 0x24(%rdx), %ecx
movl %ecx, 0x68(%rax)
xorl %eax, %eax
retq