// File: Konano[P]UselessDatabase/main.cpp
// Function: import_data(Table*, char const*, char)
void import_data(Table* table, const char* filename, char separator) {
    printf("%s\n",filename);
    ifstream inFile(filename, ios::in);
    string line;
    string field;
    int cnt = 0;
    Any* data = new Any[table->col_num];
    while (getline(inFile, line)) {
        istringstream sin(line); 
        memset(data, 0, table->col_num * sizeof(Any));
        for (uint i = 0; i < table->col_num; i++) {
            getline(sin, field, separator);  
            switch (table->col_ty[i].ty) {
            case INT:
                data[i] = atoi(field.c_str());
                break;
            case CHAR:
            case VARCHAR:
                data[i] = copyStr(field.c_str());
                break;
            case DATE:
                data[i] = date_to_uint(field);
                break;
            case DECIMAL:
                data[i] = strtold(field.c_str(), NULL);
                break;
            }
        }
        //table->index[table->p_key_index].Debug();
        int x = table->insertRecord(data);
        if (x != 0){
            if(data[0].anyCast<int>() != nullptr)
            printf("id:%d\n",*data[0].anyCast<int>());
            if(data[1].anyCast<char*>() != nullptr)
            printf("%s\n",*data[1].anyCast<char*>());
            printf("fail %d\n",x);
        }
        //table->index[table->p_key_index].Debug();
        cnt++;
    }
    delete []data;
    inFile.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x510, %rsp            # imm = 0x510
movb %dl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb %al, -0x11(%rbp)
movq -0x10(%rbp), %rsi
leaq 0x2bdf8(%rip), %rdi     # 0x8689b
xorl %eax, %eax
callq 0x6090
movq -0x10(%rbp), %rsi
leaq -0x220(%rbp), %rdi
movl $0x8, %edx
callq 0x68e0
leaq -0x240(%rbp), %rdi
callq 0x66b0
leaq -0x260(%rbp), %rdi
callq 0x66b0
movl $0x0, -0x264(%rbp)
movq -0x8(%rbp), %rax
movl 0x54(%rax), %eax
movq %rax, -0x470(%rbp)
leaq 0x8(,%rax,8), %rdi
movq %rdi, -0x468(%rbp)
callq 0x6040
movq %rax, -0x460(%rbp)
jmp 0x5ab0c
movq -0x470(%rbp), %rax
movq -0x460(%rbp), %rcx
movq %rax, (%rcx)
addq $0x8, %rcx
movq %rcx, -0x478(%rbp)
cmpq $0x0, %rax
je 0x5ab87
movq -0x478(%rbp), %rax
movq -0x470(%rbp), %rdx
shlq $0x3, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, -0x488(%rbp)
movq %rax, -0x480(%rbp)
movq -0x480(%rbp), %rdi
movq %rdi, -0x490(%rbp)
callq 0xd240
jmp 0x5ab69
movq -0x488(%rbp), %rcx
movq -0x490(%rbp), %rax
addq $0x8, %rax
cmpq %rcx, %rax
movq %rax, -0x480(%rbp)
jne 0x5ab54
movq -0x478(%rbp), %rax
movq %rax, -0x270(%rbp)
leaq -0x220(%rbp), %rdi
leaq -0x240(%rbp), %rsi
callq 0x6120
movq %rax, -0x498(%rbp)
jmp 0x5abb1
movq -0x498(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x6610
movb %al, -0x499(%rbp)
jmp 0x5abcf
movb -0x499(%rbp), %al
testb $0x1, %al
jne 0x5abde
jmp 0x5afb2
leaq -0x400(%rbp), %rdi
leaq -0x240(%rbp), %rsi
movl $0x8, %edx
callq 0x6840
jmp 0x5abf8
movq -0x270(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x54(%rax), %eax
movl %eax, %edx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x62c0
movl $0x0, -0x404(%rbp)
movl -0x404(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x54(%rcx), %eax
jae 0x5ae8b
movsbl -0x11(%rbp), %edx
leaq -0x400(%rbp), %rdi
leaq -0x260(%rbp), %rsi
callq 0x6900
jmp 0x5ac49
movq -0x8(%rbp), %rax
movl -0x404(%rbp), %ecx
imulq $0x38, %rcx, %rcx
movl 0x7c(%rax,%rcx), %eax
movq %rax, -0x4a8(%rbp)
subq $0x4, %rax
ja 0x5ae75
movq -0x4a8(%rbp), %rax
leaq 0x291ae(%rip), %rcx     # 0x83e28
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x278(%rbp)
movl %eax, -0x27c(%rbp)
jmp 0x5b087
movq -0x478(%rbp), %rcx
movq %rax, %rsi
movq -0x490(%rbp), %rax
movq %rsi, -0x278(%rbp)
movl %edx, -0x27c(%rbp)
cmpq %rax, %rcx
movq %rax, -0x4b0(%rbp)
je 0x5acf5
movq -0x4b0(%rbp), %rdi
addq $-0x8, %rdi
movq %rdi, -0x4b8(%rbp)
callq 0xc3c0
movq -0x478(%rbp), %rcx
movq -0x4b8(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x4b0(%rbp)
jne 0x5acc4
movq -0x468(%rbp), %rsi
movq -0x460(%rbp), %rdi
callq 0x6970
jmp 0x5b087
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x278(%rbp)
movl %eax, -0x27c(%rbp)
jmp 0x5afa1
leaq -0x260(%rbp), %rdi
callq 0x6210
movq %rax, %rdi
callq 0x6790
movl %eax, -0x408(%rbp)
movq -0x270(%rbp), %rax
movl -0x404(%rbp), %ecx
leaq (%rax,%rcx,8), %rdi
leaq -0x408(%rbp), %rsi
callq 0x52f60
jmp 0x5ad5d
jmp 0x5ae75
leaq -0x260(%rbp), %rdi
callq 0x6210
movq %rax, %rdi
callq 0x61500
movq %rax, -0x4c0(%rbp)
jmp 0x5ad7f
movq -0x4c0(%rbp), %rax
movq %rax, -0x410(%rbp)
movq -0x270(%rbp), %rax
movl -0x404(%rbp), %ecx
leaq (%rax,%rcx,8), %rdi
leaq -0x410(%rbp), %rsi
callq 0x52fe0
jmp 0x5adac
jmp 0x5ae75
leaq -0x438(%rbp), %rdi
leaq -0x260(%rbp), %rsi
callq 0x6240
jmp 0x5adc6
leaq -0x438(%rbp), %rdi
callq 0x61550
movl %eax, -0x4c4(%rbp)
jmp 0x5adda
movl -0x4c4(%rbp), %eax
movl %eax, -0x414(%rbp)
movq -0x270(%rbp), %rax
movl -0x404(%rbp), %ecx
leaq (%rax,%rcx,8), %rdi
leaq -0x414(%rbp), %rsi
callq 0x53060
jmp 0x5ae05
leaq -0x438(%rbp), %rdi
callq 0x6340
jmp 0x5ae75
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x278(%rbp)
movl %eax, -0x27c(%rbp)
leaq -0x438(%rbp), %rdi
callq 0x6340
jmp 0x5afa1
leaq -0x260(%rbp), %rdi
callq 0x6210
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x69d8
fstpt -0x450(%rbp)
movq -0x270(%rbp), %rax
movl -0x404(%rbp), %ecx
leaq (%rax,%rcx,8), %rdi
leaq -0x450(%rbp), %rsi
callq 0x530e0
jmp 0x5ae73
jmp 0x5ae75
jmp 0x5ae77
movl -0x404(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x404(%rbp)
jmp 0x5ac1d
movq -0x8(%rbp), %rdi
movq -0x270(%rbp), %rsi
callq 0x499c0
movl %eax, -0x4c8(%rbp)
jmp 0x5aea3
movl -0x4c8(%rbp), %eax
movl %eax, -0x454(%rbp)
cmpl $0x0, -0x454(%rbp)
je 0x5af81
movq -0x270(%rbp), %rdi
callq 0x10b40
movq %rax, -0x4d0(%rbp)
jmp 0x5aed1
movq -0x4d0(%rbp), %rax
cmpq $0x0, %rax
je 0x5af0e
movq -0x270(%rbp), %rdi
callq 0x10b40
movq %rax, -0x4d8(%rbp)
jmp 0x5aef3
movq -0x4d8(%rbp), %rax
movl (%rax), %esi
leaq 0x28f39(%rip), %rdi     # 0x83e3c
xorl %eax, %eax
callq 0x6090
jmp 0x5af0c
jmp 0x5af0e
movq -0x270(%rbp), %rdi
addq $0x8, %rdi
callq 0x10a50
movq %rax, -0x4e0(%rbp)
jmp 0x5af27
movq -0x4e0(%rbp), %rax
cmpq $0x0, %rax
je 0x5af69
movq -0x270(%rbp), %rdi
addq $0x8, %rdi
callq 0x10a50
movq %rax, -0x4e8(%rbp)
jmp 0x5af4d
movq -0x4e8(%rbp), %rax
movq (%rax), %rsi
leaq 0x2b93d(%rip), %rdi     # 0x8689b
xorl %eax, %eax
callq 0x6090
jmp 0x5af67
jmp 0x5af69
movl -0x454(%rbp), %esi
leaq 0x2b73f(%rip), %rdi     # 0x866b5
xorl %eax, %eax
callq 0x6090
jmp 0x5af7f
jmp 0x5af81
movl -0x264(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x264(%rbp)
leaq -0x400(%rbp), %rdi
callq 0x6290
jmp 0x5ab95
leaq -0x400(%rbp), %rdi
callq 0x6290
jmp 0x5b087
movq -0x270(%rbp), %rax
movq %rax, -0x4f0(%rbp)
cmpq $0x0, %rax
je 0x5b04c
movq -0x4f0(%rbp), %rcx
movq %rcx, %rax
addq $-0x8, %rax
movq %rax, -0x508(%rbp)
movq -0x8(%rcx), %rdx
movq %rdx, -0x500(%rbp)
shlq $0x3, %rdx
movq %rcx, %rax
addq %rdx, %rax
cmpq %rax, %rcx
movq %rax, -0x4f8(%rbp)
je 0x5b031
movq -0x4f8(%rbp), %rdi
addq $-0x8, %rdi
movq %rdi, -0x510(%rbp)
callq 0xc3c0
movq -0x4f0(%rbp), %rcx
movq -0x510(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x4f8(%rbp)
jne 0x5b000
movq -0x508(%rbp), %rdi
movq -0x500(%rbp), %rsi
shlq $0x3, %rsi
addq $0x8, %rsi
callq 0x6970
leaq -0x220(%rbp), %rdi
callq 0x6130
jmp 0x5b05a
leaq -0x260(%rbp), %rdi
callq 0x6340
leaq -0x240(%rbp), %rdi
callq 0x6340
leaq -0x220(%rbp), %rdi
callq 0x6150
addq $0x510, %rsp            # imm = 0x510
popq %rbp
retq
leaq -0x260(%rbp), %rdi
callq 0x6340
leaq -0x240(%rbp), %rdi
callq 0x6340
leaq -0x220(%rbp), %rdi
callq 0x6150
movq -0x278(%rbp), %rdi
callq 0x6890
nopw (%rax,%rax)