// File: /workspace/github_cpp_makefile_star2_O1/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, 0x10(%rsp)
movq %rdi, 0x8(%rsp)
leaq 0x28(%rsp), %r13
leaq 0xa711(%rip), %r12      # 0xe208
leaq 0xa0(%rsp), %rbp
xorl %ebx, %ebx
xorl %r15d, %r15d
movl 0x18(%rbx,%r12), %eax
testl %eax, %eax
je 0x4175
cmpl $0x0, 0x1c(%rbx,%r12)
je 0x3c43
movl 0x5c(%rbx,%r12), %edx
movl $0x8000, %ecx           # imm = 0x8000
addl %ecx, %edx
movl 0x60(%rbx,%r12), %r8d
movzwl %ax, %esi
movl 0x10(%rsp), %edi
movq %rbp, %rcx
callq 0x3715
testl %eax, %eax
jne 0x4190
movl $0xffffffff, 0x14(%rsp) # imm = 0xFFFFFFFF
movl 0x60(%rbx,%r12), %eax
movb $0x0, 0xa0(%rsp,%rax)
movq 0x8(%rsp), %rax
cmpb $0x0, (%rax)
movl %r15d, 0x3c(%rsp)
movslq %r15d, %r15
je 0x3cf2
movq %r13, 0x18(%rsp)
movq %rbp, %rdi
callq 0x3110
leaq (%rsp,%rax), %rdx
addq $0xa0, %rdx
leaq 0x18(%rsp), %r13
movq %r13, %rdi
movq %rbp, %rsi
callq 0x4fbe
leaq 0x90(%rsp), %rdi
movq %r13, %rsi
callq 0x4dd2
movq 0x8(%rsp), %rdi
leaq 0x5516(%rip), %rsi      # 0x90ca
callq 0x4a54
movq %rax, %rdi
movq %r15, %rsi
callq 0x4bd6
movq %rax, %rdi
leaq 0x5501(%rip), %rsi      # 0x90cf
callq 0x4a54
movq %rax, %rbp
leaq 0x90(%rsp), %r13
movq %r13, %rdi
callq 0x6efc
movb (%rbp), %al
movb 0x90(%rsp), %cl
movb %cl, (%rbp)
movb %al, 0x90(%rsp)
movq 0x8(%rbp), %rax
movq 0x98(%rsp), %rcx
movq %rcx, 0x8(%rbp)
movq %rax, 0x98(%rsp)
movq %rbp, %rdi
callq 0x6efc
movq %r13, %rdi
callq 0x4db0
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %r13
cmpq %r13, %rdi
je 0x3c36
callq 0x3200
leaq 0xa0(%rsp), %rbp
jmp 0x3d08
movq 0x8(%rsp), %rax
cmpb $0x0, (%rax)
je 0x4172
movq 0x8(%rsp), %r13
movl %r15d, %r14d
movb $0x0, 0x40(%rsp)
movq $0x0, 0x48(%rsp)
leaq 0x40(%rsp), %r15
movq %r15, %rdi
callq 0x6efc
movq %r15, %rdi
callq 0x6efc
movq %r13, %rdi
leaq 0x5444(%rip), %rsi      # 0x90ca
callq 0x4a54
movslq %r14d, %rsi
movq %rax, %rdi
callq 0x4bd6
movq %rax, %r15
leaq 0x40(%rsp), %r13
movq %r13, %rdi
callq 0x6efc
movb (%r15), %al
movb 0x40(%rsp), %cl
movb %cl, (%r15)
movb %al, 0x40(%rsp)
movq 0x8(%r15), %rax
movq 0x48(%rsp), %rcx
movq %rcx, 0x8(%r15)
movq %rax, 0x48(%rsp)
movq %r15, %rdi
callq 0x6efc
movq %r13, %rdi
callq 0x4db0
leaq 0xa52b(%rip), %r12      # 0xe208
leaq 0xa0(%rsp), %rbp
movl %r14d, %r15d
leaq 0x28(%rsp), %r13
jmp 0x4172
movl 0x18(%rbx,%r12), %esi
leaq 0x53de(%rip), %rdi      # 0x90dc
movq %rbp, %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 0x10(%rsp), %edi
movq %rbp, %rcx
callq 0x3715
testl %eax, %eax
jne 0x4198
movl 0x68(%rbx,%r12), %eax
movb $0x0, 0xa0(%rsp,%rax)
movq 0x8(%rsp), %rax
cmpb $0x0, (%rax)
je 0x3e1e
movq %r13, 0x18(%rsp)
movq %rbp, %rdi
callq 0x3110
leaq (%rsp,%rax), %rdx
addq $0xa0, %rdx
leaq 0x18(%rsp), %r13
movq %r13, %rdi
movq %rbp, %rsi
callq 0x4fbe
leaq 0x80(%rsp), %rdi
movq %r13, %rsi
callq 0x4dd2
movq 0x8(%rsp), %rdi
leaq 0x5338(%rip), %rsi      # 0x90ca
callq 0x4a54
movq %rax, %rdi
movq %r15, %rsi
callq 0x4bd6
movq %rax, %rdi
leaq 0x534c(%rip), %rsi      # 0x90f8
callq 0x4a54
movq %rax, %rbp
leaq 0x80(%rsp), %r13
movq %r13, %rdi
callq 0x6efc
movb (%rbp), %al
movb 0x80(%rsp), %cl
movb %cl, (%rbp)
movb %al, 0x80(%rsp)
movq 0x8(%rbp), %rax
movq 0x88(%rsp), %rcx
movq %rcx, 0x8(%rbp)
movq %rax, 0x88(%rsp)
movq %rbp, %rdi
callq 0x6efc
movq %r13, %rdi
callq 0x4db0
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %r13
cmpq %r13, %rdi
je 0x3e14
callq 0x3200
leaq 0xa0(%rsp), %rbp
jmp 0x3e2f
leaq 0x52e0(%rip), %rdi      # 0x9105
movq %rbp, %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 0x10(%rsp), %edi
movq %rbp, %rcx
callq 0x3715
testl %eax, %eax
jne 0x4198
movl 0x70(%rbx,%r12), %eax
movb $0x0, 0xa0(%rsp,%rax)
movq 0x8(%rsp), %rax
cmpb $0x0, (%rax)
je 0x3f33
movq %r13, 0x18(%rsp)
movq %rbp, %rdi
callq 0x3110
leaq (%rsp,%rax), %rdx
addq $0xa0, %rdx
leaq 0x18(%rsp), %r13
movq %r13, %rdi
movq %rbp, %rsi
callq 0x4fbe
leaq 0x70(%rsp), %rdi
movq %r13, %rsi
callq 0x4dd2
movq 0x8(%rsp), %rdi
leaq 0x5214(%rip), %rsi      # 0x90ca
callq 0x4a54
movq %rax, %rdi
movq %r15, %rsi
callq 0x4bd6
movq %rax, %rdi
leaq 0x5247(%rip), %rsi      # 0x9117
callq 0x4a54
movq %rax, %rbp
leaq 0x70(%rsp), %r13
movq %r13, %rdi
callq 0x6efc
movb (%rbp), %al
movb 0x70(%rsp), %cl
movb %cl, (%rbp)
movb %al, 0x70(%rsp)
movq 0x8(%rbp), %rax
movq 0x78(%rsp), %rcx
movq %rcx, 0x8(%rbp)
movq %rax, 0x78(%rsp)
movq %rbp, %rdi
callq 0x6efc
movq %r13, %rdi
callq 0x4db0
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %r13
cmpq %r13, %rdi
je 0x3f29
callq 0x3200
leaq 0xa0(%rsp), %rbp
jmp 0x3f44
leaq 0x51eb(%rip), %rdi      # 0x9125
movq %rbp, %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 0x10(%rsp), %edi
movq %rbp, %rcx
callq 0x3715
testl %eax, %eax
jne 0x4198
movl 0x78(%rbx,%r12), %eax
movb $0x0, 0xa0(%rsp,%rax)
movq 0x8(%rsp), %rax
cmpb $0x0, (%rax)
je 0x4048
movq %r13, 0x18(%rsp)
movq %rbp, %rdi
callq 0x3110
leaq (%rsp,%rax), %rdx
addq $0xa0, %rdx
leaq 0x18(%rsp), %r13
movq %r13, %rdi
movq %rbp, %rsi
callq 0x4fbe
leaq 0x60(%rsp), %rdi
movq %r13, %rsi
callq 0x4dd2
movq 0x8(%rsp), %rdi
leaq 0x50ff(%rip), %rsi      # 0x90ca
callq 0x4a54
movq %rax, %rdi
movq %r15, %rsi
callq 0x4bd6
movq %rax, %rdi
leaq 0x5153(%rip), %rsi      # 0x9138
callq 0x4a54
movq %rax, %rbp
leaq 0x60(%rsp), %r13
movq %r13, %rdi
callq 0x6efc
movb (%rbp), %al
movb 0x60(%rsp), %cl
movb %cl, (%rbp)
movb %al, 0x60(%rsp)
movq 0x8(%rbp), %rax
movq 0x68(%rsp), %rcx
movq %rcx, 0x8(%rbp)
movq %rax, 0x68(%rsp)
movq %rbp, %rdi
callq 0x6efc
movq %r13, %rdi
callq 0x4db0
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %r13
cmpq %r13, %rdi
je 0x403e
callq 0x3200
leaq 0xa0(%rsp), %rbp
jmp 0x4059
leaq 0x50f9(%rip), %rdi      # 0x9148
movq %rbp, %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 0x10(%rsp), %edi
movq %rbp, %rcx
callq 0x3715
testl %eax, %eax
jne 0x4198
movl 0x80(%rbx,%r12), %eax
movb $0x0, 0xa0(%rsp,%rax)
movq 0x8(%rsp), %rax
cmpb $0x0, (%rax)
je 0x415c
movq %r13, %r14
movq %r13, 0x18(%rsp)
movq %rbp, %rdi
callq 0x3110
leaq (%rsp,%rax), %rdx
addq $0xa0, %rdx
leaq 0x18(%rsp), %r13
movq %r13, %rdi
movq %rbp, %rsi
callq 0x4fbe
leaq 0x50(%rsp), %rdi
movq %r13, %rsi
callq 0x4dd2
movq 0x8(%rsp), %rdi
leaq 0x4fe1(%rip), %rsi      # 0x90ca
callq 0x4a54
movq %rax, %rdi
movq %r15, %rsi
callq 0x4bd6
movq %rax, %rdi
leaq 0x5052(%rip), %rsi      # 0x9155
callq 0x4a54
movq %rax, %r15
leaq 0x50(%rsp), %r13
movq %r13, %rdi
callq 0x6efc
movb (%r15), %al
movb 0x50(%rsp), %cl
movb %cl, (%r15)
movb %al, 0x50(%rsp)
movq 0x8(%r15), %rax
movq 0x58(%rsp), %rcx
movq %rcx, 0x8(%r15)
movq %rax, 0x58(%rsp)
movq %r15, %rdi
callq 0x6efc
movq %r13, %rdi
callq 0x4db0
movq 0x18(%rsp), %rdi
movq %r14, %r13
cmpq %r14, %rdi
je 0x416d
callq 0x3200
jmp 0x416d
leaq 0x5000(%rip), %rdi      # 0x9163
movq %rbp, %rsi
xorl %eax, %eax
callq 0x3040
movl 0x3c(%rsp), %r15d
incl %r15d
addq $0x6c, %rbx
cmpq $0x288, %rbx            # imm = 0x288
jne 0x3b04
movl $0x0, 0x14(%rsp)
jmp 0x4198
movl $0xffffffff, 0x14(%rsp) # imm = 0xFFFFFFFF
movl 0x14(%rsp), %eax
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x41be
jmp 0x41c3
jmp 0x41be
jmp 0x41c3
jmp 0x41be
jmp 0x41c3
jmp 0x41be
jmp 0x41c3
movq %rax, %rbx
jmp 0x4212
movq %rax, %rbx
jmp 0x4226
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x4db0
jmp 0x4226
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
jmp 0x420d
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
jmp 0x420d
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
jmp 0x420d
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
jmp 0x420d
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x4db0
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x4226
callq 0x3200
movq %rbx, %rdi
callq 0x3390