// File: /workspace/github_cpp_makefile_star2_O1/Lartu[P]coraldb/source/execute.cpp
// Function: execute_command(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, unsigned int)
int execute_command(std::string &command, unsigned int socket_fd)
{
    std::vector<std::string> tokens;
    std::string current_token = "";
    bool string_open = false;
    for (unsigned int i = 0; i < command.length(); ++i)
    {
        if (command[i] == '\\' && i < command.length() - 1 && command[i + 1] == '"')
        {
            current_token += command[i + 1];
            ++i;
        }
        else if (command[i] == '"')
        {
            string_open = !string_open;
            if (!string_open)
            {
                tokens.push_back(current_token);
                current_token.clear();
            }
        }
        else if (command[i] == ' ' && !string_open)
        {
            if (!current_token.empty())
            {
                tokens.push_back(current_token);
                current_token.clear();
            }
        }
        else
        {
            current_token += command[i];
        }
    }
    if (!current_token.empty())
    {
        tokens.push_back(current_token);
        current_token.clear();
    }

    if (display_tokens)
    {
        std::cerr << "\x1B[97;42m Message Received: " << command.length() << " bytes + \\n \033[0m" << std::endl;
        std::cerr << "\x1B[97;100m" << command << "\033[0m" << std::endl;
        std::cerr << "\x1B[33mThe message contains " << tokens.size() << " tokens.\033[0m" << std::endl;
        for (unsigned int i = 0; i < tokens.size(); ++i)
        {
            std::cerr << "\x1B[32mToken Number " << (i + 1) << ":\033[0m ";
            std::cerr << "\x1B[97;100m" << tokens[i] << "\033[0m" << std::endl;
        }
    }

    // Check for authentication key
    bool authenticated = false;
    if (tokens[0] == "KEY")
    {
        if (tokens.size() < 2)
            return 1;
        std::string received_key = tokens[1];
        std::string comparing_key = database_key;
        bool is_key_equal = true;
        // Fill buffers for full-buffer comparison
        while (received_key.length() < comparing_key.length())
        {
            received_key += ' ';
        }
        while (comparing_key.length() < received_key.length())
        {
            comparing_key += ' ';
        }
        // Compare buffers
        for (size_t i = 0; i < comparing_key.length(); ++i)
        {
            if (comparing_key[i] != received_key[i])
            {
                is_key_equal = false;
            }
        }
        if (is_key_equal)
        {
            authenticated = true;
            tokens.erase(tokens.begin()); // Remove KEY command
            tokens.erase(tokens.begin()); // Remove key
        }
    }

    // If not authenticated, throw error
    if (!authenticated && !database_key.empty())
    {
        srand(time(NULL));
        sleep((rand() % (MAX_WAIT * 10)) * 0.1 + MIN_WAIT); // Wait a random number of seconds
        return 3;
    }

    // If no command was sent, throw error
    if (tokens.empty())
    {
        return 1;
    }

    // Execute command
    if (tokens[0] == "SET")
    {
        if (tokens.size() < 3)
            return 1;
        else
            set_key(tokens[1], tokens[2]);
        return 0;
    }
    else if (tokens[0] == "GET")
    {
        if (tokens.size() < 2)
            return 1;
        std::string value;
        if (read_key(tokens[1], value))
        {
            send(socket_fd, "\"", 1, 0);
            send(socket_fd, value.c_str(), value.length(), 0);
            send(socket_fd, "\"\r\n", 3, 0);
            return 2;
        }
        else
        {
            return 1;
        }
    }
    else if (tokens[0] == "PROBE")
    {
        if (tokens.size() < 2)
            return 1;
        if (probe_key(tokens[1]))
        {
            send(socket_fd, FOUND_MSG, strlen(FOUND_MSG), 0);
        }
        else
        {
            send(socket_fd, NOT_FOUND_MSG, strlen(NOT_FOUND_MSG), 0);
        }
        return 2;
    }
    else if (tokens[0] == "DROP")
    {
        if (tokens.size() < 2)
            return 1;
        drop_key(tokens[1]);
        return 0;
    }
    else if (tokens[0] == "PING")
    {
        return 0;
    }
    else if (tokens[0] == "CHECKPOINT")
    {
        save_datafile();
        return 0;
    }
    else if (tokens[0] == "DEBUG")
    {
        if (tokens.size() < 2)
            return 1;
        if (tokens[1] == "ON")
        {
            display_tokens = true;
            return 0;
        }
        else if (tokens[1] == "OFF")
        {
            display_tokens = false;
            return 0;
        }
        else
        {
            return 1;
        }
    }
    else if (tokens[0] == "SETKEY")
    {
        if (tokens.size() < 2)
            return 1;
        database_key = tokens[1];
        return 0;
    }
    else if (tokens[0] == "DELKEY")
    {
        database_key = "";
        return 0;
    }
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %esi, -0x44(%rbp)
movq %rdi, %r14
xorpd %xmm0, %xmm0
movapd %xmm0, -0x40(%rbp)
movq $0x0, -0x30(%rbp)
leaq -0x78(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x351f(%rip), %rdx      # 0x71b4
leaq -0x88(%rbp), %rdi
movq %rdx, %rsi
callq 0x610a
movq 0x8(%r14), %rcx
testq %rcx, %rcx
je 0x3d74
xorl %r12d, %r12d
leaq -0x88(%rbp), %r15
xorl %r13d, %r13d
movq (%r14), %rdx
movzbl (%rdx,%r12), %eax
cmpl $0x5c, %eax
setne %sil
decq %rcx
cmpq %r12, %rcx
setbe %cl
orb %sil, %cl
jne 0x3cf8
leal 0x1(%r12), %ebx
movb (%rdx,%rbx), %cl
cmpb $0x22, %cl
jne 0x3cf8
movsbl %cl, %esi
movq %r15, %rdi
callq 0x3270
movl %ebx, %r12d
jmp 0x3d64
cmpl $0x20, %eax
je 0x3d27
cmpl $0x22, %eax
jne 0x3d2d
movl %r13d, %ebx
xorb $0x1, %bl
testb $0x1, %r13b
je 0x3d3a
leaq -0x40(%rbp), %rdi
movq %r15, %rsi
callq 0x5604
movq $0x0, -0x80(%rbp)
movl %ebx, %r13d
jmp 0x3d5a
testb $0x1, %r13b
je 0x3d3f
movsbl %al, %esi
movq %r15, %rdi
callq 0x3270
jmp 0x3d64
movl %ebx, %r13d
jmp 0x3d64
cmpq $0x0, -0x80(%rbp)
je 0x3d64
leaq -0x40(%rbp), %rdi
movq %r15, %rsi
callq 0x5604
movq $0x0, -0x80(%rbp)
movq -0x88(%rbp), %rax
movb $0x0, (%rax)
incl %r12d
movq 0x8(%r14), %rcx
cmpq %r12, %rcx
ja 0x3cbe
cmpq $0x0, -0x80(%rbp)
je 0x3d9d
leaq -0x40(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x5604
movq $0x0, -0x80(%rbp)
movq -0x88(%rbp), %rax
movb $0x0, (%rax)
cmpb $0x1, 0x65a4(%rip)      # 0xa348
jne 0x3fba
movq 0x623f(%rip), %rdi      # 0x9ff0
leaq 0x3378(%rip), %rsi      # 0x7130
movl $0x1b, %edx
callq 0x3330
movq 0x8(%r14), %rsi
movq 0x6223(%rip), %rdi      # 0x9ff0
callq 0x31f0
movq %rax, %rbx
leaq 0x3370(%rip), %rsi      # 0x714c
movl $0x10, %edx
movq %rax, %rdi
callq 0x3330
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3200
movq 0x61d9(%rip), %rdi      # 0x9ff0
leaq 0x333f(%rip), %rsi      # 0x715d
movl $0x9, %edx
callq 0x3330
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq 0x61ba(%rip), %rdi      # 0x9ff0
callq 0x3330
movq %rax, %rbx
leaq 0x3313(%rip), %rsi      # 0x7158
movl $0x4, %edx
movq %rax, %rdi
callq 0x3330
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3200
movq 0x6170(%rip), %rdi      # 0x9ff0
leaq 0x32e0(%rip), %rsi      # 0x7167
movl $0x1a, %edx
callq 0x3330
movq -0x38(%rbp), %rsi
subq -0x40(%rbp), %rsi
sarq $0x5, %rsi
movq 0x614c(%rip), %rdi      # 0x9ff0
callq 0x31f0
movq %rax, %rbx
leaq 0x32cf(%rip), %rsi      # 0x7182
movl $0xc, %edx
movq %rax, %rdi
callq 0x3330
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3200
movl $0x1, %r12d
movq 0x60fc(%rip), %r14      # 0x9ff0
leaq 0x3262(%rip), %r13      # 0x715d
leaq 0x3256(%rip), %rbx      # 0x7158
leal -0x1(%r12), %r15d
movq -0x38(%rbp), %rax
subq -0x40(%rbp), %rax
sarq $0x5, %rax
cmpq %r15, %rax
jbe 0x3fba
movl $0x12, %edx
movq %r14, %rdi
leaq 0x3264(%rip), %rsi      # 0x718f
callq 0x3330
movl %r12d, %esi
movq %r14, %rdi
callq 0x31f0
movl $0x6, %edx
movq %rax, %rdi
leaq 0x3258(%rip), %rsi      # 0x71a2
callq 0x3330
movl $0x9, %edx
movq %r14, %rdi
movq %r13, %rsi
callq 0x3330
movq -0x40(%rbp), %rax
shlq $0x5, %r15
movq (%rax,%r15), %rsi
movq 0x8(%rax,%r15), %rdx
movq %r14, %rdi
callq 0x3330
movq %rax, %r15
movl $0x4, %edx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x3330
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x32f0
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
incl %r12d
movq %rax, %rdi
callq 0x3200
jmp 0x3f02
movq -0x40(%rbp), %rdi
leaq 0x3222(%rip), %rsi      # 0x71e7
callq 0x30c0
testl %eax, %eax
je 0x4039
cmpq $0x0, 0x6382(%rip)      # 0xa358
je 0x4148
xorl %edi, %edi
callq 0x32a0
movl %eax, %edi
callq 0x32e0
callq 0x30a0
cltq
imulq $0x66666667, %rax, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x24, %rcx
addl %edx, %ecx
shll $0x3, %ecx
leal (%rcx,%rcx,4), %ecx
subl %ecx, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0x2fec(%rip), %xmm0     # 0x7008
addsd 0x2fec(%rip), %xmm0     # 0x7010
cvttsd2si %xmm0, %rdi
movl $0x3, %r14d
callq 0x3220
jmp 0x4421
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
subq %rax, %rcx
movl $0x1, %r14d
cmpq $0x21, %rcx
jb 0x4421
leaq -0x58(%rbp), %r14
movq %r14, -0x10(%r14)
movq 0x20(%rax), %rsi
movq 0x28(%rax), %rdx
addq %rsi, %rdx
leaq -0x68(%rbp), %rdi
callq 0x5926
leaq -0x98(%rbp), %r15
movq %r15, -0x10(%r15)
movq 0x62ce(%rip), %rsi      # 0xa350
movq 0x62cf(%rip), %rdx      # 0xa358
addq %rsi, %rdx
leaq -0xa8(%rbp), %rdi
callq 0x5926
leaq -0x68(%rbp), %rbx
movq -0x60(%rbp), %rax
cmpq -0xa0(%rbp), %rax
jae 0x40b8
movq %rbx, %rdi
movl $0x20, %esi
callq 0x3270
jmp 0x409c
leaq -0xa8(%rbp), %rbx
movq -0xa0(%rbp), %rax
cmpq -0x60(%rbp), %rax
jae 0x40db
movq %rbx, %rdi
movl $0x20, %esi
callq 0x3270
jmp 0x40bf
testq %rax, %rax
je 0x4111
movq -0xa8(%rbp), %rdx
movb $0x1, %cl
movq -0x68(%rbp), %rsi
xorl %edi, %edi
xorl %r8d, %r8d
movb (%rdx,%r8), %r9b
cmpb (%rsi,%r8), %r9b
movzbl %cl, %ecx
cmovnel %edi, %ecx
incq %r8
cmpq %r8, %rax
jne 0x40f2
testb $0x1, %cl
je 0x4275
leaq -0x40(%rbp), %rdi
movq (%rdi), %rsi
callq 0x63e4
leaq -0x40(%rbp), %rdi
movq (%rdi), %rsi
callq 0x63e4
movq -0xa8(%rbp), %rdi
cmpq %r15, %rdi
je 0x413a
callq 0x32c0
movq -0x68(%rbp), %rdi
cmpq %r14, %rdi
je 0x4148
callq 0x32c0
movq -0x40(%rbp), %rdi
movl $0x1, %r14d
cmpq -0x38(%rbp), %rdi
je 0x4421
leaq 0x3046(%rip), %rsi      # 0x71a9
callq 0x30c0
testl %eax, %eax
je 0x424b
movq -0x40(%rbp), %rdi
leaq 0x3032(%rip), %rsi      # 0x71ad
callq 0x30c0
testl %eax, %eax
je 0x429d
movq -0x40(%rbp), %rdi
leaq 0x3022(%rip), %rsi      # 0x71b5
callq 0x30c0
testl %eax, %eax
je 0x4332
movq -0x40(%rbp), %rdi
leaq 0x3010(%rip), %rsi      # 0x71bb
callq 0x30c0
testl %eax, %eax
je 0x4387
movq -0x40(%rbp), %rdi
leaq 0x2ffd(%rip), %rsi      # 0x71c0
callq 0x30c0
testl %eax, %eax
je 0x426d
movq -0x40(%rbp), %rdi
leaq 0x2fea(%rip), %rsi      # 0x71c5
callq 0x30c0
testl %eax, %eax
je 0x43aa
movq -0x40(%rbp), %rdi
leaq 0x2fdd(%rip), %rsi      # 0x71d0
callq 0x30c0
testl %eax, %eax
je 0x43b4
movq -0x40(%rbp), %rdi
leaq 0x2fd2(%rip), %rsi      # 0x71dd
callq 0x30c0
testl %eax, %eax
je 0x43fd
movq -0x40(%rbp), %rdi
leaq 0x2fc1(%rip), %rsi      # 0x71e4
callq 0x30c0
testl %eax, %eax
jne 0x4421
leaq 0x6119(%rip), %rdi      # 0xa350
leaq 0x2f76(%rip), %rsi      # 0x71b4
callq 0x33b0
xorl %r14d, %r14d
jmp 0x4421
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rax
subq %rsi, %rax
cmpq $0x41, %rax
jb 0x4421
leaq 0x20(%rsi), %rdi
addq $0x40, %rsi
callq 0x3b04
xorl %r14d, %r14d
jmp 0x4421
movq -0xa8(%rbp), %rdi
cmpq %r15, %rdi
je 0x4286
callq 0x32c0
movq -0x68(%rbp), %rdi
cmpq %r14, %rdi
je 0x3fce
callq 0x32c0
jmp 0x3fce
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rax
subq %rdi, %rax
cmpq $0x21, %rax
jb 0x4421
leaq -0x58(%rbp), %r15
movq %r15, -0x10(%r15)
movq $0x0, -0x8(%r15)
movb $0x0, (%r15)
addq $0x20, %rdi
leaq -0x68(%rbp), %rsi
callq 0x3b70
testb %al, %al
je 0x431b
leaq 0x2fd2(%rip), %rsi      # 0x72b0
movl $0x1, %edx
movl -0x44(%rbp), %edi
xorl %ecx, %ecx
callq 0x3190
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
movl -0x44(%rbp), %edi
xorl %ecx, %ecx
callq 0x3190
movl $0x2, %r14d
leaq 0x2ea5(%rip), %rsi      # 0x71b1
movl $0x3, %edx
movl -0x44(%rbp), %edi
xorl %ecx, %ecx
callq 0x3190
movq -0x68(%rbp), %rdi
cmpq %r15, %rdi
je 0x4421
callq 0x32c0
jmp 0x4421
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rax
subq %rdi, %rax
cmpq $0x21, %rax
jb 0x4421
addq $0x20, %rdi
callq 0x3c11
leaq 0x5f31(%rip), %rcx      # 0xa288
leaq 0x5f33(%rip), %rbx      # 0xa291
testb %al, %al
cmovneq %rcx, %rbx
movq %rbx, %rdi
callq 0x3150
movl $0x2, %r14d
movl -0x44(%rbp), %edi
movq %rbx, %rsi
movq %rax, %rdx
xorl %ecx, %ecx
callq 0x3190
jmp 0x4421
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rax
subq %rdi, %rax
cmpq $0x21, %rax
jb 0x4421
addq $0x20, %rdi
callq 0x3bd0
jmp 0x426d
callq 0x44d3
xorl %r14d, %r14d
jmp 0x4421
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rax
subq %rdi, %rax
cmpq $0x21, %rax
jb 0x4421
addq $0x20, %rdi
leaq 0x2e06(%rip), %rsi      # 0x71d6
callq 0x30c0
testl %eax, %eax
je 0x4454
movq -0x40(%rbp), %rdi
addq $0x20, %rdi
leaq 0x2df1(%rip), %rsi      # 0x71d9
callq 0x30c0
testl %eax, %eax
jne 0x4421
movb $0x0, 0x5f50(%rip)      # 0xa348
jmp 0x426d
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rax
subq %rsi, %rax
cmpq $0x21, %rax
jb 0x4421
addq $0x20, %rsi
leaq 0x5f37(%rip), %rdi      # 0xa350
callq 0x31b0
xorl %r14d, %r14d
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x4436
callq 0x32c0
leaq -0x40(%rbp), %rdi
callq 0x5650
movl %r14d, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, 0x5eed(%rip)      # 0xa348
jmp 0x426d
movq %rax, %rbx
movq -0x68(%rbp), %rdi
cmpq %r15, %rdi
jne 0x449f
jmp 0x44ad
jmp 0x4482
jmp 0x4482
movq %rax, %rbx
jmp 0x4496
jmp 0x44aa
jmp 0x44aa
movq %rax, %rbx
jmp 0x44c2
jmp 0x4482
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
cmpq %r15, %rdi
je 0x4496
callq 0x32c0
movq -0x68(%rbp), %rdi
cmpq %r14, %rdi
je 0x44ad
callq 0x32c0
jmp 0x44ad
jmp 0x44aa
jmp 0x44aa
movq %rax, %rbx
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x44c2
callq 0x32c0
leaq -0x40(%rbp), %rdi
callq 0x5650
movq %rbx, %rdi
callq 0x34a0