// File: /workspace/github_cpp_makefile_star2_O1/llefranc[P]42_webserv/srcs/server/Response.cpp
// Function: Response::fillError(StatusLine const&)
void Response::fillError(const StatusLine& sta)
{    
    if (sta.getCode() != _staLine.getCode())
    {
	    _staLine = sta;
	}
	
	_buffer.clear();
	
	// Filling buffer with error code + some basic headers
	fillStatusLine(sta);
	fillServerHeader();
	fillDateHeader();

    // Case HTTP redirection
    if (_staLine.getCode() == 301)
	{
        fillLocationHeader(_req->getPath());
	}

	// Value of host header field in request
	const std::string* hostField = &_req->getHeaders().find("host")->second;
	const std::string hostValue(hostField->substr(0, hostField->find(':')));

	// Looking in each virtual server names if one match host header field value, if
    // not using default server
	const ServerInfo* servMatch = findVirtServ(_infoVirServs, hostValue);
    if (!servMatch)
	{
        servMatch = &_infoVirServs->front();
	}
	
	std::string pathError;
	std::string errorCodeHTML = "/" + convertNbToString(sta.getCode()) + ".html";

    // Custom error pages if set in config file
	if (!servMatch->getError().empty())
	{
        // Adding relative file access if not well filled in config file
        pathError = (servMatch->getError()[0] == '/') ? 
                "." + servMatch->getError() + errorCodeHTML: servMatch->getError() + errorCodeHTML;

		struct stat infFile;
		if (stat(pathError.c_str(), &infFile) == -1)
			pathError = DEFAULT_PATH_ERROR_PAGES + errorCodeHTML;
	}
    
	else
		pathError = DEFAULT_PATH_ERROR_PAGES + errorCodeHTML;

    // Filling buffer
	FileParser body(pathError.c_str(), true);

	fillContentlengthHeader(convertNbToString(body.getRequestFileSize()));
	_buffer += CLRF + body.getRequestFile();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3d8, %rsp            # imm = 0x3D8
movq %rsi, %r12
movq %rdi, %r14
movl (%rsi), %eax
cmpl 0x10(%rdi), %eax
je 0xef9b
leaq -0x3f8(%rbp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x124da
movl 0x10(%r14), %eax
movl (%rbx), %ecx
movl %ecx, 0x10(%r14)
movl %eax, (%rbx)
leaq 0x18(%r14), %rdi
leaq -0x3f0(%rbp), %rsi
callq 0x42d0
leaq 0x38(%r14), %rdi
leaq -0x3d0(%rbp), %rsi
callq 0x42d0
movq %rbx, %rdi
callq 0xe174
leaq 0x58(%r14), %r13
movq $0x0, 0x60(%r14)
movq 0x58(%r14), %rax
movb $0x0, (%rax)
movq %r14, %rdi
movq %r12, %rsi
callq 0x1004e
leaq 0x6935(%rip), %rsi      # 0x158f5
movq %r13, %rdi
callq 0x4760
movq %r14, %rdi
callq 0x10374
cmpl $0x12d, 0x10(%r14)      # imm = 0x12D
jne 0xefee
movq 0x8(%r14), %rdi
callq 0xca9c
movq %r14, %rdi
movq %rax, %rsi
callq 0x11e2e
movq 0x8(%r14), %rdi
callq 0xca70
movq %rax, %r15
leaq -0x3a0(%rbp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x65db(%rip), %rsi      # 0x155e7
leaq 0x65d8(%rip), %rdx      # 0x155eb
leaq -0x3b0(%rbp), %rdi
callq 0x5790
leaq -0x3b0(%rbp), %rsi
movq %r15, %rdi
callq 0x12624
movq %rax, %r15
movq %r13, -0xb8(%rbp)
addq $0x40, %r15
movq -0x3b0(%rbp), %rdi
cmpq %rbx, %rdi
je 0xf057
movq -0x3a0(%rbp), %rsi
incq %rsi
callq 0x43e0
movq %r15, %rdi
movl $0x3a, %esi
xorl %edx, %edx
callq 0x4500
leaq -0xd8(%rbp), %r13
movq %r13, %rdi
movq %r15, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x4410
movq (%r14), %rdi
movq %r13, %rsi
callq 0x13c8a
movq %rax, %r15
testq %rax, %rax
jne 0xf096
movq (%r14), %rax
movq (%rax), %r15
leaq -0xa0(%rbp), %r13
movq %r13, -0x10(%r13)
movq $0x0, -0x8(%r13)
movb $0x0, (%r13)
movslq (%r12), %rsi
leaq -0x90(%rbp), %rdi
callq 0x1378a
leaq 0x66f1(%rip), %rcx      # 0x157b6
leaq -0x90(%rbp), %rdi
movl $0x1, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x4440
movq %rbx, -0x3b0(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0xf104
movq %rdx, -0x3b0(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x3a0(%rbp)
jmp 0xf10a
movups (%rcx), %xmm0
movups %xmm0, (%rbx)
movq 0x8(%rax), %rdx
leaq -0x3b0(%rbp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x69aa(%rip), %rsi      # 0x15ad9
callq 0x4760
leaq -0x60(%rbp), %rsi
movq %rsi, -0x10(%rsi)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0xf158
movq %rdx, -0x70(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x60(%rbp)
jmp 0xf15e
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, -0x68(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq -0x3b0(%rbp), %rdi
cmpq %rbx, %rdi
je 0xf190
movq -0x3a0(%rbp), %rsi
incq %rsi
callq 0x43e0
leaq -0x80(%rbp), %r12
movq -0x10(%r12), %rdi
cmpq %r12, %rdi
je 0xf1aa
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x43e0
movq %r15, %rdi
callq 0x5b9a
cmpq $0x0, 0x8(%rax)
je 0xf230
movq %r15, %rdi
callq 0x5b9a
movq (%rax), %rax
movb (%rax), %r13b
cmpb $0x2f, %r13b
sete -0x29(%rbp)
jne 0xf275
movq %r15, %rdi
callq 0x5b9a
leaq 0x65dc(%rip), %rsi      # 0x157c0
leaq -0x90(%rbp), %rdi
movq %rax, %rdx
callq 0x6400
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
leaq -0x90(%rbp), %rdi
callq 0x4150
movq %rbx, -0x3b0(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0xf292
movq %rdx, -0x3b0(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x3a0(%rbp)
jmp 0xf298
leaq 0x68a8(%rip), %rsi      # 0x15adf
leaq -0x3b0(%rbp), %rdi
leaq -0x70(%rbp), %rdx
callq 0x6400
leaq -0xb0(%rbp), %rdi
leaq -0x3b0(%rbp), %r15
movq %r15, %rsi
callq 0x44d0
movq (%r15), %rdi
cmpq %rbx, %rdi
je 0xf35b
movq -0x3a0(%rbp), %rsi
jmp 0xf353
movq %r15, %rdi
callq 0x5b9a
leaq -0x3b0(%rbp), %rdi
leaq -0x70(%rbp), %rdx
movq %rax, %rsi
callq 0x125bf
jmp 0xf2b2
movups (%rcx), %xmm0
movups %xmm0, (%rbx)
movq 0x8(%rax), %rdx
movq %rdx, -0x3a8(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq -0xb0(%rbp), %rdi
leaq -0x3b0(%rbp), %r15
movq %r15, %rsi
callq 0x44d0
movq (%r15), %rdi
cmpq %rbx, %rdi
je 0xf2df
movq -0x3a0(%rbp), %rsi
incq %rsi
callq 0x43e0
cmpb $0x2f, %r13b
leaq -0xa0(%rbp), %r13
jne 0xf304
movq -0x90(%rbp), %rdi
cmpq %r12, %rdi
je 0xf304
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x43e0
movq -0xb0(%rbp), %rdi
leaq -0x3b0(%rbp), %rsi
callq 0x4360
cmpl $-0x1, %eax
jne 0xf35b
leaq 0x67bc(%rip), %rsi      # 0x15adf
leaq -0x50(%rbp), %rdi
leaq -0x70(%rbp), %rdx
callq 0x6400
leaq -0xb0(%rbp), %rdi
leaq -0x50(%rbp), %r15
movq %r15, %rsi
callq 0x44d0
movq (%r15), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0xf35b
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x43e0
movq -0xb0(%rbp), %rsi
leaq -0x3b0(%rbp), %rdi
movl $0x1, %edx
callq 0x6a8c
leaq -0x3b0(%rbp), %rdi
callq 0x71a8
leaq -0x50(%rbp), %rdi
movq %rax, %rsi
callq 0x1378a
leaq -0x50(%rbp), %rsi
movq %r14, %rdi
callq 0x10af6
leaq -0x40(%rbp), %rbx
movq -0x10(%rbx), %rdi
cmpq %rbx, %rdi
je 0xf3b0
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x43e0
leaq -0x3b0(%rbp), %rdi
callq 0x700a
leaq 0x68bf(%rip), %rsi      # 0x15c82
leaq -0x50(%rbp), %rdi
movq %rax, %rdx
callq 0x6400
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0xb8(%rbp), %rdi
callq 0x4150
movq -0x50(%rbp), %rdi
cmpq %rbx, %rdi
je 0xf3f8
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x43e0
leaq -0x3b0(%rbp), %rdi
callq 0x6f74
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0xf41d
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x43e0
movq -0xb0(%rbp), %rdi
cmpq %r13, %rdi
je 0xf438
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x43e0
leaq -0xc8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xf457
movq -0xc8(%rbp), %rsi
incq %rsi
callq 0x43e0
addq $0x3d8, %rsp            # imm = 0x3D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xf4d7
jmp 0xf4d7
movq %rax, %r14
movb $0x1, -0x29(%rbp)
jmp 0xf49d
jmp 0xf4d7
movq %rax, %r14
cmpb $0x2f, %r13b
jne 0xf49d
movq -0x90(%rbp), %rdi
movb $0x1, -0x29(%rbp)
cmpq %r12, %rdi
je 0xf49d
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x43e0
cmpb $0x0, -0x29(%rbp)
jmp 0xf54a
movq %rax, %r14
movq -0x50(%rbp), %rdi
cmpq %rbx, %rdi
jne 0xf4c7
jmp 0xf53e
movq %rax, %r14
leaq -0x40(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xf53e
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x43e0
jmp 0xf53e
jmp 0xf4d7
movq %rax, %r14
jmp 0xf54a
movq %rax, %r14
movq -0x3b0(%rbp), %rdi
cmpq %rbx, %rdi
je 0xf4ff
movq -0x3a0(%rbp), %rsi
incq %rsi
callq 0x43e0
jmp 0xf4ff
movq %rax, %r14
leaq -0x80(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xf563
movq -0x80(%rbp), %rsi
jmp 0xf55b
movq %rax, %r14
jmp 0xf563
movq %rax, %r14
jmp 0xf585
movq %rax, %r14
movq -0x3b0(%rbp), %rdi
cmpq %rbx, %rdi
je 0xf5a4
movq -0x3a0(%rbp), %rsi
jmp 0xf59c
movq %rax, %r14
jmp 0xf5a4
jmp 0xf53b
movq %rax, %r14
leaq -0x3b0(%rbp), %rdi
callq 0x6f74
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0xf563
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x43e0
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0xf585
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x43e0
leaq -0xc8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xf5a4
movq -0xc8(%rbp), %rsi
incq %rsi
callq 0x43e0
movq %r14, %rdi
callq 0x46d0