// File: /workspace/github_cpp_makefile_star2_O2/SNUCSE-CTA[P]GI/src/graph.cpp
// Function: Graph::checkFormat(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
int32_t Graph::checkFormat(string aFileName)
{
	ifstream infile(aFileName);
	if(infile.fail()) {
		cerr << "Error: input file does not exist." << endl;
		nofile = true;
		return -1;
	}
	else {
		nofile = false;
	}

	char tag;
	int64_t vid, vlabel, left, right, elabel, gid;
	int64_t numNode = -1;
	int64_t numEdge = 0;

	bool flag_error = false; //turns true when file format is wrong

	string line;
	int64_t lineNumber = 0;
	//1. check the first line (t ID #nodes)
	if( getline(infile, line) ) {
		++lineNumber; //add 1 after getline
		istringstream ss(line);	//read values from this stream
		
		//check the number of words
		string oneWord;
		int32_t count = 0;
		while(ss >> oneWord)
			++count;
		if(count != 3) { //line does not consist of exactly 3 values
			cerr << "File Format Error: in line " << lineNumber << endl;
			flag_error = true;
		}

		//check the values
		if(flag_error == false) {
			ss.clear();
			ss.seekg(0);
			ss >> tag >> gid >> numNode;
			if( tag != 't' || numNode < 1 || numNode > INT32_MAX ) {
				cerr << "File Format Error: in line " << lineNumber << endl;
				flag_error = true;
			}
		}
	}
	else { //empty file!
		cerr << "Error: File is empty" << endl;
		flag_error = true;
	}
	
	//2. check the vertices line (v ID label)
	//	 vertex ID should be in the range of [0, #nodes)
	//	 vertices should appear in the increasing order of vertex ID
	if(flag_error == false) {
		for(int32_t i = 0; i < numNode; ++i) {
			if( getline(infile, line) ) {
				++lineNumber; //add 1 after getline
				istringstream ss(line);

				//check the number of words
				string oneWord;
				int32_t count = 0;
				while(ss >> oneWord)
					++count;
				if(count != 3) { //line does not consist of exactly 3 values
					cerr << "File Format Error: in line " << lineNumber << endl;
					flag_error = true;
					break;
				}

				ss.clear();
				ss.seekg(0);
				ss >> tag >> vid >> vlabel;
				if( tag != 'v' || vid != i || vlabel > INT32_MAX ) {
					cerr << "File Format Error: in line " << lineNumber << endl;
					flag_error = true;
					break;
				}
			}
			else {
				cerr << "File Format Error: not enough vertices" << endl;
				flag_error = true;
				break;
			}
		}
	}
	
	//3. check the edges line (e ID ID label)
	if(flag_error == false) {
		while( getline(infile, line) ) {
			++lineNumber; //add 1 after getline
			istringstream ss(line);

			//check the number of words
			string oneWord;
			int32_t count = 0;
			while(ss >> oneWord)
				++count;
			if(count != 4) { //line does not consist of exactly 4 values
				cerr << "File Format Error: in line " << lineNumber << endl;
				flag_error = true;
				break;
			}

			ss.clear();
			ss.seekg(0);
			ss >> tag >> left >> right >> elabel;
			if( tag != 'e' || left >= numNode || right >= numNode || elabel > INT32_MAX) {
				cerr << "File Format Error: in line " << lineNumber << endl;
				flag_error = true;
				break;
			}

			++numEdge;
		}
	}

	infile.close();

	if(numEdge > INT32_MAX) {
		cerr << "File Format Error: #edges == " << numEdge << " > " << INT32_MAX << endl;
		flag_error = true;
	}

	if(flag_error) {
		errfile = true;
		return -1;
	}
	else {
		return 0;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x418, %rsp            # imm = 0x418
movq %rdi, %rbx
leaq 0x210(%rsp), %r14
pushq $0x8
popq %rdx
movq %r14, %rdi
callq 0x2270
movq (%r14), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x230(%rsp,%rax)
je 0x2f45
movq 0xd0cb(%rip), %rdi      # 0xfff0
leaq 0x8313(%rip), %rsi      # 0xb23f
callq 0x2170
movq %rax, %rdi
callq 0x20e0
movb $0x1, 0x8(%rbx)
pushq $-0x1
popq %rbp
jmp 0x30b7
xorl %eax, %eax
movb %al, 0x8(%rbx)
orq $-0x1, 0x18(%rsp)
leaq 0x78(%rsp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x210(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x2050
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
je 0x2fa0
movq 0xd069(%rip), %rdi      # 0xfff0
leaq 0x82ef(%rip), %rsi      # 0xb27d
callq 0x2170
movq %rax, %rdi
callq 0x20e0
jmp 0x3038
leaq 0x90(%rsp), %rdi
leaq 0x68(%rsp), %rsi
pushq $0x8
popq %rdx
callq 0x22a0
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
pushq $0x3
popq %rbp
leaq 0x90(%rsp), %r14
leaq 0x20(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x21d0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2ff3
decl %ebp
jmp 0x2fd6
testl %ebp, %ebp
je 0x30d8
movq 0xcfee(%rip), %rdi      # 0xfff0
leaq 0x8258(%rip), %rsi      # 0xb261
callq 0x2170
pushq $0x1
popq %rsi
movq %rax, %rdi
callq 0x2160
movq %rax, %rdi
callq 0x20e0
leaq 0x20(%rsp), %rdi
callq 0x20c0
leaq 0x90(%rsp), %rdi
callq 0x20d0
movb $0x1, %al
movq %rax, 0x8(%rsp)
xorl %r12d, %r12d
leaq 0x210(%rsp), %rdi
callq 0x2060
movl $0x80000000, %eax       # imm = 0x80000000
cmpq %rax, %r12
jl 0x309d
movq 0xcf90(%rip), %rdi      # 0xfff0
leaq 0x8252(%rip), %rsi      # 0xb2b9
callq 0x2170
movq %rax, %rdi
movq %r12, %rsi
callq 0x2160
leaq 0x8259(%rip), %rsi      # 0xb2d7
movq %rax, %rdi
callq 0x2170
movq %rax, %rdi
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
callq 0x22c0
movq %rax, %rdi
callq 0x20e0
jmp 0x30a6
xorl %ebp, %ebp
testb $0x1, 0x8(%rsp)
je 0x30ad
movb $0x1, 0x9(%rbx)
pushq $-0x1
popq %rbp
leaq 0x68(%rsp), %rdi
callq 0x20c0
leaq 0x210(%rsp), %rdi
callq 0x2070
movl %ebp, %eax
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x90(%rsp), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x22b0
leaq 0x90(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x21c0
leaq 0x90(%rsp), %r14
leaq 0x7(%rsp), %rsi
movq %r14, %rdi
callq 0x21f0
leaq 0x88(%rsp), %rsi
movq %rax, %rdi
callq 0x21a0
leaq 0x18(%rsp), %rsi
movq %rax, %rdi
callq 0x21a0
cmpb $0x74, 0x7(%rsp)
jne 0x2ffb
movq $-0x80000000, %rax      # imm = 0x80000000
addq 0x18(%rsp), %rax
cmpq $-0x7fffffff, %rax      # imm = 0x80000001
jb 0x2ffb
pushq $0x1
popq %rax
movq %rax, 0x10(%rsp)
leaq 0x20(%rsp), %r12
movq %r12, %rdi
callq 0x20c0
movq %r14, %rdi
callq 0x20d0
xorl %r13d, %r13d
leaq 0x68(%rsp), %rbp
movq $0x0, 0x8(%rsp)
cmpq %r13, 0x18(%rsp)
jle 0x32b3
leaq 0x210(%rsp), %rdi
movq %rbp, %rsi
callq 0x2050
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x3415
movq %r14, %rdi
movq %rbp, %r15
movq %rbp, %rsi
pushq $0x8
popq %rdx
callq 0x22a0
leaq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
andq $0x0, 0x28(%rsp)
incq 0x10(%rsp)
movb $0x0, 0x30(%rsp)
pushq $0x3
popq %rbp
movq %r14, %rdi
movq %r12, %rsi
callq 0x21d0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x31fa
decl %ebp
jmp 0x31dd
testl %ebp, %ebp
jne 0x3263
movq 0x90(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
xorl %esi, %esi
callq 0x22b0
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x21c0
movq %r14, %rdi
leaq 0x7(%rsp), %rsi
callq 0x21f0
movq %rax, %rdi
leaq 0x60(%rsp), %rsi
callq 0x21a0
movq %rax, %rdi
leaq 0x58(%rsp), %rsi
callq 0x21a0
cmpb $0x76, 0x7(%rsp)
jne 0x3263
cmpq %r13, 0x60(%rsp)
jne 0x3263
movb $0x1, %bpl
cmpq $0x7fffffff, 0x58(%rsp) # imm = 0x7FFFFFFF
jle 0x3294
movq 0xcd86(%rip), %rdi      # 0xfff0
leaq 0x7ff0(%rip), %rsi      # 0xb261
callq 0x2170
movq %rax, %rdi
movq 0x10(%rsp), %rsi
callq 0x2160
movq %rax, %rdi
callq 0x20e0
movb $0x1, %al
movq %rax, 0x8(%rsp)
xorl %ebp, %ebp
movq %r12, %rdi
callq 0x20c0
movq %r14, %rdi
callq 0x20d0
incq %r13
testb %bpl, %bpl
movq %r15, %rbp
jne 0x3182
testb $0x1, 0x8(%rsp)
jne 0x303f
xorl %r12d, %r12d
leaq 0x68(%rsp), %rbp
leaq 0x20(%rsp), %r13
leaq 0x210(%rsp), %rdi
movq %rbp, %rsi
callq 0x2050
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x3042
movq %r14, %rdi
movq %rbp, %r15
movq %rbp, %rsi
pushq $0x8
popq %rdx
callq 0x22a0
leaq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
andq $0x0, 0x28(%rsp)
incq 0x10(%rsp)
movb $0x0, 0x30(%rsp)
pushq $0x4
popq %rbp
movq %r14, %rdi
movq %r13, %rsi
callq 0x21d0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x3338
decl %ebp
jmp 0x331b
testl %ebp, %ebp
jne 0x33c3
movq 0x90(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
xorl %esi, %esi
callq 0x22b0
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x21c0
movq %r14, %rdi
leaq 0x7(%rsp), %rsi
callq 0x21f0
movq %rax, %rdi
leaq 0x50(%rsp), %rsi
callq 0x21a0
movq %rax, %rdi
leaq 0x48(%rsp), %rsi
callq 0x21a0
movq %rax, %rdi
leaq 0x40(%rsp), %rsi
callq 0x21a0
cmpb $0x65, 0x7(%rsp)
jne 0x33c3
movq 0x18(%rsp), %rax
cmpq %rax, 0x50(%rsp)
jge 0x33c3
cmpq %rax, 0x48(%rsp)
jge 0x33c3
cmpq $0x7fffffff, 0x40(%rsp) # imm = 0x7FFFFFFF
jg 0x33c3
incq %r12
movb $0x1, %bpl
jmp 0x33f4
movq 0xcc26(%rip), %rdi      # 0xfff0
leaq 0x7e90(%rip), %rsi      # 0xb261
callq 0x2170
movq %rax, %rdi
movq 0x10(%rsp), %rsi
callq 0x2160
movq %rax, %rdi
callq 0x20e0
movb $0x1, %al
movq %rax, 0x8(%rsp)
xorl %ebp, %ebp
movq %r13, %rdi
callq 0x20c0
movq %r14, %rdi
callq 0x20d0
testb %bpl, %bpl
movq %r15, %rbp
jne 0x32cb
jmp 0x3042
movq 0xcbd4(%rip), %rdi      # 0xfff0
leaq 0x7e6f(%rip), %rsi      # 0xb292
callq 0x2170
movq %rax, %rdi
callq 0x20e0
jmp 0x3038
jmp 0x344c
jmp 0x344c
jmp 0x344c
jmp 0x344c
jmp 0x344c
jmp 0x344c
jmp 0x3455
jmp 0x3455
movq %rax, %rbx
jmp 0x3479
jmp 0x3455
movq %rax, %rbx
jmp 0x346f
jmp 0x3455
jmp 0x3455
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x20c0
leaq 0x90(%rsp), %rdi
callq 0x20d0
leaq 0x68(%rsp), %rdi
callq 0x20c0
leaq 0x210(%rsp), %rdi
callq 0x2070
movq %rbx, %rdi
callq 0x22e0