// File: /workspace/github_c_makefile_star2_O0/silverneko[P]miku/isolate/isolate.c
// Function: setup_environment
static char **
setup_environment(void)
{
  // Link built-in rules with user rules
  for (int i=ARRAY_SIZE(default_env_rules)-1; i >= 0; i--)
    {
      default_env_rules[i].next = first_env_rule;
      first_env_rule = &default_env_rules[i];
    }

  // Scan the original environment
  char **orig_env = environ;
  int orig_size = 0;
  while (orig_env[orig_size])
    orig_size++;

  // For each rule, reserve one more slot and calculate length
  int num_rules = 0;
  for (struct env_rule *r = first_env_rule; r; r=r->next)
    {
      num_rules++;
      r->var_len = strlen(r->var);
    }

  // Create a new environment
  char **env = xmalloc((orig_size + num_rules + 1) * sizeof(char *));
  int size;
  if (pass_environ)
    {
      memcpy(env, environ, orig_size * sizeof(char *));
      size = orig_size;
    }
  else
    size = 0;
  env[size] = NULL;

  // Apply the rules one by one
  for (struct env_rule *r = first_env_rule; r; r=r->next)
    apply_env_rule(env, &size, r);

  // Return the new env and pass some gossip
  if (verbose > 1)
    {
      fprintf(stderr, "Passing environment:\n");
      for (int i=0; env[i]; i++)
	fprintf(stderr, "\t%s\n", env[i]);
    }
  return env;
}

// Assembly:
subq $0x48, %rsp
movl $0x0, 0x44(%rsp)
cmpl $0x0, 0x44(%rsp)
jl 0x5408
movq 0x4f5e(%rip), %rcx      # 0xa328
movslq 0x44(%rsp), %rdx
leaq 0x4eaa(%rip), %rax      # 0xa280
shlq $0x5, %rdx
addq %rdx, %rax
movq %rcx, 0x18(%rax)
movslq 0x44(%rsp), %rcx
leaq 0x4e93(%rip), %rax      # 0xa280
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, 0x4f2d(%rip)      # 0xa328
movl 0x44(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0x53bc
movq 0x4bd1(%rip), %rax      # 0x9fe0
movq (%rax), %rax
movq %rax, 0x38(%rsp)
movl $0x0, 0x34(%rsp)
movq 0x38(%rsp), %rax
movslq 0x34(%rsp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x543d
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x541f
movl $0x0, 0x30(%rsp)
movq 0x4edc(%rip), %rax      # 0xa328
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
je 0x548b
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
movq 0x28(%rsp), %rax
movq (%rax), %rdi
callq 0x2180
movl %eax, %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0x10(%rax)
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x28(%rsp)
jmp 0x5451
movl 0x34(%rsp), %eax
addl 0x30(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rdi
shlq $0x3, %rdi
callq 0x35b0
movq %rax, 0x20(%rsp)
cmpl $0x0, 0x4e16(%rip)      # 0xa2c4
je 0x54d7
movq 0x20(%rsp), %rdi
movq 0x4b24(%rip), %rax      # 0x9fe0
movq (%rax), %rsi
movslq 0x34(%rsp), %rdx
shlq $0x3, %rdx
callq 0x2330
movl 0x34(%rsp), %eax
movl %eax, 0x1c(%rsp)
jmp 0x54df
movl $0x0, 0x1c(%rsp)
movq 0x20(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movq $0x0, (%rax,%rcx,8)
movq 0x4e30(%rip), %rax      # 0xa328
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
je 0x5529
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rdx
leaq 0x1c(%rsp), %rsi
callq 0x58c0
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x10(%rsp)
jmp 0x54fd
cmpl $0x1, 0x4dcc(%rip)      # 0xa2fc
jle 0x5598
movq 0x4abf(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x22d8(%rip), %rsi      # 0x781b
movb $0x0, %al
callq 0x2300
movl $0x0, 0xc(%rsp)
movq 0x20(%rsp), %rax
movslq 0xc(%rsp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x5596
movq 0x4a8e(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
movq 0x20(%rsp), %rax
movslq 0xc(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
leaq 0x22af(%rip), %rsi      # 0x7831
movb $0x0, %al
callq 0x2300
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x5552
jmp 0x5598
movq 0x20(%rsp), %rax
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)