// File: PrarabdhJoshi[P]DatabaseImplementation/Record.cc
// Function: Record::Print(Schema*)
void Record :: Print (Schema *mySchema) {

	int n = mySchema->GetNumAtts();
	Attribute *atts = mySchema->GetAtts();

	// loop through all of the attributes
	for (int i = 0; i < n; i++) {

		// print the attribute name
		cout << atts[i].name << ": ";

		// use the i^th slot at the head of the record to get the
		// offset to the correct attribute in the record
		int pointer = ((int *) bits)[i + 1];

		// here we determine the type, which given in the schema;
		// depending on the type we then print out the contents
		cout << "[";

		// first is integer
		if (atts[i].myType == Int) {
			int *myInt = (int *) &(bits[pointer]);
			cout << *myInt;	

		// then is a double
		} else if (atts[i].myType == Double) {
			double *myDouble = (double *) &(bits[pointer]);
			cout << *myDouble;	

		// then is a character string
		} else if (atts[i].myType == String) {
			char *myString = (char *) &(bits[pointer]);
			cout << myString;	
		} 

		cout << "]";

		// print out a comma as needed to make things pretty
		if (i != n - 1) {
			cout << ", ";
		}
	}

	cout << "\n";
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq 0x40(%rsp), %rax
movq %rax, (%rsp)
movq 0x38(%rsp), %rdi
callq 0x5d30
movl %eax, 0x34(%rsp)
movq 0x38(%rsp), %rdi
callq 0x5d40
movq %rax, 0x28(%rsp)
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
cmpl 0x34(%rsp), %eax
jge 0x33b0
movq 0x28(%rsp), %rax
movslq 0x24(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rsi
movq 0xcd53(%rip), %rdi      # 0xffb8
callq 0x2140
movq %rax, %rdi
leaq 0x9999(%rip), %rsi      # 0xcc0d
callq 0x2140
movq (%rsp), %rax
movq (%rax), %rax
movl 0x24(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x20(%rsp)
movq 0xcd20(%rip), %rdi      # 0xffb8
leaq 0x8d8a(%rip), %rsi      # 0xc029
callq 0x2140
movq 0x28(%rsp), %rax
movslq 0x24(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpl $0x0, 0x8(%rax)
jne 0x32e7
movq (%rsp), %rax
movq (%rax), %rax
movslq 0x20(%rsp), %rcx
addq %rcx, %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movl (%rax), %esi
movq 0xccdb(%rip), %rdi      # 0xffb8
callq 0x2290
jmp 0x3369
movq 0x28(%rsp), %rax
movslq 0x24(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpl $0x1, 0x8(%rax)
jne 0x3329
movq (%rsp), %rax
movq (%rax), %rax
movslq 0x20(%rsp), %rcx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movsd (%rax), %xmm0
movq 0xcc96(%rip), %rdi      # 0xffb8
callq 0x2320
jmp 0x3367
movq 0x28(%rsp), %rax
movslq 0x24(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpl $0x2, 0x8(%rax)
jne 0x3365
movq (%rsp), %rax
movq (%rax), %rax
movslq 0x20(%rsp), %rcx
addq %rcx, %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rsi
movq 0xcc58(%rip), %rdi      # 0xffb8
callq 0x2140
jmp 0x3367
jmp 0x3369
movq 0xcc48(%rip), %rdi      # 0xffb8
leaq 0x8cb4(%rip), %rsi      # 0xc02b
callq 0x2140
movl 0x24(%rsp), %eax
movl 0x34(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
je 0x339e
movq 0xcc26(%rip), %rdi      # 0xffb8
leaq 0x8c94(%rip), %rsi      # 0xc02d
callq 0x2140
jmp 0x33a0
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x323c
movq 0xcc01(%rip), %rdi      # 0xffb8
leaq 0x97b7(%rip), %rsi      # 0xcb75
callq 0x2140
addq $0x48, %rsp
retq
nopl (%rax,%rax)