// File: zimpha[P]MiniSQL/API.cc
// Function: API::Insert(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::vector<element, std::allocator<element>>)
Response API::Insert(const std::string &tableName, const std::vector<element> entry) {
    if (!cm.hasTable(tableName + ".table")) {
        return Response("Table does not exist");
    }
    Table nt = cm.loadTable(tableName + ".table");
    std::string dbName = tableName + ".db";
    if (nt.attributes.size() != entry.size()) {
        return Response("Type mismatch");
    }
    
    for (size_t i = 0; i < nt.attributes.size(); ++ i) {
        if (nt.attributes[i].unique) {
            Filter filter;
            filter.addRule(Rule(i, 2, entry[i]));
            Response tmp = Select(tableName, filter);
            if (!tmp.result.empty()) {
                return Response("unique integrity violation");
            }
        }
    }
    // Record Manager insert record
    // 传入数据库文件名(dbName)，插入数据(entry)，当前表格(nt)
    rm.RecordManagerRecordInsert(dbName, entry, nt);
    // NOTE: table information may be changed after that
    return Response();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2b0, %rsp            # imm = 0x2B0
movq %rcx, -0x268(%rbp)
movq %rdi, -0x260(%rbp)
movq %rdi, %rax
movq %rax, -0x258(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x250(%rbp)
movq -0x18(%rbp), %rsi
leaq 0x1ff4c(%rip), %rdx     # 0x27035
leaq -0x40(%rbp), %rdi
movq %rdi, -0x248(%rbp)
callq 0x76d0
movq -0x250(%rbp), %rdi
movq -0x248(%rbp), %rsi
callq 0x1b550
movb %al, -0x239(%rbp)
jmp 0x7114
movb -0x239(%rbp), %al
xorb $-0x1, %al
movb %al, -0x269(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x35b8
movb -0x269(%rbp), %al
testb $0x1, %al
jne 0x713a
jmp 0x71d7
leaq -0x71(%rbp), %rdi
movq %rdi, -0x278(%rbp)
callq 0x3500
movq -0x278(%rbp), %rdx
leaq 0x1fee4(%rip), %rsi     # 0x2703c
leaq -0x70(%rbp), %rdi
callq 0x3400
jmp 0x7163
movq -0x260(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x24ba0
jmp 0x7175
leaq -0x70(%rbp), %rdi
callq 0x35b8
leaq -0x71(%rbp), %rdi
callq 0x3320
jmp 0x7675
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x35b8
jmp 0x7685
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x71c9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x35b8
leaq -0x71(%rbp), %rdi
callq 0x3320
jmp 0x7685
movq -0x18(%rbp), %rsi
leaq 0x1fe53(%rip), %rdx     # 0x27035
leaq -0xe0(%rbp), %rdi
movq %rdi, -0x280(%rbp)
callq 0x76d0
movq -0x250(%rbp), %rsi
movq -0x280(%rbp), %rdx
leaq -0xc0(%rbp), %rdi
callq 0x1b750
jmp 0x7211
leaq -0xe0(%rbp), %rdi
callq 0x35b8
movq -0x18(%rbp), %rsi
leaq 0x1fe7a(%rip), %rdx     # 0x270a2
leaq -0x100(%rbp), %rdi
callq 0x76d0
jmp 0x7236
leaq -0xc0(%rbp), %rdi
addq $0x28, %rdi
callq 0x7750
movq -0x268(%rbp), %rdi
movq %rax, -0x288(%rbp)
callq 0x8230
movq %rax, %rcx
movq -0x288(%rbp), %rax
cmpq %rcx, %rax
je 0x733c
leaq -0x121(%rbp), %rdi
movq %rdi, -0x290(%rbp)
callq 0x3500
movq -0x290(%rbp), %rdx
leaq 0x1fec8(%rip), %rsi     # 0x27155
leaq -0x120(%rbp), %rdi
callq 0x3400
jmp 0x729b
movq -0x260(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x24ba0
jmp 0x72b0
leaq -0x120(%rbp), %rdi
callq 0x35b8
leaq -0x121(%rbp), %rdi
callq 0x3320
movl $0x1, -0x128(%rbp)
jmp 0x7641
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x35b8
jmp 0x7685
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x7667
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x732b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x35b8
leaq -0x121(%rbp), %rdi
callq 0x3320
jmp 0x765b
movq $0x0, -0x130(%rbp)
movq -0x130(%rbp), %rax
movq %rax, -0x298(%rbp)
leaq -0xc0(%rbp), %rdi
addq $0x28, %rdi
callq 0x7750
movq %rax, %rcx
movq -0x298(%rbp), %rax
cmpq %rcx, %rax
jae 0x75b7
leaq -0xc0(%rbp), %rdi
addq $0x28, %rdi
movq -0x130(%rbp), %rsi
callq 0x7810
testb $0x1, 0x28(%rax)
je 0x759e
leaq -0x148(%rbp), %rdi
callq 0x1d8a0
jmp 0x73a7
movq -0x268(%rbp), %rdi
movq -0x130(%rbp), %rsi
movl %esi, %eax
movl %eax, -0x29c(%rbp)
callq 0x8260
movq %rax, %rsi
leaq -0x1b0(%rbp), %rdi
callq 0x7aa0
jmp 0x73d3
movl -0x29c(%rbp), %esi
leaq -0x180(%rbp), %rdi
movl $0x2, %edx
leaq -0x1b0(%rbp), %rcx
callq 0x1d860
jmp 0x73f3
leaq -0x148(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x1d8c0
jmp 0x7408
leaq -0x180(%rbp), %rdi
callq 0x7f90
leaq -0x1b0(%rbp), %rdi
callq 0x7af0
movq -0x250(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x1f0(%rbp), %rdi
leaq -0x148(%rbp), %rcx
callq 0x4b60
jmp 0x7440
leaq -0x1f0(%rbp), %rdi
addq $0x28, %rdi
callq 0x8280
testb $0x1, %al
jne 0x7559
leaq -0x211(%rbp), %rdi
movq %rdi, -0x2a8(%rbp)
callq 0x3500
movq -0x2a8(%rbp), %rdx
leaq 0x1fd64(%rip), %rsi     # 0x271dd
leaq -0x210(%rbp), %rdi
callq 0x3400
jmp 0x7487
movq -0x260(%rbp), %rdi
leaq -0x210(%rbp), %rsi
callq 0x24ba0
jmp 0x749c
leaq -0x210(%rbp), %rdi
callq 0x35b8
leaq -0x211(%rbp), %rdi
callq 0x3320
movl $0x1, -0x128(%rbp)
jmp 0x7563
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x765b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x758d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x750b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x180(%rbp), %rdi
callq 0x7f90
leaq -0x1b0(%rbp), %rdi
callq 0x7af0
jmp 0x758d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x753f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x210(%rbp), %rdi
callq 0x35b8
leaq -0x211(%rbp), %rdi
callq 0x3320
leaq -0x1f0(%rbp), %rdi
callq 0x78f0
jmp 0x758d
movl $0x0, -0x128(%rbp)
leaq -0x1f0(%rbp), %rdi
callq 0x78f0
leaq -0x148(%rbp), %rdi
callq 0x82c0
movl -0x128(%rbp), %eax
testl %eax, %eax
jne 0x7641
jmp 0x758b
jmp 0x759e
leaq -0x148(%rbp), %rdi
callq 0x82c0
jmp 0x765b
jmp 0x75a0
movq -0x130(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x130(%rbp)
jmp 0x7347
movq -0x250(%rbp), %rax
addq $0x30, %rax
movq %rax, -0x2b0(%rbp)
leaq -0x238(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x3130
jmp 0x75de
movq -0x268(%rbp), %rdx
movq -0x2b0(%rbp), %rdi
leaq -0x238(%rbp), %rsi
leaq -0xc0(%rbp), %rcx
callq 0x22bb0
jmp 0x7601
leaq -0x238(%rbp), %rdi
callq 0x35b8
movq -0x260(%rbp), %rdi
callq 0x24b60
jmp 0x761b
movl $0x1, -0x128(%rbp)
jmp 0x7641
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x238(%rbp), %rdi
callq 0x35b8
jmp 0x765b
leaq -0x100(%rbp), %rdi
callq 0x35b8
leaq -0xc0(%rbp), %rdi
callq 0x7920
jmp 0x7675
leaq -0x100(%rbp), %rdi
callq 0x35b8
leaq -0xc0(%rbp), %rdi
callq 0x7920
jmp 0x7685
movq -0x258(%rbp), %rax
addq $0x2b0, %rsp            # imm = 0x2B0
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x34f0
nop