// File: solaldunckel[P]webserv/srcs/HTTP/Response.cpp
// Function: Response::buildErrorPage(int)
int Response::buildErrorPage(int status_code) {
  if (!config_.getErrorPages()[status_code].empty()) {
    std::string target = ft::unique_char(config_.getErrorPages()[status_code]);
    std::string cur_target = ft::unique_char("/" + config_.getTarget());

    if (target != cur_target) {
      config_.getMethod() = "GET";

      redirect_ = true;
      redirect_code_ = status_code;
      redirect_target_ = target;

      return 0;
    }
  }
  body_ += "<html>\r\n";
  body_ += "<head><title>" + ft::to_string(status_code) + " " + g_status[status_code] + "</title></head>\r\n";
  body_ += "<body>\r\n";
  body_ += "<center><h1>" + ft::to_string(status_code) + " " + g_status[status_code] + "</h1></center>\r\n";
  body_ += "<hr><center>" + headers_["Server"] + "</center>\r\n";
  body_ += "</body>\r\n";
  body_ += "</html>\r\n";
  headers_["Content-Type"] = g_mimes.getType(".html");
  headers_["Content-Length"] = ft::to_string(body_.length());
  if (status_code == 401)
    headers_["WWW-Authenticate"] = "Basic realm=\"Access to restricted area\"";
  if (status_code == 408 || status_code == 503)
    headers_["Connection"] = "close";
  if (status_code == 503)
    headers_["Retry-After"] = "30";
  return status_code;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x470, %rsp            # imm = 0x470
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x390(%rbp)
movq (%rax), %rdi
callq 0x12fd0
movq %rax, %rdi
leaq -0x14(%rbp), %rsi
callq 0x18eb0
movq %rax, %rdi
callq 0x5900
testb $0x1, %al
jne 0x25b0d
movq -0x390(%rbp), %rax
movq (%rax), %rdi
callq 0x12fd0
movq %rax, %rdi
leaq -0x14(%rbp), %rsi
callq 0x18eb0
movq %rax, %rsi
leaq -0x58(%rbp), %rdi
movq %rdi, -0x398(%rbp)
callq 0x5200
movq -0x398(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x41780
jmp 0x25991
leaq -0x58(%rbp), %rdi
callq 0x5aa8
movq -0x390(%rbp), %rax
movq (%rax), %rdi
callq 0x12dc0
movq %rax, -0x3a0(%rbp)
jmp 0x259b2
movq -0x3a0(%rbp), %rdx
leaq 0x1dbe3(%rip), %rsi     # 0x435a3
leaq -0xa8(%rbp), %rdi
callq 0x6ad0
jmp 0x259ce
leaq -0x88(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x41780
jmp 0x259e3
leaq -0xa8(%rbp), %rdi
callq 0x5aa8
leaq -0x38(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x29f20
testb $0x1, %al
jne 0x25a08
jmp 0x25acd
movq -0x390(%rbp), %rax
movq (%rax), %rdi
callq 0x13030
movq %rax, -0x3a8(%rbp)
jmp 0x25a20
movq -0x3a8(%rbp), %rdi
leaq 0x1dd49(%rip), %rsi     # 0x43777
callq 0x5780
jmp 0x25a35
movq -0x390(%rbp), %rdi
movb $0x1, 0x100(%rdi)
movl -0x14(%rbp), %eax
movl %eax, 0x128(%rdi)
addq $0x108, %rdi            # imm = 0x108
leaq -0x38(%rbp), %rsi
callq 0x5050
jmp 0x25a5e
movl $0x0, -0x4(%rbp)
movl $0x1, -0xac(%rbp)
jmp 0x25ad7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x5aa8
jmp 0x264bc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x25aff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x5aa8
jmp 0x25aff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x5aa8
jmp 0x25aff
movl $0x0, -0xac(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x5aa8
leaq -0x38(%rbp), %rdi
callq 0x5aa8
movl -0xac(%rbp), %eax
testl %eax, %eax
je 0x25afd
jmp 0x25af8
jmp 0x264b0
jmp 0x25b0d
leaq -0x38(%rbp), %rdi
callq 0x5aa8
jmp 0x264bc
movq -0x390(%rbp), %rdi
addq $0xe0, %rdi
leaq 0x1dc73(%rip), %rsi     # 0x43795
callq 0x5520
movl -0x14(%rbp), %esi
leaq -0x150(%rbp), %rdi
movq %rdi, -0x3b0(%rbp)
callq 0x9070
movq -0x3b0(%rbp), %rdx
leaq 0x1dc53(%rip), %rsi     # 0x4379e
leaq -0x130(%rbp), %rdi
callq 0x107f0
jmp 0x25b59
leaq 0x1dd03(%rip), %rdx     # 0x43863
leaq -0x110(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x6a80
jmp 0x25b75
movl -0x14(%rbp), %esi
leaq 0x36ac9(%rip), %rdi     # 0x5c648
callq 0x40e10
movq %rax, -0x3b8(%rbp)
jmp 0x25b8d
movq -0x3b8(%rbp), %rdx
leaq -0xf0(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x6a30
jmp 0x25ba9
leaq 0x1dbfc(%rip), %rdx     # 0x437ac
leaq -0xd0(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x6a80
jmp 0x25bc5
movq -0x390(%rbp), %rdi
addq $0xe0, %rdi
leaq -0xd0(%rbp), %rsi
callq 0x5710
jmp 0x25be1
leaq -0xd0(%rbp), %rdi
callq 0x5aa8
leaq -0xf0(%rbp), %rdi
callq 0x5aa8
leaq -0x110(%rbp), %rdi
callq 0x5aa8
leaq -0x130(%rbp), %rdi
callq 0x5aa8
leaq -0x150(%rbp), %rdi
callq 0x5aa8
movq -0x390(%rbp), %rdi
addq $0xe0, %rdi
leaq 0x1db8c(%rip), %rsi     # 0x437be
callq 0x5520
movl -0x14(%rbp), %esi
leaq -0x1f0(%rbp), %rdi
movq %rdi, -0x3c0(%rbp)
callq 0x9070
movq -0x3c0(%rbp), %rdx
leaq 0x1db6c(%rip), %rsi     # 0x437c7
leaq -0x1d0(%rbp), %rdi
callq 0x107f0
jmp 0x25c69
leaq 0x1dbf3(%rip), %rdx     # 0x43863
leaq -0x1b0(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
callq 0x6a80
jmp 0x25c85
movl -0x14(%rbp), %esi
leaq 0x369b9(%rip), %rdi     # 0x5c648
callq 0x40e10
movq %rax, -0x3c8(%rbp)
jmp 0x25c9d
movq -0x3c8(%rbp), %rdx
leaq -0x190(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x6a30
jmp 0x25cb9
leaq 0x1db14(%rip), %rdx     # 0x437d4
leaq -0x170(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x6a80
jmp 0x25cd5
movq -0x390(%rbp), %rdi
addq $0xe0, %rdi
leaq -0x170(%rbp), %rsi
callq 0x5710
jmp 0x25cf1
leaq -0x170(%rbp), %rdi
callq 0x5aa8
leaq -0x190(%rbp), %rdi
callq 0x5aa8
leaq -0x1b0(%rbp), %rdi
callq 0x5aa8
leaq -0x1d0(%rbp), %rdi
callq 0x5aa8
leaq -0x1f0(%rbp), %rdi
callq 0x5aa8
movq -0x390(%rbp), %rax
addq $0x190, %rax            # imm = 0x190
movq %rax, -0x3d8(%rbp)
leaq -0x251(%rbp), %rdi
movq %rdi, -0x3d0(%rbp)
callq 0x5960
movq -0x3d0(%rbp), %rdx
leaq 0x1da90(%rip), %rsi     # 0x437f2
leaq -0x250(%rbp), %rdi
callq 0x6be0
jmp 0x25d70
movq -0x3d8(%rbp), %rdi
leaq -0x250(%rbp), %rsi
callq 0x20e30
movq %rax, -0x3e0(%rbp)
jmp 0x25d8c
movq -0x3e0(%rbp), %rdx
leaq 0x1da4b(%rip), %rsi     # 0x437e5
leaq -0x230(%rbp), %rdi
callq 0x6ad0
jmp 0x25da8
leaq 0x1da2a(%rip), %rdx     # 0x437d9
leaq -0x210(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x6a80
jmp 0x25dc4
movq -0x390(%rbp), %rdi
addq $0xe0, %rdi
leaq -0x210(%rbp), %rsi
callq 0x5710
jmp 0x25de0
leaq -0x210(%rbp), %rdi
callq 0x5aa8
leaq -0x230(%rbp), %rdi
callq 0x5aa8
leaq -0x250(%rbp), %rdi
callq 0x5aa8
leaq -0x251(%rbp), %rdi
callq 0x55e0
movq -0x390(%rbp), %rdi
addq $0xe0, %rdi
movq %rdi, -0x3f0(%rbp)
leaq 0x1e0b7(%rip), %rsi     # 0x43ee3
callq 0x5520
movq -0x3f0(%rbp), %rdi
leaq 0x1d9ba(%rip), %rsi     # 0x437f9
callq 0x5520
leaq -0x299(%rbp), %rdi
movq %rdi, -0x3e8(%rbp)
callq 0x5960
movq -0x3e8(%rbp), %rdx
leaq 0x1d99e(%rip), %rsi     # 0x43803
leaq -0x298(%rbp), %rdi
callq 0x6be0
jmp 0x25e73
leaq 0x367fe(%rip), %rsi     # 0x5c678
leaq -0x278(%rbp), %rdi
leaq -0x298(%rbp), %rdx
callq 0x403d0
jmp 0x25e8f
movq -0x390(%rbp), %rax
addq $0x190, %rax            # imm = 0x190
movq %rax, -0x400(%rbp)
leaq -0x2c1(%rbp), %rdi
movq %rdi, -0x3f8(%rbp)
callq 0x5960
movq -0x3f8(%rbp), %rdx
leaq 0x1d72b(%rip), %rsi     # 0x435ef
leaq -0x2c0(%rbp), %rdi
callq 0x6be0
jmp 0x25ed2
movq -0x400(%rbp), %rdi
leaq -0x2c0(%rbp), %rsi
callq 0x20e30
movq %rax, -0x408(%rbp)
jmp 0x25eee
movq -0x408(%rbp), %rdi
leaq -0x278(%rbp), %rsi
movq %rsi, -0x420(%rbp)
callq 0x56d0
leaq -0x2c0(%rbp), %rdi
callq 0x5aa8
leaq -0x2c1(%rbp), %rdi
callq 0x55e0
movq -0x420(%rbp), %rdi
callq 0x5aa8
leaq -0x298(%rbp), %rdi
callq 0x5aa8
leaq -0x299(%rbp), %rdi
callq 0x55e0
movq -0x390(%rbp), %rdi
addq $0xe0, %rdi
callq 0x5830
movq %rax, %rsi
leaq -0x2e8(%rbp), %rdi
callq 0x20f10
movq -0x390(%rbp), %rax
addq $0x190, %rax            # imm = 0x190
movq %rax, -0x418(%rbp)
leaq -0x309(%rbp), %rdi
movq %rdi, -0x410(%rbp)
callq 0x5960
movq -0x410(%rbp), %rdx
leaq 0x1d645(%rip), %rsi     # 0x435e0
leaq -0x308(%rbp), %rdi
callq 0x6be0
jmp 0x25fa9
movq -0x418(%rbp), %rdi
leaq -0x308(%rbp), %rsi
callq 0x20e30
movq %rax, -0x428(%rbp)
jmp 0x25fc5
movq -0x428(%rbp), %rdi
leaq -0x2e8(%rbp), %rsi
callq 0x56d0
leaq -0x308(%rbp), %rdi
callq 0x5aa8
leaq -0x309(%rbp), %rdi
callq 0x55e0
leaq -0x2e8(%rbp), %rdi
callq 0x5aa8
cmpl $0x191, -0x14(%rbp)     # imm = 0x191
jne 0x26300
movq -0x390(%rbp), %rax
addq $0x190, %rax            # imm = 0x190
movq %rax, -0x438(%rbp)
leaq -0x331(%rbp), %rdi
movq %rdi, -0x430(%rbp)
callq 0x5960
movq -0x430(%rbp), %rdx
leaq 0x1d7f3(%rip), %rsi     # 0x43831
leaq -0x330(%rbp), %rdi
callq 0x6be0
jmp 0x2604c
movq -0x438(%rbp), %rdi
leaq -0x330(%rbp), %rsi
callq 0x20e30
movq %rax, -0x440(%rbp)
jmp 0x26068
movq -0x440(%rbp), %rdi
leaq 0x1d793(%rip), %rsi     # 0x43809
callq 0x5780
jmp 0x2607d
leaq -0x330(%rbp), %rdi
callq 0x5aa8
leaq -0x331(%rbp), %rdi
callq 0x55e0
jmp 0x26300
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x2610e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x26102
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x260f6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x260ea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x5aa8
leaq -0xf0(%rbp), %rdi
callq 0x5aa8
leaq -0x110(%rbp), %rdi
callq 0x5aa8
leaq -0x130(%rbp), %rdi
callq 0x5aa8
leaq -0x150(%rbp), %rdi
callq 0x5aa8
jmp 0x264bc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x26193
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x26187
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x2617b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x2616f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x5aa8
leaq -0x190(%rbp), %rdi
callq 0x5aa8
leaq -0x1b0(%rbp), %rdi
callq 0x5aa8
leaq -0x1d0(%rbp), %rdi
callq 0x5aa8
leaq -0x1f0(%rbp), %rdi
callq 0x5aa8
jmp 0x264bc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x261fe
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x261f2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x261e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x210(%rbp), %rdi
callq 0x5aa8
leaq -0x230(%rbp), %rdi
callq 0x5aa8
leaq -0x250(%rbp), %rdi
callq 0x5aa8
leaq -0x251(%rbp), %rdi
callq 0x55e0
jmp 0x264bc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x26275
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x26269
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x26251
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x2c0(%rbp), %rdi
callq 0x5aa8
leaq -0x2c1(%rbp), %rdi
callq 0x55e0
leaq -0x278(%rbp), %rdi
callq 0x5aa8
leaq -0x298(%rbp), %rdi
callq 0x5aa8
leaq -0x299(%rbp), %rdi
callq 0x55e0
jmp 0x264bc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x262ac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x308(%rbp), %rdi
callq 0x5aa8
leaq -0x309(%rbp), %rdi
callq 0x55e0
leaq -0x2e8(%rbp), %rdi
callq 0x5aa8
jmp 0x264bc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x262ef
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x330(%rbp), %rdi
callq 0x5aa8
leaq -0x331(%rbp), %rdi
callq 0x55e0
jmp 0x264bc
cmpl $0x198, -0x14(%rbp)     # imm = 0x198
je 0x26316
cmpl $0x1f7, -0x14(%rbp)     # imm = 0x1F7
jne 0x263db
movq -0x390(%rbp), %rax
addq $0x190, %rax            # imm = 0x190
movq %rax, -0x450(%rbp)
leaq -0x359(%rbp), %rdi
movq %rdi, -0x448(%rbp)
callq 0x5960
movq -0x448(%rbp), %rdx
leaq 0x1d4fd(%rip), %rsi     # 0x43848
leaq -0x358(%rbp), %rdi
callq 0x6be0
jmp 0x26359
movq -0x450(%rbp), %rdi
leaq -0x358(%rbp), %rsi
callq 0x20e30
movq %rax, -0x458(%rbp)
jmp 0x26375
movq -0x458(%rbp), %rdi
leaq 0x1d4bf(%rip), %rsi     # 0x43842
callq 0x5780
jmp 0x2638a
leaq -0x358(%rbp), %rdi
callq 0x5aa8
leaq -0x359(%rbp), %rdi
callq 0x55e0
jmp 0x263db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x263ca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x358(%rbp), %rdi
callq 0x5aa8
leaq -0x359(%rbp), %rdi
callq 0x55e0
jmp 0x264bc
cmpl $0x1f7, -0x14(%rbp)     # imm = 0x1F7
jne 0x264aa
movq -0x390(%rbp), %rax
addq $0x190, %rax            # imm = 0x190
movq %rax, -0x468(%rbp)
leaq -0x381(%rbp), %rdi
movq %rdi, -0x460(%rbp)
callq 0x5960
movq -0x460(%rbp), %rdx
leaq 0x1d439(%rip), %rsi     # 0x43856
leaq -0x380(%rbp), %rdi
callq 0x6be0
jmp 0x2642b
movq -0x468(%rbp), %rdi
leaq -0x380(%rbp), %rsi
callq 0x20e30
movq %rax, -0x470(%rbp)
jmp 0x26447
movq -0x470(%rbp), %rdi
leaq 0x1d3fe(%rip), %rsi     # 0x43853
callq 0x5780
jmp 0x2645c
leaq -0x380(%rbp), %rdi
callq 0x5aa8
leaq -0x381(%rbp), %rdi
callq 0x55e0
jmp 0x264aa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x2649c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x380(%rbp), %rdi
callq 0x5aa8
leaq -0x381(%rbp), %rdi
callq 0x55e0
jmp 0x264bc
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x470, %rsp            # imm = 0x470
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0x5950
nopw %cs:(%rax,%rax)