// File: /workspace/github_cpp_makefile_star2_O1/mattdibi[P]Programmatore-JTAG-per-Xilinx/svftoserial.cpp
// Function: GenerateBITSTREAMOutput(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>)
vector<string> GenerateBITSTREAMOutput(vector<string> bitstream)
{
	vector<string> decBitstream;
	int indexRow, indexCol, initialCol;
	bool found = false;

	// Ignoriamo tutti i bit della SMASK
	indexRow  = bitstream.size() - 1;

	// Ciclo di ignore fino al carattere ')' che segnala la fine della SMASK
	while(indexRow >= 0 && found == false)
	{
		indexCol = bitstream[indexRow].length();

		while(indexCol >= 0 && found == false)
		{
			if(bitstream[indexRow][indexCol] == ')')
				found = true;

			indexCol--;
		}

		indexRow--;
	}

	indexRow++;

	// Il bitstream va inserito al contrario: dall'ultima riga alla prima
	for(int i = indexRow; i >= 0; i--)
	{
		string str = "";

		// Se è la prima riga dell'istruzione inseriamo la parte iniziale comune a tutte le istruzioni SDR
		// e partiamo con la copia dell'istruzione cominciando dalla posizione della ')'
		if(i == indexRow)
		{
			str += "!*";
			initialCol = indexCol;
		}
		else
		{
			// Se non è la prima riga partiamo dall'ultimo carattere della stringa
			initialCol = bitstream[i].length()-1;
		}

		for (int k = initialCol; k >= 0; k--)
		{
			if(i == 0 && k == 0)
			{
				string binval = hexCharToBin(bitstream[i][k]);

				for (i=binval.length()-1; i>0; i--)
				{
					if (binval[i]=='0') 
						str += ".";
					else if(binval[i]=='1') 
						str += ",";
				}

				if (binval[i]=='0') 
					str += ":";
				else if (binval[i]=='1') 
					str += ";";

				continue;
			}

			if(bitstream[i][k] != '\n' && bitstream[i][k] != '\r')
				str += bitstream[i][k];
		}

		// Se è l'ultima riga immetto la parte finale comune a tutte le istruzioni SDR
		if(i == 0)
			str+= "!*";

		decBitstream.push_back(str);
	}

	return decBitstream;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq %rdi, -0x30(%rbp)
movq $0x0, 0x10(%rdi)
movq (%rsi), %rax
movq %rsi, -0x38(%rbp)
movq 0x8(%rsi), %rbx
subq %rax, %rbx
shrq $0x5, %rbx
movl %ebx, %ecx
decl %ecx
js 0x6a14
movl %ecx, %esi
xorl %ecx, %ecx
movl $0x1, %edx
movq %rsi, %rbx
shlq $0x5, %rsi
movl 0x8(%rax,%rsi), %r15d
testl %r15d, %r15d
js 0x6a01
movl %ecx, %edi
andb $0x1, %dil
jne 0x6a01
addq %rax, %rsi
movq (%rsi), %rsi
movl %r15d, %edi
movl %r15d, %r8d
cmpb $0x29, (%rsi,%r8)
movzbl %cl, %ecx
cmovel %edx, %ecx
leal -0x1(%rdi), %r15d
testl %edi, %edi
jle 0x6a01
movl %ecx, %edi
andb $0x1, %dil
je 0x69e0
testq %rbx, %rbx
jle 0x6a14
leaq -0x1(%rbx), %rsi
movl %ecx, %edi
andb $0x1, %dil
je 0x69c1
jmp 0x6a14
testl %ebx, %ebx
js 0x6bbb
leaq -0x78(%rbp), %r12
leaq 0xd7b(%rip), %r13       # 0x77a2
movl %ebx, %r14d
movq %rbx, -0x80(%rbp)
leaq -0x68(%rbp), %rax
movq %rax, -0x78(%rbp)
movq %r12, %rdi
leaq 0x63f(%rip), %rdx       # 0x707f
movq %rdx, %rsi
callq 0x51c0
cmpl %ebx, %r14d
jne 0x6a61
movq %r12, %rdi
leaq 0xd5d(%rip), %rsi       # 0x77b4
callq 0x3420
movl %r15d, %eax
jmp 0x6a75
movl %r14d, %eax
movq -0x38(%rbp), %rcx
movq (%rcx), %rcx
shlq $0x5, %rax
movl 0x8(%rcx,%rax), %eax
decl %eax
testl %eax, %eax
js 0x6b6e
movl %eax, %ebx
movl %ebx, %eax
orl %r14d, %eax
je 0x6abe
movslq %r14d, %rax
movq -0x38(%rbp), %rcx
movq (%rcx), %rcx
shlq $0x5, %rax
movq (%rcx,%rax), %rax
movzbl (%rax,%rbx), %eax
cmpl $0xa, %eax
je 0x6b5e
cmpl $0xd, %eax
je 0x6b5e
movsbl %al, %esi
movq %r12, %rdi
callq 0x31f0
jmp 0x6b5e
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
movsbl (%rax), %esi
leaq -0x58(%rbp), %rdi
callq 0x675a
movl -0x50(%rbp), %r14d
decl %r14d
testl %r14d, %r14d
jle 0x6b18
movl %r14d, %r14d
incq %r14
movq -0x58(%rbp), %rax
movzbl -0x1(%rax,%r14), %eax
movq %r13, %rsi
cmpl $0x31, %eax
je 0x6b04
cmpl $0x30, %eax
jne 0x6b0c
leaq 0xa59(%rip), %rsi       # 0x755d
movq %r12, %rdi
callq 0x3420
decq %r14
cmpq $0x1, %r14
jg 0x6ae6
decl %r14d
movslq %r14d, %rax
movq -0x58(%rbp), %rcx
movzbl (%rcx,%rax), %eax
cmpl $0x31, %eax
je 0x6b36
leaq 0x605(%rip), %rsi       # 0x7134
cmpl $0x30, %eax
je 0x6b3d
jmp 0x6b45
leaq 0xc7e(%rip), %rsi       # 0x77bb
movq %r12, %rdi
callq 0x3420
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x6b5e
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x3250
leaq -0x1(%rbx), %rax
testq %rbx, %rbx
movq %rax, %rbx
jg 0x6a7f
testl %r14d, %r14d
movq -0x80(%rbp), %rbx
jne 0x6b86
movq %r12, %rdi
leaq 0xc33(%rip), %rsi       # 0x77b4
callq 0x3420
movq -0x30(%rbp), %rdi
movq %r12, %rsi
callq 0x50da
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x6bab
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x3250
leal -0x1(%r14), %eax
testl %r14d, %r14d
movl %eax, %r14d
jg 0x6a2e
movq -0x30(%rbp), %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
jmp 0x6c13
jmp 0x6bd9
jmp 0x6bd9
jmp 0x6bde
movq %rax, %r14
jmp 0x6bfa
movq %rax, %r14
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x6bfa
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x6c13
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x3250
movq -0x30(%rbp), %rdi
callq 0x4fce
movq %r14, %rdi
callq 0x33e0