// File: /workspace/github_cpp_makefile_star2_O3/mbourand[P]webserv/srcs/Methods/DeleteMethod.cpp
// Function: DeleteMethod::process(Request const&, ConfigContext const&, ServerSocket const&)
Response DeleteMethod::process(const Request& request, const ConfigContext& config, const ServerSocket&)
{
	URL url(request._url._path);
	int base_depth = 0;
	std::string realPath = config.rootPath(url._path, base_depth);
	try
	{
		realPath = ft::simplify_path(realPath, true, base_depth);
	}
	catch (std::exception& e)
	{
		return Response(404, url._path);
	}
	Response response(200, url._path);
	try
	{
		std::string file_path = realPath;
		struct stat	file_stats;
		if (lstat(file_path.c_str(), &file_stats) == 0 && S_ISREG(file_stats.st_mode))
		{
			if (unlink(file_path.c_str()) == 0)
				response.setCode(204);
			else
				response.setCode(202);
		}
		else
			response.setCode(404);
	}
	catch (std::exception& e)
	{
		response.setCode(500);
	}
	return (response);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
movq %rcx, %r14
movq %rdi, %rbx
leaq 0xb8(%rdx), %rsi
leaq 0xd8(%rsp), %rdi
callq 0x1aede
leaq 0x4(%rsp), %rcx
movl $0x0, (%rcx)
leaq 0x160(%rsp), %r15
leaq 0x8(%rsp), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x2b9a8
movl 0x4(%rsp), %ecx
leaq 0x48(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movl $0x1, %edx
callq 0x1d26b
leaq 0x8(%rsp), %rdi
leaq 0x48(%rsp), %r14
movq %r14, %rsi
callq 0x7590
movq (%r14), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0xa01f
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x74b0
movq %rbx, %rdi
movl $0xc8, %esi
movq %r15, %rdx
callq 0x36f58
leaq 0x38(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
leaq 0x28(%rsp), %rdi
callq 0x8a92
movq 0x28(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x78e0
movl $0x194, %esi            # imm = 0x194
testl %eax, %eax
jne 0xa090
movl $0xf000, %eax           # imm = 0xF000
andl 0x60(%rsp), %eax
cmpl $0x8000, %eax           # imm = 0x8000
jne 0xa090
movq 0x28(%rsp), %rdi
callq 0x7240
xorl %ecx, %ecx
testl %eax, %eax
sete %cl
leal 0xca(,%rcx,2), %esi
movq %rbx, %rdi
callq 0x37aee
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
je 0xa0af
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x74b0
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa0ca
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x74b0
leaq 0xd8(%rsp), %rdi
callq 0x1b836
movq %rbx, %rax
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq %rdx, %r15
movq %rax, %r14
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
je 0xa10e
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0xa10e
movq %rdx, %r15
movq %rax, %r14
cmpl $0x1, %r15d
jne 0xa140
movq %r14, %rdi
callq 0x7210
movq %rbx, %rdi
movl $0x1f4, %esi            # imm = 0x1F4
callq 0x37aee
callq 0x7780
jmp 0xa0af
movq %rax, %r14
jmp 0xa140
movq %rax, %r14
callq 0x7780
movq %rbx, %rdi
callq 0x36d9a
jmp 0xa14d
movq %rax, %r14
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa1ab
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0xa1ab
movq %rax, %r14
cmpl $0x1, %edx
jne 0xa14d
movq %r14, %rdi
callq 0x7210
movq %rbx, %rdi
movl $0x194, %esi            # imm = 0x194
movq %r15, %rdx
callq 0x36f58
callq 0x7780
jmp 0xa0af
jmp 0xa14a
movq %rax, %r14
callq 0x7780
jmp 0xa14d
movq %rax, %rdi
callq 0x96aa
movq %rax, %r14
leaq 0xd8(%rsp), %rdi
callq 0x1b836
movq %r14, %rdi
callq 0x7810