// File: solaldunckel[P]webserv/srcs/HTTP/CGI.cpp
// Function: CGI::init(int)
void CGI::init(int worker_id) {
  char *cwd = getcwd(NULL, 0);
  if (!cwd)
    return ;
  cwd_ = cwd;
  free(cwd);

  env_ = NULL;
  argv_[0] = NULL;
  argv_[1] = NULL;
  argv_[2] = NULL;
  extension_ = file_.getMimeExtension();
  cgi_exe_ = config_.getCGI()[extension_];
  if (config_.getCGIBin()[0] == '/') {
    cgi_path_ = config_.getCGIBin() + "/" + cgi_exe_;
  } else {
    cgi_path_ = cwd_ + "/" + config_.getCGIBin() + "/" + cgi_exe_;
  }
  std::string cgi_path = "/tmp/webserv_cgi_tmp_" + ft::to_string(worker_id);
  tmp_file_.set_path(cgi_path.c_str());
  tmp_file_.open(true);
  if (worker_id)
    Log.print(DEBUG, "worker[" + ft::to_string(worker_id) + "] : CGI -> " + cgi_path_);
  else
    Log.print(DEBUG, "server : CGI -> " + cgi_path_);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x290, %rsp            # imm = 0x290
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x248(%rbp)
xorl %eax, %eax
movl %eax, %esi
movq %rsi, %rdi
callq 0x5290
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x1e989
jmp 0x1efd2
movq -0x248(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x78, %rdi
callq 0x5780
movq -0x18(%rbp), %rdi
callq 0x56b0
movq -0x248(%rbp), %rax
movq $0x0, 0x1c8(%rax)
movq $0x0, 0x1d0(%rax)
movq $0x0, 0x1d8(%rax)
movq $0x0, 0x1e0(%rax)
movq (%rax), %rdi
callq 0x37f70
movq -0x248(%rbp), %rdi
movq %rax, %rsi
addq $0x58, %rdi
callq 0x5050
movq -0x248(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x12f10
movq -0x248(%rbp), %rsi
movq %rax, %rdi
addq $0x58, %rsi
callq 0x19050
movq -0x248(%rbp), %rdi
movq %rax, %rsi
addq $0x38, %rdi
callq 0x5050
movq -0x248(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x12f30
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x5a80
movsbl (%rax), %eax
cmpl $0x2f, %eax
jne 0x1eade
movq -0x248(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x12f30
movq %rax, %rsi
leaq 0x24b37(%rip), %rdx     # 0x435a3
leaq -0x58(%rbp), %rdi
movq %rdi, -0x250(%rbp)
callq 0x8f70
movq -0x248(%rbp), %rdx
movq -0x250(%rbp), %rsi
addq $0x38, %rdx
leaq -0x38(%rbp), %rdi
callq 0x6a30
jmp 0x1ea99
movq -0x248(%rbp), %rdi
addq $0x18, %rdi
leaq -0x38(%rbp), %rsi
callq 0x56d0
leaq -0x38(%rbp), %rdi
callq 0x5aa8
leaq -0x58(%rbp), %rdi
callq 0x5aa8
jmp 0x1ec07
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x5aa8
jmp 0x1efe7
movq -0x248(%rbp), %rsi
addq $0x78, %rsi
leaq 0x24ab3(%rip), %rdx     # 0x435a3
leaq -0xe8(%rbp), %rdi
callq 0x8f70
movq -0x248(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x12f30
movq %rax, -0x258(%rbp)
jmp 0x1eb15
movq -0x258(%rbp), %rdx
leaq -0xc8(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x6a30
jmp 0x1eb31
leaq 0x24a6b(%rip), %rdx     # 0x435a3
leaq -0xa8(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x6a80
jmp 0x1eb4d
movq -0x248(%rbp), %rdx
addq $0x38, %rdx
leaq -0x88(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x6a30
jmp 0x1eb6d
movq -0x248(%rbp), %rdi
addq $0x18, %rdi
leaq -0x88(%rbp), %rsi
callq 0x56d0
leaq -0x88(%rbp), %rdi
callq 0x5aa8
leaq -0xa8(%rbp), %rdi
callq 0x5aa8
leaq -0xc8(%rbp), %rdi
callq 0x5aa8
leaq -0xe8(%rbp), %rdi
callq 0x5aa8
jmp 0x1ec07
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x1ebf6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x1ebea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x5aa8
leaq -0xc8(%rbp), %rdi
callq 0x5aa8
leaq -0xe8(%rbp), %rdi
callq 0x5aa8
jmp 0x1efe7
movl -0xc(%rbp), %esi
leaq -0x128(%rbp), %rdi
movq %rdi, -0x260(%rbp)
callq 0x9070
movq -0x260(%rbp), %rdx
leaq 0x2497a(%rip), %rsi     # 0x435a5
leaq -0x108(%rbp), %rdi
callq 0x107f0
jmp 0x1ec39
leaq -0x128(%rbp), %rdi
callq 0x5aa8
movq -0x248(%rbp), %rax
addq $0xf8, %rax
movq %rax, -0x278(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x51f0
movq %rax, -0x270(%rbp)
leaq -0x149(%rbp), %rdi
movq %rdi, -0x268(%rbp)
callq 0x5960
movq -0x270(%rbp), %rsi
movq -0x268(%rbp), %rdx
leaq -0x148(%rbp), %rdi
callq 0x6be0
jmp 0x1ec9b
movq -0x278(%rbp), %rdi
leaq -0x148(%rbp), %rsi
xorl %edx, %edx
callq 0x35840
jmp 0x1ecb2
leaq -0x148(%rbp), %rdi
callq 0x5aa8
leaq -0x149(%rbp), %rdi
callq 0x55e0
movq -0x248(%rbp), %rdi
addq $0xf8, %rdi
movl $0x1, %esi
callq 0x35ee0
jmp 0x1ece4
cmpl $0x0, -0xc(%rbp)
je 0x1eeed
movl -0xc(%rbp), %esi
leaq -0x1d0(%rbp), %rdi
callq 0x9070
jmp 0x1ecff
leaq 0x248b5(%rip), %rsi     # 0x435bb
leaq -0x1b0(%rbp), %rdi
leaq -0x1d0(%rbp), %rdx
callq 0x107f0
jmp 0x1ed1b
leaq 0x248a1(%rip), %rdx     # 0x435c3
leaq -0x190(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x6a80
jmp 0x1ed37
movq -0x248(%rbp), %rdx
addq $0x18, %rdx
leaq -0x170(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x6a30
jmp 0x1ed57
leaq -0x1f1(%rbp), %rdi
movq %rdi, -0x280(%rbp)
callq 0x5960
movq -0x280(%rbp), %rdx
leaq 0x242a2(%rip), %rsi     # 0x4301a
leaq -0x1f0(%rbp), %rdi
callq 0x6be0
jmp 0x1ed86
leaq 0x3d86b(%rip), %rdi     # 0x5c5f8
movl $0x2, %esi
leaq -0x170(%rbp), %rdx
leaq -0x1f0(%rbp), %rcx
xorl %r8d, %r8d
callq 0x3b240
jmp 0x1edaa
leaq -0x1f0(%rbp), %rdi
callq 0x5aa8
leaq -0x1f1(%rbp), %rdi
callq 0x55e0
leaq -0x170(%rbp), %rdi
callq 0x5aa8
leaq -0x190(%rbp), %rdi
callq 0x5aa8
leaq -0x1b0(%rbp), %rdi
callq 0x5aa8
leaq -0x1d0(%rbp), %rdi
callq 0x5aa8
jmp 0x1efc6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x5aa8
jmp 0x1efe7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x1ee3a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x148(%rbp), %rdi
callq 0x5aa8
leaq -0x149(%rbp), %rdi
callq 0x55e0
jmp 0x1efdb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x1efdb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x1eedc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x1eed0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x1eec4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x1eeac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x1f0(%rbp), %rdi
callq 0x5aa8
leaq -0x1f1(%rbp), %rdi
callq 0x55e0
leaq -0x170(%rbp), %rdi
callq 0x5aa8
leaq -0x190(%rbp), %rdi
callq 0x5aa8
leaq -0x1b0(%rbp), %rdi
callq 0x5aa8
leaq -0x1d0(%rbp), %rdi
callq 0x5aa8
jmp 0x1efdb
movq -0x248(%rbp), %rdx
addq $0x18, %rdx
leaq 0x246d0(%rip), %rsi     # 0x435cf
leaq -0x218(%rbp), %rdi
callq 0x6ad0
jmp 0x1ef0d
leaq -0x239(%rbp), %rdi
movq %rdi, -0x288(%rbp)
callq 0x5960
movq -0x288(%rbp), %rdx
leaq 0x240ec(%rip), %rsi     # 0x4301a
leaq -0x238(%rbp), %rdi
callq 0x6be0
jmp 0x1ef3c
leaq 0x3d6b5(%rip), %rdi     # 0x5c5f8
movl $0x2, %esi
leaq -0x218(%rbp), %rdx
leaq -0x238(%rbp), %rcx
xorl %r8d, %r8d
callq 0x3b240
jmp 0x1ef60
leaq -0x238(%rbp), %rdi
callq 0x5aa8
leaq -0x239(%rbp), %rdi
callq 0x55e0
leaq -0x218(%rbp), %rdi
callq 0x5aa8
jmp 0x1efc6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x1efac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x238(%rbp), %rdi
callq 0x5aa8
leaq -0x239(%rbp), %rdi
callq 0x55e0
leaq -0x218(%rbp), %rdi
callq 0x5aa8
jmp 0x1efdb
leaq -0x108(%rbp), %rdi
callq 0x5aa8
addq $0x290, %rsp            # imm = 0x290
popq %rbp
retq
leaq -0x108(%rbp), %rdi
callq 0x5aa8
movq -0x60(%rbp), %rdi
callq 0x5950