// File: /workspace/github_c_makefile_star2_O2/redis-force[P]rpm/module/rpm.c
// Function: rpm_worker_create
static worker_process *rpm_worker_create(RedisModuleCtx *ctx, rpm_context *rpm) {
  int32_t idx;
  int status;
  time_t now;
  pid_t pid;
  worker_process *worker = RedisModule_Calloc(1, sizeof(worker_process));
  worker->request_id_to_client = hash_map_create(&int_key_map, 1024);
  worker->client_id_to_request_id = hash_map_create(&int_key_map, 1024);
  worker->num_downstreams = rpm->num_downstreams;
  worker->num_upstreams = rpm->num_upstreams;
  if ((worker->downstreams = RedisModule_Calloc(1, sizeof(worker->downstreams[0]) * worker->num_downstreams)) == NULL) {
    RedisModule_Log(ctx, "warning", "Could not allocate enough memory for downstreams, restart worker again");
    goto cleanup_exit;
  }
  for (idx = 0; idx < worker->num_downstreams; ++idx) {
    if (RedisModule_CreateClient(ctx, worker->downstreams + idx) != REDISMODULE_OK) {
      RedisModule_Log(ctx, "warning", "Could not create client for downstream %d, restart worker again", idx);
      goto cleanup_exit;
    }
  }
  if ((worker->readers = RedisModule_Calloc(1, sizeof(worker->readers[0]) * worker->num_upstreams)) == NULL) {
    RedisModule_Log(ctx, "warning", "Could not allocate enough memory for response reader, restart worker again");
    goto cleanup_exit;
  }
  if ((worker->upstreams = RedisModule_Calloc(1, sizeof(worker->upstreams[0]) * worker->num_upstreams)) == NULL) {
    RedisModule_Log(ctx, "warning", "Could not allocate enough memory for response reader, restart worker again");
    goto cleanup_exit;
  }
  for (idx = 0; idx < worker->num_upstreams; ++idx) {
    worker->readers[idx] = redis_response_reader_create(rpm->allocator, 1024 * 1024);
    if (rpm_worker_pipe_init(ctx, worker, worker->upstreams + idx, rpm_worker_upstream_read, 1)) {
      RedisModule_Log(ctx, "warning", "Could not initiate upstream pipe %d, restart worker again", idx);
      goto cleanup_exit;
    }
    worker->upstreams[idx].user_data = worker->readers[idx];
  }
  worker->active_upstreams = worker->num_upstreams;
  if (rpm_worker_pipe_init(ctx, worker, &worker->out, rpm_worker_stdout_read, 0) ||
      rpm_worker_pipe_init(ctx, worker, &worker->err, rpm_worker_stderr_read, 0)) {
    RedisModule_Log(ctx, "warning", "Could not initiate stdout and stderr pipe, restart worker again");
    goto cleanup_exit;
  }

  time(&now);
  if (now >= rpm->restart_count_reset_time && (now - rpm->restart_count_reset_time) > rpm->retry_timeout) {
    rpm->restart_count_reset_time = now;
    rpm->restart_count = 0;
  }

  if ((pid = fork()) == 0) {
    rpm_worker_process_start(worker, rpm->argv);
  } else if (pid == -1) {
    RedisModule_Log(ctx, "warning", "Could not create new worker process, restart worker again: %s", strerror(errno));
    goto cleanup_exit;
  } else {
    status = 0;
    waitpid(pid, &status, 0);
    if (WEXITSTATUS(status) != 0) {
      RedisModule_Log(ctx, "warning", "Could not daemonize worker process, restart worker again: %s", strerror(errno));
      goto cleanup_exit;
    }
    for (idx = 0; idx < worker->num_upstreams; ++idx) {
      if (worker->upstreams[idx].pipe[1] != 0) {
        close(worker->upstreams[idx].pipe[1]);
        worker->upstreams[idx].pipe[1] = 0;
      }
    }
    close(worker->out.pipe[1]);
    worker->out.pipe[1] = 0;
    close(worker->err.pipe[1]);
    worker->err.pipe[1] = 0;
    for (idx = 0; idx < worker->num_downstreams; ++idx) {
      if (worker->downstreams[idx] != 0) {
        close(worker->downstreams[idx]);
        worker->downstreams[idx] = 0;
      }
    }
  }
  return worker;
cleanup_exit:
  rpm_worker_destroy(ctx, rpm, worker);
  return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %r14
movq %rdi, %r15
movq 0x76e3(%rip), %rbp      # 0xdc58
pushq $0x1
popq %r12
movl $0x1000a8, %esi         # imm = 0x1000A8
movq %r12, %rdi
callq *(%rbp)
movq %rax, %rbx
leaq 0x7ce2(%rip), %r13      # 0xe270
movl $0x400, %esi            # imm = 0x400
movq %r13, %rdi
callq 0x5250
movq %rax, 0x98(%rbx)
movl $0x400, %esi            # imm = 0x400
movq %r13, %rdi
callq 0x5250
movq %rax, 0xa0(%rbx)
movslq 0x28(%r14), %rsi
movl %esi, 0x78(%rbx)
movl 0x2c(%r14), %eax
movl %eax, 0x88(%rbx)
shlq $0x2, %rsi
movq %r12, %rdi
callq *(%rbp)
movq %rax, 0x80(%rbx)
testq %rax, %rax
je 0x6614
xorl %r13d, %r13d
movq 0x7851(%rip), %rbp      # 0xde38
xorl %r12d, %r12d
movslq 0x78(%rbx), %rax
cmpq %rax, %r12
jge 0x662e
movq 0x80(%rbx), %rsi
addq %r13, %rsi
movq %r15, %rdi
callq *(%rbp)
testl %eax, %eax
jne 0x66e9
incq %r12
addq $0x4, %r13
jmp 0x65ea
movq 0x784d(%rip), %rcx      # 0xde68
leaq 0x47b2(%rip), %rsi      # 0xadd4
leaq 0x48aa(%rip), %rdx      # 0xaed3
jmp 0x6779
movslq 0x88(%rbx), %rsi
shlq $0x3, %rsi
pushq $0x1
popq %rdi
movq 0x7615(%rip), %r12      # 0xdc58
callq *(%r12)
movq %rax, 0x70(%rbx)
testq %rax, %rax
je 0x670b
movslq 0x88(%rbx), %rax
imulq $0x38, %rax, %rsi
pushq $0x1
popq %rdi
callq *(%r12)
movq %rax, 0x90(%rbx)
testq %rax, %rax
je 0x670b
xorl %r13d, %r13d
pushq $0x1
popq %rbp
xorl %r12d, %r12d
movslq 0x88(%rbx), %rax
cmpq %rax, %r12
jge 0x6722
movq 0x20(%r14), %rdi
movl $0x100000, %esi         # imm = 0x100000
callq 0x5360
movq 0x70(%rbx), %rcx
movq %rax, (%rcx,%r12,8)
movq 0x90(%rbx), %rdx
addq %r13, %rdx
movq %r15, %rdi
movq %rbx, %rsi
leaq 0x841(%rip), %rcx       # 0x6efd
movl %ebp, %r8d
callq 0x6e61
testl %eax, %eax
jne 0x67a2
movq 0x70(%rbx), %rax
movq 0x90(%rbx), %rcx
movq (%rax,%r12,8), %rax
movq %rax, 0x30(%rcx,%r13)
incq %r12
addq $0x38, %r13
jmp 0x667f
movq 0x7778(%rip), %r8       # 0xde68
leaq 0x46dd(%rip), %rsi      # 0xadd4
leaq 0x481c(%rip), %rdx      # 0xaf1a
movq %r15, %rdi
movl %r12d, %ecx
xorl %eax, %eax
callq *(%r8)
jmp 0x6780
movq 0x7756(%rip), %rcx      # 0xde68
leaq 0x46bb(%rip), %rsi      # 0xadd4
leaq 0x483a(%rip), %rdx      # 0xaf5a
jmp 0x6779
movl %eax, 0x8c(%rbx)
leaq 0xa12(%rip), %rcx       # 0x7141
movq %r15, %rdi
movq %rbx, %rsi
movq %rbx, %rdx
xorl %r8d, %r8d
callq 0x6e61
testl %eax, %eax
jne 0x6764
movq %rbx, %rdx
addq $0x38, %rdx
leaq 0x9fb(%rip), %rcx       # 0x714d
movq %r15, %rdi
movq %rbx, %rsi
xorl %r8d, %r8d
callq 0x6e61
testl %eax, %eax
je 0x67bc
movq 0x76fd(%rip), %rcx      # 0xde68
leaq 0x4662(%rip), %rsi      # 0xadd4
leaq 0x4866(%rip), %rdx      # 0xafdf
movq %r15, %rdi
xorl %eax, %eax
callq *(%rcx)
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x7159
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x76bf(%rip), %r8       # 0xde68
leaq 0x4624(%rip), %rsi      # 0xadd4
leaq 0x47ee(%rip), %rdx      # 0xafa5
jmp 0x66fe
leaq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x5240
movq (%r12), %rax
movq %rax, %rcx
subq 0x40(%r14), %rcx
jl 0x67e8
movslq 0x34(%r14), %rdx
cmpq %rdx, %rcx
jle 0x67e8
movq %rax, 0x40(%r14)
andl $0x0, 0x30(%r14)
callq 0x53e0
cmpl $-0x1, %eax
je 0x683e
testl %eax, %eax
je 0x68fb
leaq 0x30(%rsp), %r12
andl $0x0, (%r12)
movl %eax, %edi
movq %r12, %rsi
xorl %edx, %edx
callq 0x5300
cmpb $0x0, 0x1(%r12)
je 0x6872
movq 0x7649(%rip), %rax      # 0xde68
movq (%rax), %r12
callq 0x5030
movl (%rax), %edi
callq 0x53b0
leaq 0x459f(%rip), %rsi      # 0xadd4
leaq 0x4821(%rip), %rdx      # 0xb05d
jmp 0x6862
movq 0x7623(%rip), %rax      # 0xde68
movq (%rax), %r12
callq 0x5030
movl (%rax), %edi
callq 0x53b0
leaq 0x4579(%rip), %rsi      # 0xadd4
leaq 0x47bd(%rip), %rdx      # 0xb01f
movq %r15, %rdi
movq %rax, %rcx
xorl %eax, %eax
callq *%r12
jmp 0x6780
pushq $0x28
popq %r14
xorl %r15d, %r15d
movslq 0x88(%rbx), %rax
cmpq %rax, %r15
jge 0x68ae
movq 0x90(%rbx), %rax
movl (%rax,%r14), %edi
testl %edi, %edi
je 0x68a5
callq 0x5140
movq 0x90(%rbx), %rax
andl $0x0, (%rax,%r14)
incq %r15
addq $0x38, %r14
jmp 0x6879
movl 0x28(%rbx), %edi
callq 0x5140
andl $0x0, 0x28(%rbx)
movl 0x60(%rbx), %edi
callq 0x5140
andl $0x0, 0x60(%rbx)
xorl %r14d, %r14d
movslq 0x78(%rbx), %rax
cmpq %rax, %r14
jge 0x6790
movq 0x80(%rbx), %rax
movl (%rax,%r14,4), %edi
testl %edi, %edi
je 0x68f6
callq 0x5140
movq 0x80(%rbx), %rax
andl $0x0, (%rax,%r14,4)
incq %r14
jmp 0x68c9
movq (%r14), %rax
movq %rax, (%rsp)
pushq $0x4
popq %rdi
callq 0x5330
movq %rax, %r15
pushq $0x17
popq %rdi
callq 0x5200
callq 0x5160
pushq $0x11
popq %rdi
pushq $0x1
popq %r12
movq %r12, %rsi
callq 0x51e0
pushq $0x1
popq %rdi
movq %r12, %rsi
callq 0x51e0
callq 0x53e0
testl %eax, %eax
jne 0x69c9
xorl %r14d, %r14d
movslq 0x28(%rbx), %rdi
cmpq %r15, %r12
jge 0x69d6
cmpq %rdi, %r12
je 0x69c1
movslq 0x60(%rbx), %rax
cmpq %rax, %r12
je 0x69c1
movl 0x88(%rbx), %eax
testl %eax, %eax
cmovlel %r14d, %eax
imulq $0x38, %rax, %rax
addq $0x38, %rax
xorl %ecx, %ecx
leaq 0x38(%rcx), %rdx
cmpq %rdx, %rax
je 0x6994
movq 0x90(%rbx), %rsi
movslq 0x28(%rsi,%rcx), %rsi
movq %rdx, %rcx
cmpq %rsi, %r12
jne 0x6975
jmp 0x69c1
movl 0x78(%rbx), %eax
testl %eax, %eax
cmovlel %r14d, %eax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x69b9
movq 0x80(%rbx), %rdx
movslq (%rdx,%rcx,4), %rdx
incq %rcx
cmpq %rdx, %r12
jne 0x699f
jmp 0x69c1
movl %r12d, %edi
callq 0x5140
incq %r12
jmp 0x6944
js 0x6b55
xorl %edi, %edi
callq 0x53a0
pushq $0x1
popq %rbp
movl %ebp, %esi
callq 0x7694
movl 0x60(%rbx), %edi
pushq $0x2
popq %rsi
callq 0x7694
movl 0x88(%rbx), %ecx
leaq 0x4c62(%rip), %rdx      # 0xb65a
leaq 0x10(%rsp), %r12
pushq $0x20
popq %rsi
movq %r12, %rdi
xorl %eax, %eax
callq 0x50f0
leaq 0x474e(%rip), %rdi      # 0xb15f
movq %r12, %rsi
movl %ebp, %edx
callq 0x5080
pushq $0x28
popq %rbp
leaq 0x30(%rsp), %r15
pushq $0x42
popq %r13
xorl %r14d, %r14d
movslq 0x88(%rbx), %rax
cmpq %rax, %r14
jge 0x6a89
movq %r15, %rdi
movq %r13, %rsi
leaq 0x4730(%rip), %rdx      # 0xb173
leaq 0x4731(%rip), %rcx      # 0xb17b
movq %r14, %r8
xorl %eax, %eax
callq 0x50f0
movq 0x90(%rbx), %rax
movl (%rax,%rbp), %ecx
movq %r12, %rdi
pushq $0x20
popq %rsi
leaq 0x4bef(%rip), %rdx      # 0xb65a
xorl %eax, %eax
callq 0x50f0
movq %r15, %rdi
movq %r12, %rsi
pushq $0x1
popq %rdx
callq 0x5080
incq %r14
addq $0x38, %rbp
jmp 0x6a2a
movl 0x78(%rbx), %ecx
leaq 0x4bc7(%rip), %rdx      # 0xb65a
leaq 0x10(%rsp), %r12
pushq $0x20
popq %rsi
movq %r12, %rdi
xorl %eax, %eax
callq 0x50f0
leaq 0x46df(%rip), %rdi      # 0xb18b
pushq $0x1
popq %rdx
movq %r12, %rsi
callq 0x5080
leaq 0x46e3(%rip), %r15      # 0xb1a1
leaq 0x30(%rsp), %r13
pushq $0x42
popq %rbp
xorl %r14d, %r14d
movslq 0x78(%rbx), %rax
cmpq %rax, %r14
jge 0x6b1e
movq %r13, %rdi
movq %rbp, %rsi
leaq 0x4694(%rip), %rdx      # 0xb173
movq %r15, %rcx
movq %r14, %r8
xorl %eax, %eax
callq 0x50f0
movq 0x80(%rbx), %rax
movl (%rax,%r14,4), %ecx
movq %r12, %rdi
pushq $0x20
popq %rsi
leaq 0x4b56(%rip), %rdx      # 0xb65a
xorl %eax, %eax
callq 0x50f0
movq %r13, %rdi
movq %r12, %rsi
pushq $0x1
popq %rdx
callq 0x5080
incq %r14
jmp 0x6ac9
movq 0x70bb(%rip), %r14      # 0xdbe0
movq (%r14), %rbx
callq 0x50a0
movslq %eax, %rdx
leaq 0x467c(%rip), %rsi      # 0xb1b3
movq %rbx, %rdi
xorl %eax, %eax
callq 0x51f0
movq (%r14), %rdi
callq 0x5290
movq (%rsp), %rsi
movq (%rsi), %rdi
callq 0x5350
pushq $0x1
popq %rdi
callq 0x53a0