// File: 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:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
cmpl $0x28, -0x1c(%rbp)
jge 0x14128
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x144ec
movq -0x18(%rbp), %rdi
movl $0x28, %esi
callq 0x14070
movzwl %ax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x1414b
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x144ec
movq -0x10(%rbp), %rax
addq $0x20, %rax
movslq -0x8(%rbp), %rcx
imulq $0x6c, %rcx, %rcx
addq %rcx, %rax
movl $0x1, 0x4(%rax)
movq -0x18(%rbp), %rax
movzbl 0x6(%rax), %ecx
movq -0x10(%rbp), %rax
addq $0x20, %rax
movslq -0x8(%rbp), %rdx
imulq $0x6c, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0xc(%rax)
movq -0x18(%rbp), %rax
movzbl 0x7(%rax), %ecx
movq -0x10(%rbp), %rax
addq $0x20, %rax
movslq -0x8(%rbp), %rdx
imulq $0x6c, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x10(%rax)
movq -0x18(%rbp), %rax
movzbl 0xf(%rax), %ecx
shll $0x8, %ecx
movq -0x18(%rbp), %rax
movzbl 0xe(%rax), %eax
orl %eax, %ecx
movq -0x10(%rbp), %rax
addq $0x20, %rax
movslq -0x8(%rbp), %rdx
imulq $0x6c, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x14(%rax)
movl $0x0, -0x20(%rbp)
cmpl $0x4, -0x20(%rbp)
jge 0x142b9
movq -0x18(%rbp), %rax
movl -0x20(%rbp), %ecx
shll $0x2, %ecx
addl $0x10, %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x18(%rbp), %rcx
movl -0x20(%rbp), %edx
shll $0x2, %edx
addl $0x10, %edx
movslq %edx, %rdx
movzbl (%rcx,%rdx), %ecx
orl %ecx, %eax
movl %eax, -0x24(%rbp)
movq -0x18(%rbp), %rax
movl -0x20(%rbp), %ecx
shll $0x2, %ecx
addl $0x12, %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x18(%rbp), %rcx
movl -0x20(%rbp), %edx
shll $0x2, %edx
addl $0x12, %edx
movslq %edx, %rdx
movzbl (%rcx,%rdx), %ecx
orl %ecx, %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x14251
cmpl $0x0, -0x24(%rbp)
jne 0x14251
jmp 0x142b9
movl -0x24(%rbp), %edx
movq -0x10(%rbp), %rax
addq $0x20, %rax
movslq -0x8(%rbp), %rcx
imulq $0x6c, %rcx, %rcx
addq %rcx, %rax
movslq -0x20(%rbp), %rcx
movl %edx, 0x24(%rax,%rcx,8)
movl -0x28(%rbp), %edx
movq -0x10(%rbp), %rax
addq $0x20, %rax
movslq -0x8(%rbp), %rcx
imulq $0x6c, %rcx, %rcx
addq %rcx, %rax
movslq -0x20(%rbp), %rcx
movl %edx, 0x28(%rax,%rcx,8)
movq -0x10(%rbp), %rax
addq $0x20, %rax
movslq -0x8(%rbp), %rcx
imulq $0x6c, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x20(%rax)
jmp 0x142ab
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x141d3
movq -0x10(%rbp), %rax
addq $0x20, %rax
movslq -0x8(%rbp), %rcx
imulq $0x6c, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x1435b
movq -0x10(%rbp), %rax
addq $0x20, %rax
movslq -0x8(%rbp), %rcx
imulq $0x6c, %rcx, %rcx
addq %rcx, %rax
movl 0x1c(%rax), %ecx
movl $0x1, %edx
shll %cl, %edx
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rcx
addq $0x20, %rcx
movslq -0x8(%rbp), %rsi
imulq $0x6c, %rsi, %rsi
addq %rsi, %rcx
movslq 0x8(%rcx), %rcx
orl 0x14(%rax,%rcx,4), %edx
movl %edx, 0x14(%rax,%rcx,4)
movq -0x10(%rbp), %rax
addq $0x20, %rax
movslq -0x8(%rbp), %rcx
imulq $0x6c, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
movl $0x1, %edx
shll %cl, %edx
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rcx
addq $0x20, %rcx
movslq -0x8(%rbp), %rsi
imulq $0x6c, %rsi, %rsi
addq %rsi, %rcx
movslq 0x1c(%rcx), %rcx
orl 0x14(%rax,%rcx,4), %edx
movl %edx, 0x14(%rax,%rcx,4)
movl $0x28, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
movq -0x10(%rbp), %rax
addq $0x20, %rax
movslq -0x8(%rbp), %rdx
imulq $0x6c, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x44(%rax)
movq -0x18(%rbp), %rax
movzbl 0x20(%rax), %ecx
movq -0x10(%rbp), %rax
addq $0x20, %rax
movslq -0x8(%rbp), %rdx
imulq $0x6c, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x48(%rax)
movq -0x10(%rbp), %rax
addq $0x20, %rax
movslq -0x8(%rbp), %rcx
imulq $0x6c, %rcx, %rcx
addq %rcx, %rax
movl 0x48(%rax), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
movq -0x10(%rbp), %rax
addq $0x20, %rax
movslq -0x8(%rbp), %rdx
imulq $0x6c, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x4c(%rax)
movq -0x18(%rbp), %rax
movzbl 0x21(%rax), %ecx
movq -0x10(%rbp), %rax
addq $0x20, %rax
movslq -0x8(%rbp), %rdx
imulq $0x6c, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x50(%rax)
movq -0x10(%rbp), %rax
addq $0x20, %rax
movslq -0x8(%rbp), %rcx
imulq $0x6c, %rcx, %rcx
addq %rcx, %rax
movl 0x50(%rax), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
movq -0x10(%rbp), %rax
addq $0x20, %rax
movslq -0x8(%rbp), %rdx
imulq $0x6c, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x54(%rax)
movq -0x18(%rbp), %rax
movzbl 0x22(%rax), %ecx
movq -0x10(%rbp), %rax
addq $0x20, %rax
movslq -0x8(%rbp), %rdx
imulq $0x6c, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x58(%rax)
movq -0x10(%rbp), %rax
addq $0x20, %rax
movslq -0x8(%rbp), %rcx
imulq $0x6c, %rcx, %rcx
addq %rcx, %rax
movl 0x58(%rax), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
movq -0x10(%rbp), %rax
addq $0x20, %rax
movslq -0x8(%rbp), %rdx
imulq $0x6c, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x5c(%rax)
movq -0x18(%rbp), %rax
movzbl 0x23(%rax), %ecx
movq -0x10(%rbp), %rax
addq $0x20, %rax
movslq -0x8(%rbp), %rdx
imulq $0x6c, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x60(%rax)
movq -0x10(%rbp), %rax
addq $0x20, %rax
movslq -0x8(%rbp), %rcx
imulq $0x6c, %rcx, %rcx
addq %rcx, %rax
movl 0x60(%rax), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
movq -0x10(%rbp), %rax
addq $0x20, %rax
movslq -0x8(%rbp), %rdx
imulq $0x6c, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x64(%rax)
movq -0x18(%rbp), %rax
movzbl 0x24(%rax), %ecx
movq -0x10(%rbp), %rax
addq $0x20, %rax
movslq -0x8(%rbp), %rdx
imulq $0x6c, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x68(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)