// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x28, %rsp
pushq $0x32
popq %rdi
callq 0x2240
movq %rax, %rbx
movq 0x6ff7(%rip), %rdi      # 0x9fd0
leaq 0x30e5(%rip), %rsi      # 0x60c5
callq 0x2180
movq 0x6ff4(%rip), %rdi      # 0x9fe0
movq %rbx, %rsi
callq 0x459a
leaq 0x3420(%rip), %rdi      # 0x641b
leaq 0x30d6(%rip), %rsi      # 0x60d8
callq 0x21f0
movq %rax, %r14
testq %rax, %rax
jne 0x3022
movq 0x6fba(%rip), %rdi      # 0x9fd0
leaq 0x30be(%rip), %rsi      # 0x60db
callq 0x2180
leaq 0x33ae(%rip), %r15      # 0x63d7
leaq 0x10(%rsp), %r12
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x2350
cmpl $-0x1, %eax
je 0x306a
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2250
testl %eax, %eax
jne 0x302e
movq 0x6f77(%rip), %rdi      # 0x9fd0
leaq 0x3091(%rip), %rsi      # 0x60f1
callq 0x2180
jmp 0x3151
movq 0x6f5f(%rip), %rdi      # 0x9fd0
leaq 0x309a(%rip), %rsi      # 0x6112
callq 0x2180
movq 0x6f5c(%rip), %rdi      # 0x9fe0
leaq 0xc(%rsp), %r15
movq %r15, %rsi
callq 0x2100
movl (%r15), %esi
movq %rbx, %rdi
callq 0x2d8b
testq %rax, %rax
je 0x3151
movq %rax, %r15
movq %rax, %rdi
callq 0x2d2d
movl %eax, 0x3f8(%r15)
movslq 0x400(%r15), %rdi
callq 0x2240
movq %rax, 0x410(%r15)
movq %r15, %rdi
addq $0x3e4, %rdi            # imm = 0x3E4
leaq 0x2f88(%rip), %rsi      # 0x6063
callq 0x2c0a
movq %rax, %r12
movq 0x410(%r15), %rdi
movslq 0x400(%r15), %rdx
pushq $0x1
popq %rsi
movq %r14, %rcx
callq 0x2360
movq %r12, %rdi
callq 0x2190
movq %r15, %rdi
callq 0x2ceb
movq 0x410(%r15), %rdi
callq 0x2200
movq %r15, %rdi
callq 0x2200
pushq $0x2
popq %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x21d0
leaq 0x2ff5(%rip), %rsi      # 0x6129
movq %r14, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2270
movq %r14, %rdi
callq 0x2190
movq %rbx, %rdi
callq 0x2200
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq