// File: SYZYGYfpga[P]brain-tools/src/smartvio-brain.cpp
// Function: printVIOStrings(nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer>&, int)
int printVIOStrings (json &json_handler, int i2c_file)
{
	uint8_t temp_string[257];
	int i;
	int j = 0;

	for (i = 0; i < SVIO_NUM_PORTS; i++) {
		if (svio.ports[i].i2c_addr == 0x00) {
			// don't print anything for FPGA "ports"
			continue;
		}

		if (svio.ports[i].present == 0) {
			if (!json_handler.is_null()) {
				json_handler["port"][j] = nullptr;
			}

			// just increment the port counter for non-present ports
			j++;
			continue;
		}

		// retrieve manufacturer
		if (readMCU(i2c_file, svio.ports[i].i2c_addr,
		        0x8000 + svio.ports[i].mfr_offset, temp_string,
		        svio.ports[i].mfr_length) != 0) {
			return -1;
		}

		temp_string[svio.ports[i].mfr_length] = '\0';

		if (!json_handler.is_null()) {
			json_handler["port"][j]["manufacturer"] = std::string((char*) temp_string);
		} else {
			printf("Port 0x%X Manufacturer: %s\n", svio.ports[i].i2c_addr, temp_string);
		}

		// retrieve product name
		if (readMCU(i2c_file, svio.ports[i].i2c_addr,
		        0x8000 + svio.ports[i].product_name_offset, temp_string,
		        svio.ports[i].product_name_length) != 0) {
			return -1;
		}

		temp_string[svio.ports[i].product_name_length] = '\0';

		if (!json_handler.is_null()) {
			json_handler["port"][j]["product_name"] = std::string((char*) temp_string);
		} else {
			printf("Product Name: %s\n", temp_string);
		}

		// retrieve product model
		if (readMCU(i2c_file, svio.ports[i].i2c_addr,
		        0x8000 + svio.ports[i].product_model_offset, temp_string,
		        svio.ports[i].product_model_length) != 0) {
			return -1;
		}

		temp_string[svio.ports[i].product_model_length] = '\0';

		if (!json_handler.is_null()) {
			json_handler["port"][j]["product_model"] = std::string((char*) temp_string);
		} else {
			printf("Product Model: %s\n", temp_string);
		}

		// retrieve product version
		if (readMCU(i2c_file, svio.ports[i].i2c_addr,
		        0x8000 + svio.ports[i].product_version_offset, temp_string,
		        svio.ports[i].product_version_length) != 0) {
			return -1;
		}

		temp_string[svio.ports[i].product_version_length] = '\0';

		if (!json_handler.is_null()) {
			json_handler["port"][j]["product_version"] = std::string((char*) temp_string);
		} else {
			printf("Version: %s\n", temp_string);
		}

		// retrieve serial
		if (readMCU(i2c_file, svio.ports[i].i2c_addr,
		        0x8000 + svio.ports[i].serial_number_offset, temp_string,
		        svio.ports[i].serial_number_length) != 0) {
			return -1;
		}

		temp_string[svio.ports[i].serial_number_length] = '\0';

		if (!json_handler.is_null()) {
			json_handler["port"][j]["serial_number"] = std::string((char*) temp_string);
		} else {
			printf("Serial: %s\n", temp_string);
		}
		j++;
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x310, %rsp            # imm = 0x310
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl $0x0, -0x128(%rbp)
movl $0x0, -0x124(%rbp)
cmpl $0x6, -0x124(%rbp)
jge 0x492d
movslq -0x124(%rbp), %rcx
leaq 0x1c447(%rip), %rax     # 0x20278
addq $0x18, %rax
imulq $0x6c, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, (%rax)
jne 0x3e46
jmp 0x4919
movslq -0x124(%rbp), %rcx
leaq 0x1c424(%rip), %rax     # 0x20278
addq $0x18, %rax
imulq $0x6c, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x4(%rax)
jne 0x3f17
movq -0x10(%rbp), %rdi
callq 0x55f0
testb $0x1, %al
jne 0x3f03
xorl %eax, %eax
movl %eax, %esi
leaq -0x138(%rbp), %rdi
callq 0x5610
movq -0x10(%rbp), %rdi
leaq 0x10510(%rip), %rsi     # 0x143a5
callq 0x5650
movq %rax, -0x268(%rbp)
jmp 0x3ea3
movq -0x268(%rbp), %rdi
movslq -0x128(%rbp), %rsi
callq 0x5890
movq %rax, -0x270(%rbp)
jmp 0x3ebf
movq -0x270(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x5b20
leaq -0x138(%rbp), %rdi
callq 0x5b90
jmp 0x3f03
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x140(%rbp)
movl %eax, -0x144(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x5b90
jmp 0x4940
movl -0x128(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x128(%rbp)
jmp 0x4919
movl -0x14(%rbp), %edi
movslq -0x124(%rbp), %rcx
leaq 0x1c350(%rip), %rax     # 0x20278
addq $0x18, %rax
imulq $0x6c, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
movslq -0x124(%rbp), %rdx
leaq 0x1c335(%rip), %rcx     # 0x20278
addq $0x18, %rcx
imulq $0x6c, %rdx, %rdx
addq %rdx, %rcx
movl 0x44(%rcx), %edx
addl $0x8000, %edx           # imm = 0x8000
leaq -0x120(%rbp), %rcx
movslq -0x124(%rbp), %r8
leaq 0x1c30c(%rip), %rsi     # 0x20278
addq $0x18, %rsi
imulq $0x6c, %r8, %r8
addq %r8, %rsi
movl 0x48(%rsi), %r8d
movzwl %ax, %esi
callq 0x38d0
cmpl $0x0, %eax
je 0x3f94
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4934
movslq -0x124(%rbp), %rcx
leaq 0x1c2d6(%rip), %rax     # 0x20278
addq $0x18, %rax
imulq $0x6c, %rcx, %rcx
addq %rcx, %rax
movl 0x48(%rax), %eax
movb $0x0, -0x120(%rbp,%rax)
movq -0x10(%rbp), %rdi
callq 0x55f0
testb $0x1, %al
jne 0x40fd
leaq -0x179(%rbp), %rdi
movq %rdi, -0x278(%rbp)
callq 0x3460
movq -0x278(%rbp), %rdx
leaq -0x178(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x3340
jmp 0x3ff8
leaq -0x158(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0x5bd0
jmp 0x400d
movq -0x10(%rbp), %rdi
leaq 0x1038d(%rip), %rsi     # 0x143a5
callq 0x5650
movq %rax, -0x280(%rbp)
jmp 0x4026
movq -0x280(%rbp), %rdi
movslq -0x128(%rbp), %rsi
callq 0x5890
movq %rax, -0x288(%rbp)
jmp 0x4042
movq -0x288(%rbp), %rdi
leaq 0x1035a(%rip), %rsi     # 0x143aa
callq 0x5650
movq %rax, -0x290(%rbp)
jmp 0x405e
movq -0x290(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x5b20
leaq -0x158(%rbp), %rdi
callq 0x5b90
leaq -0x178(%rbp), %rdi
callq 0x31c0
leaq -0x179(%rbp), %rdi
callq 0x32e0
jmp 0x412d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x140(%rbp)
movl %eax, -0x144(%rbp)
jmp 0x40ec
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x140(%rbp)
movl %eax, -0x144(%rbp)
jmp 0x40e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x140(%rbp)
movl %eax, -0x144(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x5b90
leaq -0x178(%rbp), %rdi
callq 0x31c0
leaq -0x179(%rbp), %rdi
callq 0x32e0
jmp 0x4940
movslq -0x124(%rbp), %rcx
leaq 0x1c16d(%rip), %rax     # 0x20278
addq $0x18, %rax
imulq $0x6c, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %esi
leaq -0x120(%rbp), %rdx
leaq 0x10291(%rip), %rdi     # 0x143b7
movb $0x0, %al
callq 0x3050
movl -0x14(%rbp), %edi
movslq -0x124(%rbp), %rcx
leaq 0x1c13a(%rip), %rax     # 0x20278
addq $0x18, %rax
imulq $0x6c, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
movslq -0x124(%rbp), %rdx
leaq 0x1c11f(%rip), %rcx     # 0x20278
addq $0x18, %rcx
imulq $0x6c, %rdx, %rdx
addq %rdx, %rcx
movl 0x4c(%rcx), %edx
addl $0x8000, %edx           # imm = 0x8000
leaq -0x120(%rbp), %rcx
movslq -0x124(%rbp), %r8
leaq 0x1c0f6(%rip), %rsi     # 0x20278
addq $0x18, %rsi
imulq $0x6c, %r8, %r8
addq %r8, %rsi
movl 0x50(%rsi), %r8d
movzwl %ax, %esi
callq 0x38d0
cmpl $0x0, %eax
je 0x41aa
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4934
movslq -0x124(%rbp), %rcx
leaq 0x1c0c0(%rip), %rax     # 0x20278
addq $0x18, %rax
imulq $0x6c, %rcx, %rcx
addq %rcx, %rax
movl 0x50(%rax), %eax
movb $0x0, -0x120(%rbp,%rax)
movq -0x10(%rbp), %rdi
callq 0x55f0
testb $0x1, %al
jne 0x4310
leaq -0x1b1(%rbp), %rdi
movq %rdi, -0x298(%rbp)
callq 0x3460
movq -0x298(%rbp), %rdx
leaq -0x1b0(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x3340
jmp 0x420e
leaq -0x190(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x5bd0
jmp 0x4223
movq -0x10(%rbp), %rdi
leaq 0x10177(%rip), %rsi     # 0x143a5
callq 0x5650
movq %rax, -0x2a0(%rbp)
jmp 0x423c
movq -0x2a0(%rbp), %rdi
movslq -0x128(%rbp), %rsi
callq 0x5890
movq %rax, -0x2a8(%rbp)
jmp 0x4258
movq -0x2a8(%rbp), %rdi
leaq 0x1016d(%rip), %rsi     # 0x143d3
callq 0x5650
movq %rax, -0x2b0(%rbp)
jmp 0x4274
movq -0x2b0(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x5b20
leaq -0x190(%rbp), %rdi
callq 0x5b90
leaq -0x1b0(%rbp), %rdi
callq 0x31c0
leaq -0x1b1(%rbp), %rdi
callq 0x32e0
jmp 0x4325
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x140(%rbp)
movl %eax, -0x144(%rbp)
jmp 0x42ff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x140(%rbp)
movl %eax, -0x144(%rbp)
jmp 0x42f3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x140(%rbp)
movl %eax, -0x144(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x5b90
leaq -0x1b0(%rbp), %rdi
callq 0x31c0
leaq -0x1b1(%rbp), %rdi
callq 0x32e0
jmp 0x4940
leaq -0x120(%rbp), %rsi
leaq 0x100c2(%rip), %rdi     # 0x143e0
movb $0x0, %al
callq 0x3050
movl -0x14(%rbp), %edi
movslq -0x124(%rbp), %rcx
leaq 0x1bf42(%rip), %rax     # 0x20278
addq $0x18, %rax
imulq $0x6c, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
movslq -0x124(%rbp), %rdx
leaq 0x1bf27(%rip), %rcx     # 0x20278
addq $0x18, %rcx
imulq $0x6c, %rdx, %rdx
addq %rdx, %rcx
movl 0x54(%rcx), %edx
addl $0x8000, %edx           # imm = 0x8000
leaq -0x120(%rbp), %rcx
movslq -0x124(%rbp), %r8
leaq 0x1befe(%rip), %rsi     # 0x20278
addq $0x18, %rsi
imulq $0x6c, %r8, %r8
addq %r8, %rsi
movl 0x58(%rsi), %r8d
movzwl %ax, %esi
callq 0x38d0
cmpl $0x0, %eax
je 0x43a2
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4934
movslq -0x124(%rbp), %rcx
leaq 0x1bec8(%rip), %rax     # 0x20278
addq $0x18, %rax
imulq $0x6c, %rcx, %rcx
addq %rcx, %rax
movl 0x58(%rax), %eax
movb $0x0, -0x120(%rbp,%rax)
movq -0x10(%rbp), %rdi
callq 0x55f0
testb $0x1, %al
jne 0x4508
leaq -0x1e9(%rbp), %rdi
movq %rdi, -0x2b8(%rbp)
callq 0x3460
movq -0x2b8(%rbp), %rdx
leaq -0x1e8(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x3340
jmp 0x4406
leaq -0x1c8(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0x5bd0
jmp 0x441b
movq -0x10(%rbp), %rdi
leaq 0xff7f(%rip), %rsi      # 0x143a5
callq 0x5650
movq %rax, -0x2c0(%rbp)
jmp 0x4434
movq -0x2c0(%rbp), %rdi
movslq -0x128(%rbp), %rsi
callq 0x5890
movq %rax, -0x2c8(%rbp)
jmp 0x4450
movq -0x2c8(%rbp), %rdi
leaq 0xff94(%rip), %rsi      # 0x143f2
callq 0x5650
movq %rax, -0x2d0(%rbp)
jmp 0x446c
movq -0x2d0(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
callq 0x5b20
leaq -0x1c8(%rbp), %rdi
callq 0x5b90
leaq -0x1e8(%rbp), %rdi
callq 0x31c0
leaq -0x1e9(%rbp), %rdi
callq 0x32e0
jmp 0x451d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x140(%rbp)
movl %eax, -0x144(%rbp)
jmp 0x44f7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x140(%rbp)
movl %eax, -0x144(%rbp)
jmp 0x44eb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x140(%rbp)
movl %eax, -0x144(%rbp)
leaq -0x1c8(%rbp), %rdi
callq 0x5b90
leaq -0x1e8(%rbp), %rdi
callq 0x31c0
leaq -0x1e9(%rbp), %rdi
callq 0x32e0
jmp 0x4940
leaq -0x120(%rbp), %rsi
leaq 0xfeea(%rip), %rdi      # 0x14400
movb $0x0, %al
callq 0x3050
movl -0x14(%rbp), %edi
movslq -0x124(%rbp), %rcx
leaq 0x1bd4a(%rip), %rax     # 0x20278
addq $0x18, %rax
imulq $0x6c, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
movslq -0x124(%rbp), %rdx
leaq 0x1bd2f(%rip), %rcx     # 0x20278
addq $0x18, %rcx
imulq $0x6c, %rdx, %rdx
addq %rdx, %rcx
movl 0x5c(%rcx), %edx
addl $0x8000, %edx           # imm = 0x8000
leaq -0x120(%rbp), %rcx
movslq -0x124(%rbp), %r8
leaq 0x1bd06(%rip), %rsi     # 0x20278
addq $0x18, %rsi
imulq $0x6c, %r8, %r8
addq %r8, %rsi
movl 0x60(%rsi), %r8d
movzwl %ax, %esi
callq 0x38d0
cmpl $0x0, %eax
je 0x459a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4934
movslq -0x124(%rbp), %rcx
leaq 0x1bcd0(%rip), %rax     # 0x20278
addq $0x18, %rax
imulq $0x6c, %rcx, %rcx
addq %rcx, %rax
movl 0x60(%rax), %eax
movb $0x0, -0x120(%rbp,%rax)
movq -0x10(%rbp), %rdi
callq 0x55f0
testb $0x1, %al
jne 0x4700
leaq -0x221(%rbp), %rdi
movq %rdi, -0x2d8(%rbp)
callq 0x3460
movq -0x2d8(%rbp), %rdx
leaq -0x220(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x3340
jmp 0x45fe
leaq -0x200(%rbp), %rdi
leaq -0x220(%rbp), %rsi
callq 0x5bd0
jmp 0x4613
movq -0x10(%rbp), %rdi
leaq 0xfd87(%rip), %rsi      # 0x143a5
callq 0x5650
movq %rax, -0x2e0(%rbp)
jmp 0x462c
movq -0x2e0(%rbp), %rdi
movslq -0x128(%rbp), %rsi
callq 0x5890
movq %rax, -0x2e8(%rbp)
jmp 0x4648
movq -0x2e8(%rbp), %rdi
leaq 0xfdbd(%rip), %rsi      # 0x14413
callq 0x5650
movq %rax, -0x2f0(%rbp)
jmp 0x4664
movq -0x2f0(%rbp), %rdi
leaq -0x200(%rbp), %rsi
callq 0x5b20
leaq -0x200(%rbp), %rdi
callq 0x5b90
leaq -0x220(%rbp), %rdi
callq 0x31c0
leaq -0x221(%rbp), %rdi
callq 0x32e0
jmp 0x4715
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x140(%rbp)
movl %eax, -0x144(%rbp)
jmp 0x46ef
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x140(%rbp)
movl %eax, -0x144(%rbp)
jmp 0x46e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x140(%rbp)
movl %eax, -0x144(%rbp)
leaq -0x200(%rbp), %rdi
callq 0x5b90
leaq -0x220(%rbp), %rdi
callq 0x31c0
leaq -0x221(%rbp), %rdi
callq 0x32e0
jmp 0x4940
leaq -0x120(%rbp), %rsi
leaq 0xfd15(%rip), %rdi      # 0x14423
movb $0x0, %al
callq 0x3050
movl -0x14(%rbp), %edi
movslq -0x124(%rbp), %rcx
leaq 0x1bb52(%rip), %rax     # 0x20278
addq $0x18, %rax
imulq $0x6c, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
movslq -0x124(%rbp), %rdx
leaq 0x1bb37(%rip), %rcx     # 0x20278
addq $0x18, %rcx
imulq $0x6c, %rdx, %rdx
addq %rdx, %rcx
movl 0x64(%rcx), %edx
addl $0x8000, %edx           # imm = 0x8000
leaq -0x120(%rbp), %rcx
movslq -0x124(%rbp), %r8
leaq 0x1bb0e(%rip), %rsi     # 0x20278
addq $0x18, %rsi
imulq $0x6c, %r8, %r8
addq %r8, %rsi
movl 0x68(%rsi), %r8d
movzwl %ax, %esi
callq 0x38d0
cmpl $0x0, %eax
je 0x4792
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4934
movslq -0x124(%rbp), %rcx
leaq 0x1bad8(%rip), %rax     # 0x20278
addq $0x18, %rax
imulq $0x6c, %rcx, %rcx
addq %rcx, %rax
movl 0x68(%rax), %eax
movb $0x0, -0x120(%rbp,%rax)
movq -0x10(%rbp), %rdi
callq 0x55f0
testb $0x1, %al
jne 0x48f5
leaq -0x259(%rbp), %rdi
movq %rdi, -0x2f8(%rbp)
callq 0x3460
movq -0x2f8(%rbp), %rdx
leaq -0x258(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x3340
jmp 0x47f6
leaq -0x238(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x5bd0
jmp 0x480b
movq -0x10(%rbp), %rdi
leaq 0xfb8f(%rip), %rsi      # 0x143a5
callq 0x5650
movq %rax, -0x300(%rbp)
jmp 0x4824
movq -0x300(%rbp), %rdi
movslq -0x128(%rbp), %rsi
callq 0x5890
movq %rax, -0x308(%rbp)
jmp 0x4840
movq -0x308(%rbp), %rdi
leaq 0xfbe2(%rip), %rsi      # 0x14430
callq 0x5650
movq %rax, -0x310(%rbp)
jmp 0x485c
movq -0x310(%rbp), %rdi
leaq -0x238(%rbp), %rsi
callq 0x5b20
leaq -0x238(%rbp), %rdi
callq 0x5b90
leaq -0x258(%rbp), %rdi
callq 0x31c0
leaq -0x259(%rbp), %rdi
callq 0x32e0
jmp 0x490a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x140(%rbp)
movl %eax, -0x144(%rbp)
jmp 0x48e7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x140(%rbp)
movl %eax, -0x144(%rbp)
jmp 0x48db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x140(%rbp)
movl %eax, -0x144(%rbp)
leaq -0x238(%rbp), %rdi
callq 0x5b90
leaq -0x258(%rbp), %rdi
callq 0x31c0
leaq -0x259(%rbp), %rdi
callq 0x32e0
jmp 0x4940
leaq -0x120(%rbp), %rsi
leaq 0xfb3b(%rip), %rdi      # 0x1443e
movb $0x0, %al
callq 0x3050
movl -0x128(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x128(%rbp)
movl -0x124(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x124(%rbp)
jmp 0x3e16
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x310, %rsp            # imm = 0x310
popq %rbp
retq
movq -0x140(%rbp), %rdi
callq 0x3450
nopl (%rax)