// File: /workspace/github_cpp_makefile_star2_O3/luizaes[P]post-machine-simulator/post_machine_sim.cpp
// Function: PostMachineSimulator::BuildDiagram()
DiagramState* PostMachineSimulator::BuildDiagram() {
	string state_name, input_entry, transition, error_text;
	int number_states, number_transitions, output, start_index = 0;
	node node_aux;
	state state_aux;
	bool error_found = false, state_found = false;
	char symbol, current_queue_symbol = NONE;

	/* Read the number of states the Post Machine has */
	cin >> number_states;

	/* Read the name of each of these states, storing them in an adjacency list */
	for (int i = 0; i < number_states; i++) {
		cin >> state_name;
		node_aux.name = state_name;
		flow_diagram.push_back(node_aux);
	}

	/* Read the name of the starting state */
	cin >> start_state;

	/* Read the name of the accepting state - we don't have a rejection state, 
	   the machine halts and rejects an input by indefinition */
	cin >> accept_state;

	/* Read the number of transitions present in the diagram */
	cin >> number_transitions;

	/* Read each transition */
	for(int i = 0; i < number_transitions; i++) {
		cin >> transition;
		state_found = false;

		for (int j = 0; j < number_states; j++) {
			/* If the state specified in the transition exists */
			if(flow_diagram[j].name.compare(transition) == 0) {
				state_found = true;

				/* If the transition starts with a READ state */
				if(transition.front() == 'R' || transition.front() == 'r') {
					cin >> symbol;
					ReadInputLine(transition);

					if(transition.compare(start_state) == 0) {
						string message = "[ERROR] Invalid transition: it's not possible to have a transition pointing to the starting state.";
						DiagramState* response = new DiagramState(/*has_error=*/true, message);
						return response;
					} else if(transition.compare(" " + accept_state) != 0 && (transition.at(1) == 'A' || transition.at(1) == 'a')) {
						current_queue_symbol = transition.substr(transition.length()-1, 1).front();
						transition = transition.substr(1, transition.length()-3);
					} else {
						transition = transition.substr(1, transition.length()-1);
					}

					state_aux.name = transition;
					state_aux.read_symbol = symbol;
					state_aux.add_symbol = current_queue_symbol;
					current_queue_symbol = NONE;
					flow_diagram[j].flows.push_back(state_aux);

				/* If the transition starts with a START state */
				} else if(transition.compare(start_state) == 0) {
					ReadInputLine(transition);

					if(transition.at(1) == 'A' || transition.at(1) == 'a') {
						current_queue_symbol = transition.substr(transition.length()-1, 1).front();
						transition = transition.substr(1, transition.length()-3);
					}

					state_aux.name = transition;
					state_aux.read_symbol = NONE;
					state_aux.add_symbol = current_queue_symbol;
					current_queue_symbol = NONE;
					flow_diagram[j].flows.push_back(state_aux);
				}  else if(transition.compare(accept_state) == 0) {
					string message = "[ERROR] Invalid transition: the accepting state cannot have a transition to any other state.";
					DiagramState* response = new DiagramState(/*has_error=*/true, message);
					return response;
				/* If the transition starts with an ADD state */
				} else if(transition.front() == 'A' || transition.front() == 'a') {
					cin >> symbol;
					ReadInputLine(transition);
					if(transition.compare(" " + start_state) == 0) {
						string message = "[ERROR] Invalid transition: it's not possible to have a transition pointing to the starting state.";
						DiagramState* response = new DiagramState(/*has_error=*/true, message);
						return response;
					} else if(transition.at(1) == 'A' || transition.at(1) == 'a') {
						current_queue_symbol = transition.substr(transition.length()-1, 1).front();
						transition = transition.substr(1, transition.length()-3);
					} else {
						transition = transition.substr(1, transition.length()-1);
					}
					state_aux.name = transition;
					state_aux.read_symbol = NONE;
					state_aux.add_symbol = current_queue_symbol;
					current_queue_symbol = NONE;
					flow_diagram[j].flows.push_back(state_aux);
				}
				break;
			}
		}

		if(!state_found) {
			string message = "[ERROR] Invalid transition: the specified state does not exist.";
			DiagramState* response = new DiagramState(/*has_error=*/true, message);
			return response;
		}
	}
	string message = "";
	DiagramState* response = new DiagramState(/*has_error=*/false, message);
	return response;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movq %rdi, %r14
leaq -0xd8(%rbp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0x118(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0x70(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0xf8(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0x150(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0x140(%rbp), %rcx
movq %rcx, 0x8(%rcx)
movq %rcx, (%rcx)
movq %rax, 0x10(%rcx)
leaq -0xa0(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
movq 0x4321(%rip), %rdi      # 0x6fe0
leaq -0x5c(%rbp), %rsi
callq 0x2100
cmpl $0x0, -0x5c(%rbp)
jle 0x2d10
xorl %r13d, %r13d
movq 0x4308(%rip), %rbx      # 0x6fe0
leaq -0xe8(%rbp), %r15
leaq -0x160(%rbp), %r12
movq %rbx, %rdi
movq %r15, %rsi
callq 0x21d0
movq %r12, %rdi
movq %r15, %rsi
callq 0x20e0
movq %r14, %rdi
movq %r12, %rsi
callq 0x3736
incl %r13d
cmpl -0x5c(%rbp), %r13d
jl 0x2ce6
leaq 0x68(%r14), %rsi
movq 0x42c5(%rip), %rdi      # 0x6fe0
movq %rsi, -0xb8(%rbp)
callq 0x21d0
leaq 0x88(%r14), %rsi
movq 0x42ab(%rip), %rdi      # 0x6fe0
movq %rsi, -0xc0(%rbp)
callq 0x21d0
movq 0x4298(%rip), %rdi      # 0x6fe0
leaq -0x84(%rbp), %rsi
callq 0x2100
cmpl $0x0, -0x84(%rbp)
leaq -0x40(%rbp), %r15
jle 0x3416
xorl %eax, %eax
movq 0x4272(%rip), %rdi      # 0x6fe0
leaq -0x80(%rbp), %rsi
movq %r15, %r13
movq %rax, -0xc8(%rbp)
movq %rsi, %r12
callq 0x21d0
cmpl $0x0, -0x5c(%rbp)
jle 0x32e5
movl $0x20, %ebx
xorl %r15d, %r15d
movq (%r14), %rax
leaq (%rax,%rbx), %rdi
addq $-0x20, %rdi
movq %r12, %rsi
callq 0x2040
testl %eax, %eax
je 0x2dc2
incq %r15
movslq -0x5c(%rbp), %rax
addq $0x38, %rbx
cmpq %rax, %r15
jl 0x2d96
jmp 0x32e5
movq -0x80(%rbp), %rax
movzbl (%rax), %eax
orl $0x20, %eax
cmpl $0x72, %eax
jne 0x2e61
movq 0x4204(%rip), %rdi      # 0x6fe0
leaq -0x29(%rbp), %rsi
callq 0x21e0
movq %r12, %rdi
callq 0x2970
movq %r12, %rdi
movq -0xb8(%rbp), %rsi
callq 0x2040
testl %eax, %eax
je 0x3459
leaq -0x50(%rbp), %rdi
leaq 0x22ec(%rip), %rsi      # 0x50fb
movq -0xc0(%rbp), %rdx
callq 0x376e
movq -0x78(%rbp), %r15
movq -0x48(%rbp), %r13
cmpq %r15, %r13
movq %r15, %rdx
cmovbq %r13, %rdx
testq %rdx, %rdx
je 0x2f21
movq -0x50(%rbp), %rsi
movq %rsi, -0x58(%rbp)
movq -0x80(%rbp), %rdi
callq 0x2190
movq -0x58(%rbp), %rdi
cmpq %r13, %r15
jne 0x2f8a
testl %eax, %eax
je 0x2f2a
jmp 0x2f8a
movq %r12, %rdi
movq -0xb8(%rbp), %rsi
callq 0x2040
movq %r13, %r15
testl %eax, %eax
je 0x30c5
movq %r12, %rdi
movq -0xc0(%rbp), %rsi
callq 0x2040
testl %eax, %eax
je 0x3496
movq -0x80(%rbp), %rax
movzbl (%rax), %eax
orl $0x20, %eax
cmpl $0x61, %eax
movq -0xc8(%rbp), %rax
movq %r12, %rsi
jne 0x30ab
movq 0x412a(%rip), %rdi      # 0x6fe0
leaq -0x29(%rbp), %rsi
callq 0x21e0
movq %r12, %rdi
callq 0x2970
leaq -0x50(%rbp), %rdi
leaq 0x2229(%rip), %rsi      # 0x50fb
movq -0xb8(%rbp), %rdx
callq 0x376e
movq -0x78(%rbp), %r15
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %r13
cmpq %r15, %r13
movq %r15, %rdx
cmovbq %r13, %rdx
testq %rdx, %rdx
je 0x3173
movq -0x80(%rbp), %rdi
movq %rax, %rsi
movq %rax, -0x58(%rbp)
callq 0x2190
testl %eax, %eax
movq -0x58(%rbp), %rax
je 0x3173
xorl %r15d, %r15d
jmp 0x317a
cmpq %r13, %r15
jne 0x2f8a
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %r13
cmpq %r13, %rdi
je 0x2f3f
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2180
movq %r12, %r15
movq -0x78(%rbp), %rcx
decq %rcx
movl $0x1, %edx
leaq -0x50(%rbp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x21a0
movq %r15, %rdi
movq %r13, %rsi
callq 0x21c0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %r15
cmpq %r15, %rdi
je 0x2f81
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2180
movb $0x24, -0x58(%rbp)
jmp 0x305f
cmpq $0x1, %r15
jbe 0x3510
movq -0x80(%rbp), %rax
movb 0x1(%rax), %r13b
cmpb $0x41, %r13b
jne 0x2fc0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %r13
cmpq %r13, %rdi
movq %r12, %r15
je 0x2fe6
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2180
jmp 0x2fe6
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
movq %r12, %r15
je 0x2fdc
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2180
cmpb $0x61, %r13b
jne 0x2f42
movq -0x78(%rbp), %rdx
decq %rdx
movl $0x1, %ecx
leaq -0x50(%rbp), %rdi
movq %r15, %rsi
callq 0x21a0
movq -0x50(%rbp), %rdi
movb (%rdi), %al
movb %al, -0x58(%rbp)
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x301c
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2180
movq -0x78(%rbp), %rcx
addq $-0x3, %rcx
movl $0x1, %edx
leaq -0x50(%rbp), %r15
movq %r15, %rdi
movq %r12, %r13
movq %r12, %rsi
callq 0x21a0
movq %r13, %rdi
movq %r15, %rsi
callq 0x21c0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %r15
cmpq %r15, %rdi
je 0x305f
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2180
leaq -0xb0(%rbp), %rdi
movq %r12, %rsi
callq 0x20e0
movb -0x29(%rbp), %al
movb %al, -0x90(%rbp)
movb -0x58(%rbp), %al
movb %al, -0x8f(%rbp)
addq (%r14), %rbx
movq %rbx, %rdi
leaq -0xb0(%rbp), %rsi
callq 0x3d38
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2050
incq 0x10(%rbx)
movq -0xc8(%rbp), %rax
movq %r12, %rsi
incl %eax
cmpl -0x84(%rbp), %eax
movq 0x3f26(%rip), %rdi      # 0x6fe0
jl 0x2d72
jmp 0x3416
movq %r12, %rdi
callq 0x2970
movq -0x78(%rbp), %rax
cmpq $0x2, %rax
jb 0x3526
movq -0x80(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
orl $0x20, %ecx
cmpl $0x61, %ecx
jne 0x32ae
movq %r12, %rsi
decq %rax
movl $0x1, %ecx
leaq -0x50(%rbp), %rdi
movq %rax, %rdx
callq 0x21a0
movq -0x50(%rbp), %rdi
movb (%rdi), %al
movb %al, -0x58(%rbp)
cmpq %r15, %rdi
je 0x3120
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2180
movq -0x78(%rbp), %rcx
addq $-0x3, %rcx
movl $0x1, %edx
leaq -0x50(%rbp), %r15
movq %r15, %rdi
movq %r12, %r13
movq %r12, %rsi
callq 0x21a0
movq %r13, %rdi
movq %r15, %rsi
callq 0x21c0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %r15
cmpq %r15, %rdi
je 0x3163
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2180
leaq -0xb0(%rbp), %rdi
movb -0x58(%rbp), %r13b
jmp 0x32b8
cmpq %r13, %r15
sete %r15b
leaq -0x40(%rbp), %r13
cmpq %r13, %rax
je 0x3192
movq -0x40(%rbp), %rsi
incq %rsi
movq %rax, %rdi
callq 0x2180
testb %r15b, %r15b
jne 0x34d3
movq -0x78(%rbp), %rax
cmpq $0x1, %rax
jbe 0x3526
movq -0x80(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
orl $0x20, %ecx
cmpl $0x61, %ecx
movq %r12, %r15
jne 0x3236
decq %rax
movl $0x1, %ecx
leaq -0x50(%rbp), %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x21a0
movq -0x50(%rbp), %rdi
movb (%rdi), %al
movb %al, -0x58(%rbp)
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x31f1
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2180
movq -0x78(%rbp), %rcx
addq $-0x3, %rcx
movl $0x1, %edx
leaq -0x50(%rbp), %r15
movq %r15, %rdi
movq %r12, %r13
movq %r12, %rsi
callq 0x21a0
movq %r13, %rdi
movq %r15, %rsi
callq 0x21c0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %r15
cmpq %r15, %rdi
je 0x3278
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2180
jmp 0x3278
decq %rax
movl $0x1, %edx
leaq -0x50(%rbp), %r13
movq %r13, %rdi
movq %r15, %rsi
movq %rax, %rcx
callq 0x21a0
movq %r15, %rdi
movq %r13, %rsi
callq 0x21c0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %r15
cmpq %r15, %rdi
je 0x3274
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2180
movb $0x24, -0x58(%rbp)
leaq -0xb0(%rbp), %rdi
movq %r12, %rsi
callq 0x20e0
movb $0x24, -0x90(%rbp)
movb -0x58(%rbp), %al
movb %al, -0x8f(%rbp)
addq (%r14), %rbx
movq %rbx, %rdi
leaq -0xb0(%rbp), %rsi
callq 0x3d38
jmp 0x3092
movb $0x24, %r13b
leaq -0xb0(%rbp), %rdi
movq %r12, %rsi
callq 0x20e0
movb $0x24, -0x90(%rbp)
movb %r13b, -0x8f(%rbp)
addq (%r14), %rbx
movq %rbx, %rdi
leaq -0xb0(%rbp), %rsi
callq 0x3d38
jmp 0x3092
leaq -0x50(%rbp), %rdi
movq %r13, (%rdi)
leaq 0x1e67(%rip), %rsi      # 0x515a
leaq 0x1e9f(%rip), %rdx      # 0x5199
callq 0x3f1a
movl $0x28, %edi
callq 0x2170
movq %rax, %r14
leaq -0x50(%rbp), %rdx
movq %rax, %rdi
movl $0x1, %esi
callq 0x3fb8
movq -0x50(%rbp), %rdi
cmpq %r13, %rdi
je 0x3332
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2180
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x3354
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x2180
leaq -0x140(%rbp), %rdi
callq 0x291e
movq -0x160(%rbp), %rdi
leaq -0x150(%rbp), %rax
cmpq %rax, %rdi
je 0x3382
movq -0x150(%rbp), %rsi
incq %rsi
callq 0x2180
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
cmpq %rax, %rdi
je 0x33a4
movq -0xf8(%rbp), %rsi
incq %rsi
callq 0x2180
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x33bd
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2180
movq -0x128(%rbp), %rdi
leaq -0x118(%rbp), %rax
cmpq %rax, %rdi
je 0x33df
movq -0x118(%rbp), %rsi
incq %rsi
callq 0x2180
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0x3401
movq -0xd8(%rbp), %rsi
incq %rsi
callq 0x2180
movq %r14, %rax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x50(%rbp), %rdi
movq %r15, (%rdi)
leaq 0x1cd8(%rip), %rdx      # 0x50fc
movq %rdx, %rsi
callq 0x3f1a
movl $0x28, %edi
callq 0x2170
movq %rax, %r14
leaq -0x50(%rbp), %rdx
movq %rax, %rdi
xorl %esi, %esi
callq 0x3fb8
movq -0x50(%rbp), %rdi
cmpq %r15, %rdi
jne 0x3326
jmp 0x3332
leaq -0x50(%rbp), %rdi
movq %r13, (%rdi)
leaq 0x1c31(%rip), %rsi      # 0x5098
leaq 0x1c8c(%rip), %rdx      # 0x50fa
callq 0x3f1a
movl $0x28, %edi
callq 0x2170
movq %rax, %r14
leaq -0x50(%rbp), %rdx
movq %rax, %rdi
movl $0x1, %esi
callq 0x3fb8
jmp 0x331d
leaq -0x50(%rbp), %rdi
movq %r15, (%rdi)
leaq 0x1c59(%rip), %rsi      # 0x50fd
leaq 0x1cae(%rip), %rdx      # 0x5159
callq 0x3f1a
movl $0x28, %edi
callq 0x2170
movq %rax, %r14
leaq -0x50(%rbp), %rdx
movq %rax, %rdi
movl $0x1, %esi
callq 0x3fb8
jmp 0x3447
leaq -0x50(%rbp), %rdi
movq %r13, (%rdi)
leaq 0x1bb7(%rip), %rsi      # 0x5098
leaq 0x1c12(%rip), %rdx      # 0x50fa
callq 0x3f1a
movl $0x28, %edi
callq 0x2170
movq %rax, %r14
leaq -0x50(%rbp), %rdx
movq %rax, %rdi
movl $0x1, %esi
callq 0x3fb8
jmp 0x331d
leaq 0x1cf7(%rip), %rdi      # 0x520e
movl $0x1, %esi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2200
leaq 0x1ce1(%rip), %rdi      # 0x520e
movl $0x1, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2200
jmp 0x3582
jmp 0x3594
jmp 0x35b8
jmp 0x3576
jmp 0x357b
jmp 0x35b8
jmp 0x3582
jmp 0x3594
jmp 0x35b8
jmp 0x35b8
jmp 0x35b8
jmp 0x35b8
jmp 0x35b8
jmp 0x35b8
jmp 0x35b8
jmp 0x35b8
jmp 0x35b8
jmp 0x35b8
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
jne 0x35a0
jmp 0x35bb
jmp 0x35b8
jmp 0x35b8
movq %r15, %r13
jmp 0x3582
movq %r15, %r13
jmp 0x3594
jmp 0x35b8
movq %rax, %rbx
movl $0x28, %esi
movq %r14, %rdi
callq 0x2180
jmp 0x3597
movq %rax, %rbx
movq -0x50(%rbp), %rdi
cmpq %r13, %rdi
je 0x35bb
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2180
jmp 0x35bb
jmp 0x35b8
jmp 0x35b8
jmp 0x35b8
jmp 0x35b8
jmp 0x35b8
movq %rax, %rbx
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x35dd
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x2180
leaq -0x160(%rbp), %rdi
callq 0x3800
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
cmpq %rax, %rdi
je 0x360b
movq -0xf8(%rbp), %rsi
incq %rsi
callq 0x2180
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x3624
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2180
movq -0x128(%rbp), %rdi
leaq -0x118(%rbp), %rax
cmpq %rax, %rdi
je 0x3646
movq -0x118(%rbp), %rsi
incq %rsi
callq 0x2180
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0x3668
movq -0xd8(%rbp), %rsi
incq %rsi
callq 0x2180
movq %rbx, %rdi
callq 0x2250