// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdx, 0x30(%rsp)
movq $0x0, 0x10(%rsp)
movq 0x30(%rsp), %rax
movq 0x98(%rax), %rdi
callq 0x53f0
movq %rax, (%rsp)
movq (%rsp), %rdi
callq 0x52b0
movzbl %al, %eax
cmpl $0x0, %eax
je 0x80da
movq (%rsp), %rdi
leaq 0x28(%rsp), %rsi
leaq 0x20(%rsp), %r8
leaq 0x10(%rsp), %rcx
movq %r8, %rdx
callq 0x5070
movq 0x8db4(%rip), %rax      # 0x10e78
movq (%rax), %rax
movq 0x10(%rsp), %rdi
movq 0x8e4d(%rip), %rcx      # 0x10f20
movq (%rcx), %rsi
callq *%rax
jmp 0x8091
movq (%rsp), %rdi
callq 0x5340
movq 0x30(%rsp), %rax
movq 0x98(%rax), %rdi
callq 0x5120
movq 0x30(%rsp), %rax
movq 0xa0(%rax), %rdi
callq 0x5120
movq 0x30(%rsp), %rax
cmpq $0x0, 0x80(%rax)
je 0x819d
movl $0x0, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
movq 0x30(%rsp), %rcx
cmpl 0x78(%rcx), %eax
jge 0x8185
movq 0x30(%rsp), %rax
movq 0x80(%rax), %rax
movslq 0x1c(%rsp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x8176
movq 0x30(%rsp), %rax
movq 0x80(%rax), %rax
movslq 0x1c(%rsp), %rcx
movl (%rax,%rcx,4), %edi
callq 0x5140
movq 0x30(%rsp), %rax
movq 0x80(%rax), %rax
movslq 0x1c(%rsp), %rcx
movl $0x0, (%rax,%rcx,4)
jmp 0x8178
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x8120
movq 0x8a94(%rip), %rax      # 0x10c20
movq (%rax), %rax
movq 0x30(%rsp), %rcx
movq 0x80(%rcx), %rdi
callq *%rax
movq 0x30(%rsp), %rax
cmpq $0x0, 0x90(%rax)
je 0x820c
movl $0x0, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
movq 0x30(%rsp), %rcx
cmpl 0x88(%rcx), %eax
jge 0x81f4
movq 0x40(%rsp), %rdi
movq 0x30(%rsp), %rax
movq 0x90(%rax), %rsi
movslq 0x1c(%rsp), %rax
imulq $0x38, %rax, %rax
addq %rax, %rsi
callq 0x8610
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x81b4
movq 0x8a25(%rip), %rax      # 0x10c20
movq (%rax), %rax
movq 0x30(%rsp), %rcx
movq 0x90(%rcx), %rdi
callq *%rax
movq 0x30(%rsp), %rax
cmpq $0x0, 0x70(%rax)
je 0x827c
movl $0x0, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
movq 0x30(%rsp), %rcx
cmpl 0x88(%rcx), %eax
jge 0x8267
movq 0x30(%rsp), %rax
movq 0x70(%rax), %rax
movslq 0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x8258
movq 0x8(%rsp), %rdi
callq 0x51a0
jmp 0x825a
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x8220
movq 0x89b2(%rip), %rax      # 0x10c20
movq (%rax), %rax
movq 0x30(%rsp), %rcx
movq 0x70(%rcx), %rdi
callq *%rax
movq 0x40(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x8610
movq 0x40(%rsp), %rdi
movq 0x30(%rsp), %rsi
addq $0x38, %rsi
callq 0x8610
movq 0x8bcb(%rip), %rax      # 0x10e70
movq (%rax), %rcx
movq 0x40(%rsp), %rdi
leaq 0x5b10(%rip), %rsi      # 0xddc4
leaq 0x5f26(%rip), %rdx      # 0xe1e1
movb $0x0, %al
callq *%rcx
movq 0x8b0a(%rip), %rax      # 0x10dd0
movq (%rax), %rax
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rcx
movq 0x38(%rsp), %r9
addq $0x50, %r9
movl $0xa, %esi
leaq 0x868(%rip), %rdx       # 0x8b50
xorl %r8d, %r8d
callq *%rax
movq 0x38(%rsp), %rax
movl 0x30(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x30(%rax)
movq 0x891e(%rip), %rax      # 0x10c20
movq (%rax), %rax
movq 0x30(%rsp), %rdi
callq *%rax
movq 0x38(%rsp), %rcx
movl 0x30(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x30(%rcx)
movq 0x38(%rsp), %rcx
cmpl 0x38(%rcx), %eax
jl 0x8366
movq 0x8b45(%rip), %rax      # 0x10e70
movq (%rax), %r9
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rax
movl 0x30(%rax), %ecx
movq 0x38(%rsp), %rax
movl 0x34(%rax), %r8d
leaq 0x5a79(%rip), %rsi      # 0xddc4
leaq 0x5ed7(%rip), %rdx      # 0xe229
movb $0x0, %al
callq *%r9
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x8bb0
movq 0x38(%rsp), %rax
movq $0x0, 0x10(%rax)
addq $0x48, %rsp
retq
nopl (%rax,%rax)