// File: /workspace/github_c_makefile_star2_O1/redis-force[P]rpm/module/rpm.c
// Function: rpm_worker_destroy
static void rpm_worker_destroy(RedisModuleCtx *ctx, rpm_context *rpm, worker_process *worker) {
  /* send worker dead error to pending requests of current worker */
  int64_t request_id;
  size_t ignored;
  int32_t idx;

  RedisModuleBlockedClient *bc = NULL;
  redis_response_reader *reader;

  hash_map_iterator *iterator = hash_map_iterator_create(worker->request_id_to_client);
  while (hash_map_iterator_next(iterator) != 0) {
    hash_map_iterator_get(iterator, (const void **) &request_id, &ignored, (const void **) &bc, &ignored);
    RedisModule_UnblockClient(bc, (void *) RPM_BAD_GATEWAY);
  }
  hash_map_iterator_destroy(iterator);
  hash_map_destroy(worker->request_id_to_client);
  hash_map_destroy(worker->client_id_to_request_id);
  if (worker->downstreams != NULL) {
    for (idx = 0; idx < worker->num_downstreams; ++idx) {
      if (worker->downstreams[idx] != 0) {
        close(worker->downstreams[idx]);
        worker->downstreams[idx] = 0;
      }
    }
    RedisModule_Free(worker->downstreams);
  }
  if (worker->upstreams != NULL) {
    for (idx = 0; idx < worker->num_upstreams; ++idx) {
      rpm_worker_close_pipe(ctx, worker->upstreams + idx);
    }
    RedisModule_Free(worker->upstreams);
  }
  if (worker->readers != NULL) {
    for (idx = 0; idx < worker->num_upstreams; ++idx) {
      if ((reader = worker->readers[idx]) != NULL) {
        redis_response_reader_free(reader);
      }
    }
    RedisModule_Free(worker->readers);
  }
  rpm_worker_close_pipe(ctx, &worker->out);
  rpm_worker_close_pipe(ctx, &worker->err);
  RedisModule_Log(ctx, "warning", "worker process is terminated prematurely, a new worker is being spawned");
  /* failed to create worker during initialization, setup a timer to try it again 10 ms later */
  RedisModule_CreateTimeEvent(ctx, 10, rpm_worker_create_later, rpm, NULL, &rpm->restart_timer);
  rpm->restart_count--;
  RedisModule_Free(worker);
  if (++rpm->restart_count >= rpm->retry_attempts) {
    RedisModule_Log(ctx, "warning", "worker has been stopped %d times within last %d seconds, shutdown redis automatically", rpm->restart_count, rpm->retry_timeout);
    rpm_context_shutdown_redis(ctx, rpm);
  }
  rpm->worker = NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r15
movq %rsi, 0x10(%rsp)
movq %rdi, 0x8(%rsp)
movq $0x0, (%rsp)
movq 0x98(%rdx), %rdi
callq 0x53e0
movq %rax, %r12
movq %rax, %rdi
callq 0x52a0
testb %al, %al
je 0x7316
movq %rsp, %rbp
leaq 0x18(%rsp), %rbx
movq 0x6b8e(%rip), %r14      # 0xde70
movq 0x6c2f(%rip), %r13      # 0xdf18
movq %r12, %rdi
leaq 0x20(%rsp), %rsi
movq %rbx, %rdx
movq %rbp, %rcx
movq %rbx, %r8
callq 0x5060
movq (%rsp), %rdi
movq (%r13), %rsi
callq *(%r14)
movq %r12, %rdi
callq 0x52a0
testb %al, %al
jne 0x72e9
movq %r12, %rdi
callq 0x5330
movq 0x98(%r15), %rdi
callq 0x5110
movq 0xa0(%r15), %rdi
callq 0x5110
cmpq $0x0, 0x80(%r15)
movq 0x8(%rsp), %r12
je 0x738b
cmpl $0x0, 0x78(%r15)
jle 0x737b
xorl %ebx, %ebx
movq 0x80(%r15), %rax
movl (%rax,%rbx,4), %edi
testl %edi, %edi
je 0x736f
callq 0x5130
movq 0x80(%r15), %rax
movl $0x0, (%rax,%rbx,4)
incq %rbx
movslq 0x78(%r15), %rax
cmpq %rax, %rbx
jl 0x734e
movq 0x6896(%rip), %rax      # 0xdc18
movq 0x80(%r15), %rdi
callq *(%rax)
cmpq $0x0, 0x90(%r15)
je 0x73d9
cmpl $0x0, 0x88(%r15)
jle 0x73c9
xorl %ebx, %ebx
xorl %r14d, %r14d
movq 0x90(%r15), %rsi
addq %rbx, %rsi
movq %r12, %rdi
callq 0x758b
incq %r14
movslq 0x88(%r15), %rax
addq $0x38, %rbx
cmpq %rax, %r14
jl 0x73a4
movq 0x6848(%rip), %rax      # 0xdc18
movq 0x90(%r15), %rdi
callq *(%rax)
cmpq $0x0, 0x70(%r15)
movq 0x10(%rsp), %r14
je 0x741f
cmpl $0x0, 0x88(%r15)
jle 0x7412
xorl %ebx, %ebx
movq 0x70(%r15), %rax
movq (%rax,%rbx,8), %rdi
testq %rdi, %rdi
je 0x7403
callq 0x5190
incq %rbx
movslq 0x88(%r15), %rax
cmpq %rax, %rbx
jl 0x73f1
movq 0x67ff(%rip), %rax      # 0xdc18
movq 0x70(%r15), %rdi
callq *(%rax)
movq %r12, %rdi
movq %r15, %rsi
callq 0x758b
leaq 0x38(%r15), %rsi
movq %r12, %rdi
callq 0x758b
movq 0x6a2b(%rip), %rbx      # 0xde68
leaq 0x3990(%rip), %rsi      # 0xadd4
leaq 0x3da6(%rip), %rdx      # 0xb1f1
movq %r12, %rdi
xorl %eax, %eax
callq *(%rbx)
movq 0x696f(%rip), %rax      # 0xddc8
leaq 0x50(%r14), %r9
leaq 0x401(%rip), %rdx       # 0x7865
movl $0xa, %esi
movq %r12, %rdi
movq %r14, %rcx
xorl %r8d, %r8d
callq *(%rax)
decl 0x30(%r14)
movq 0x6799(%rip), %rax      # 0xdc18
movq %r15, %rdi
callq *(%rax)
movl 0x30(%r14), %ecx
incl %ecx
movl %ecx, 0x30(%r14)
cmpl 0x38(%r14), %ecx
jl 0x74e5
movl 0x34(%r14), %r8d
leaq 0x3935(%rip), %rsi      # 0xadd4
leaq 0x3d93(%rip), %rdx      # 0xb239
movq %r12, %rdi
xorl %eax, %eax
callq *(%rbx)
movq 0x48(%r14), %rax
testq %rax, %rax
leaq 0x3dd4(%rip), %rsi      # 0xb28f
cmovneq %rax, %rsi
movq 0x6b2a(%rip), %rcx      # 0xdff0
leaq 0x3e2c(%rip), %rdx      # 0xb2f9
movq %r12, %rdi
xorl %eax, %eax
callq *(%rcx)
testq %rax, %rax
je 0x74e5
movq 0x6a60(%rip), %rcx      # 0xdf40
movq %rax, %rdi
callq *(%rcx)
movq $0x0, 0x10(%r14)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq