// File: /workspace/github_cpp_makefile_star2_O1/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 %r15
movq %r15, %rdi
callq 0x2250
movq %rax, %rbx
movq 0x6c0f(%rip), %rdi      # 0x8fd0
leaq 0x3cfd(%rip), %rsi      # 0x60c5
pushq $0x12
popq %rdx
callq 0x21e0
movq 0x6c09(%rip), %r14      # 0x8fe0
movq (%r14), %rax
movq -0x18(%rax), %rax
movq 0x10(%r14,%rax), %r12
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2320
movq (%r14), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x20(%r14,%rax)
jne 0x2420
addq $-0x33, %r12
cmpq $-0x33, %r12
ja 0x2420
movq 0xe8(%r14,%rax), %rdi
movq 0x10(%rdi), %rax
cmpq 0x18(%rdi), %rax
jae 0x2592
leaq 0x3ff4(%rip), %rdi      # 0x641b
leaq 0x3caa(%rip), %rsi      # 0x60d8
callq 0x2200
movq %rax, %r14
testq %rax, %rax
jne 0x2451
movq 0x6b8e(%rip), %rdi      # 0x8fd0
leaq 0x3c92(%rip), %rsi      # 0x60db
pushq $0x15
popq %rdx
callq 0x21e0
leaq 0x3f7f(%rip), %r15      # 0x63d7
leaq 0x10(%rsp), %r12
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x2370
cmpl $-0x1, %eax
je 0x249c
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2260
testl %eax, %eax
jne 0x245d
movq 0x6b48(%rip), %rdi      # 0x8fd0
leaq 0x3c62(%rip), %rsi      # 0x60f1
pushq $0x20
popq %rdx
callq 0x21e0
jmp 0x2586
movq 0x6b2d(%rip), %rdi      # 0x8fd0
leaq 0x3c68(%rip), %rsi      # 0x6112
pushq $0x16
popq %rdx
callq 0x21e0
movq 0x6b27(%rip), %rdi      # 0x8fe0
leaq 0xc(%rsp), %r15
movq %r15, %rsi
callq 0x2100
movl (%r15), %esi
movq %rbx, %rdi
callq 0x3dd3
testq %rax, %rax
je 0x2586
movq %rax, %r15
movq %rax, %rdi
callq 0x3d81
movl %eax, 0x3f8(%r15)
movslq 0x400(%r15), %rdi
callq 0x2250
movq %rax, 0x410(%r15)
movq %r15, %rdi
addq $0x3e4, %rdi            # imm = 0x3E4
leaq 0x3b53(%rip), %rsi      # 0x6063
callq 0x3c5a
movq %rax, %r12
movq 0x410(%r15), %rdi
movslq 0x400(%r15), %rdx
pushq $0x1
popq %rsi
movq %r14, %rcx
callq 0x2380
movq %r12, %rdi
callq 0x2190
movq %r15, %rdi
callq 0x3d3d
movq 0x410(%r15), %rdi
callq 0x2210
movq %r15, %rdi
callq 0x2210
pushq $0x2
popq %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x21d0
leaq 0x3bc0(%rip), %rsi      # 0x6129
movq %r14, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2280
movq %r14, %rdi
callq 0x2190
movq %rbx, %rdi
callq 0x2210
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq (%rdi), %rax
callq *0x48(%rax)
cmpl $-0x1, %eax
jne 0x2420
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x2, %esi
callq 0x2310
jmp 0x2420