// File: 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
subq $0x4a0, %rsp            # imm = 0x4A0
movq %rdi, -0x458(%rbp)
movq %rdi, %rax
movq %rax, -0x450(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb $0x0, -0x11(%rbp)
callq 0x7e90
movq -0x10(%rbp), %rsi
leaq -0x220(%rbp), %rdi
movl $0x8, %edx
callq 0x3430
jmp 0x3844
jmp 0x3846
movq -0x220(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x220(%rbp,%rax), %rdi
callq 0x33b0
movb %al, -0x459(%rbp)
jmp 0x3866
movb -0x459(%rbp), %al
testb $0x1, %al
jne 0x3875
jmp 0x3d2f
leaq -0x220(%rbp), %rdi
leaq -0x330(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x30a0
jmp 0x388f
leaq -0x220(%rbp), %rdi
callq 0x34a0
movq %rax, -0x468(%rbp)
jmp 0x38a4
movq -0x468(%rbp), %rax
cmpq $0x100, %rax            # imm = 0x100
jne 0x3919
movsbl -0x231(%rbp), %eax
cmpl $0x0, %eax
je 0x3919
movl $0x8, %edi
callq 0x3120
movq %rax, %rdi
leaq 0xf7ed(%rip), %rax      # 0x130c0
movq %rax, (%rdi)
movq 0x186e3(%rip), %rsi     # 0x1bfc0
xorl %eax, %eax
movl %eax, %edx
callq 0x33c0
jmp 0x3d93
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
jmp 0x3d7b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
jmp 0x3d51
leaq -0x351(%rbp), %rdi
movq %rdi, -0x470(%rbp)
callq 0x3410
movq -0x470(%rbp), %rdx
leaq -0x350(%rbp), %rdi
leaq -0x330(%rbp), %rsi
callq 0x7ec0
jmp 0x3948
leaq -0x351(%rbp), %rdi
callq 0x3280
leaq -0x350(%rbp), %rdi
callq 0x3190
cmpq $0x0, %rax
jne 0x3a08
xorps %xmm0, %xmm0
movaps %xmm0, -0x370(%rbp)
movq $0x0, -0x360(%rbp)
leaq -0x370(%rbp), %rdi
movq %rdi, -0x478(%rbp)
callq 0x7fa0
movq -0x458(%rbp), %rdi
movq -0x478(%rbp), %rsi
callq 0x7f70
jmp 0x39a7
leaq -0x370(%rbp), %rdi
callq 0x7fc0
movl $0x2, -0x374(%rbp)
jmp 0x3c81
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
leaq -0x351(%rbp), %rdi
callq 0x3280
jmp 0x3d51
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
leaq -0x370(%rbp), %rdi
callq 0x7fc0
jmp 0x3d21
movq -0x458(%rbp), %rdi
callq 0x7dd0
cmpq $0x0, %rax
jne 0x3a5d
movl $0x8, %edi
callq 0x3120
movq %rax, %rdi
leaq 0xf6d0(%rip), %rax      # 0x130fe
movq %rax, (%rdi)
movq 0x18588(%rip), %rsi     # 0x1bfc0
xorl %eax, %eax
movl %eax, %edx
callq 0x33c0
jmp 0x3d93
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
jmp 0x3d21
leaq -0x350(%rbp), %rdi
leaq 0xf6e2(%rip), %rsi      # 0x1314d
xorl %eax, %eax
movl %eax, %edx
callq 0x3490
movl %eax, -0x378(%rbp)
cmpl $-0x1, -0x378(%rbp)
je 0x3ac7
movl -0x378(%rbp), %eax
movl %eax, -0x484(%rbp)
leaq 0xf6b7(%rip), %rsi      # 0x1314d
leaq -0x350(%rbp), %rdi
movq $-0x1, %rdx
callq 0x3390
movq %rax, -0x480(%rbp)
jmp 0x3ab2
movl -0x484(%rbp), %eax
movq -0x480(%rbp), %rcx
cmpl %ecx, %eax
je 0x3b8b
movb $0x1, -0x399(%rbp)
movl $0x20, %edi
callq 0x3120
movq %rax, -0x490(%rbp)
leaq 0xf669(%rip), %rsi      # 0x1314f
leaq -0x398(%rbp), %rdi
leaq -0x350(%rbp), %rdx
callq 0x8070
jmp 0x3afb
movq -0x490(%rbp), %rdi
leaq 0xf662(%rip), %rdx      # 0x1316b
leaq -0x398(%rbp), %rsi
callq 0x8020
jmp 0x3b17
movq -0x490(%rbp), %rdi
movb $0x0, -0x399(%rbp)
leaq 0x18264(%rip), %rsi     # 0x1bd90
movq 0x18495(%rip), %rdx     # 0x1bfc8
callq 0x33c0
jmp 0x3d93
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
jmp 0x3b6f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
leaq -0x398(%rbp), %rdi
callq 0x34b8
testb $0x1, -0x399(%rbp)
jne 0x3b7a
jmp 0x3b86
movq -0x490(%rbp), %rdi
callq 0x31b0
jmp 0x3d21
movl -0x378(%rbp), %eax
incl %eax
movslq %eax, %rdx
leaq -0x3c0(%rbp), %rdi
leaq -0x350(%rbp), %rsi
movq $-0x1, %rcx
callq 0x3240
jmp 0x3bb2
movq -0x458(%rbp), %rsi
leaq -0x3c8(%rbp), %rdi
movq %rdi, -0x4a0(%rbp)
callq 0x8180
movq -0x4a0(%rbp), %rdi
callq 0x81d0
movq %rax, -0x498(%rbp)
jmp 0x3be1
movslq -0x378(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0x428(%rbp), %rdi
leaq -0x350(%rbp), %rsi
callq 0x3240
jmp 0x3c01
leaq -0x448(%rbp), %rdi
leaq -0x3c0(%rbp), %rsi
callq 0x30f0
jmp 0x3c16
leaq -0x408(%rbp), %rdi
leaq -0x428(%rbp), %rsi
leaq -0x448(%rbp), %rdx
callq 0x8240
jmp 0x3c32
movq -0x498(%rbp), %rdi
leaq -0x408(%rbp), %rsi
callq 0x8210
jmp 0x3c47
leaq -0x408(%rbp), %rdi
callq 0x82d0
leaq -0x448(%rbp), %rdi
callq 0x34b8
leaq -0x428(%rbp), %rdi
callq 0x34b8
leaq -0x3c0(%rbp), %rdi
callq 0x34b8
movl $0x0, -0x374(%rbp)
leaq -0x350(%rbp), %rdi
callq 0x34b8
movl -0x374(%rbp), %eax
testl %eax, %eax
je 0x3c9e
jmp 0x3c99
jmp 0x3846
jmp 0x3846
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
jmp 0x3d15
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
jmp 0x3d09
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
jmp 0x3cfd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x228(%rbp)
movl %eax, -0x22c(%rbp)
leaq -0x408(%rbp), %rdi
callq 0x82d0
leaq -0x448(%rbp), %rdi
callq 0x34b8
leaq -0x428(%rbp), %rdi
callq 0x34b8
leaq -0x3c0(%rbp), %rdi
callq 0x34b8
leaq -0x350(%rbp), %rdi
callq 0x34b8
jmp 0x3d51
movb $0x1, -0x11(%rbp)
movl $0x1, -0x374(%rbp)
leaq -0x220(%rbp), %rdi
callq 0x3080
testb $0x1, -0x11(%rbp)
jne 0x3d6b
jmp 0x3d5f
leaq -0x220(%rbp), %rdi
callq 0x3080
jmp 0x3d7b
movq -0x458(%rbp), %rdi
callq 0x8300
movq -0x450(%rbp), %rax
addq $0x4a0, %rsp            # imm = 0x4A0
popq %rbp
retq
movq -0x458(%rbp), %rdi
callq 0x8300
movq -0x228(%rbp), %rdi
callq 0x3400
nopw %cs:(%rax,%rax)