// File: dhruvbhargava[P]microTP/src/HttpMethods.cpp
// Function: HttpServer::GET(char const*, bool)
void HttpServer::GET(const char *filepath, bool close)
{
    std::string root_path = PROJECT_ROOT, file_p = filepath;
    std::string full_path = root_path + file_p + ".html";
    std::cout<<full_path<<std::endl;
    if (!exists(full_path))
    {
        char response[] = "HTTP/1.1 404 NOT FOUND\r\nContent-Type: text/plain\r\nContent-Length: 3\r\n\r\n404";
        std::cout << response << std::endl;
        write(new_socket_fd, response, strlen(response));
        return;
    }

    std::ifstream html(full_path);
    std::ostringstream html_stream;
    html_stream << html.rdbuf();
    std::string html_string = html_stream.str();
    std::string http_template = close ? (char *)HTTP_OK_CLOSE_START : HTTP_OK_KEEP_ALIVE_START;
    std::string http_string = format(http_template,html_string.length());
    std::string response = http_string + html_string;
    write(new_socket_fd, response.c_str(), strlen(response.c_str()));
    return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x5c0, %rsp            # imm = 0x5C0
movb %dl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x558(%rbp)
movq 0x30(%rax), %rax
movq %rax, -0x550(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x548(%rbp)
callq 0x3400
movq -0x550(%rbp), %rsi
movq -0x548(%rbp), %rdx
leaq -0x38(%rbp), %rdi
callq 0x3e20
jmp 0x3819
leaq -0x39(%rbp), %rdi
callq 0x32b0
movq -0x10(%rbp), %rax
movq %rax, -0x568(%rbp)
leaq -0x71(%rbp), %rdi
movq %rdi, -0x560(%rbp)
callq 0x3400
movq -0x568(%rbp), %rsi
movq -0x560(%rbp), %rdx
leaq -0x70(%rbp), %rdi
callq 0x3e20
jmp 0x3856
leaq -0x71(%rbp), %rdi
callq 0x32b0
leaq -0xb8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
leaq -0x70(%rbp), %rdx
callq 0x3f20
jmp 0x3875
leaq 0x37a6(%rip), %rdx      # 0x7022
leaq -0x98(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x3fa0
jmp 0x3891
leaq -0xb8(%rbp), %rdi
callq 0x31a0
movq 0x672c(%rip), %rdi      # 0x9fd0
leaq -0x98(%rbp), %rsi
callq 0x3230
movq %rax, -0x570(%rbp)
jmp 0x38b9
movq -0x570(%rbp), %rdi
movq 0x66f9(%rip), %rsi      # 0x9fc0
callq 0x3290
jmp 0x38ce
leaq -0x98(%rbp), %rdi
callq 0x3ff0
movb %al, -0x571(%rbp)
jmp 0x38e2
movb -0x571(%rbp), %al
testb $0x1, %al
jne 0x3a25
jmp 0x38f2
movups 0x37c2(%rip), %xmm0     # 0x70bb
movups %xmm0, -0xd5(%rbp)
movaps 0x37a9(%rip), %xmm0     # 0x70b0
movaps %xmm0, -0xe0(%rbp)
movaps 0x378b(%rip), %xmm0     # 0x70a0
movaps %xmm0, -0xf0(%rbp)
movaps 0x376d(%rip), %xmm0     # 0x7090
movaps %xmm0, -0x100(%rbp)
movaps 0x374f(%rip), %xmm0     # 0x7080
movaps %xmm0, -0x110(%rbp)
movq 0x6691(%rip), %rdi      # 0x9fd0
leaq -0x110(%rbp), %rsi
callq 0x3250
movq %rax, -0x580(%rbp)
jmp 0x3954
movq -0x580(%rbp), %rdi
movq 0x665e(%rip), %rsi      # 0x9fc0
callq 0x3290
jmp 0x3969
movq -0x558(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x58c(%rbp)
leaq -0x110(%rbp), %rdi
movq %rdi, -0x588(%rbp)
callq 0x3150
movl -0x58c(%rbp), %edi
movq -0x588(%rbp), %rsi
movq %rax, %rdx
callq 0x3100
jmp 0x39a3
movl $0x1, -0x114(%rbp)
jmp 0x3ca9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x39(%rbp), %rdi
callq 0x32b0
jmp 0x3cee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x71(%rbp), %rdi
callq 0x32b0
jmp 0x3ce5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x3cdc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x31a0
jmp 0x3cdc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x3cd0
leaq -0x320(%rbp), %rdi
leaq -0x98(%rbp), %rsi
movl $0x8, %edx
callq 0x33c0
jmp 0x3a3f
leaq -0x498(%rbp), %rdi
callq 0x3330
jmp 0x3a4d
leaq -0x320(%rbp), %rdi
callq 0x33a0
movq %rax, -0x598(%rbp)
jmp 0x3a62
movq -0x598(%rbp), %rsi
leaq -0x498(%rbp), %rdi
callq 0x3070
jmp 0x3a77
leaq -0x4b8(%rbp), %rdi
leaq -0x498(%rbp), %rsi
callq 0x3280
jmp 0x3a8c
leaq 0x3595(%rip), %rax      # 0x7028
movq %rax, -0x5a8(%rbp)
leaq -0x4d9(%rbp), %rdi
movq %rdi, -0x5a0(%rbp)
callq 0x3400
movq -0x5a8(%rbp), %rsi
movq -0x5a0(%rbp), %rdx
leaq -0x4d8(%rbp), %rdi
callq 0x3e20
jmp 0x3ac9
leaq -0x4d9(%rbp), %rdi
callq 0x32b0
leaq -0x520(%rbp), %rdi
leaq -0x4d8(%rbp), %rsi
callq 0x3140
jmp 0x3aea
leaq -0x4b8(%rbp), %rdi
callq 0x3370
movl %eax, %edx
leaq -0x500(%rbp), %rdi
leaq -0x520(%rbp), %rsi
callq 0x3670
jmp 0x3b0d
leaq -0x520(%rbp), %rdi
callq 0x31a0
leaq -0x540(%rbp), %rdi
leaq -0x500(%rbp), %rsi
leaq -0x4b8(%rbp), %rdx
callq 0x3f20
jmp 0x3b35
movq -0x558(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x5b4(%rbp)
leaq -0x540(%rbp), %rdi
movq %rdi, -0x5c0(%rbp)
callq 0x3130
movq -0x5c0(%rbp), %rdi
movq %rax, -0x5b0(%rbp)
callq 0x3130
movq %rax, %rdi
callq 0x3150
movl -0x5b4(%rbp), %edi
movq -0x5b0(%rbp), %rsi
movq %rax, %rdx
callq 0x3100
jmp 0x3b8a
movl $0x1, -0x114(%rbp)
leaq -0x540(%rbp), %rdi
callq 0x31a0
leaq -0x500(%rbp), %rdi
callq 0x31a0
leaq -0x4d8(%rbp), %rdi
callq 0x31a0
leaq -0x4b8(%rbp), %rdi
callq 0x31a0
leaq -0x498(%rbp), %rdi
callq 0x3090
leaq -0x320(%rbp), %rdi
callq 0x30b0
jmp 0x3ca9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x3c9b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x3c8f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x4d9(%rbp), %rdi
callq 0x32b0
jmp 0x3c83
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x3c77
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x520(%rbp), %rdi
callq 0x31a0
jmp 0x3c77
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x3c6b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x540(%rbp), %rdi
callq 0x31a0
leaq -0x500(%rbp), %rdi
callq 0x31a0
leaq -0x4d8(%rbp), %rdi
callq 0x31a0
leaq -0x4b8(%rbp), %rdi
callq 0x31a0
leaq -0x498(%rbp), %rdi
callq 0x3090
leaq -0x320(%rbp), %rdi
callq 0x30b0
jmp 0x3cd0
leaq -0x98(%rbp), %rdi
callq 0x31a0
leaq -0x70(%rbp), %rdi
callq 0x31a0
leaq -0x38(%rbp), %rdi
callq 0x31a0
addq $0x5c0, %rsp            # imm = 0x5C0
popq %rbp
retq
leaq -0x98(%rbp), %rdi
callq 0x31a0
leaq -0x70(%rbp), %rdi
callq 0x31a0
leaq -0x38(%rbp), %rdi
callq 0x31a0
movq -0x48(%rbp), %rdi
callq 0x33f0
nopw (%rax,%rax)