// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movl %esi, %ebp
movq %rdi, %r14
leaq 0xa783(%rip), %r12      # 0xe218
leaq 0xa0(%rsp), %r9
leaq 0x20(%rsp), %r13
xorl %ebx, %ebx
xorl %ecx, %ecx
cmpq $0x288, %rbx            # imm = 0x288
je 0x3f8d
movl 0x18(%rbx,%r12), %eax
testl %eax, %eax
je 0x3f7f
cmpl $0x0, 0x1c(%rbx,%r12)
movslq %ecx, %rdx
movq %rdx, 0x10(%rsp)
je 0x3b95
movl %ecx, 0x1c(%rsp)
movl 0x5c(%rbx,%r12), %edx
movl $0x8000, %ecx           # imm = 0x8000
addl %ecx, %edx
movl 0x60(%rbx,%r12), %r8d
movzwl %ax, %esi
movl %ebp, %edi
movq %r9, %rcx
callq 0x36fd
testl %eax, %eax
jne 0x3f88
movl 0x60(%rbx,%r12), %eax
movb $0x0, 0xa0(%rsp,%rax)
cmpb $0x0, (%r14)
je 0x3c05
movq %r13, %rdi
leaq 0xa0(%rsp), %rsi
leaq 0xf(%rsp), %rdx
callq 0x30e0
leaq 0x80(%rsp), %rdi
movq %r13, %rsi
callq 0x4b22
movq %r14, %rdi
leaq 0x45ba(%rip), %rsi      # 0x80fe
callq 0x484a
movq %rax, %rdi
movq 0x10(%rsp), %rsi
callq 0x496c
movq %rax, %rdi
leaq 0x45a3(%rip), %rsi      # 0x8103
callq 0x484a
movq %rax, %rdi
leaq 0x80(%rsp), %r15
movq %r15, %rsi
callq 0x4ac0
movq %r15, %rdi
callq 0x4b00
movq %r13, %rdi
callq 0x3110
leaq 0xa0(%rsp), %r13
jmp 0x3c23
cmpb $0x0, (%r14)
je 0x3bfe
movq %r12, %r13
movl %ebp, %r12d
movl %ecx, %ebp
leaq 0x90(%rsp), %rdi
xorl %esi, %esi
callq 0x482e
movq %r14, %rdi
leaq 0x4542(%rip), %rsi      # 0x80fe
callq 0x484a
movq %rax, %rdi
movq 0x10(%rsp), %rsi
callq 0x496c
movq %rax, %rdi
leaq 0x90(%rsp), %r15
movq %r15, %rsi
callq 0x4ac0
movq %r15, %rdi
callq 0x4b00
leaq 0xa0(%rsp), %r9
movl %ebp, %ecx
movl %r12d, %ebp
movq %r13, %r12
leaq 0x20(%rsp), %r13
incl %ecx
jmp 0x3f7f
movl 0x18(%rbx,%r12), %esi
leaq 0x44ff(%rip), %rdi      # 0x8110
leaq 0xa0(%rsp), %r13
movq %r13, %rdx
xorl %eax, %eax
callq 0x3040
movzwl 0x18(%rbx,%r12), %esi
movl 0x64(%rbx,%r12), %edx
movl $0x8000, %eax           # imm = 0x8000
addl %eax, %edx
movl 0x68(%rbx,%r12), %r8d
movl %ebp, %edi
movq %r13, %rcx
callq 0x36fd
testl %eax, %eax
jne 0x3f88
movl 0x68(%rbx,%r12), %eax
movb $0x0, 0xa0(%rsp,%rax)
cmpb $0x0, (%r14)
je 0x3cdb
leaq 0x20(%rsp), %r13
movq %r13, %rdi
leaq 0xa0(%rsp), %rsi
leaq 0xf(%rsp), %rdx
callq 0x30e0
leaq 0x70(%rsp), %rdi
movq %r13, %rsi
callq 0x4b22
movq %r14, %rdi
leaq 0x446e(%rip), %rsi      # 0x80fe
callq 0x484a
movq %rax, %rdi
movq 0x10(%rsp), %rsi
callq 0x496c
movq %rax, %rdi
leaq 0x4480(%rip), %rsi      # 0x812c
callq 0x484a
movq %rax, %rdi
leaq 0x70(%rsp), %r15
movq %r15, %rsi
callq 0x4ac0
movq %r15, %rdi
callq 0x4b00
movq %r13, %rdi
callq 0x3110
leaq 0xa0(%rsp), %r13
jmp 0x3cf4
leaq 0x4457(%rip), %rdi      # 0x8139
leaq 0xa0(%rsp), %r13
movq %r13, %rsi
xorl %eax, %eax
callq 0x3040
movzwl 0x18(%rbx,%r12), %esi
movl 0x6c(%rbx,%r12), %edx
movl $0x8000, %eax           # imm = 0x8000
addl %eax, %edx
movl 0x70(%rbx,%r12), %r8d
movl %ebp, %edi
movq %r13, %rcx
callq 0x36fd
testl %eax, %eax
jne 0x3f88
movl 0x70(%rbx,%r12), %eax
movb $0x0, 0xa0(%rsp,%rax)
cmpb $0x0, (%r14)
je 0x3dac
leaq 0x20(%rsp), %r13
movq %r13, %rdi
leaq 0xa0(%rsp), %rsi
leaq 0xf(%rsp), %rdx
callq 0x30e0
leaq 0x60(%rsp), %rdi
movq %r13, %rsi
callq 0x4b22
movq %r14, %rdi
leaq 0x439d(%rip), %rsi      # 0x80fe
callq 0x484a
movq %rax, %rdi
movq 0x10(%rsp), %rsi
callq 0x496c
movq %rax, %rdi
leaq 0x43ce(%rip), %rsi      # 0x814b
callq 0x484a
movq %rax, %rdi
leaq 0x60(%rsp), %r15
movq %r15, %rsi
callq 0x4ac0
movq %r15, %rdi
callq 0x4b00
movq %r13, %rdi
callq 0x3110
leaq 0xa0(%rsp), %r13
jmp 0x3dc5
leaq 0x43a6(%rip), %rdi      # 0x8159
leaq 0xa0(%rsp), %r13
movq %r13, %rsi
xorl %eax, %eax
callq 0x3040
movzwl 0x18(%rbx,%r12), %esi
movl 0x74(%rbx,%r12), %edx
movl $0x8000, %eax           # imm = 0x8000
addl %eax, %edx
movl 0x78(%rbx,%r12), %r8d
movl %ebp, %edi
movq %r13, %rcx
callq 0x36fd
testl %eax, %eax
jne 0x3f88
movl 0x78(%rbx,%r12), %eax
movb $0x0, 0xa0(%rsp,%rax)
cmpb $0x0, (%r14)
je 0x3e87
leaq 0x20(%rsp), %r13
movq %r13, %rdi
leaq 0xa0(%rsp), %rsi
leaq 0xf(%rsp), %rdx
callq 0x30e0
leaq 0x50(%rsp), %rdi
movq %r13, %rsi
callq 0x4b22
movl %ebp, %r15d
movq %r14, %rdi
leaq 0x42c5(%rip), %rsi      # 0x80fe
callq 0x484a
movq %rax, %rdi
movq 0x10(%rsp), %rsi
callq 0x496c
movq %rax, %rdi
leaq 0x4317(%rip), %rsi      # 0x816c
callq 0x484a
movq %rax, %rdi
leaq 0x50(%rsp), %rbp
movq %rbp, %rsi
callq 0x4ac0
movq %rbp, %rdi
callq 0x4b00
movq %r13, %rdi
callq 0x3110
leaq 0xa0(%rsp), %r13
movl %r15d, %ebp
jmp 0x3ea0
leaq 0x42ee(%rip), %rdi      # 0x817c
leaq 0xa0(%rsp), %r13
movq %r13, %rsi
xorl %eax, %eax
callq 0x3040
movzwl 0x18(%rbx,%r12), %esi
movl 0x7c(%rbx,%r12), %edx
movl $0x8000, %eax           # imm = 0x8000
addl %eax, %edx
movl 0x80(%rbx,%r12), %r8d
movl %ebp, %edi
movq %r13, %rcx
callq 0x36fd
testl %eax, %eax
jne 0x3f88
movl 0x80(%rbx,%r12), %eax
movb $0x0, 0xa0(%rsp,%rax)
cmpb $0x0, (%r14)
je 0x3f56
leaq 0x20(%rsp), %r13
movq %r13, %rdi
leaq 0xa0(%rsp), %rsi
leaq 0xf(%rsp), %rdx
callq 0x30e0
leaq 0x40(%rsp), %rdi
movq %r13, %rsi
callq 0x4b22
movq %r14, %rdi
leaq 0x41eb(%rip), %rsi      # 0x80fe
callq 0x484a
movq %rax, %rdi
movq 0x10(%rsp), %rsi
callq 0x496c
movq %rax, %rdi
leaq 0x425a(%rip), %rsi      # 0x8189
callq 0x484a
movq %rax, %rdi
leaq 0x40(%rsp), %r15
movq %r15, %rsi
callq 0x4ac0
movq %r15, %rdi
callq 0x4b00
movq %r13, %rdi
callq 0x3110
jmp 0x3f71
leaq 0x423a(%rip), %rdi      # 0x8197
leaq 0xa0(%rsp), %rsi
xorl %eax, %eax
callq 0x3040
leaq 0x20(%rsp), %r13
movl 0x1c(%rsp), %ecx
incl %ecx
leaq 0xa0(%rsp), %r9
addq $0x6c, %rbx
jmp 0x3aa6
pushq $-0x1
popq %rax
jmp 0x3f8f
xorl %eax, %eax
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3fb6
jmp 0x3fb1
jmp 0x3fb1
jmp 0x3fb6
jmp 0x3fb1
jmp 0x3fb6
jmp 0x3fb1
jmp 0x3fb6
movq %rax, %rbx
jmp 0x4005
movq %rax, %rbx
jmp 0x400f
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x4b00
jmp 0x400f
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
jmp 0x4000
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
jmp 0x4000
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
jmp 0x4000
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
jmp 0x4000
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x4b00
leaq 0x20(%rsp), %rdi
callq 0x3110
movq %rbx, %rdi
callq 0x33b0