// File: solaldunckel[P]webserv/srcs/HTTP/Client.cpp
// Function: Client::setupResponse(std::vector<ServerConfig, std::allocator<ServerConfig>>&, InputArgs&, int)
void Client::setupResponse(std::vector<ServerConfig> &servers, InputArgs &options, int error_code) {
  if (!request_)
    request_ = getRequest(true);

  if (!config_)
    setupConfig(servers, options);

  response_ = new Response(*config_, worker_id_, error_code);

  int loop = 0;

  for (int ret = 1; ret != 0; loop++) {
    ret = 0;

    response_->build();

    if (response_->redirect()) {
      ret = 1;
      config_->redirectLocation(response_->redirect_target());
      Log.print(INFO, "INTERNAL REDIRECT : [target: " + response_->redirect_target() + "]");
      response_->clear();
    }
    if (loop >= 10) {
      ft::delete_(response_);
      response_ = new Response(*config_, worker_id_, 500);
      response_->build();
      break ;
    }
  }

  ft::delete_(request_);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xe8(%rbp)
cmpq $0x0, 0x38(%rax)
jne 0x217fb
movq -0xe8(%rbp), %rdi
movl $0x1, %esi
callq 0x21b50
movq %rax, %rcx
movq -0xe8(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0xe8(%rbp), %rax
cmpq $0x0, 0x40(%rax)
jne 0x2181d
movq -0xe8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x21720
movl $0x1c0, %edi            # imm = 0x1C0
callq 0x5550
movq %rax, %rdi
movq -0xe8(%rbp), %rax
movq %rdi, %rcx
movq %rcx, -0xf0(%rbp)
movq 0x40(%rax), %rsi
movl 0x30(%rax), %edx
movl -0x1c(%rbp), %ecx
callq 0x24310
jmp 0x2184c
movq -0xe8(%rbp), %rax
movq -0xf0(%rbp), %rcx
movq %rcx, 0x48(%rax)
movl $0x0, -0x30(%rbp)
movl $0x1, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x21b25
movq -0xe8(%rbp), %rax
movl $0x0, -0x34(%rbp)
movq 0x48(%rax), %rdi
callq 0x265f0
movq -0xe8(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x29500
testb $0x1, %al
jne 0x218a6
jmp 0x21a92
movq -0xe8(%rbp), %rax
movl $0x1, -0x34(%rbp)
movq 0x40(%rax), %rcx
movq %rcx, -0x100(%rbp)
movq 0x48(%rax), %rsi
leaq -0x58(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x29520
movq -0x100(%rbp), %rdi
movq -0xf8(%rbp), %rsi
callq 0x12af0
jmp 0x218e8
leaq -0x58(%rbp), %rdi
callq 0x5aa8
movq -0xe8(%rbp), %rax
movq 0x48(%rax), %rsi
leaq -0xb8(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x29520
movq -0x108(%rbp), %rdx
leaq 0x21dfb(%rip), %rsi     # 0x43718
leaq -0x98(%rbp), %rdi
callq 0x107f0
jmp 0x2192b
leaq 0x21a21(%rip), %rdx     # 0x43353
leaq -0x78(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x6a80
jmp 0x21944
leaq -0xd9(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0x5960
movq -0x110(%rbp), %rdx
leaq 0x216b5(%rip), %rsi     # 0x4301a
leaq -0xd8(%rbp), %rdi
callq 0x6be0
jmp 0x21973
leaq 0x3ac7e(%rip), %rdi     # 0x5c5f8
movl $0x1, %esi
leaq -0x78(%rbp), %rdx
leaq -0xd8(%rbp), %rcx
xorl %r8d, %r8d
callq 0x3b240
jmp 0x21994
leaq -0xd8(%rbp), %rdi
callq 0x5aa8
leaq -0xd9(%rbp), %rdi
callq 0x55e0
leaq -0x78(%rbp), %rdi
callq 0x5aa8
leaq -0x98(%rbp), %rdi
callq 0x5aa8
leaq -0xb8(%rbp), %rdi
callq 0x5aa8
movq -0xe8(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x24900
jmp 0x21a92
movq -0xf0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x1c0, %esi            # imm = 0x1C0
callq 0x5580
jmp 0x21b3e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x5aa8
jmp 0x21b3e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x21a81
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x21a75
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x21a60
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x5aa8
leaq -0xd9(%rbp), %rdi
callq 0x55e0
leaq -0x78(%rbp), %rdi
callq 0x5aa8
leaq -0x98(%rbp), %rdi
callq 0x5aa8
leaq -0xb8(%rbp), %rdi
callq 0x5aa8
jmp 0x21b3e
cmpl $0xa, -0x30(%rbp)
jl 0x21b15
movq -0xe8(%rbp), %rdi
addq $0x48, %rdi
callq 0x21dd0
movl $0x1c0, %edi            # imm = 0x1C0
callq 0x5550
movq %rax, %rdi
movq -0xe8(%rbp), %rax
movq %rdi, %rcx
movq %rcx, -0x118(%rbp)
movq 0x40(%rax), %rsi
movl 0x30(%rax), %edx
movl $0x1f4, %ecx            # imm = 0x1F4
callq 0x24310
jmp 0x21ad9
movq -0xe8(%rbp), %rax
movq -0x118(%rbp), %rcx
movq %rcx, 0x48(%rax)
movq 0x48(%rax), %rdi
callq 0x265f0
jmp 0x21b25
movq -0x118(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x1c0, %esi            # imm = 0x1C0
callq 0x5580
jmp 0x21b3e
jmp 0x21b17
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x2186c
movq -0xe8(%rbp), %rdi
addq $0x38, %rdi
callq 0x21d30
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0x5950
nopw (%rax,%rax)