// File: zimpha[P]MiniSQL/API.cc
// Function: API::createIndex(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
Response API::createIndex(const std::string &indexName, const std::string &tableName, const std::string &attrName) {
    if (!cm.hasTable(tableName + ".table")) {
        return Response("Table does not exist");
    }
    Table nt = cm.loadTable(tableName + ".table");
    int attrIndex = -1;
    for (size_t i = 0; i < nt.attributes.size(); ++ i) {
        if (nt.attributes[i].name == attrName) {
            attrIndex = i;
            break;
        }
    }
    if (attrIndex == -1) {
        return Response("Attribute does not exist");
    }
    if (!nt.attributes[attrIndex].unique) {
        return Response("This attribute must be unique");
    }
    if (!cm.createIndex(tableName, indexName, attrIndex)) {
        return Response("This index already exists");
    }
    nt.attributes[attrIndex].indices.insert(indexName);
    nt.write();
    if (nt.attributes[attrIndex].indices.size() == 1) {
        // Index Manager add index
        // 提供index文件名和当前表，以及attrIndex给Record Manager
        // rmAddIndex(tableName+".db",tableName+"."+nt.attributes[attrIndex].name+".index",nt,attrIndex);
        im.create(tableName+"."+nt.attributes[attrIndex].name, tableName+".db", nt, nt.attributes[attrIndex]);
    }
    return Response();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2a0, %rsp            # imm = 0x2A0
movq %rdi, -0x248(%rbp)
movq %rdi, %rax
movq %rax, -0x240(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x238(%rbp)
movq -0x20(%rbp), %rsi
leaq 0x2347f(%rip), %rdx     # 0x27035
leaq -0x48(%rbp), %rdi
movq %rdi, -0x230(%rbp)
callq 0x76d0
movq -0x238(%rbp), %rdi
movq -0x230(%rbp), %rsi
callq 0x1b550
movb %al, -0x221(%rbp)
jmp 0x3be1
movb -0x221(%rbp), %al
xorb $-0x1, %al
movb %al, -0x249(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x35b8
movb -0x249(%rbp), %al
testb $0x1, %al
jne 0x3c07
jmp 0x3ca4
leaq -0x79(%rbp), %rdi
movq %rdi, -0x258(%rbp)
callq 0x3500
movq -0x258(%rbp), %rdx
leaq 0x23417(%rip), %rsi     # 0x2703c
leaq -0x78(%rbp), %rdi
callq 0x3400
jmp 0x3c30
movq -0x248(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x24ba0
jmp 0x3c42
leaq -0x78(%rbp), %rdi
callq 0x35b8
leaq -0x79(%rbp), %rdi
callq 0x3320
jmp 0x41db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x35b8
jmp 0x41eb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x3c96
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x35b8
leaq -0x79(%rbp), %rdi
callq 0x3320
jmp 0x41eb
movq -0x20(%rbp), %rsi
leaq 0x23386(%rip), %rdx     # 0x27035
leaq -0xe8(%rbp), %rdi
movq %rdi, -0x260(%rbp)
callq 0x76d0
movq -0x238(%rbp), %rsi
movq -0x260(%rbp), %rdx
leaq -0xc8(%rbp), %rdi
callq 0x1b750
jmp 0x3cde
leaq -0xe8(%rbp), %rdi
callq 0x35b8
movl $0xffffffff, -0xec(%rbp) # imm = 0xFFFFFFFF
movq $0x0, -0xf8(%rbp)
movq -0xf8(%rbp), %rax
movq %rax, -0x268(%rbp)
leaq -0xc8(%rbp), %rdi
addq $0x28, %rdi
callq 0x7750
movq %rax, %rcx
movq -0x268(%rbp), %rax
cmpq %rcx, %rax
jae 0x3d9a
leaq -0xc8(%rbp), %rdi
addq $0x28, %rdi
movq -0xf8(%rbp), %rsi
callq 0x7810
movq %rax, %rdi
movq -0x28(%rbp), %rsi
callq 0x7780
testb $0x1, %al
jne 0x3d55
jmp 0x3d81
movq -0xf8(%rbp), %rax
movl %eax, -0xec(%rbp)
jmp 0x3d9a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x35b8
jmp 0x41eb
jmp 0x3d83
movq -0xf8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xf8(%rbp)
jmp 0x3cff
cmpl $-0x1, -0xec(%rbp)
jne 0x3e49
leaq -0x119(%rbp), %rdi
movq %rdi, -0x270(%rbp)
callq 0x3500
movq -0x270(%rbp), %rdx
leaq 0x23289(%rip), %rsi     # 0x27051
leaq -0x118(%rbp), %rdi
callq 0x3400
jmp 0x3dd6
movq -0x248(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x24ba0
jmp 0x3deb
leaq -0x118(%rbp), %rdi
callq 0x35b8
leaq -0x119(%rbp), %rdi
callq 0x3320
movl $0x1, -0x120(%rbp)
jmp 0x41bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x3e38
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x35b8
leaq -0x119(%rbp), %rdi
callq 0x3320
jmp 0x41cd
leaq -0xc8(%rbp), %rdi
addq $0x28, %rdi
movslq -0xec(%rbp), %rsi
callq 0x7810
testb $0x1, 0x28(%rax)
jne 0x3f0c
leaq -0x141(%rbp), %rdi
movq %rdi, -0x278(%rbp)
callq 0x3500
movq -0x278(%rbp), %rdx
leaq 0x231df(%rip), %rsi     # 0x2706a
leaq -0x140(%rbp), %rdi
callq 0x3400
jmp 0x3e99
movq -0x248(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x24ba0
jmp 0x3eae
leaq -0x140(%rbp), %rdi
callq 0x35b8
leaq -0x141(%rbp), %rdi
callq 0x3320
movl $0x1, -0x120(%rbp)
jmp 0x41bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x3efb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x140(%rbp), %rdi
callq 0x35b8
leaq -0x141(%rbp), %rdi
callq 0x3320
jmp 0x41cd
movq -0x238(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rdx
movl -0xec(%rbp), %ecx
callq 0x1beb0
movb %al, -0x279(%rbp)
jmp 0x3f2e
movb -0x279(%rbp), %al
testb $0x1, %al
jne 0x3ff1
jmp 0x3f3e
leaq -0x169(%rbp), %rdi
movq %rdi, -0x288(%rbp)
callq 0x3500
movq -0x288(%rbp), %rdx
leaq 0x23129(%rip), %rsi     # 0x27088
leaq -0x168(%rbp), %rdi
callq 0x3400
jmp 0x3f6d
movq -0x248(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0x24ba0
jmp 0x3f82
leaq -0x168(%rbp), %rdi
callq 0x35b8
leaq -0x169(%rbp), %rdi
callq 0x3320
movl $0x1, -0x120(%rbp)
jmp 0x41bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x41cd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x3fe0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x168(%rbp), %rdi
callq 0x35b8
leaq -0x169(%rbp), %rdi
callq 0x3320
jmp 0x41cd
leaq -0xa0(%rbp), %rdi
movslq -0xec(%rbp), %rsi
callq 0x7810
movq %rax, %rdi
addq $0x30, %rdi
movq -0x18(%rbp), %rsi
callq 0x7830
movb %dl, -0x291(%rbp)
movq %rax, -0x290(%rbp)
jmp 0x4023
movb -0x291(%rbp), %al
movq -0x290(%rbp), %rcx
movq %rcx, -0x180(%rbp)
movb %al, -0x178(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x240c0
jmp 0x404b
leaq -0xc8(%rbp), %rdi
addq $0x28, %rdi
movslq -0xec(%rbp), %rsi
callq 0x7810
movq %rax, %rdi
addq $0x30, %rdi
callq 0x7880
cmpq $0x1, %rax
jne 0x41a7
movq -0x238(%rbp), %rax
addq $0x40, %rax
movq %rax, -0x2a0(%rbp)
movq -0x20(%rbp), %rsi
leaq 0x231f5(%rip), %rdx     # 0x2728a
leaq -0x200(%rbp), %rdi
callq 0x76d0
jmp 0x40a3
leaq -0xa0(%rbp), %rdi
movslq -0xec(%rbp), %rsi
callq 0x7810
movq %rax, %rdx
leaq -0x1e0(%rbp), %rdi
leaq -0x200(%rbp), %rsi
callq 0x78a0
jmp 0x40ce
movq -0x20(%rbp), %rsi
leaq 0x22fc9(%rip), %rdx     # 0x270a2
leaq -0x220(%rbp), %rdi
callq 0x76d0
jmp 0x40e7
leaq -0xa0(%rbp), %rdi
movslq -0xec(%rbp), %rsi
callq 0x7810
movq -0x2a0(%rbp), %rsi
movq %rax, %r9
leaq -0x1c0(%rbp), %rdi
leaq -0x1e0(%rbp), %rdx
leaq -0x220(%rbp), %rcx
leaq -0xc8(%rbp), %r8
callq 0x136b0
jmp 0x4127
leaq -0x1c0(%rbp), %rdi
callq 0x78f0
leaq -0x220(%rbp), %rdi
callq 0x35b8
leaq -0x1e0(%rbp), %rdi
callq 0x35b8
leaq -0x200(%rbp), %rdi
callq 0x35b8
jmp 0x41a7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x4199
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x418d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x220(%rbp), %rdi
callq 0x35b8
leaq -0x1e0(%rbp), %rdi
callq 0x35b8
leaq -0x200(%rbp), %rdi
callq 0x35b8
jmp 0x41cd
movq -0x248(%rbp), %rdi
callq 0x24b60
jmp 0x41b5
movl $0x1, -0x120(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x7920
jmp 0x41db
leaq -0xc8(%rbp), %rdi
callq 0x7920
jmp 0x41eb
movq -0x240(%rbp), %rax
addq $0x2a0, %rsp            # imm = 0x2A0
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x34f0
nopw %cs:(%rax,%rax)