// File: /workspace/github_c_makefile_star2_O3/redis-force[P]rpm/module/rpm.c
// Function: rpm_worker_process_start
static void rpm_worker_process_start(worker_process *worker, char **argv) {
  long idx, cidx, closefd, max = sysconf(_SC_OPEN_MAX);
  char buff[32], envbuff[32 + sizeof(ENV_RPM_DOWNSTREAM_FD_PREFIX) + sizeof(ENV_RPM_UPSTREAM_FD_PREFIX)];
  rpm_worker_process_daemonize();
  for (idx = 1; idx < max; ++idx) {
    if (idx == worker->out.pipe[1] || idx == worker->err.pipe[1]) {
      continue;
    }
    closefd = 1;
    if (closefd != 0) {
      for (cidx = 0; cidx < worker->num_upstreams; ++cidx) {
        if (idx == worker->upstreams[cidx].pipe[1]) {
          closefd = 0;
          break;
        }
      }
    }
    if (closefd != 0) {
      for (cidx = 0; cidx < worker->num_downstreams; ++cidx) {
        if (idx == worker->downstreams[cidx]) {
          closefd = 0;
          break;
        }
      }
    }
    if (closefd != 0) {
      close(idx);
    }
  }
  rpm_worker_redirect_fd(worker->out.pipe[1], STDOUT_FILENO);
  rpm_worker_redirect_fd(worker->err.pipe[1], STDERR_FILENO);
  snprintf(buff, sizeof(buff), "%d", worker->num_upstreams);
  setenv(ENV_RPM_UPSTREAM_FD_NUM, buff, 1);
  for (cidx = 0; cidx < worker->num_upstreams; ++cidx) {
    snprintf(envbuff, sizeof(envbuff), "%s[%ld]", ENV_RPM_UPSTREAM_FD_PREFIX, cidx);
    snprintf(buff, sizeof(buff), "%d", worker->upstreams[cidx].pipe[1]);
    setenv(envbuff, buff, 1);
  }
  snprintf(buff, sizeof(buff), "%d", worker->num_downstreams);
  setenv(ENV_RPM_DOWNSTREAM_FD_NUM, buff, 1);
  for (cidx = 0; cidx < worker->num_downstreams; ++cidx) {
    snprintf(envbuff, sizeof(envbuff), "%s[%ld]", ENV_RPM_DOWNSTREAM_FD_PREFIX, cidx);
    snprintf(buff, sizeof(buff), "%d", worker->downstreams[cidx]);
    setenv(envbuff, buff, 1);
  }
  fprintf(stdout, "worker process %lld is spawned and prepare to serve requests\n", (long long) getpid());
  fflush(stdout);
  execvp(argv[0], argv);
  exit(1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movl $0x4, %edi
callq 0x5320
movq %rax, %r15
movl $0x17, %edi
callq 0x51f0
callq 0x5150
movl $0x1, %esi
movl $0x11, %edi
callq 0x51d0
movl $0x1, %esi
movl $0x1, %edi
callq 0x51d0
callq 0x53d0
testl %eax, %eax
jne 0x72dc
cmpq $0x2, %r15
jl 0x7101
movl $0x1, %r12d
movslq 0x28(%r14), %rax
cmpq %rax, %r12
je 0x70f9
movslq 0x60(%r14), %rax
cmpq %rax, %r12
je 0x70f9
movslq 0x88(%r14), %rax
testq %rax, %rax
jle 0x70ce
movq 0x90(%r14), %rcx
addq $0x28, %rcx
movslq (%rcx), %rdx
cmpq %rdx, %r12
je 0x70f9
addq $0x38, %rcx
decq %rax
jne 0x70bd
movslq 0x78(%r14), %rax
testq %rax, %rax
jle 0x70f1
movq 0x80(%r14), %rcx
xorl %edx, %edx
movslq (%rcx,%rdx,4), %rsi
cmpq %rsi, %r12
je 0x70f9
incq %rdx
cmpq %rdx, %rax
jne 0x70e0
movl %r12d, %edi
callq 0x5130
incq %r12
cmpq %r15, %r12
jne 0x7094
movq %rbx, 0x8(%rsp)
movl 0x28(%r14), %ebx
cmpl $0x1, %ebx
je 0x7122
movl %ebx, %edi
movl $0x1, %esi
callq 0x50c0
movl %ebx, %edi
callq 0x5130
movl 0x60(%r14), %ebx
cmpl $0x2, %ebx
je 0x713e
movl %ebx, %edi
movl $0x2, %esi
callq 0x50c0
movl %ebx, %edi
callq 0x5130
movl 0x88(%r14), %ecx
leaq 0x450e(%rip), %rdx      # 0xb65a
leaq 0x10(%rsp), %rbx
movl $0x20, %esi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x50e0
leaq 0x3ff8(%rip), %rdi      # 0xb15f
movq %rbx, %rsi
movl $0x1, %edx
callq 0x5070
cmpl $0x0, 0x88(%r14)
jle 0x71f8
movl $0x28, %r12d
leaq 0x30(%rsp), %r13
leaq 0x44ca(%rip), %rbp      # 0xb65a
leaq 0x10(%rsp), %rbx
xorl %r15d, %r15d
movl $0x42, %esi
movq %r13, %rdi
leaq 0x3fcc(%rip), %rdx      # 0xb173
leaq 0x3fcd(%rip), %rcx      # 0xb17b
movq %r15, %r8
xorl %eax, %eax
callq 0x50e0
movq 0x90(%r14), %rax
movl (%rax,%r12), %ecx
movl $0x20, %esi
movq %rbx, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x50e0
movq %r13, %rdi
movq %rbx, %rsi
movl $0x1, %edx
callq 0x5070
incq %r15
movslq 0x88(%r14), %rax
addq $0x38, %r12
cmpq %rax, %r15
jl 0x7198
movl 0x78(%r14), %ecx
leaq 0x4457(%rip), %rdx      # 0xb65a
leaq 0x10(%rsp), %rbx
movl $0x20, %esi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x50e0
leaq 0x3f6d(%rip), %rdi      # 0xb18b
movq %rbx, %rsi
movl $0x1, %edx
callq 0x5070
cmpl $0x0, 0x78(%r14)
jle 0x72a2
leaq 0x3f68(%rip), %rbx      # 0xb1a1
leaq 0x30(%rsp), %r12
leaq 0x4415(%rip), %r13      # 0xb65a
leaq 0x10(%rsp), %rbp
xorl %r15d, %r15d
movl $0x42, %esi
movq %r12, %rdi
leaq 0x3f17(%rip), %rdx      # 0xb173
movq %rbx, %rcx
movq %r15, %r8
xorl %eax, %eax
callq 0x50e0
movq 0x80(%r14), %rax
movl (%rax,%r15,4), %ecx
movl $0x20, %esi
movq %rbp, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x50e0
movq %r12, %rdi
movq %rbp, %rsi
movl $0x1, %edx
callq 0x5070
incq %r15
movslq 0x78(%r14), %rax
cmpq %rax, %r15
jl 0x724d
movq 0x6937(%rip), %r14      # 0xdbe0
movq (%r14), %rbx
callq 0x5090
movslq %eax, %rdx
leaq 0x3ef8(%rip), %rsi      # 0xb1b3
movq %rbx, %rdi
xorl %eax, %eax
callq 0x51e0
movq (%r14), %rdi
callq 0x5280
movq 0x8(%rsp), %rsi
movq (%rsi), %rdi
callq 0x5340
jmp 0x72de
jns 0x72e8
movl $0x1, %edi
callq 0x5390
xorl %edi, %edi
callq 0x5390