// File: /workspace/github_cpp_makefile_star2_O3/pawan231[P]MiniDataBase/include/insert.h
// Function: insert()
void insert(){
	char *tab;
	tab=(char*)malloc(sizeof(char)*MAX_PATH+1);
	cout<<"enter table name: ";
	cin>>tab;
	int check=search_table(tab);
	if(check==0){
		printf("Table %s not exists\n",tab);
		return ;
	}

	else{
		cout<<"\nTable exists enter data\n\n";
		char dir[100];
		strcpy(dir,"./table/");
		strcat(dir,tab);
		strcat(dir,"/met");
     	table inp1;
		int count;
		//read column details from file;
		FILE *fp = open_file(tab, const_cast<char*>("r"));
		int i=0;
		while(fread(&inp1,sizeof(table),1,fp)){
			printf("------------------------------------\n");
			cout<<"\ninsert the following details ::\n";
			printf("\n------------------------------------\n");
			count=inp1.count;
			for(i=0;i<inp1.count;i++){
				cout<<inp1.col[i].col_name<<"("<<inp1.col[i].type<<"),size:"<<inp1.col[i].size;
				cout<<"\t";
			}
		}
		printf("\n------------------------------------\n");
		//enter data;
		char var[MAX_NAME+1];
		void * data[MAX_ATTR];
		//void *data1[MAX_ATTR];

		//input data for the table of desired datatype 1.int 2.varchar;
		int size=0;
		int total=0;
		for(int i=0;i<count;i++){
			if(inp1.col[i].type==INT){
				data[i] =(int*) malloc(sizeof(int));
				total+=sizeof(int);
				string inp_int;
				cin>>inp_int;
				if(inp_int.length() > (unsigned)inp1.col[i].size){
					printf("\nwrong input, size <= %d\nexiting...\n",inp1.col[i].size);
					return;
				}else{
					//verify if entered input is integer and not a string;
					int num = 0;
					int factor_10 = 1;
					for(int j=inp_int.length()-1;j>=0;j--){
						if(inp_int[j] < 48 || inp_int[j] > 57){
							printf("\nwrong input, input should be integer\nexiting...\n");
							return;
						}else{
							num += (inp_int[j] - 48)*factor_10;
							factor_10 = factor_10 * 10;
						}
					}
					*((int*)data[i])=num;
				}
				size++;
			}else if(inp1.col[i].type==VARCHAR){
				//cout<<"inside varchar\n";
				data[i] = malloc(sizeof(char) * (MAX_NAME + 1));
				int flag=1;
				while(flag){
					cin>>var;
					total+=sizeof(char) * (MAX_NAME + 1);
					if(strlen(var)>(unsigned int)inp1.col[i].size){
						cout<<"error\nEntered size of string is greater than specified \n";
					}else flag=0;
				}
				strcpy((char*)(data[i]),var);
				//cout<<(char *)data[1]<<endl;
				size++;
			}
		}
		insert_command(tab,data,total);
	}
	free(tab);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x598, %rsp            # imm = 0x598
movl $0x3e9, %edi            # imm = 0x3E9
callq 0x2250
movq %rax, %r14
movq 0x69ed(%rip), %rdi      # 0x8fd0
leaq 0x3b78(%rip), %rsi      # 0x6162
pushq $0x12
popq %rdx
callq 0x21e0
movq 0x69e7(%rip), %r15      # 0x8fe0
movq (%r15), %rax
movq -0x18(%rax), %rax
movq $-0x3ea, %rbx           # imm = 0xFC16
addq 0x10(%r15,%rax), %rbx
movl $0x3e9, %edx            # imm = 0x3E9
movq %r15, %rdi
movq %r14, %rsi
callq 0x2320
movq (%r15), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x20(%r15,%rax)
jne 0x2651
cmpq $-0x3ea, %rbx           # imm = 0xFC16
ja 0x2651
movq 0x69a5(%rip), %rcx      # 0x8fe0
movq 0xe8(%rcx,%rax), %rdi
movq 0x10(%rdi), %rax
cmpq 0x18(%rdi), %rax
jae 0x2a18
movq %r14, %rdi
callq 0x401f
testl %eax, %eax
je 0x29b7
movq 0x6968(%rip), %rdi      # 0x8fd0
leaq 0x3b1b(%rip), %rsi      # 0x618a
pushq $0x1a
popq %rdx
callq 0x21e0
leaq 0x4203(%rip), %rsi      # 0x6881
movq %r14, 0x38(%rsp)
movq %r14, %rdi
callq 0x3bd3
leaq 0x178(%rsp), %rdi
pushq $0x1
popq %rdx
movl $0x420, %esi            # imm = 0x420
movq %rax, 0x8(%rsp)
movq %rax, %rcx
callq 0x22b0
testq %rax, %rax
je 0x29d9
movq 0x6918(%rip), %r12      # 0x8fd0
leaq 0x3b08(%rip), %r15      # 0x61c7
pushq $0x1
popq %rbp
leaq 0x3b08(%rip), %r14      # 0x61d1
leaq 0x44c3(%rip), %rdi      # 0x6b93
callq 0x22d0
movq %r12, %rdi
leaq 0x3ac6(%rip), %rsi      # 0x61a5
pushq $0x21
popq %rdx
callq 0x21e0
leaq 0x44a4(%rip), %rdi      # 0x6b92
callq 0x22d0
movslq 0x558(%rsp), %rax
movq %rax, 0x30(%rsp)
testq %rax, %rax
jle 0x27a3
leaq 0x1f4(%rsp), %r13
xorl %ebx, %ebx
movq %r13, %rdi
callq 0x20b0
movq %r12, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x21e0
movq %r12, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x21e0
movl 0x14(%r13), %esi
movq %r12, %rdi
callq 0x2330
movq %rbp, %r12
movq %r14, %rbp
movq %r15, %r14
movq %rax, %r15
movq %rax, %rdi
leaq 0x3a70(%rip), %rsi      # 0x61c9
pushq $0x7
popq %rdx
callq 0x21e0
movl 0x18(%r13), %esi
movq %r15, %rdi
movq %r14, %r15
movq %rbp, %r14
movq %r12, %rbp
movq 0x6858(%rip), %r12      # 0x8fd0
callq 0x2330
movq %r12, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x21e0
incq %rbx
movslq 0x558(%rsp), %rax
addq $0x1c, %r13
cmpq %rax, %rbx
jl 0x2713
movl $0x420, %esi            # imm = 0x420
leaq 0x178(%rsp), %rdi
movq %rbp, %rdx
movq 0x8(%rsp), %rcx
callq 0x22b0
testq %rax, %rax
jne 0x26c9
leaq 0x43c5(%rip), %rdi      # 0x6b92
callq 0x22d0
movq 0x30(%rsp), %r15
testl %r15d, %r15d
jle 0x29e5
xorl %r14d, %r14d
leaq 0x40(%rsp), %r12
xorl %ebp, %ebp
imulq $0x1c, %r14, %rax
leaq 0x1f4(%rsp), %rcx
leaq (%rcx,%rax), %rbx
movl 0x14(%rcx,%rax), %eax
cmpl $0x2, %eax
je 0x286b
cmpl $0x1, %eax
jne 0x29a9
pushq $0x4
popq %rdi
callq 0x2250
movq %rax, %r13
movq %rax, 0x80(%rsp,%r14,8)
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
andq $0x0, 0x18(%rsp)
movb $0x0, 0x20(%rsp)
movq 0x67a5(%rip), %rdi      # 0x8fe0
leaq 0x10(%rsp), %rsi
callq 0x2230
movq 0x18(%rsp), %rax
movl 0x18(%rbx), %esi
cmpq %rsi, %rax
jbe 0x293d
xorl %ebx, %ebx
leaq 0x3974(%rip), %rdi      # 0x61d3
xorl %eax, %eax
callq 0x2030
jmp 0x2986
pushq $0x33
popq %rdi
callq 0x2250
movq %rax, 0x8(%rsp)
movq %rax, 0x80(%rsp,%r14,8)
addl $0x33, %ebp
movq 0x6756(%rip), %r15      # 0x8fe0
movq (%r15), %rax
movq -0x18(%rax), %rax
movq 0x10(%r15,%rax), %r13
movq %r15, %rdi
movq %r12, %rsi
pushq $0x33
popq %rdx
callq 0x2320
movq (%r15), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x20(%r15,%rax)
jne 0x28d6
addq $-0x34, %r13
cmpq $-0x34, %r13
ja 0x28d6
movq 0x671c(%rip), %rcx      # 0x8fe0
movq 0xe8(%rcx,%rax), %rdi
movq 0x10(%rdi), %rax
cmpq 0x18(%rdi), %rax
jae 0x28fe
movq %r12, %rdi
callq 0x20b0
movl 0x18(%rbx), %ecx
cmpq %rcx, %rax
jbe 0x2929
movq 0x66e3(%rip), %rdi      # 0x8fd0
leaq 0x3904(%rip), %rsi      # 0x61f8
pushq $0x38
popq %rdx
callq 0x21e0
jmp 0x2880
movq (%rdi), %rax
callq *0x48(%rax)
cmpl $-0x1, %eax
jne 0x28d6
movq 0x66d0(%rip), %rcx      # 0x8fe0
movq (%rcx), %rax
movq -0x18(%rax), %rax
leaq (%rcx,%rax), %rdi
movl 0x20(%rcx,%rax), %esi
orl $0x2, %esi
callq 0x2310
jmp 0x28d6
movq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x2180
movq 0x30(%rsp), %r15
jmp 0x29a9
movl %eax, %ecx
decl %ecx
js 0x296e
xorl %ecx, %ecx
movq 0x10(%rsp), %rdx
pushq $0x1
popq %rsi
decl %eax
movzbl (%rdx,%rax), %edi
leal -0x3a(%rdi), %r8d
cmpb $-0xb, %r8b
jbe 0x2978
addl $-0x30, %edi
imull %esi, %edi
addl %edi, %ecx
imull $0xa, %esi, %esi
testl %eax, %eax
jg 0x294d
jmp 0x2970
xorl %ecx, %ecx
movl %ecx, (%r13)
movb $0x1, %bl
jmp 0x2986
leaq 0x4166(%rip), %rdi      # 0x6ae5
callq 0x22d0
xorl %ebx, %ebx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x29a2
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21b0
testb %bl, %bl
je 0x2a06
addl $0x4, %ebp
incq %r14
cmpq %r15, %r14
jne 0x27ea
jmp 0x29e7
leaq 0x37b7(%rip), %rdi      # 0x6175
movq %r14, %rsi
xorl %eax, %eax
addq $0x598, %rsp            # imm = 0x598
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2030
leaq 0x41b2(%rip), %rdi      # 0x6b92
callq 0x22d0
xorl %ebp, %ebp
leaq 0x80(%rsp), %rsi
movq 0x38(%rsp), %rbx
movq %rbx, %rdi
movl %ebp, %edx
callq 0x4077
movq %rbx, %rdi
callq 0x2210
addq $0x598, %rsp            # imm = 0x598
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rdi), %rax
callq *0x48(%rax)
cmpl $-0x1, %eax
jne 0x2651
movq 0x65b2(%rip), %rcx      # 0x8fe0
movq (%rcx), %rax
movq -0x18(%rax), %rax
leaq (%rcx,%rax), %rdi
movl 0x20(%rcx,%rax), %esi
orl $0x2, %esi
callq 0x2310
jmp 0x2651
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x2a69
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21b0
movq %rbx, %rdi
callq 0x2340