// File: /workspace/github_cpp_makefile_star2_O2/BU-DiSC[P]BF-Shared-Hashing/db.cpp
// Function: db::ReadSettings()
int db::ReadSettings()
{
	ifstream infile;
	infile.open( settings_file );
	 
	if( infile.fail() ){
		cout << "Error opening " << settings_file << endl;
	}

	bool bf_rebuild = false;

	int num = 0;
	while( infile.peek() != EOF ){
		//int line = 0;
		string line;
		getline( infile, line);
		int value = stoi(line);
		//cout << num << " " << value << endl;
		if ( num==0 ) {
			if (value != P)
				return -1;
		} else if ( num==1 ){
			if (value != B)
				return -1;
		} else if ( num==2 ){
				if (value != E)
					return -1;
		} else if ( num==3 ){
			if (value != K)
				return -1;
		} else if ( num==4 ){
			if (value != num_filter_units){
				bf_rebuild = true;
			}
		
		} else if ( num==5 ){
			if ( value > 0 ){
				num_levels = value;
				num_sstPerLevel.resize( num_levels, 0);
				fence_pointers.resize( num_levels );
			}
			else {
				return -1;
			}
		} else if ( num==6 ){
			if( value == 0){
				return -1;
			}
			last_sst_keys = value;
		} else if ( num>=7 && num<7+num_levels ){
			num_sstPerLevel[num-7] = value;
			num_sst += value;
		}
		num++;
	}
	infile.close();

	if ( num < 7+num_levels )
		return -1;

	if (bf_rebuild==true){
		return 1;
	}

	//cout << fence_file << endl;
	infile.open( fence_file );
	if( infile.fail() ){
		cout << "Error opening " << fence_file << endl;
	}
	for ( int i=0 ; i<num_levels ; i++ ){
		vector <string> fence_pointer_one_level ( num_sstPerLevel[i]+1 );
		for ( int j=0 ; j<=num_sstPerLevel[i] ; j++ ){
			string first, last;
			getline( infile, first );
			fence_pointer_one_level[j] = first;
		}
		fence_pointers[i] = fence_pointer_one_level;
	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x288, %rsp            # imm = 0x288
movq %rdi, %r15
leaq 0x80(%rsp), %r14
movq %r14, %rdi
callq 0x6460
leaq 0x80(%r15), %rbx
pushq $0x8
popq %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6390
movq 0x80(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0xa0(%rsp,%rax)
je 0x83e7
movq 0x2cc00(%rip), %rdi     # 0x34fc8
leaq 0x19c6b(%rip), %rsi     # 0x2203a
callq 0x6410
movq %rax, %rdi
movq %rbx, %rsi
callq 0x63b0
movq %rax, %rdi
callq 0x6210
leaq 0xe8(%r15), %rax
movq %rax, 0x18(%rsp)
movq %r15, 0x8(%rsp)
leaq 0x140(%r15), %rax
movq %rax, 0x20(%rsp)
movq $0x0, 0x10(%rsp)
leaq 0x80(%rsp), %r13
leaq 0x28(%rsp), %rbp
pushq $-0x1
popq %r12
xorl %ebx, %ebx
movq %r13, %rdi
callq 0x61a0
cmpl $-0x1, %eax
je 0x85a2
leaq 0x38(%rsp), %rax
movq %rax, 0x28(%rsp)
andq $0x0, 0x30(%rsp)
movb $0x0, 0x38(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x60c0
movq %rbp, %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0xb37c
movl %ebx, %ecx
cmpl $0x6, %ebx
ja 0x84ed
leaq 0x19ce4(%rip), %rdx     # 0x22154
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
xorl %r15d, %r15d
movl $0x0, %r14d
movq 0x8(%rsp), %rcx
cmpl 0xc4(%rcx), %eax
je 0x8574
jmp 0x858c
movq 0x8(%rsp), %rcx
cmpl 0x110(%rcx), %eax
setne %al
movq 0x10(%rsp), %rcx
orb %al, %cl
movq %rcx, 0x10(%rsp)
jmp 0x8574
movq 0x8(%rsp), %rcx
cmpl 0xcc(%rcx), %eax
je 0x8574
xorl %r14d, %r14d
pushq $0x2
jmp 0x858a
movq 0x8(%rsp), %rcx
cmpl 0xd0(%rcx), %eax
je 0x8574
xorl %r14d, %r14d
pushq $0x3
jmp 0x858a
jle 0x8574
movq 0x8(%rsp), %rsi
movl 0xdc(%rsi), %edx
addl $0x7, %edx
cmpl %edx, %ebx
jge 0x8574
movq 0xe8(%rsi), %rdx
movl %eax, -0x1c(%rdx,%rcx,4)
addl %eax, 0xe0(%rsi)
jmp 0x8574
movq 0x8(%rsp), %rcx
cmpl 0xc8(%rcx), %eax
je 0x8574
xorl %r14d, %r14d
pushq $0x1
jmp 0x858a
testl %eax, %eax
jle 0x857e
movq 0x8(%rsp), %r14
movl %eax, 0xdc(%r14)
movl %eax, %esi
andl $0x0, 0x48(%rsp)
movq 0x18(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0xb398
movslq 0xdc(%r14), %rsi
movq 0x20(%rsp), %rdi
callq 0xb3cc
jmp 0x8574
testl %eax, %eax
je 0x8585
movq 0x8(%rsp), %rcx
movl %eax, 0x100(%rcx)
incl %ebx
movb $0x1, %r14b
movl %ebx, %r15d
jmp 0x858c
xorl %r14d, %r14d
pushq $0x5
jmp 0x858a
xorl %r14d, %r14d
pushq $0x6
popq %r15
movq %rbp, %rdi
callq 0x61f0
movl %r15d, %ebx
testb %r14b, %r14b
jne 0x8420
jmp 0x85dc
leaq 0x80(%rsp), %rdi
callq 0x60e0
movq 0x8(%rsp), %r15
movl 0xdc(%r15), %eax
addl $0x7, %eax
xorl %r12d, %r12d
cmpl %eax, %ebx
setl %al
movq 0x10(%rsp), %rcx
orb %al, %cl
testb $0x1, %cl
je 0x85fe
movb %al, %r12b
negl %r12d
orl $0x1, %r12d
leaq 0x80(%rsp), %rdi
callq 0x6120
movl %r12d, %eax
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xa0(%r15), %rbx
leaq 0x80(%rsp), %rdi
pushq $0x8
popq %rdx
movq %rbx, %rsi
callq 0x6390
movq 0x80(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0xa0(%rsp,%rax)
je 0x8654
movq 0x2c993(%rip), %rdi     # 0x34fc8
leaq 0x199fe(%rip), %rsi     # 0x2203a
callq 0x6410
movq %rax, %rdi
movq %rbx, %rsi
callq 0x63b0
movq %rax, %rdi
callq 0x6210
xorl %r12d, %r12d
leaq 0x68(%rsp), %rbp
leaq 0x28(%rsp), %r13
leaq 0x48(%rsp), %rbx
xorl %r14d, %r14d
movslq 0xdc(%r15), %rax
cmpq %rax, %r14
jge 0x85dc
movq 0x18(%rsp), %rax
movq (%rax), %rax
movslq (%rax,%r14,4), %rsi
incq %rsi
movq %rbp, %rdi
movq %r13, %rdx
callq 0xb402
xorl %r15d, %r15d
xorl %ebp, %ebp
movq 0x18(%rsp), %rax
movq (%rax), %rax
movslq (%rax,%r14,4), %rax
cmpq %rax, %rbp
jg 0x870c
leaq 0x38(%rsp), %rax
movq %rax, 0x28(%rsp)
andq $0x0, 0x30(%rsp)
movb %r12b, 0x38(%rsp)
leaq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
andq $0x0, 0x50(%rsp)
movb %r12b, 0x58(%rsp)
leaq 0x80(%rsp), %rdi
movq %r13, %rsi
callq 0x60c0
movq 0x68(%rsp), %rdi
addq %r15, %rdi
movq %r13, %rsi
callq 0x6250
movq %rbx, %rdi
callq 0x61f0
movq %r13, %rdi
callq 0x61f0
incq %rbp
addq $0x20, %r15
jmp 0x8698
imulq $0x18, %r14, %rdi
movq 0x20(%rsp), %rax
addq (%rax), %rdi
leaq 0x68(%rsp), %rbp
movq %rbp, %rsi
callq 0xb454
movq %rbp, %rdi
callq 0x739e
incq %r14
movq 0x8(%rsp), %r15
jmp 0x8669
jmp 0x874e
jmp 0x8749
jmp 0x8749
movq %rax, %rbx
jmp 0x8774
jmp 0x8749
jmp 0x874e
movq %rax, %rbx
jmp 0x877e
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x61f0
jmp 0x877e
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x61f0
leaq 0x28(%rsp), %rdi
callq 0x61f0
leaq 0x68(%rsp), %rdi
callq 0x739e
leaq 0x80(%rsp), %rdi
callq 0x6120
movq %rbx, %rdi
callq 0x66b0
nop