// File: /workspace/github_c_makefile_star2_O3/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 0x7370
movq %rsp, %rbp
leaq 0x18(%rsp), %rbx
movq 0x6b34(%rip), %r14      # 0xde70
movq 0x6bd5(%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 0x7343
movq %r12, %rdi
callq 0x5330
movq 0x98(%r15), %rdi
callq 0x5110
movq 0xa0(%r15), %rdi
callq 0x5110
movq 0x80(%r15), %rdi
testq %rdi, %rdi
movq 0x10(%rsp), %r12
je 0x73df
movl 0x78(%r15), %ecx
testl %ecx, %ecx
jle 0x73d6
xorl %ebx, %ebx
movl (%rdi,%rbx,4), %eax
testl %eax, %eax
je 0x73cb
movl %eax, %edi
callq 0x5130
movq 0x80(%r15), %rdi
movl $0x0, (%rdi,%rbx,4)
movl 0x78(%r15), %ecx
incq %rbx
movslq %ecx, %rax
cmpq %rax, %rbx
jl 0x73ab
movq 0x683b(%rip), %rax      # 0xdc18
callq *(%rax)
movq 0x90(%r15), %rdi
testq %rdi, %rdi
movq 0x8(%rsp), %r13
je 0x7434
cmpl $0x0, 0x88(%r15)
jle 0x742b
xorl %ebx, %ebx
xorl %r14d, %r14d
movq 0x90(%r15), %rsi
addq %rbx, %rsi
movq %r13, %rdi
callq 0x75f2
incq %r14
movslq 0x88(%r15), %rax
addq $0x38, %rbx
cmpq %rax, %r14
jl 0x73ff
movq 0x90(%r15), %rdi
movq 0x67e6(%rip), %rax      # 0xdc18
callq *(%rax)
movq 0x70(%r15), %rdi
testq %rdi, %rdi
je 0x747b
movl 0x88(%r15), %eax
testl %eax, %eax
jle 0x7472
xorl %ebx, %ebx
movq 0x70(%r15), %rcx
movq (%rcx,%rbx,8), %rdi
testq %rdi, %rdi
je 0x7463
callq 0x5190
movl 0x88(%r15), %eax
incq %rbx
movslq %eax, %rcx
cmpq %rcx, %rbx
jl 0x744a
movq 0x70(%r15), %rdi
movq 0x679f(%rip), %rax      # 0xdc18
callq *(%rax)
movq %r13, %rdi
movq %r15, %rsi
callq 0x75f2
leaq 0x38(%r15), %rsi
movq %r13, %rdi
callq 0x75f2
movq 0x69cf(%rip), %rbx      # 0xde68
leaq 0x3934(%rip), %rsi      # 0xadd4
leaq 0x3d4a(%rip), %rdx      # 0xb1f1
movq %r13, %rdi
xorl %eax, %eax
callq *(%rbx)
movq 0x6913(%rip), %rax      # 0xddc8
leaq 0x50(%r12), %r9
leaq 0x3f7(%rip), %rdx       # 0x78b8
movl $0xa, %esi
movq %r13, %rdi
movq %r12, %rcx
xorl %r8d, %r8d
callq *(%rax)
decl 0x30(%r12)
movq 0x673b(%rip), %rax      # 0xdc18
movq %r15, %rdi
callq *(%rax)
movl 0x30(%r12), %ecx
incl %ecx
movl %ecx, 0x30(%r12)
cmpl 0x38(%r12), %ecx
jl 0x7548
movl 0x34(%r12), %r8d
leaq 0x38d3(%rip), %rsi      # 0xadd4
leaq 0x3d31(%rip), %rdx      # 0xb239
movq %r13, %rdi
xorl %eax, %eax
callq *(%rbx)
movq 0x48(%r12), %rax
testq %rax, %rax
leaq 0x3d71(%rip), %rsi      # 0xb28f
cmovneq %rax, %rsi
movq 0x6ac7(%rip), %rcx      # 0xdff0
leaq 0x3dc9(%rip), %rdx      # 0xb2f9
movq %r13, %rdi
xorl %eax, %eax
callq *(%rcx)
testq %rax, %rax
je 0x7548
movq 0x69fd(%rip), %rcx      # 0xdf40
movq %rax, %rdi
callq *(%rcx)
movq $0x0, 0x10(%r12)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq