// File: /workspace/github_cpp_makefile_star2_O3/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, %r14
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 0x35fd
movq 0xca41(%rip), %rbx      # 0xfff0
leaq 0x8c89(%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 0xca0f(%rip), %rdi      # 0xfff0
callq 0x2040
movq %rax, %rdi
callq 0x2100
movb $0x1, 0x8(%r14)
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x3b3a
xorl %ecx, %ecx
movq %r14, 0x58(%rsp)
movb %cl, 0x8(%r14)
movq $-0x1, 0x30(%rsp)
leaq 0x48(%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 0x38(%rsp), %rsi
callq 0x2310
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
je 0x36a3
movq 0xc991(%rip), %rbx      # 0xfff0
leaq 0x8c17(%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 0xc95f(%rip), %rdi      # 0xfff0
callq 0x2040
movq %rax, %rdi
callq 0x2100
jmp 0x3a71
leaq 0x90(%rsp), %rdi
leaq 0x38(%rsp), %rsi
movl $0x8, %edx
callq 0x22b0
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movl $0x3, %ebp
leaq 0x90(%rsp), %rbx
leaq 0x10(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x21e0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x36fd
decl %ebp
jmp 0x36e0
testl %ebp, %ebp
je 0x3746
movq 0xc8e8(%rip), %rdi      # 0xfff0
leaq 0x8b52(%rip), %rsi      # 0xc261
movl $0x1b, %edx
callq 0x21c0
movq 0xc8d0(%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
jmp 0x37f9
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 0xf(%rsp), %rsi
callq 0x2200
leaq 0x88(%rsp), %rsi
movq %rax, %rdi
callq 0x21a0
leaq 0x30(%rsp), %rsi
movq %rax, %rdi
callq 0x21a0
cmpb $0x74, 0xf(%rsp)
jne 0x37b9
movq $-0x80000000, %rax      # imm = 0x80000000
addq 0x30(%rsp), %rax
movb $0x1, %bl
cmpq $-0x80000000, %rax      # imm = 0x80000000
ja 0x380e
movq 0xc830(%rip), %rdi      # 0xfff0
leaq 0x8a9a(%rip), %rsi      # 0xc261
movl $0x1b, %edx
callq 0x21c0
movq 0xc818(%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
movq %rax, %rdi
callq 0x2100
xorl %ebx, %ebx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x382a
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2190
movq 0xc78f(%rip), %rsi      # 0xffc0
leaq 0x90(%rsp), %r15
movq %r15, %rdi
callq 0x2230
leaq 0x108(%rsp), %rdi
callq 0x2090
testb %bl, %bl
je 0x3a71
cmpq $0x0, 0x30(%rsp)
jle 0x3b5b
movb $0x1, 0xe(%rsp)
movl $0x1, %r12d
xorl %ebp, %ebp
leaq 0x10(%rsp), %r14
xorl %ebx, %ebx
movq 0x210(%rsp), %rax
movq -0x18(%rax), %rdi
leaq 0x210(%rsp), %r13
addq %r13, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %edx
movq %r13, %rdi
leaq 0x38(%rsp), %rsi
callq 0x2310
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x3d69
movq %r15, %rdi
leaq 0x38(%rsp), %rsi
movl $0x8, %edx
callq 0x22b0
incq %r12
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movb $0x0, 0x20(%rsp)
movl $0x3, %r13d
movq %r15, %rdi
movq %r14, %rsi
callq 0x21e0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x390a
decl %r13d
jmp 0x38ec
testl %r13d, %r13d
je 0x3952
movl $0x1b, %edx
movq 0xc6d5(%rip), %rdi      # 0xfff0
leaq 0x893f(%rip), %rsi      # 0xc261
callq 0x21c0
movq 0xc6c2(%rip), %rdi      # 0xfff0
movq %r12, %rsi
callq 0x2160
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2170
jmp 0x39fc
movq 0x90(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
xorl %esi, %esi
callq 0x22c0
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x21d0
movq %r15, %rdi
leaq 0xf(%rsp), %rsi
callq 0x2200
movq %rax, %rdi
leaq 0x80(%rsp), %rsi
callq 0x21a0
movq %rax, %rdi
leaq 0x78(%rsp), %rsi
callq 0x21a0
cmpb $0x76, 0xf(%rsp)
jne 0x39be
cmpq %rbp, 0x80(%rsp)
jne 0x39be
movb $0x1, %r13b
movl $0x80000000, %eax       # imm = 0x80000000
cmpq %rax, 0x78(%rsp)
jl 0x3a14
movl $0x1b, %edx
movq 0xc626(%rip), %rdi      # 0xfff0
leaq 0x8890(%rip), %rsi      # 0xc261
callq 0x21c0
movq 0xc613(%rip), %rdi      # 0xfff0
movq %r12, %rsi
callq 0x2160
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %r13, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2100
movb $0x1, %bl
xorl %r13d, %r13d
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x3a30
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2190
movq %r15, %rdi
movq 0xc586(%rip), %rsi      # 0xffc0
callq 0x2230
leaq 0x108(%rsp), %rdi
callq 0x2090
testb %r13b, %r13b
je 0x3a5f
incq %rbp
cmpq %rbp, 0x30(%rsp)
jg 0x3876
testb $0x1, %bl
je 0x3b63
xorl %r13d, %r13d
movb %bl, 0xe(%rsp)
jmp 0x3a79
movb $0x1, 0xe(%rsp)
xorl %r13d, %r13d
leaq 0x210(%rsp), %rdi
callq 0x2060
movl $0x80000000, %eax       # imm = 0x80000000
cmpq %rax, %r13
jl 0x3b07
movq 0xc559(%rip), %rdi      # 0xfff0
leaq 0x881b(%rip), %rsi      # 0xc2b9
movl $0x1d, %edx
callq 0x21c0
movq 0xc541(%rip), %rdi      # 0xfff0
movq %r13, %rsi
callq 0x2160
movq %rax, %rbx
leaq 0x8816(%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
movq %rax, %rdi
callq 0x2100
jmp 0x3b10
xorl %ebx, %ebx
testb $0x1, 0xe(%rsp)
je 0x3b1e
movq 0x58(%rsp), %rax
movb $0x1, 0x9(%rax)
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x3b3a
movq 0x48(%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
movl $0x1, %r12d
xorl %ebx, %ebx
xorl %r13d, %r13d
leaq 0x38(%rsp), %rbp
leaq 0x10(%rsp), %r14
movb %bl, 0xe(%rsp)
movq 0x210(%rsp), %rax
movq -0x18(%rax), %rdi
leaq 0x210(%rsp), %rbx
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %edx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x2310
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x3a79
movq %r15, %rdi
movq %rbp, %rsi
movl $0x8, %edx
callq 0x22b0
incq %r12
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movb $0x0, 0x20(%rsp)
movl $0x4, %ebx
movq %r15, %rdi
movq %r14, %rsi
callq 0x21e0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x3c02
decl %ebx
jmp 0x3be5
testl %ebx, %ebx
je 0x3c49
movl $0x1b, %edx
movq 0xc3de(%rip), %rdi      # 0xfff0
leaq 0x8648(%rip), %rsi      # 0xc261
callq 0x21c0
movq 0xc3cb(%rip), %rdi      # 0xfff0
movq %r12, %rsi
callq 0x2160
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
jmp 0x3d0a
movq 0x90(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
xorl %esi, %esi
callq 0x22c0
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x21d0
movq %r15, %rdi
leaq 0xf(%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, 0xf(%rsp)
jne 0x3ccc
movq 0x30(%rsp), %rax
cmpq %rax, 0x70(%rsp)
jge 0x3ccc
cmpq %rax, 0x68(%rsp)
jge 0x3ccc
movl $0x80000000, %eax       # imm = 0x80000000
cmpq %rax, 0x60(%rsp)
jge 0x3ccc
incq %r13
movb $0x1, %bl
jmp 0x3d24
movl $0x1b, %edx
movq 0xc318(%rip), %rdi      # 0xfff0
leaq 0x8582(%rip), %rsi      # 0xc261
callq 0x21c0
movq 0xc305(%rip), %rdi      # 0xfff0
movq %r12, %rsi
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
movq %rax, %rdi
callq 0x2100
movb $0x1, 0xe(%rsp)
xorl %ebx, %ebx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x3d40
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2190
movq %r15, %rdi
movq 0xc276(%rip), %rsi      # 0xffc0
callq 0x2230
leaq 0x108(%rsp), %rdi
callq 0x2090
testb %bl, %bl
jne 0x3b74
jmp 0x3a79
movq 0xc280(%rip), %rbx      # 0xfff0
leaq 0x851b(%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 0xc24e(%rip), %rdi      # 0xfff0
callq 0x2040
movq %rax, %rdi
callq 0x2100
jmp 0x3a76
jmp 0x3dc9
jmp 0x3dc9
jmp 0x3dc9
jmp 0x3dc9
jmp 0x3dd4
jmp 0x3dc9
jmp 0x3dc9
movq %rax, %rbx
jmp 0x3e30
jmp 0x3dd4
movq %rax, %rbx
jmp 0x3e14
jmp 0x3dd4
jmp 0x3dd4
jmp 0x3dd4
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x3df3
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2190
movq 0xc1c6(%rip), %rsi      # 0xffc0
leaq 0x90(%rsp), %rdi
callq 0x2230
leaq 0x108(%rsp), %rdi
callq 0x2090
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x3e30
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x2190
leaq 0x210(%rsp), %rdi
callq 0x2070
movq %rbx, %rdi
callq 0x22f0
nop