// File: /workspace/github_cpp_makefile_star2_O1/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 0x2a53
movq %r14, %rdi
callq 0x4079
testl %eax, %eax
je 0x27c5
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 0x3c5a
leaq 0x178(%rsp), %rdi
pushq $0x1
popq %rdx
movl $0x420, %esi            # imm = 0x420
movq %rax, 0x10(%rsp)
movq %rax, %rcx
callq 0x22b0
testq %rax, %rax
je 0x27e7
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
movl 0x558(%rsp), %eax
movl %eax, 0x8(%rsp)
testl %eax, %eax
jle 0x27a0
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 0x3a73(%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 0x685b(%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 0x2710
movl $0x420, %esi            # imm = 0x420
leaq 0x178(%rsp), %rdi
movq %rbp, %rdx
movq 0x10(%rsp), %rcx
callq 0x22b0
testq %rax, %rax
jne 0x26c9
jmp 0x27e7
leaq 0x39a9(%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 0x43a4(%rip), %rdi      # 0x6b92
callq 0x22d0
movl 0x8(%rsp), %eax
testl %eax, %eax
setg %r15b
jle 0x2a1a
leaq 0x1f4(%rsp), %r13
movl %eax, %eax
movq %rax, 0x10(%rsp)
xorl %r14d, %r14d
leaq 0x40(%rsp), %r12
xorl %ebp, %ebp
imulq $0x1c, %r14, %rax
leaq (%rax,%r13), %rbx
movl 0x14(%r13,%rax), %eax
cmpl $0x2, %eax
je 0x289b
cmpl $0x1, %eax
jne 0x2a06
movb %r15b, 0x8(%rsp)
pushq $0x4
popq %rdi
callq 0x2250
movq %rax, %r15
movq %rax, 0x80(%rsp,%r14,8)
leaq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
andq $0x0, 0x20(%rsp)
movb $0x0, 0x28(%rsp)
movq 0x6775(%rip), %rdi      # 0x8fe0
leaq 0x18(%rsp), %rsi
callq 0x2230
movq 0x20(%rsp), %rax
movl 0x18(%rbx), %esi
cmpq %rsi, %rax
jbe 0x2973
xorl %ebx, %ebx
leaq 0x3944(%rip), %rdi      # 0x61d3
xorl %eax, %eax
callq 0x2030
jmp 0x29de
pushq $0x33
popq %rdi
callq 0x2250
movq %rax, 0x8(%rsp)
movq %rax, 0x80(%rsp,%r14,8)
addl $0x33, %ebp
movq 0x6726(%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 0x2906
addq $-0x34, %r13
cmpq $-0x34, %r13
ja 0x2906
movq 0x66ec(%rip), %rcx      # 0x8fe0
movq 0xe8(%rcx,%rax), %rdi
movq 0x10(%rdi), %rax
cmpq 0x18(%rdi), %rax
jae 0x292e
movq %r12, %rdi
callq 0x20b0
movl 0x18(%rbx), %ecx
cmpq %rcx, %rax
jbe 0x2959
movq 0x66b3(%rip), %rdi      # 0x8fd0
leaq 0x38d4(%rip), %rsi      # 0x61f8
pushq $0x38
popq %rdx
callq 0x21e0
jmp 0x28b0
movq (%rdi), %rax
callq *0x48(%rax)
cmpl $-0x1, %eax
jne 0x2906
movq 0x66a0(%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 0x2906
movq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x2180
leaq 0x1f4(%rsp), %r13
jmp 0x2a06
leal -0x1(%rax), %edx
movl %edx, %ebx
shrl $0x1f, %ebx
testl %edx, %edx
js 0x29d9
movq 0x18(%rsp), %rcx
movl %edx, %edx
movb (%rcx,%rdx), %sil
leal -0x3a(%rsi), %edx
cmpb $-0xa, %dl
jb 0x29cb
addl $-0x2, %eax
xorl %edx, %edx
pushq $0x1
popq %rdi
movl %edx, %r8d
leal 0x1(%rax), %r9d
movzbl %sil, %edx
addl $-0x30, %edx
imull %edi, %edx
addl %r8d, %edx
testl %r9d, %r9d
setle %bl
jle 0x29db
imull $0xa, %edi, %edi
movl %eax, %esi
movb (%rcx,%rsi), %sil
leal -0x3a(%rsi), %r8d
decl %eax
cmpb $-0xb, %r8b
ja 0x299a
leaq 0x4113(%rip), %rdi      # 0x6ae5
callq 0x22d0
jmp 0x29de
xorl %edx, %edx
movl %edx, (%r15)
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x29fa
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21b0
addl $0x4, %ebp
testb %bl, %bl
movb 0x8(%rsp), %r15b
je 0x2a1c
incq %r14
cmpq 0x10(%rsp), %r14
setb %r15b
jne 0x281c
jmp 0x2a1c
xorl %ebp, %ebp
testb $0x1, %r15b
jne 0x2a41
leaq 0x80(%rsp), %rsi
movq 0x38(%rsp), %rbx
movq %rbx, %rdi
movl %ebp, %edx
callq 0x40d1
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 0x6577(%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 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x2aa4
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21b0
movq %rbx, %rdi
callq 0x2340