// File: /workspace/github_cpp_makefile_star2_O2/szmer[P]brill/./src/corpus.cpp
// Function: Corpus::load_file(char const*)
Corpus Corpus::load_file(const char* fname) {
	Corpus corp;
	ifstream corp_file(fname);

	char buff [256];
	while(corp_file.good()) {

		corp_file.getline(buff, 256);
		if(corp_file.gcount() == 256 && buff[255] != '\0')
			throw "load_file: corpus file has a line longer than 256 characters!";

		string corp_file_line(buff);

		// Empty line = a new sentence in the corpus (initialize new sentence vector).
		if(corp_file_line.size() == 0) {
			corp.sentences.push_back( vector<TaggedWord>() );
			continue;
		}
		if(corp.sentences.size() == 0) // (occurs when there is no leading empty line in the file)
			throw "load_file: corpus file has no sentence start marker! (should be an empty line)";

		// ELSE: add new tagged word to the latest sentence vector.
		int tab_ind = corp_file_line.find("\t");
		if(tab_ind == -1 || tab_ind != (int)corp_file_line.rfind("\t"))
			throw "load_file: line in corpus \""+corp_file_line+"\" is improperly formatted!";

		string tag = corp_file_line.substr(tab_ind+1);
		corp.sentences.rbegin()->push_back( TaggedWord(
						corp_file_line.substr(0, tab_ind),
						tag
					) );
	}

	return corp;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3d8, %rsp            # imm = 0x3D8
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
leaq 0x20(%rdi), %rax
andl $0x0, 0x20(%rdi)
andq $0x0, 0x28(%rdi)
movq %rax, 0x30(%rdi)
movq %rax, 0x38(%rdi)
movq %rdi, -0x30(%rbp)
andq $0x0, 0x40(%rdi)
leaq -0x2f8(%rbp), %rdi
pushq $0x8
popq %rdx
callq 0x2300
leaq -0x400(%rbp), %r15
leaq -0xd0(%rbp), %r13
leaq -0x70(%rbp), %r14
leaq 0x5b12(%rip), %r12      # 0x816d
pushq $-0x1
popq %rbx
movq -0x2f8(%rbp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, -0x2d8(%rbp,%rax)
jne 0x27fa
movl $0x100, %edx            # imm = 0x100
leaq -0x2f8(%rbp), %rdi
movq %r15, %rsi
callq 0x2080
cmpq $0x100, -0x2f0(%rbp) # imm = 0x100
jne 0x26a5
cmpb $0x0, -0x301(%rbp)
jne 0x286f
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x4d8c
cmpq $0x0, -0xc8(%rbp)
je 0x27cd
movq -0x30(%rbp), %rcx
movq 0x8(%rcx), %rax
cmpq (%rcx), %rax
je 0x2894
movq %r13, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x2350
movq %rax, %r14
cmpl $-0x1, %r14d
je 0x281c
movq %r13, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x2290
cmpl %eax, %r14d
jne 0x281c
shlq $0x20, %r14
movabsq $0x100000000, %rax      # imm = 0x100000000
leaq (%r14,%rax), %rdx
sarq $0x20, %rdx
leaq -0xb0(%rbp), %rdi
movq %r13, %rsi
movq %rbx, %r12
movq %rbx, %rcx
callq 0x21b0
movq -0x30(%rbp), %rax
movq 0x8(%rax), %r15
sarq $0x20, %r14
leaq -0x90(%rbp), %rdi
movq %r13, %rbx
movq %r13, %rsi
xorl %edx, %edx
movq %r14, %rcx
callq 0x21b0
leaq -0xf0(%rbp), %r13
movq %r13, %rdi
leaq -0xb0(%rbp), %rsi
callq 0x2210
leaq -0x70(%rbp), %r14
movq %r14, %rdi
leaq -0x90(%rbp), %rsi
movq %r13, %rdx
callq 0x4e92
addq $-0x18, %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x5f32
movq %r14, %rdi
callq 0x4efe
movq %r13, %rdi
callq 0x2368
leaq -0x90(%rbp), %rdi
callq 0x2368
leaq -0xb0(%rbp), %rdi
callq 0x2368
leaq -0x400(%rbp), %r15
leaq 0x59ab(%rip), %rax      # 0x816d
movq %rbx, %r13
movq %r12, %rbx
movq %rax, %r12
jmp 0x27ed
xorps %xmm0, %xmm0
movaps %xmm0, -0x70(%rbp)
andq $0x0, -0x60(%rbp)
movq -0x30(%rbp), %rdi
movq %r14, %rsi
callq 0x5d3c
movq %r14, %rdi
callq 0x4dc8
movq %r13, %rdi
callq 0x2368
jmp 0x265e
leaq -0x2f8(%rbp), %rdi
callq 0x2060
movq -0x30(%rbp), %rax
addq $0x3d8, %rsp            # imm = 0x3D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x20
popq %rdi
callq 0x20f0
movq %rax, %r15
leaq 0x5941(%rip), %rsi      # 0x816f
leaq -0x70(%rbp), %rdi
leaq -0xd0(%rbp), %rdx
callq 0x4e1c
movb $0x1, %r12b
leaq 0x5943(%rip), %rdx      # 0x818b
leaq -0x70(%rbp), %rsi
movq %r15, %rdi
callq 0x4df3
xorl %r12d, %r12d
leaq 0x953a(%rip), %rsi      # 0xbd98
movq 0x975b(%rip), %rdx      # 0xbfc0
movq %r15, %rdi
callq 0x22b0
jmp 0x28b7
pushq $0x8
popq %rdi
callq 0x20f0
leaq 0x5862(%rip), %rcx      # 0x80e0
movq %rcx, (%rax)
movq 0x9740(%rip), %rsi      # 0xbfc8
movq %rax, %rdi
xorl %edx, %edx
callq 0x22b0
jmp 0x28b7
pushq $0x8
popq %rdi
callq 0x20f0
leaq 0x587b(%rip), %rcx      # 0x811e
movq %rcx, (%rax)
movq 0x971b(%rip), %rsi      # 0xbfc8
movq %rax, %rdi
xorl %edx, %edx
callq 0x22b0
movq %rax, %r14
jmp 0x2956
movq %rax, %r14
leaq -0x70(%rbp), %rdi
callq 0x4dc8
jmp 0x2935
jmp 0x2932
movq %rax, %r14
leaq -0x70(%rbp), %rdi
callq 0x4efe
jmp 0x2902
movq %rax, %r14
leaq -0x70(%rbp), %rdi
callq 0x2368
testb %r12b, %r12b
jne 0x28f5
jmp 0x2935
jmp 0x2932
movq %rax, %r14
movq %r15, %rdi
callq 0x2140
jmp 0x2935
movq %rax, %r14
leaq -0xf0(%rbp), %rdi
callq 0x2368
jmp 0x2913
movq %rax, %r14
leaq -0x90(%rbp), %rdi
callq 0x2368
jmp 0x2924
movq %rax, %r14
leaq -0xb0(%rbp), %rdi
callq 0x2368
jmp 0x2935
movq %rax, %r14
leaq -0xd0(%rbp), %rdi
callq 0x2368
jmp 0x294a
jmp 0x2947
jmp 0x2947
movq %rax, %r14
leaq -0x2f8(%rbp), %rdi
callq 0x2060
movq -0x30(%rbp), %rdi
callq 0x4f1e
movq %r14, %rdi
callq 0x22e0
nop