// File: /workspace/github_cpp_makefile_star2_O1/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, %r12
leaq 0x210(%rsp), %rbx
movq %rbx, %rdi
movl $0x8, %edx
callq 0x2280
movq (%rbx), %rax
movq -0x18(%rax), %rcx
testb $0x5, 0x230(%rsp,%rcx)
je 0x360e
movq 0xca31(%rip), %rbx      # 0xfff0
leaq 0x8c79(%rip), %rsi      # 0xc23f
movl $0x21, %edx
movq %rbx, %rdi
callq 0x21c0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq 0xc9ff(%rip), %rdi      # 0xfff0
callq 0x2040
movq %rax, %rdi
callq 0x2100
movb $0x1, 0x8(%r12)
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x3ded
xorl %ecx, %ecx
movb %cl, 0x8(%r12)
movq $-0x1, 0x28(%rsp)
leaq 0x40(%rsp), %rdx
movq %rdx, -0x10(%rdx)
movq $0x0, -0x8(%rdx)
movb %cl, (%rdx)
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %edx
leaq 0x210(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x2310
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
je 0x36b6
movq 0xc984(%rip), %rbx      # 0xfff0
leaq 0x8c0a(%rip), %rsi      # 0xc27d
movl $0x14, %edx
movq %rbx, %rdi
callq 0x21c0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq 0xc952(%rip), %rdi      # 0xfff0
callq 0x2040
movq %rax, %rdi
callq 0x2100
movb $0x1, %r14b
xorl %r15d, %r15d
jmp 0x387d
leaq 0x90(%rsp), %rdi
leaq 0x30(%rsp), %rsi
movl $0x8, %edx
callq 0x22b0
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
movq $0x0, -0x8(%r15)
movb $0x0, (%r15)
movl $0x3, %ebp
leaq 0x90(%rsp), %rbx
leaq 0x8(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x21e0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x3711
decl %ebp
jmp 0x36f4
testl %ebp, %ebp
je 0x376d
movq 0xc8d4(%rip), %rdi      # 0xfff0
leaq 0x8b3e(%rip), %rsi      # 0xc261
movl $0x1b, %edx
callq 0x21c0
movq 0xc8bc(%rip), %rdi      # 0xfff0
movl $0x1, %esi
callq 0x2160
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movb $0x1, %r14b
movq %rax, %rdi
callq 0x2100
jmp 0x3770
xorl %r14d, %r14d
testl %ebp, %ebp
jne 0x383f
movq 0x90(%rsp), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x22c0
leaq 0x90(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x21d0
leaq 0x90(%rsp), %rdi
leaq 0x3(%rsp), %rsi
callq 0x2200
leaq 0x88(%rsp), %rsi
movq %rax, %rdi
callq 0x21a0
leaq 0x28(%rsp), %rsi
movq %rax, %rdi
callq 0x21a0
cmpb $0x74, 0x3(%rsp)
jne 0x37e9
movq $-0x80000000, %rax      # imm = 0x80000000
addq 0x28(%rsp), %rax
cmpq $-0x80000000, %rax      # imm = 0x80000000
ja 0x383f
movq 0xc800(%rip), %rdi      # 0xfff0
leaq 0x8a6a(%rip), %rsi      # 0xc261
movl $0x1b, %edx
callq 0x21c0
movq 0xc7e8(%rip), %rdi      # 0xfff0
movl $0x1, %esi
callq 0x2160
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movb $0x1, %r14b
movq %rax, %rdi
callq 0x2100
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x3856
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2190
movq 0xc763(%rip), %rsi      # 0xffc0
leaq 0x90(%rsp), %rdi
callq 0x2230
leaq 0x108(%rsp), %rdi
callq 0x2090
movl $0x1, %r15d
testb %r14b, %r14b
movq %r12, 0x58(%rsp)
movl %r14d, 0x4(%rsp)
jne 0x3aee
cmpq $0x0, 0x28(%rsp)
leaq 0x210(%rsp), %r12
jle 0x3aee
xorl %ebx, %ebx
leaq 0x90(%rsp), %r13
leaq 0x8(%rsp), %rbp
movq 0x210(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %edx
movq %r12, %rdi
leaq 0x30(%rsp), %rsi
callq 0x2310
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x3aa2
movq %r13, %rdi
leaq 0x30(%rsp), %rsi
movl $0x8, %edx
callq 0x22b0
incq %r15
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movb $0x0, 0x18(%rsp)
movl $0x3, %r12d
movq %r13, %rdi
movq %rbp, %rsi
callq 0x21e0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x393f
decl %r12d
jmp 0x3921
testl %r12d, %r12d
je 0x3987
movl $0x1b, %edx
movq 0xc6a0(%rip), %rdi      # 0xfff0
leaq 0x890a(%rip), %rsi      # 0xc261
callq 0x21c0
movq 0xc68d(%rip), %rdi      # 0xfff0
movq %r15, %rsi
callq 0x2160
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2170
jmp 0x3a31
movq 0x90(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
xorl %esi, %esi
callq 0x22c0
movq %r13, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x21d0
movq %r13, %rdi
leaq 0x3(%rsp), %rsi
callq 0x2200
movq %rax, %rdi
leaq 0x80(%rsp), %rsi
callq 0x21a0
movq %rax, %rdi
leaq 0x78(%rsp), %rsi
callq 0x21a0
cmpb $0x76, 0x3(%rsp)
jne 0x39f3
cmpq %rbx, 0x80(%rsp)
jne 0x39f3
movb $0x1, %r12b
movl $0x80000000, %eax       # imm = 0x80000000
cmpq %rax, 0x78(%rsp)
jl 0x3a4d
movl $0x1b, %edx
movq 0xc5f1(%rip), %rdi      # 0xfff0
leaq 0x885b(%rip), %rsi      # 0xc261
callq 0x21c0
movq 0xc5de(%rip), %rdi      # 0xfff0
movq %r15, %rsi
callq 0x2160
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2100
movb $0x1, %al
movl %eax, 0x4(%rsp)
xorl %r12d, %r12d
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x3a69
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2190
movq %r13, %rdi
movq 0xc54d(%rip), %rsi      # 0xffc0
callq 0x2230
leaq 0x108(%rsp), %rdi
callq 0x2090
testb %r12b, %r12b
je 0x3aee
incq %rbx
cmpq %rbx, 0x28(%rsp)
leaq 0x210(%rsp), %r12
jg 0x38b3
jmp 0x3aee
movq 0xc547(%rip), %rbx      # 0xfff0
leaq 0x87e2(%rip), %rsi      # 0xc292
movl $0x26, %edx
movq %rbx, %rdi
callq 0x21c0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq 0xc515(%rip), %rdi      # 0xfff0
callq 0x2040
movb $0x1, %cl
movl %ecx, 0x4(%rsp)
movq %rax, %rdi
callq 0x2100
testb $0x1, 0x4(%rsp)
jne 0x3d19
leaq 0x18(%rsp), %rbp
movq $0x0, 0x50(%rsp)
leaq 0x90(%rsp), %rbx
leaq 0x8(%rsp), %r12
movq 0x58(%rsp), %r13
movq %rbp, %r14
movq 0x210(%rsp), %rax
movq -0x18(%rax), %rdi
leaq 0x210(%rsp), %rbp
addq %rbp, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %edx
movq %rbp, %rdi
leaq 0x30(%rsp), %rsi
callq 0x2310
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x3d27
movq %rbx, %rdi
leaq 0x30(%rsp), %rsi
movl $0x8, %edx
callq 0x22b0
incq %r15
movq %r14, %rbp
movq %r14, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movb $0x0, 0x18(%rsp)
movl $0x4, %r13d
movq %rbx, %rdi
movq %r12, %rsi
callq 0x21e0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x3bae
decl %r13d
jmp 0x3b90
testl %r13d, %r13d
je 0x3bf6
movl $0x1b, %edx
movq 0xc431(%rip), %rdi      # 0xfff0
leaq 0x869b(%rip), %rsi      # 0xc261
callq 0x21c0
movq 0xc41e(%rip), %rdi      # 0xfff0
movq %r15, %rsi
callq 0x2160
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2170
jmp 0x3cba
movq 0x90(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
xorl %esi, %esi
callq 0x22c0
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x21d0
movq %rbx, %rdi
leaq 0x3(%rsp), %rsi
callq 0x2200
movq %rax, %rdi
leaq 0x70(%rsp), %rsi
callq 0x21a0
movq %rax, %rdi
leaq 0x68(%rsp), %rsi
callq 0x21a0
movq %rax, %rdi
leaq 0x60(%rsp), %rsi
callq 0x21a0
cmpb $0x65, 0x3(%rsp)
jne 0x3c7c
movq 0x28(%rsp), %rax
cmpq %rax, 0x70(%rsp)
jge 0x3c7c
cmpq %rax, 0x68(%rsp)
jge 0x3c7c
movl $0x80000000, %eax       # imm = 0x80000000
cmpq %rax, 0x60(%rsp)
jge 0x3c7c
incq 0x50(%rsp)
movb $0x1, %r13b
jmp 0x3cd6
movl $0x1b, %edx
movq 0xc368(%rip), %rdi      # 0xfff0
leaq 0x85d2(%rip), %rsi      # 0xc261
callq 0x21c0
movq 0xc355(%rip), %rdi      # 0xfff0
movq %r15, %rsi
callq 0x2160
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2100
movb $0x1, %al
movl %eax, 0x4(%rsp)
xorl %r13d, %r13d
movq 0x8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x3ced
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2190
movq %rbx, %rdi
movq 0xc2c9(%rip), %rsi      # 0xffc0
callq 0x2230
leaq 0x108(%rsp), %rdi
callq 0x2090
testb %r13b, %r13b
movq 0x58(%rsp), %r13
jne 0x3b19
jmp 0x3d27
movq $0x0, 0x50(%rsp)
movq 0x58(%rsp), %r13
leaq 0x210(%rsp), %rdi
callq 0x2060
movq 0x50(%rsp), %rbx
movl $0x80000000, %eax       # imm = 0x80000000
cmpq %rax, %rbx
jl 0x3dbe
movq 0xc2a6(%rip), %rdi      # 0xfff0
leaq 0x8568(%rip), %rsi      # 0xc2b9
movl $0x1d, %edx
callq 0x21c0
movq 0xc28e(%rip), %rdi      # 0xfff0
movq %rbx, %rsi
callq 0x2160
movq %rax, %rbx
leaq 0x8563(%rip), %rsi      # 0xc2d7
movl $0x3, %edx
movq %rax, %rdi
callq 0x21c0
movq %rbx, %rdi
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
callq 0x22d0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movb $0x1, %cl
movl %ecx, 0x4(%rsp)
movq %rax, %rdi
callq 0x2100
xorl %ebx, %ebx
testb $0x1, 0x4(%rsp)
je 0x3dd1
movb $0x1, 0x9(%r13)
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x3ded
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2190
leaq 0x210(%rsp), %rdi
callq 0x2070
movl %ebx, %eax
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3e33
jmp 0x3e33
jmp 0x3e24
jmp 0x3e33
movq %rax, %r14
jmp 0x3ea7
jmp 0x3e33
jmp 0x3e33
jmp 0x3e33
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
jne 0x3e5d
jmp 0x3e6a
movq %rax, %r14
jmp 0x3e8b
jmp 0x3e3c
jmp 0x3e50
movq %rax, %r14
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
jne 0x3e5d
jmp 0x3e6a
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x3e6a
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2190
movq 0xc14f(%rip), %rsi      # 0xffc0
leaq 0x90(%rsp), %rdi
callq 0x2230
leaq 0x108(%rsp), %rdi
callq 0x2090
leaq 0x40(%rsp), %rax
movq 0x30(%rsp), %rdi
cmpq %rax, %rdi
je 0x3ea7
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2190
leaq 0x210(%rsp), %rdi
callq 0x2070
movq %r14, %rdi
callq 0x22f0