// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
movq %r8, %r13
movq %rcx, %r15
movq %rdx, -0x38(%rbp)
movq %rsi, %r14
movq %rdi, %rbx
leaq 0xd6e4(%rip), %rdx      # 0x11051
leaq -0xb0(%rbp), %r12
movq %r12, %rdi
movq %rcx, %rsi
callq 0x5d7d
movq %r14, %rdi
movq %r12, %rsi
callq 0xb838
movl %eax, %r12d
leaq -0xb0(%rbp), %rdi
callq 0x34f8
testb %r12b, %r12b
je 0x3a2c
movq %rbx, -0x30(%rbp)
leaq 0xd6a4(%rip), %rdx      # 0x11051
leaq -0x58(%rbp), %r12
movq %r12, %rdi
movq %r15, -0x60(%rbp)
movq %r15, %rsi
callq 0x5d7d
leaq -0xb0(%rbp), %rdi
movq %r14, -0x68(%rbp)
movq %r14, %rsi
movq %r12, %rdx
callq 0xb966
leaq -0x58(%rbp), %rdi
callq 0x34f8
xorl %r14d, %r14d
pushq $0x60
popq %r15
xorl %ebx, %ebx
xorl %r12d, %r12d
movq -0x88(%rbp), %rdi
movq -0x80(%rbp), %rax
subq %rdi, %rax
cqto
idivq %r15
cmpq %rax, %r12
jae 0x3b91
addq %r14, %rdi
movq %r13, %rsi
callq 0x5db5
testb %al, %al
jne 0x3a66
incq %r12
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %rbx
addq $0x60, %r14
jmp 0x39eb
leaq 0xd625(%rip), %rsi      # 0x11058
leaq -0x170(%rbp), %rdi
leaq -0xb0(%rbp), %rdx
callq 0x30e0
leaq -0x170(%rbp), %rsi
movq %rbx, %rdi
callq 0xfde4
leaq -0x170(%rbp), %rdi
callq 0x34f8
jmp 0x3bd3
cmpl $-0x1, %r12d
je 0x3b91
sarq $0x20, %rbx
movq -0x88(%rbp), %rax
imulq $0x60, %rbx, %r13
cmpb $0x0, 0x28(%rax,%r13)
je 0x3be8
movq -0x68(%rbp), %r14
movq %r14, %rdi
movq -0x60(%rbp), %r15
movq %r15, %rsi
movq -0x38(%rbp), %rdx
movl %r12d, %ecx
callq 0xbe0e
movq -0x30(%rbp), %rbx
testb %al, %al
je 0x3c1b
movq -0x88(%rbp), %rax
leaq (%rax,%r13), %rdi
addq $0x30, %rdi
movq -0x38(%rbp), %rsi
callq 0x6e2e
leaq -0xb0(%rbp), %rdi
callq 0xf884
movq -0x88(%rbp), %rax
cmpq $0x1, 0x58(%rax,%r13)
jne 0x3b87
leaq 0xd7b7(%rip), %rdx      # 0x112a6
leaq -0xf0(%rbp), %rdi
movq %r15, %rsi
callq 0x5d7d
movq -0x88(%rbp), %rdx
addq %r13, %rdx
leaq -0x58(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x5dd8
leaq 0xd59f(%rip), %rdx      # 0x110be
leaq -0xd0(%rbp), %rdi
movq %r15, %rsi
callq 0x5d7d
addq $0x40, %r14
leaq -0xb0(%rbp), %r8
addq 0x28(%r8), %r13
leaq -0x1b0(%rbp), %rdi
leaq -0x58(%rbp), %rdx
leaq -0xd0(%rbp), %rcx
movq %r14, %rsi
movq %r13, %r9
callq 0x969e
leaq -0x1b0(%rbp), %rdi
callq 0x5e02
leaq -0xd0(%rbp), %rdi
callq 0x34f8
leaq -0x58(%rbp), %rdi
callq 0x34f8
leaq -0xf0(%rbp), %rdi
callq 0x34f8
movq %rbx, %rdi
callq 0xfdbe
jmp 0x3bc7
leaq 0xd4d5(%rip), %rsi      # 0x1106d
leaq -0x150(%rbp), %rdi
leaq -0x58(%rbp), %rdx
callq 0x30e0
leaq -0x150(%rbp), %rsi
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
callq 0xfde4
leaq -0x150(%rbp), %rdi
callq 0x34f8
leaq -0xb0(%rbp), %rdi
callq 0x5e26
movq %rbx, %rax
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd497(%rip), %rsi      # 0x11086
leaq -0x130(%rbp), %rdi
leaq -0x58(%rbp), %rdx
callq 0x30e0
movq -0x30(%rbp), %rbx
leaq -0x130(%rbp), %rsi
movq %rbx, %rdi
callq 0xfde4
leaq -0x130(%rbp), %rdi
jmp 0x3bc2
leaq 0xd482(%rip), %rsi      # 0x110a4
leaq -0x110(%rbp), %rdi
leaq -0x58(%rbp), %rdx
callq 0x30e0
leaq -0x110(%rbp), %rsi
movq %rbx, %rdi
callq 0xfde4
leaq -0x110(%rbp), %rdi
jmp 0x3bc2
movq %rax, %rbx
leaq -0xd0(%rbp), %rdi
callq 0x34f8
jmp 0x3c61
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x34f8
jmp 0x3c6f
movq %rax, %rbx
leaq -0xf0(%rbp), %rdi
jmp 0x3ca2
jmp 0x3ca9
movq %rax, %rbx
leaq -0x110(%rbp), %rdi
jmp 0x3ca2
jmp 0x3ca9
movq %rax, %rbx
leaq -0x130(%rbp), %rdi
jmp 0x3ca2
jmp 0x3ca9
jmp 0x3ca9
movq %rax, %rbx
leaq -0x150(%rbp), %rdi
callq 0x34f8
jmp 0x3cac
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
callq 0x5e26
jmp 0x3ce3
movq %rax, %rbx
leaq -0x170(%rbp), %rdi
jmp 0x3cde
movq %rax, %rbx
jmp 0x3ce3
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
jmp 0x3cde
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
callq 0x34f8
movq %rbx, %rdi
callq 0x3450
nop