// File: /workspace/github_cpp_makefile_star2_O2/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 $0x88, %rsp
movq %rdi, %r12
movq 0x8(%rdi), %rdi
callq 0x8e4e
leaq 0xf251(%rip), %rsi      # 0x1c579
movq %rax, %rdi
callq 0x610b
testb %al, %al
je 0xd404
movq 0x10(%r12), %rbx
leaq 0xf286(%rip), %rsi      # 0x1c5ca
leaq 0x10(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x5328
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x91fa
movq %rax, %r14
leaq 0xf26d(%rip), %rsi      # 0x1c5d7
leaq 0x38(%rsp), %rdi
leaq 0x5f(%rsp), %rdx
callq 0x5328
leaq 0x198(%r12), %rbx
leaq 0x38(%rsp), %rsi
movq %rbx, %rdi
callq 0xdd56
movq %rax, %rdi
movq %r14, %rsi
callq 0x4240
leaq 0x38(%rsp), %rdi
callq 0x4898
leaq 0x10(%rsp), %rdi
callq 0x4898
movq 0xe0(%r12), %rsi
leaq 0x10(%rsp), %rdi
callq 0xddbc
leaq 0xf21e(%rip), %rsi      # 0x1c5e4
leaq 0x38(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x5328
leaq 0x38(%rsp), %rsi
movq %rbx, %rdi
callq 0xdd56
leaq 0x10(%rsp), %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4560
leaq 0x38(%rsp), %rdi
callq 0x4898
movq %rbx, %rdi
callq 0x4898
leaq 0xf1f0(%rip), %rsi      # 0x1c5fb
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0x5328
leaq 0x198(%r12), %rdi
leaq 0x10(%rsp), %rsi
movq %rdi, 0x30(%rsp)
callq 0xdd56
leaq 0xf1bb(%rip), %rsi      # 0x1c5f3
movq %rax, %rdi
callq 0x4830
leaq 0x10(%rsp), %rdi
callq 0x4898
leaq 0xf1bc(%rip), %rsi      # 0x1c60d
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0x5328
leaq 0x10(%rsp), %rsi
movq 0x30(%rsp), %rdi
callq 0xdd56
leaq 0x98(%r12), %r15
movq %rax, %rdi
movq %r15, %rsi
callq 0x4240
leaq 0x10(%rsp), %rdi
callq 0x4898
leaq 0xf184(%rip), %rsi      # 0x1c617
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0x5328
leaq 0x10(%rsp), %rsi
movq 0x30(%rsp), %rdi
callq 0xdd56
movq %rax, %rdi
movq %r15, %rsi
callq 0x4240
leaq 0x10(%rsp), %rdi
callq 0x4898
movq 0x8(%r12), %rdi
callq 0x8dac
movq %rax, %rbx
leaq 0xf14d(%rip), %rsi      # 0x1c627
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0x5328
leaq 0x10(%rsp), %rsi
movq 0x30(%rsp), %rdi
callq 0xdd56
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4240
leaq 0x10(%rsp), %rdi
callq 0x4898
movq 0x8(%r12), %rdi
callq 0x8dce
movq %rax, %rdi
callq 0xe414
movq %rax, %rbx
leaq 0xf10b(%rip), %rsi      # 0x1c634
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0x5328
leaq 0x10(%rsp), %rsi
movq 0x30(%rsp), %rdi
callq 0xdd56
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4240
leaq 0x10(%rsp), %rdi
callq 0x4898
movq 0x8(%r12), %rdi
callq 0x8dde
leaq 0xfb5a(%rip), %rsi      # 0x1d0c7
movq %rax, %rdi
callq 0x61cb
testb %al, %al
je 0xd6b5
leaq 0xf0c2(%rip), %rsi      # 0x1c646
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0x5328
leaq 0x10(%rsp), %rsi
movq 0x30(%rsp), %rdi
callq 0xdd56
leaq 0xf097(%rip), %rsi      # 0x1c640
movq %rax, %rdi
callq 0x4830
leaq 0x10(%rsp), %rdi
callq 0x4898
movq 0x8(%r12), %rdi
callq 0x8dde
movq %rax, %rbx
movq 0x8(%r12), %rdi
callq 0x8dde
pushq $0x3a
popq %rsi
movq %rax, %rdi
xorl %edx, %edx
callq 0x45a0
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x44a0
leaq 0xf058(%rip), %rsi      # 0x1c650
leaq 0x38(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x5328
leaq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rdi
callq 0xdd56
leaq 0x10(%rsp), %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4560
leaq 0x38(%rsp), %rdi
callq 0x4898
movq %rbx, %rdi
callq 0x4898
movq 0x8(%r12), %rdi
callq 0x8dde
movq %rax, %rbx
movq 0x8(%r12), %rdi
callq 0x8dde
pushq $0x3a
popq %rsi
movq %rax, %rdi
xorl %edx, %edx
callq 0x45a0
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x44a0
leaq 0xefe8(%rip), %rsi      # 0x1c65d
leaq 0x38(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x5328
leaq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rdi
callq 0xdd56
leaq 0x10(%rsp), %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4560
leaq 0x38(%rsp), %rdi
callq 0x4898
movq %rbx, %rdi
callq 0x4898
movq 0x8(%r12), %rdi
callq 0x8e4e
movq %rax, %rbx
leaq 0xefa0(%rip), %rsi      # 0x1c669
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0x5328
leaq 0x10(%rsp), %rsi
movq 0x30(%rsp), %rdi
callq 0xdd56
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4240
leaq 0x10(%rsp), %rdi
callq 0x4898
leaq 0xef75(%rip), %rsi      # 0x1c678
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0x5328
leaq 0x10(%rsp), %rsi
movq 0x30(%rsp), %rdi
callq 0xdd56
movq %rax, %rdi
movq %r15, %rsi
callq 0x4240
leaq 0x10(%rsp), %rdi
callq 0x4898
leaq 0xef47(%rip), %rsi      # 0x1c684
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0x5328
leaq 0x10(%rsp), %rsi
movq 0x30(%rsp), %rdi
callq 0xdd56
leaq 0x18(%r12), %rsi
movq %rax, %rdi
callq 0x4240
leaq 0x10(%rsp), %rdi
callq 0x4898
movq 0x8(%r12), %rdi
callq 0x8dbe
movq %rax, %rbx
leaq 0xef0a(%rip), %rsi      # 0x1c690
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0x5328
leaq 0x10(%rsp), %rsi
movq 0x30(%rsp), %rdi
callq 0xdd56
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4240
leaq 0x10(%rsp), %rdi
callq 0x4898
movq 0x8(%r12), %rdi
callq 0x8e70
movq %rax, %rbx
leaq 0xeecf(%rip), %rsi      # 0x1c69c
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0x5328
leaq 0x10(%rsp), %rsi
movq 0x30(%rsp), %rdi
callq 0xdd56
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4240
leaq 0x10(%rsp), %rdi
callq 0x4898
movq 0x8(%r12), %rdi
callq 0x8dc4
movl (%rax), %esi
leaq 0x10(%rsp), %rdi
callq 0xde17
leaq 0xee8f(%rip), %rsi      # 0x1c6ac
leaq 0x38(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x5328
leaq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rdi
callq 0xdd56
leaq 0x10(%rsp), %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4560
leaq 0x38(%rsp), %rdi
callq 0x4898
movq %rbx, %rdi
callq 0x4898
leaq 0xee60(%rip), %rsi      # 0x1c6c4
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0x5328
leaq 0x10(%rsp), %rsi
movq 0x30(%rsp), %rdi
callq 0xdd56
leaq 0xee2f(%rip), %rsi      # 0x1c6b8
movq %rax, %rdi
callq 0x4830
leaq 0x10(%rsp), %rdi
callq 0x4898
leaq 0x58(%r12), %rdi
leaq 0xee2d(%rip), %rsi      # 0x1c6d4
callq 0x610b
testb %al, %al
je 0xd8ee
leaq 0xee26(%rip), %rsi      # 0x1c6dd
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0x5328
leaq 0x10(%rsp), %rsi
movq 0x30(%rsp), %rdi
callq 0xdd56
leaq 0xedfd(%rip), %rsi      # 0x1c6d9
movq %rax, %rdi
callq 0x4830
leaq 0x10(%rsp), %rdi
callq 0x4898
movq %r12, 0x60(%rsp)
movq 0x10(%r12), %rbp
movq 0x18(%rbp), %r13
leaq 0x68(%rsp), %r15
leaq 0x38(%rsp), %r12
leaq 0x10(%rsp), %r14
leaq 0xf(%rsp), %rbx
leaq 0x8(%rbp), %rax
cmpq %rax, %r13
je 0xd9bd
cmpq $0x0, 0x48(%r13)
je 0xd9ad
leaq 0x20(%r13), %rsi
movq %r15, %rdi
callq 0x45e0
movq %r12, %rdi
movq %r15, %rsi
callq 0x1b33d
movq %r14, %rdi
leaq 0xeda4(%rip), %rsi      # 0x1c6ed
movq %r12, %rdx
callq 0x8234
movq %r12, %rdi
callq 0x4898
movq %r15, %rdi
callq 0x4898
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
addq %rdi, %rsi
movb $0x2d, 0x38(%rsp)
movb $0x5f, 0xf(%rsp)
movq %r12, %rdx
movq %rbx, %rcx
callq 0xde6e
movq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0xb208
leaq 0x40(%r13), %rsi
movq %rax, %rdi
callq 0x4240
movq %r14, %rdi
callq 0x4898
movq 0x60(%rsp), %rax
movq 0x10(%rax), %rbp
movq %r13, %rdi
callq 0x42e0
movq %rax, %r13
jmp 0xd910
movq 0x60(%rsp), %r14
movq 0x1c0(%r14), %rax
leaq 0x8(,%rax,8), %rdi
callq 0x45b0
movq %rax, 0x1c8(%r14)
testq %rax, %rax
je 0xda69
movq 0x1b0(%r14), %rbx
addq $0x1a0, %r14            # imm = 0x1A0
xorl %ebp, %ebp
leaq 0x38(%rsp), %r15
leaq 0x10(%rsp), %r12
cmpq %r14, %rbx
je 0xda6d
leaq 0x20(%rbx), %rsi
movq %r15, %rdi
leaq 0xee7b(%rip), %rdx      # 0x1c88e
callq 0x60d3
leaq 0x40(%rbx), %rdx
movq %r12, %rdi
movq %r15, %rsi
callq 0x5273
movq %r15, %rdi
callq 0x4898
movq 0x10(%rsp), %rdi
callq 0x1b496
movq %rax, %r13
movq 0x60(%rsp), %rax
movq 0x1c8(%rax), %rax
movq %r13, (%rax,%rbp,8)
movq %r12, %rdi
callq 0x4898
testq %r13, %r13
je 0xda69
incq %rbp
movq %rbx, %rdi
callq 0x42e0
movq %rax, %rbx
jmp 0xda00
xorl %eax, %eax
jmp 0xda82
movq 0x60(%rsp), %rax
movq 0x1c8(%rax), %rax
movl %ebp, %ecx
andq $0x0, (%rax,%rcx,8)
movb $0x1, %al
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xdac6
jmp 0xdacb
jmp 0xdb15
jmp 0xdacb
jmp 0xdb15
jmp 0xdac6
jmp 0xdacb
jmp 0xdb15
jmp 0xdb15
jmp 0xdb15
jmp 0xdac6
jmp 0xdb15
jmp 0xdac6
jmp 0xdacb
jmp 0xdb15
jmp 0xdac6
jmp 0xdac6
jmp 0xdac6
jmp 0xdac6
jmp 0xdac6
jmp 0xdb15
jmp 0xdac6
jmp 0xdac6
jmp 0xdac6
jmp 0xdac6
movq %rax, %rbx
jmp 0xdb22
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x4898
jmp 0xdb18
jmp 0xdb15
jmp 0xdb15
jmp 0xdb15
jmp 0xdb15
jmp 0xdb15
jmp 0xdb15
jmp 0xdb15
jmp 0xdb15
jmp 0xdb15
jmp 0xdb15
jmp 0xdb15
jmp 0xdb15
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
jmp 0xdb1d
movq %rax, %rbx
jmp 0xdb0e
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x4898
leaq 0x68(%rsp), %rdi
jmp 0xdb1d
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x4898
movq %rbx, %rdi
callq 0x4750