// File: /workspace/github_c_makefile_star2_O1/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 $0x18, %rsp
movq %rsi, %r14
movq %rdi, %r15
movq 0x76a5(%rip), %r13      # 0xdc58
movl $0x1, %edi
movl $0x1000a8, %esi         # imm = 0x1000A8
callq *(%r13)
movq %rax, %rbx
leaq 0x7c9d(%rip), %r12      # 0xe268
movl $0x400, %esi            # imm = 0x400
movq %r12, %rdi
callq 0x5240
movq %rax, 0x98(%rbx)
movl $0x400, %esi            # imm = 0x400
movq %r12, %rdi
callq 0x5240
movq %rax, 0xa0(%rbx)
movslq 0x28(%r14), %rsi
movl %esi, 0x78(%rbx)
movl 0x2c(%r14), %eax
movl %eax, 0x88(%rbx)
shlq $0x2, %rsi
movl $0x1, %edi
callq *(%r13)
movq %rax, 0x80(%rbx)
testq %rax, %rax
je 0x677e
movq %r14, (%rsp)
cmpl $0x0, 0x78(%rbx)
jle 0x665f
xorl %ebp, %ebp
movq 0x7804(%rip), %r14      # 0xde38
xorl %r12d, %r12d
movq 0x80(%rbx), %rsi
addq %rbp, %rsi
movq %r15, %rdi
callq *(%r14)
testl %eax, %eax
jne 0x6795
incq %r12
movslq 0x78(%rbx), %rax
addq $0x4, %rbp
cmpq %rax, %r12
jl 0x6637
movslq 0x88(%rbx), %rsi
shlq $0x3, %rsi
movl $0x1, %edi
callq *(%r13)
movq %rax, 0x70(%rbx)
testq %rax, %rax
je 0x67b7
movslq 0x88(%rbx), %rax
imulq $0x38, %rax, %rsi
movl $0x1, %edi
callq *(%r13)
movq %rax, 0x90(%rbx)
testq %rax, %rax
movq (%rsp), %r14
je 0x67d9
movl 0x88(%rbx), %eax
testl %eax, %eax
jle 0x6721
xorl %ebp, %ebp
leaq 0x695(%rip), %r13       # 0x6d50
xorl %r12d, %r12d
movq 0x20(%r14), %rdi
movl $0x100000, %esi         # imm = 0x100000
callq 0x5350
movq 0x70(%rbx), %rcx
movq %rax, (%rcx,%r12,8)
movq 0x90(%rbx), %rdx
addq %rbp, %rdx
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rcx
movl $0x1, %r8d
callq 0x6ca7
testl %eax, %eax
jne 0x6817
movq 0x70(%rbx), %rax
movq 0x90(%rbx), %rcx
movq (%rax,%r12,8), %rax
movq %rax, 0x30(%rcx,%rbp)
incq %r12
movslq 0x88(%rbx), %rax
addq $0x38, %rbp
cmpq %rax, %r12
jl 0x66be
movl %eax, 0x8c(%rbx)
leaq 0x88d(%rip), %rcx       # 0x6fbb
movq %r15, %rdi
movq %rbx, %rsi
movq %rbx, %rdx
xorl %r8d, %r8d
callq 0x6ca7
testl %eax, %eax
jne 0x6767
movq %rbx, %rdx
addq $0x38, %rdx
leaq 0x876(%rip), %rcx       # 0x6fc7
movq %r15, %rdi
movq %rbx, %rsi
xorl %r8d, %r8d
callq 0x6ca7
testl %eax, %eax
je 0x6839
movq 0x76fa(%rip), %rcx      # 0xde68
leaq 0x465f(%rip), %rsi      # 0xadd4
leaq 0x4863(%rip), %rdx      # 0xafdf
jmp 0x67ee
movq 0x76e3(%rip), %rcx      # 0xde68
leaq 0x4648(%rip), %rsi      # 0xadd4
leaq 0x4740(%rip), %rdx      # 0xaed3
jmp 0x67ee
movq 0x76cc(%rip), %r8       # 0xde68
leaq 0x4631(%rip), %rsi      # 0xadd4
leaq 0x4770(%rip), %rdx      # 0xaf1a
movq %r15, %rdi
movl %r12d, %ecx
xorl %eax, %eax
callq *(%r8)
jmp 0x67d3
movq 0x76aa(%rip), %rcx      # 0xde68
leaq 0x460f(%rip), %rsi      # 0xadd4
leaq 0x478e(%rip), %rdx      # 0xaf5a
movq %r15, %rdi
xorl %eax, %eax
callq *(%rcx)
movq (%rsp), %r14
jmp 0x67f5
movq 0x7688(%rip), %rcx      # 0xde68
leaq 0x45ed(%rip), %rsi      # 0xadd4
leaq 0x476c(%rip), %rdx      # 0xaf5a
movq %r15, %rdi
xorl %eax, %eax
callq *(%rcx)
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x7295
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x764a(%rip), %r8       # 0xde68
leaq 0x45af(%rip), %rsi      # 0xadd4
leaq 0x4779(%rip), %rdx      # 0xafa5
movq %r15, %rdi
movl %r12d, %ecx
xorl %eax, %eax
callq *(%r8)
jmp 0x67f5
leaq 0x10(%rsp), %r12
movq %r12, %rdi
callq 0x5230
movq (%r12), %rax
movq %rax, %rcx
subq 0x40(%r14), %rcx
jl 0x6868
movslq 0x34(%r14), %rdx
cmpq %rdx, %rcx
jle 0x6868
movq %rax, 0x40(%r14)
movl $0x0, 0x30(%r14)
callq 0x53d0
cmpl $-0x1, %eax
je 0x68c1
testl %eax, %eax
je 0x6995
leaq 0xc(%rsp), %r12
movl $0x0, (%r12)
movl %eax, %edi
movq %r12, %rsi
xorl %edx, %edx
callq 0x52f0
cmpb $0x0, 0x1(%r12)
je 0x68f5
movq 0x75c6(%rip), %rax      # 0xde68
movq (%rax), %r14
callq 0x5030
movl (%rax), %edi
callq 0x53a0
leaq 0x451c(%rip), %rsi      # 0xadd4
leaq 0x479e(%rip), %rdx      # 0xb05d
jmp 0x68e5
movq 0x75a0(%rip), %rax      # 0xde68
movq (%rax), %r14
callq 0x5030
movl (%rax), %edi
callq 0x53a0
leaq 0x44f6(%rip), %rsi      # 0xadd4
leaq 0x473a(%rip), %rdx      # 0xb01f
movq %r15, %rdi
movq %rax, %rcx
xorl %eax, %eax
callq *%r14
jmp 0x67d3
cmpl $0x0, 0x88(%rbx)
jle 0x693d
movl $0x28, %r14d
xorl %r15d, %r15d
movq 0x90(%rbx), %rax
movl (%rax,%r14), %edi
testl %edi, %edi
je 0x692a
callq 0x5130
movq 0x90(%rbx), %rax
movl $0x0, (%rax,%r14)
incq %r15
movslq 0x88(%rbx), %rax
addq $0x38, %r14
cmpq %rax, %r15
jl 0x6907
movl 0x28(%rbx), %edi
callq 0x5130
xorl %ebp, %ebp
movl %ebp, 0x28(%rbx)
movl 0x60(%rbx), %edi
callq 0x5130
movl %ebp, 0x60(%rbx)
cmpl %ebp, 0x78(%rbx)
jle 0x6805
xorl %r14d, %r14d
movq 0x80(%rbx), %rax
movl (%rax,%r14,4), %edi
testl %edi, %edi
je 0x6984
callq 0x5130
movq 0x80(%rbx), %rax
movl $0x0, (%rax,%r14,4)
incq %r14
movslq 0x78(%rbx), %rax
cmpq %rax, %r14
jl 0x6961
jmp 0x6805
movq (%r14), %rsi
movq %rbx, %rdi
callq 0x6fd3