// File: ankit-1517[P]dbms_rTree/sample_run.cpp
// Function: main
int main() {
	FileManager fm;

	// Create a brand new file
	FileHandler fh = fm.CreateFile("temp.txt");
	cout << "File created " << endl;

	// Create a new page
	PageHandler ph = fh.NewPage ();
	char *data = ph.GetData ();

	// Store an integer at the very first location
	int num = 5;
	memcpy (&data[0], &num, sizeof(int));

	// Store an integer at the second location
	num = 1000;
	memcpy (&data[4], &num, sizeof(int));

	// Flush the page
	fh.FlushPages ();
	cout << "Data written and flushed" << endl;

	// Close the file
	fm.CloseFile(fh);

	// Reopen the same file, but for reading this time
	fh = fm.OpenFile ("temp.txt");
	cout << "File opened" << endl;

	// Get the very first page and its data
	ph = fh.FirstPage ();
	data = ph.GetData ();

	// Output the first integer
	memcpy (&num, &data[0], sizeof(int));
	cout << "First number: " << num << endl;

	// Output the second integer
	memcpy (&num, &data[4], sizeof(int));
	cout << "Second number: " << num << endl;;

	// Close the file and destory it
	fm.CloseFile (fh);
	fm.DestroyFile ("temp.txt");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
leaq -0x8(%rbp), %rdi
movq %rdi, -0x98(%rbp)
callq 0x6f40
movq -0x98(%rbp), %rsi
leaq 0xe33(%rip), %rdx       # 0x83ac
leaq -0x30(%rbp), %rdi
callq 0x7040
jmp 0x7584
movq 0x5a4d(%rip), %rdi      # 0xcfd8
leaq 0xe23(%rip), %rsi       # 0x83b5
callq 0x2150
movq %rax, -0xa0(%rbp)
jmp 0x75a0
movq -0xa0(%rbp), %rdi
movq 0x5a12(%rip), %rsi      # 0xcfc0
callq 0x2170
jmp 0x75b5
leaq -0x50(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x6c10
jmp 0x75c4
leaq -0x50(%rbp), %rdi
callq 0x6780
movq %rax, -0xa8(%rbp)
jmp 0x75d6
movq -0xa8(%rbp), %rax
movq %rax, -0x58(%rbp)
movl $0x5, -0x5c(%rbp)
movq -0x58(%rbp), %rax
movl -0x5c(%rbp), %ecx
movl %ecx, (%rax)
movl $0x3e8, -0x5c(%rbp)     # imm = 0x3E8
movq -0x58(%rbp), %rax
movl -0x5c(%rbp), %ecx
movl %ecx, 0x4(%rax)
leaq -0x30(%rbp), %rdi
callq 0x6e20
jmp 0x760d
movq 0x59c4(%rip), %rdi      # 0xcfd8
leaq 0xda8(%rip), %rsi       # 0x83c3
callq 0x2150
movq %rax, -0xb0(%rbp)
jmp 0x7629
movq -0xb0(%rbp), %rdi
movq 0x5989(%rip), %rsi      # 0xcfc0
callq 0x2170
jmp 0x763e
leaq -0x8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x7290
jmp 0x764d
leaq 0xd58(%rip), %rdx       # 0x83ac
leaq -0x80(%rbp), %rdi
leaq -0x8(%rbp), %rsi
callq 0x7160
jmp 0x7663
movups -0x80(%rbp), %xmm0
movups -0x70(%rbp), %xmm1
movaps %xmm1, -0x20(%rbp)
movaps %xmm0, -0x30(%rbp)
movq 0x595e(%rip), %rdi      # 0xcfd8
leaq 0xd5b(%rip), %rsi       # 0x83dc
callq 0x2150
movq %rax, -0xb8(%rbp)
jmp 0x768f
movq -0xb8(%rbp), %rdi
movq 0x5923(%rip), %rsi      # 0xcfc0
callq 0x2170
jmp 0x76a4
leaq -0x90(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x6870
jmp 0x76b6
movups -0x90(%rbp), %xmm0
movaps %xmm0, -0x50(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x6780
movq %rax, -0xc0(%rbp)
jmp 0x76d3
movq -0xc0(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x5c(%rbp)
movq 0x58ea(%rip), %rdi      # 0xcfd8
leaq 0xcf3(%rip), %rsi       # 0x83e8
callq 0x2150
movq %rax, -0xc8(%rbp)
jmp 0x7703
movq -0xc8(%rbp), %rdi
movl -0x5c(%rbp), %esi
callq 0x2200
movq %rax, -0xd0(%rbp)
jmp 0x771b
movq -0xd0(%rbp), %rdi
movq 0x5897(%rip), %rsi      # 0xcfc0
callq 0x2170
jmp 0x7730
movq -0x58(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x5c(%rbp)
movq 0x5897(%rip), %rdi      # 0xcfd8
leaq 0xcaf(%rip), %rsi       # 0x83f7
callq 0x2150
movq %rax, -0xd8(%rbp)
jmp 0x7756
movq -0xd8(%rbp), %rdi
movl -0x5c(%rbp), %esi
callq 0x2200
movq %rax, -0xe0(%rbp)
jmp 0x776e
movq -0xe0(%rbp), %rdi
movq 0x5844(%rip), %rsi      # 0xcfc0
callq 0x2170
jmp 0x7783
leaq -0x8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x7290
jmp 0x7792
leaq 0xc13(%rip), %rsi       # 0x83ac
leaq -0x8(%rbp), %rdi
callq 0x7260
jmp 0x77a4
leaq -0x8(%rbp), %rdi
callq 0x7000
xorl %eax, %eax
addq $0xe0, %rsp
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x8(%rbp), %rdi
callq 0x7000
movq -0x38(%rbp), %rdi
callq 0x2210