// File: /workspace/github_cpp_makefile_star2_O1/solaldunckel[P]webserv/srcs/HTTP/CGI.cpp
// Function: CGI::setCGIEnv()
bool CGI::setCGIEnv() {
  if (config_.getMethod() == "POST") {
		cgi_env_["CONTENT_TYPE"] = req_headers_["Content-Type"];
		cgi_env_["CONTENT_LENGTH"] = ft::to_string(req_body_.length());
	}
	cgi_env_["GATEWAY_INTERFACE"] = "CGI/1.1";
  cgi_env_["PATH_INFO"] = file_path_;
	cgi_env_["PATH_TRANSLATED"] = file_path_;
  cgi_env_["QUERY_STRING"] = config_.getQuery();
  cgi_env_["REMOTE_ADDR"] = config_.getClient().getAddr();

  if (config_.getAuth() != "off") {
    cgi_env_["AUTH_TYPE"] = "Basic";
    cgi_env_["REMOTE_IDENT"] = config_.getAuth().substr(0, config_.getAuth().find(':'));
    cgi_env_["REMOTE_USER"] = config_.getAuth().substr(0, config_.getAuth().find(':'));
  }

  cgi_env_["REQUEST_METHOD"] = config_.getMethod();
	cgi_env_["REQUEST_URI"] = file_path_;

  cgi_env_["SCRIPT_NAME"] = cgi_path_;
	cgi_env_["SERVER_NAME"] = config_.getHost();
	cgi_env_["SERVER_PROTOCOL"] = config_.getProtocol();
	cgi_env_["SERVER_PORT"] = ft::to_string(config_.getPort());
  cgi_env_["SERVER_SOFTWARE"] = "WEBSERV/1.0";

	if (extension_ == ".php")
		cgi_env_["REDIRECT_STATUS"] = "200";

  for (std::map<std::string, std::string, ft::comp>::iterator it = req_headers_.begin(); it != req_headers_.end(); it++) {
    if (!it->second.empty()) {
      std::string header = "HTTP_" + ft::to_upper(it->first);
      std::replace(header.begin(), header.end(), '-', '_');
      cgi_env_[header] = it->second;
    }
  }

	if (!(env_ = (char **)malloc(sizeof(char *) * (cgi_env_.size() + 1))))
		return false;

	int i = 0;

	for (std::map<std::string, std::string>::iterator it = cgi_env_.begin(); it != cgi_env_.end(); it++) {
		std::string tmp = it->first + "=" + it->second;
		if (!(env_[i] = ft::strdup(tmp.c_str())))
      return false;
		i++;
	}
	env_[i] = NULL;
  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %r13
movq 0x8(%rdi), %rdi
callq 0x9f04
leaq 0x15eda(%rip), %rsi     # 0x2558f
movq %rax, %rdi
callq 0x40f0
leaq 0x10(%rsp), %r12
testl %eax, %eax
jne 0xf7d1
movq 0x10(%r13), %r14
movq %rsp, %rdi
movq %r12, (%rdi)
leaq 0x15f05(%rip), %rsi     # 0x255e0
leaq 0x15f0a(%rip), %rdx     # 0x255ec
callq 0x578e
movq %rsp, %rsi
movq %r14, %rdi
callq 0xa7d2
movq %rax, %r15
leaq 0x30(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x15ee8(%rip), %rsi     # 0x255ed
leaq 0x15eed(%rip), %rdx     # 0x255f9
leaq 0x20(%rsp), %rdi
callq 0x578e
leaq 0x198(%r13), %r14
leaq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0x104da
movq %rax, %rdi
movq %r15, %rsi
callq 0x4230
movq 0x20(%rsp), %rdi
cmpq %rbx, %rdi
je 0xf74c
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x4460
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xf762
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0xe0(%r13), %rsi
movq %rsp, %rdi
callq 0x10556
leaq 0x20(%rsp), %rdi
movq %rbx, (%rdi)
leaq 0x15e7a(%rip), %rsi     # 0x255fa
leaq 0x15e81(%rip), %rdx     # 0x25608
callq 0x578e
leaq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0x104da
movq %rsp, %rsi
movq %rax, %rdi
callq 0x4560
movq 0x20(%rsp), %rdi
cmpq %rbx, %rdi
je 0xf7bb
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x4460
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xf7d1
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4460
movq %rsp, %rdi
movq %r12, (%rdi)
leaq 0x15e33(%rip), %rsi     # 0x25611
leaq 0x15e3d(%rip), %rdx     # 0x25622
callq 0x578e
leaq 0x198(%r13), %rbp
movq %rsp, %rsi
movq %rbp, %rdi
callq 0x104da
movq 0x8(%rax), %rdx
leaq 0x15e02(%rip), %rcx     # 0x25609
movl $0x7, %r8d
movq %rax, %rdi
xorl %esi, %esi
callq 0x4680
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xf82d
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4460
movq %rsp, %rdi
movq %r12, (%rdi)
leaq 0x15de9(%rip), %rsi     # 0x25623
leaq 0x15deb(%rip), %rdx     # 0x2562c
callq 0x578e
movq %rsp, %rsi
movq %rbp, %rdi
callq 0x104da
leaq 0x98(%r13), %r15
movq %rax, %rdi
movq %r15, %rsi
callq 0x4230
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xf879
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4460
movq %rsp, %rdi
movq %r12, (%rdi)
leaq 0x15da7(%rip), %rsi     # 0x2562d
leaq 0x15daf(%rip), %rdx     # 0x2563c
callq 0x578e
movq %rsp, %rsi
movq %rbp, %rdi
callq 0x104da
movq %rax, %rdi
movq %r15, %rsi
callq 0x4230
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xf8be
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x8(%r13), %rdi
callq 0x9e62
movq %rax, %r14
movq %rsp, %rdi
movq %r12, (%rdi)
leaq 0x15d66(%rip), %rsi     # 0x2563d
leaq 0x15d6b(%rip), %rdx     # 0x25649
callq 0x578e
movq %rsp, %rsi
movq %rbp, %rdi
callq 0x104da
movq %rax, %rdi
movq %r14, %rsi
callq 0x4230
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xf90f
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x8(%r13), %rdi
callq 0x9e84
movq %rax, %rdi
callq 0x10d90
movq %rax, %r14
movq %rsp, %rdi
movq %r12, (%rdi)
leaq 0x15d1a(%rip), %rsi     # 0x2564a
leaq 0x15d1e(%rip), %rdx     # 0x25655
callq 0x578e
movq %rsp, %rsi
movq %rbp, %rdi
callq 0x104da
movq %rax, %rdi
movq %r14, %rsi
callq 0x4230
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xf968
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x8(%r13), %rdi
callq 0x9e94
leaq 0x1679f(%rip), %rsi     # 0x26117
movq %rax, %rdi
callq 0x40f0
testl %eax, %eax
je 0xfb0b
movq %rsp, %rdi
movq %r12, (%rdi)
leaq 0x15cc7(%rip), %rsi     # 0x2565c
leaq 0x15cc9(%rip), %rdx     # 0x25665
callq 0x578e
movq %rsp, %rsi
movq %rbp, %rdi
callq 0x104da
movq 0x8(%rax), %rdx
leaq 0x15c9f(%rip), %rcx     # 0x25656
movl $0x5, %r8d
movq %rax, %rdi
xorl %esi, %esi
callq 0x4680
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xf9dd
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x8(%r13), %rdi
callq 0x9e94
movq %rax, %r14
movq 0x8(%r13), %rdi
callq 0x9e94
movq %rax, %rdi
movl $0x3a, %esi
xorl %edx, %edx
callq 0x4580
movq %rsp, %rdi
movq %r14, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x4480
leaq 0x30(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x15c45(%rip), %rsi     # 0x25666
leaq 0x15c4a(%rip), %rdx     # 0x25672
leaq 0x20(%rsp), %rdi
callq 0x578e
leaq 0x20(%rsp), %rsi
movq %rbp, %rdi
callq 0x104da
movq %rsp, %rsi
movq %rax, %rdi
callq 0x4560
movq 0x20(%rsp), %rdi
cmpq %rbx, %rdi
je 0xfa61
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x4460
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xfa77
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x8(%r13), %rdi
callq 0x9e94
movq %rax, %r14
movq 0x8(%r13), %rdi
callq 0x9e94
movq %rax, %rdi
movl $0x3a, %esi
xorl %edx, %edx
callq 0x4580
movq %rsp, %rdi
movq %r14, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x4480
leaq 0x20(%rsp), %rdi
movq %rbx, (%rdi)
leaq 0x15bb9(%rip), %rsi     # 0x25673
leaq 0x15bbd(%rip), %rdx     # 0x2567e
callq 0x578e
leaq 0x20(%rsp), %rsi
movq %rbp, %rdi
callq 0x104da
movq %rsp, %rsi
movq %rax, %rdi
callq 0x4560
movq 0x20(%rsp), %rdi
cmpq %rbx, %rdi
je 0xfaf5
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x4460
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xfb0b
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x8(%r13), %rdi
callq 0x9f04
movq %rax, %r14
movq %rsp, %rdi
movq %r12, (%rdi)
leaq 0x15b5b(%rip), %rsi     # 0x2567f
leaq 0x15b62(%rip), %rdx     # 0x2568d
callq 0x578e
movq %rsp, %rsi
movq %rbp, %rdi
callq 0x104da
movq %rax, %rdi
movq %r14, %rsi
callq 0x4230
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xfb5c
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4460
movq %rsp, %rdi
movq %r12, (%rdi)
leaq 0x15b25(%rip), %rsi     # 0x2568e
leaq 0x15b29(%rip), %rdx     # 0x25699
callq 0x578e
movq %rsp, %rsi
movq %rbp, %rdi
callq 0x104da
movq %rax, %rdi
movq %r15, %rsi
callq 0x4230
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xfba1
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4460
movq %rsp, %rdi
movq %r12, (%rdi)
leaq 0x15aec(%rip), %rsi     # 0x2569a
leaq 0x15af0(%rip), %rdx     # 0x256a5
callq 0x578e
movq %rsp, %rsi
movq %rbp, %rdi
callq 0x104da
leaq 0x18(%r13), %rsi
movq %rax, %rdi
callq 0x4230
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xfbe7
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x8(%r13), %rdi
callq 0x9e74
movq %rax, %r14
movq %rsp, %rdi
movq %r12, (%rdi)
leaq 0x15aa6(%rip), %rsi     # 0x256a6
leaq 0x15aaa(%rip), %rdx     # 0x256b1
callq 0x578e
movq %rsp, %rsi
movq %rbp, %rdi
callq 0x104da
movq %rax, %rdi
movq %r14, %rsi
callq 0x4230
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xfc38
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x8(%r13), %rdi
callq 0x9f26
movq %rax, %r14
movq %rsp, %rdi
movq %r12, (%rdi)
leaq 0x15a61(%rip), %rsi     # 0x256b2
leaq 0x15a69(%rip), %rdx     # 0x256c1
callq 0x578e
movq %rsp, %rsi
movq %rbp, %rdi
callq 0x104da
movq %rax, %rdi
movq %r14, %rsi
callq 0x4230
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xfc89
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x8(%r13), %rdi
callq 0x9e7a
movl (%rax), %esi
movq %rsp, %rdi
callq 0x105d9
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x15a16(%rip), %rsi     # 0x256c2
leaq 0x15a1a(%rip), %rdx     # 0x256cd
leaq 0x20(%rsp), %rdi
callq 0x578e
leaq 0x20(%rsp), %rsi
movq %rbp, %rdi
callq 0x104da
movq %rsp, %rsi
movq %rax, %rdi
callq 0x4560
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0xfcf1
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x4460
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xfd07
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4460
movq %rsp, %rdi
movq %r12, (%rdi)
leaq 0x159c6(%rip), %rsi     # 0x256da
leaq 0x159ce(%rip), %rdx     # 0x256e9
callq 0x578e
movq %rsp, %rsi
movq %rbp, %rdi
callq 0x104da
movq 0x8(%rax), %rdx
leaq 0x15998(%rip), %rcx     # 0x256ce
movl $0xb, %r8d
movq %rax, %rdi
xorl %esi, %esi
callq 0x4680
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xfd5c
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4460
leaq 0x58(%r13), %rdi
leaq 0x15983(%rip), %rsi     # 0x256ea
callq 0x40f0
testl %eax, %eax
jne 0xfdc5
movq %rsp, %rdi
movq %r12, (%rdi)
leaq 0x15976(%rip), %rsi     # 0x256f3
leaq 0x1597e(%rip), %rdx     # 0x25702
callq 0x578e
movq %rsp, %rsi
movq %rbp, %rdi
callq 0x104da
movq 0x8(%rax), %rdx
leaq 0x15950(%rip), %rcx     # 0x256ef
movl $0x3, %r8d
movq %rax, %rdi
xorl %esi, %esi
callq 0x4680
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xfdc5
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4460
movq %r13, %r12
movq 0x10(%r13), %rax
movq 0x18(%rax), %r15
addq $0x8, %rax
cmpq %rax, %r15
je 0xff1b
leaq 0x58(%rsp), %rbx
leaq 0x48(%rsp), %r14
leaq 0x20(%rsp), %r13
cmpq $0x0, 0x48(%r15)
je 0xfefe
movq %rbx, 0x48(%rsp)
movq 0x20(%r15), %rsi
movq 0x28(%r15), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x6bac
movq %r13, %rdi
movq %r14, %rsi
callq 0x241e5
movl $0x5, %r8d
movq %r13, %rdi
xorl %esi, %esi
xorl %edx, %edx
leaq 0x158d5(%rip), %rcx     # 0x25703
callq 0x44c0
leaq 0x10(%rsp), %rsi
movq %rsi, (%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0xfe59
movq %rdx, (%rsp)
movq (%rcx), %rdx
movq %rdx, 0x10(%rsp)
jmp 0xfe5f
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x8(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0xfe93
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x48(%rsp), %rdi
cmpq %rbx, %rdi
je 0xfeaa
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0xfecc
movq (%rsp), %rcx
xorl %edx, %edx
cmpb $0x2d, (%rcx,%rdx)
jne 0xfec4
movb $0x5f, (%rcx,%rdx)
incq %rdx
cmpq %rdx, %rax
jne 0xfeba
movq %rbp, %rdi
movq %rsp, %rsi
callq 0xce88
leaq 0x40(%r15), %rsi
movq %rax, %rdi
callq 0x4230
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xfefe
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4460
movq %r15, %rdi
callq 0x42d0
movq %rax, %r15
movq 0x10(%r12), %rax
addq $0x8, %rax
cmpq %rax, %r15
jne 0xfdec
movq %r12, %rbx
movq 0x1c0(%r12), %rax
leaq 0x8(,%rax,8), %rdi
callq 0x4590
movq %rax, 0x1c8(%r12)
testq %rax, %rax
je 0x1007c
movq 0x1b0(%rbx), %r14
leaq 0x1a0(%rbx), %rax
xorl %ebx, %ebx
movq %rax, 0x40(%rsp)
cmpq %rax, %r14
sete %bpl
je 0x10064
leaq 0x20(%rsp), %r15
leaq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x20(%r14), %rsi
movq 0x28(%r14), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x6bac
movq %r15, %rdi
leaq 0x1595d(%rip), %rsi     # 0x258ef
callq 0x4830
movq 0x40(%r14), %rsi
movq 0x48(%r14), %rdx
movq %r15, %rdi
callq 0x4100
leaq 0x10(%rsp), %rsi
movq %rsi, (%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0xffcd
movq %rdx, (%rsp)
movq (%rcx), %rdx
movq %rdx, 0x10(%rsp)
jmp 0xffd3
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x8(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x10007
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x4460
movq (%rsp), %rdi
callq 0x24407
movq %rax, %r13
movq 0x1c8(%r12), %rax
movl %ebx, %ecx
movq %r13, (%rax,%rcx,8)
cmpq $0x1, %r13
sbbl $-0x1, %ebx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x10043
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4460
testq %r13, %r13
je 0x10062
movq %r14, %rdi
callq 0x42d0
movq %rax, %r14
cmpq 0x40(%rsp), %rax
sete %bpl
jne 0xff6b
movl %ebx, %ebx
testb $0x1, %bpl
je 0x1007e
movq 0x1c8(%r12), %rax
movq $0x0, (%rax,%rbx,8)
jmp 0x1007e
xorl %ebp, %ebp
andb $0x1, %bpl
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1010d
jmp 0x100ba
jmp 0x1018b
jmp 0x1018b
jmp 0x1018b
jmp 0x1010d
jmp 0x100ba
jmp 0x1018b
jmp 0x100ba
jmp 0x1018b
jmp 0x1010d
jmp 0x1012b
movq %rax, %r14
movq 0x20(%rsp), %rdi
cmpq %rbx, %rdi
jne 0x100e4
jmp 0x1018e
jmp 0x1010d
movq %rax, %r14
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x1018e
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0x1018e
jmp 0x1018b
jmp 0x1010d
jmp 0x1010d
jmp 0x1010d
jmp 0x1010d
jmp 0x1010d
jmp 0x1010d
jmp 0x1010d
jmp 0x1010d
jmp 0x1010d
movq %rax, %r14
jmp 0x101a9
jmp 0x1012b
jmp 0x1012b
jmp 0x1012b
jmp 0x1012b
jmp 0x1012b
jmp 0x1012b
jmp 0x1012b
jmp 0x1012b
jmp 0x1012b
jmp 0x1012b
jmp 0x1012b
movq %rax, %r14
movq (%rsp), %rdi
cmpq %r12, %rdi
jne 0x1019c
jmp 0x101a9
jmp 0x1013d
jmp 0x1018b
movq %rax, %r14
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x101a9
movq 0x30(%rsp), %rsi
jmp 0x101a1
movq %rax, %r14
jmp 0x1017a
movq %rax, %r14
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x1017a
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x48(%rsp), %rdi
cmpq %rbx, %rdi
je 0x101a9
movq 0x58(%rsp), %rsi
jmp 0x101a1
movq %rax, %r14
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x101a9
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x4460
movq %r14, %rdi
callq 0x4780
nop