// File: pawan231[P]MiniDataBase/include/create.h
// Function: create()
void create(){
	char *name;
	int count;
	name=(char*)malloc(sizeof(char)*MAX_NAME);
	cout<<"Enter table name: ";
	cin>>name;

	//check if new table already exists in table list or not
	FILE *fp=fopen("./table/table_list","r+");
	if(fp==NULL) cout<<"file pointer is null\n";
	char tab_name[20];
	while(fscanf(fp,"%s",tab_name)!=EOF){
		if(strcmp(tab_name,name)==0){
			cout<<"error\ntable name already exists\n";
			return;
		}
	}

	//enter table details if not exist
	cout<<"enter no. of columns: ";
	cin>>count;
	table *temp;
	temp=create_table(name,count);
	if(temp != NULL){
	//calculate the size of the block
		temp->size=record_size(temp);
		if(temp!=NULL){
		temp->blockbuf = malloc(temp->BLOCKSIZE);
		FILE *fpr;
        fpr  = open_file(temp->name, const_cast<char*>("w"));
        fwrite(temp->blockbuf, 1, temp->BLOCKSIZE, fp);
        fclose(fpr);
        store_meta_data(temp);
        free(temp->blockbuf);
		free(temp);

		//if its a new table, make a entry inside table_list
		fseek(fp,0,SEEK_END);
		fprintf(fp,"%s\n",name);
		fclose(fp);
		free(name);
	}else{
		      printf("create_table inside CREATE function returned NULL\n");
		       // return 1;
		 }
	 }else{
		 //printf("\nwrong input\nexiting...\n\n");
		 return;
	 }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl $0x32, %edi
callq 0x2260
movq %rax, -0x8(%rbp)
movq 0xc663(%rip), %rdi      # 0xffd0
leaq 0x7914(%rip), %rsi      # 0xb288
callq 0x2190
movq -0x8(%rbp), %rsi
movq 0xc65c(%rip), %rdi      # 0xffe0
callq 0x5f30
leaq 0x7d64(%rip), %rdi      # 0xb6f4
leaq 0x7904(%rip), %rsi      # 0xb29b
callq 0x2210
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x39ba
movq 0xc622(%rip), %rdi      # 0xffd0
leaq 0x78e9(%rip), %rsi      # 0xb29e
callq 0x2190
jmp 0x39bc
movq -0x18(%rbp), %rdi
leaq -0x30(%rbp), %rdx
leaq 0x7ce5(%rip), %rsi      # 0xb6b0
movb $0x0, %al
callq 0x2380
cmpl $-0x1, %eax
je 0x3a03
leaq -0x30(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x2280
cmpl $0x0, %eax
jne 0x3a01
movq 0xc5e0(%rip), %rdi      # 0xffd0
leaq 0x78bd(%rip), %rsi      # 0xb2b4
callq 0x2190
jmp 0x3b37
jmp 0x39bc
movq 0xc5c6(%rip), %rdi      # 0xffd0
leaq 0x78c4(%rip), %rsi      # 0xb2d5
callq 0x2190
movq 0xc5c3(%rip), %rdi      # 0xffe0
leaq -0xc(%rbp), %rsi
callq 0x2100
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x3330
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x3b35
movq -0x38(%rbp), %rdi
callq 0x3250
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x3f8(%rax)
cmpq $0x0, -0x38(%rbp)
je 0x3b25
movq -0x38(%rbp), %rax
movslq 0x400(%rax), %rdi
callq 0x2260
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x410(%rax)
movq -0x38(%rbp), %rdi
addq $0x3e4, %rdi            # imm = 0x3E4
leaq 0x75ea(%rip), %rsi      # 0xb07b
callq 0x30e0
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movq 0x410(%rax), %rdi
movq -0x38(%rbp), %rax
movslq 0x400(%rax), %rdx
movq -0x18(%rbp), %rcx
movl $0x1, %esi
callq 0x2390
movq -0x40(%rbp), %rdi
callq 0x21a0
movq -0x38(%rbp), %rdi
callq 0x3200
movq -0x38(%rbp), %rax
movq 0x410(%rax), %rdi
callq 0x2220
movq -0x38(%rbp), %rdi
callq 0x2220
movq -0x18(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x21e0
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rdx
leaq 0x77e2(%rip), %rsi      # 0xb2ec
movb $0x0, %al
callq 0x22a0
movq -0x18(%rbp), %rdi
callq 0x21a0
movq -0x8(%rbp), %rdi
callq 0x2220
jmp 0x3b33
leaq 0x77c4(%rip), %rdi      # 0xb2f0
movb $0x0, %al
callq 0x2030
jmp 0x3b37
jmp 0x3b37
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)