// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x58, %rsp
movq %rdi, 0x48(%rsp)
movq %rsi, 0x40(%rsp)
movl $0x1, %edi
movl $0x1000a8, %esi         # imm = 0x1000A8
movq 0xa0e1(%rip), %rax      # 0x10c60
callq *(%rax)
movq %rax, 0x20(%rsp)
leaq 0xa6e3(%rip), %rdi      # 0x11270
movl $0x400, %esi            # imm = 0x400
callq 0x5250
movq %rax, %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x98(%rax)
leaq 0xa6c3(%rip), %rdi      # 0x11270
movl $0x400, %esi            # imm = 0x400
callq 0x5250
movq %rax, %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0xa0(%rax)
movq 0x40(%rsp), %rax
movl 0x28(%rax), %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x78(%rax)
movq 0x40(%rsp), %rax
movl 0x2c(%rax), %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x88(%rax)
movq 0xa070(%rip), %rax      # 0x10c60
movq (%rax), %rax
movq 0x20(%rsp), %rcx
movslq 0x78(%rcx), %rsi
shlq $0x2, %rsi
movl $0x1, %edi
callq *%rax
movq 0x20(%rsp), %rcx
movq %rax, 0x80(%rcx)
cmpq $0x0, %rax
jne 0x6c3f
movq 0xa250(%rip), %rax      # 0x10e70
movq (%rax), %rcx
movq 0x48(%rsp), %rdi
leaq 0x7195(%rip), %rsi      # 0xddc4
leaq 0x728d(%rip), %rdx      # 0xdec3
movb $0x0, %al
callq *%rcx
jmp 0x7144
movl $0x0, 0x3c(%rsp)
movl 0x3c(%rsp), %eax
movq 0x20(%rsp), %rcx
cmpl 0x78(%rcx), %eax
jge 0x6cbd
movq 0xa1e4(%rip), %rax      # 0x10e40
movq (%rax), %rax
movq 0x48(%rsp), %rdi
movq 0x20(%rsp), %rcx
movq 0x80(%rcx), %rsi
movslq 0x3c(%rsp), %rcx
shlq $0x2, %rcx
addq %rcx, %rsi
callq *%rax
cmpl $0x0, %eax
je 0x6cae
movq 0xa1e6(%rip), %rax      # 0x10e70
movq (%rax), %r8
movq 0x48(%rsp), %rdi
movl 0x3c(%rsp), %ecx
leaq 0x7127(%rip), %rsi      # 0xddc4
leaq 0x7266(%rip), %rdx      # 0xdf0a
movb $0x0, %al
callq *%r8
jmp 0x7144
jmp 0x6cb0
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x6c47
movq 0x9f9c(%rip), %rax      # 0x10c60
movq (%rax), %rax
movq 0x20(%rsp), %rcx
movslq 0x88(%rcx), %rsi
shlq $0x3, %rsi
movl $0x1, %edi
callq *%rax
movq 0x20(%rsp), %rcx
movq %rax, 0x70(%rcx)
cmpq $0x0, %rax
jne 0x6d13
movq 0xa17c(%rip), %rax      # 0x10e70
movq (%rax), %rcx
movq 0x48(%rsp), %rdi
leaq 0x70c1(%rip), %rsi      # 0xddc4
leaq 0x7240(%rip), %rdx      # 0xdf4a
movb $0x0, %al
callq *%rcx
jmp 0x7144
movq 0x9f46(%rip), %rax      # 0x10c60
movq (%rax), %rax
movq 0x20(%rsp), %rcx
movslq 0x88(%rcx), %rcx
imulq $0x38, %rcx, %rsi
movl $0x1, %edi
callq *%rax
movq 0x20(%rsp), %rcx
movq %rax, 0x90(%rcx)
cmpq $0x0, %rax
jne 0x6d6c
movq 0xa123(%rip), %rax      # 0x10e70
movq (%rax), %rcx
movq 0x48(%rsp), %rdi
leaq 0x7068(%rip), %rsi      # 0xddc4
leaq 0x71e7(%rip), %rdx      # 0xdf4a
movb $0x0, %al
callq *%rcx
jmp 0x7144
movl $0x0, 0x3c(%rsp)
movl 0x3c(%rsp), %eax
movq 0x20(%rsp), %rcx
cmpl 0x88(%rcx), %eax
jge 0x6e53
movq 0x40(%rsp), %rax
movq 0x20(%rax), %rdi
movl $0x100000, %esi         # imm = 0x100000
callq 0x5360
movq %rax, %rdx
movq 0x20(%rsp), %rax
movq 0x70(%rax), %rax
movslq 0x3c(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x48(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x20(%rsp), %rax
movq 0x90(%rax), %rdx
movslq 0x3c(%rsp), %rax
imulq $0x38, %rax, %rax
addq %rax, %rdx
leaq 0xbd6(%rip), %rcx       # 0x79b0
movl $0x1, %r8d
callq 0x78c0
cmpl $0x0, %eax
je 0x6e15
movq 0xa07f(%rip), %rax      # 0x10e70
movq (%rax), %r8
movq 0x48(%rsp), %rdi
movl 0x3c(%rsp), %ecx
leaq 0x6fc0(%rip), %rsi      # 0xddc4
leaq 0x718a(%rip), %rdx      # 0xdf95
movb $0x0, %al
callq *%r8
jmp 0x7144
movq 0x20(%rsp), %rax
movq 0x70(%rax), %rax
movslq 0x3c(%rsp), %rcx
movq (%rax,%rcx,8), %rcx
movq 0x20(%rsp), %rax
movq 0x90(%rax), %rax
movslq 0x3c(%rsp), %rdx
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x30(%rax)
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x6d74
movq 0x20(%rsp), %rax
movl 0x88(%rax), %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x8c(%rax)
movq 0x48(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x20(%rsp), %rdx
leaq 0xd31(%rip), %rcx       # 0x7bb0
xorl %r8d, %r8d
callq 0x78c0
cmpl $0x0, %eax
jne 0x6eb3
movq 0x48(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x20(%rsp), %rdx
addq $0x38, %rdx
leaq 0xd4a(%rip), %rcx       # 0x7bf0
xorl %r8d, %r8d
callq 0x78c0
cmpl $0x0, %eax
je 0x6ed9
movq 0x9fb6(%rip), %rax      # 0x10e70
movq (%rax), %rcx
movq 0x48(%rsp), %rdi
leaq 0x6efb(%rip), %rsi      # 0xddc4
leaq 0x70ff(%rip), %rdx      # 0xdfcf
movb $0x0, %al
callq *%rcx
jmp 0x7144
leaq 0x30(%rsp), %rdi
callq 0x5240
movq 0x30(%rsp), %rax
movq 0x40(%rsp), %rcx
cmpq 0x40(%rcx), %rax
jl 0x6f29
movq 0x30(%rsp), %rax
movq 0x40(%rsp), %rcx
subq 0x40(%rcx), %rax
movq 0x40(%rsp), %rcx
movslq 0x34(%rcx), %rcx
cmpq %rcx, %rax
jle 0x6f29
movq 0x30(%rsp), %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x40(%rax)
movq 0x40(%rsp), %rax
movl $0x0, 0x30(%rax)
callq 0x53e0
movl %eax, 0x2c(%rsp)
cmpl $0x0, %eax
jne 0x6f4e
movq 0x20(%rsp), %rdi
movq 0x40(%rsp), %rax
movq (%rax), %rsi
callq 0x7c30
jmp 0x7138
cmpl $-0x1, 0x2c(%rsp)
jne 0x6f9f
movq 0x9f14(%rip), %rax      # 0x10e70
movq (%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rsp)
callq 0x5030
movl (%rax), %edi
callq 0x53b0
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %r8
movq %rax, %rcx
leaq 0x6e36(%rip), %rsi      # 0xddc4
leaq 0x707a(%rip), %rdx      # 0xe00f
movb $0x0, %al
callq *%r8
jmp 0x7144
movl $0x0, 0x38(%rsp)
movl 0x2c(%rsp), %edi
leaq 0x38(%rsp), %rsi
xorl %edx, %edx
callq 0x5300
movl 0x38(%rsp), %eax
andl $0xff00, %eax           # imm = 0xFF00
sarl $0x8, %eax
cmpl $0x0, %eax
je 0x7010
movq 0x9ea1(%rip), %rax      # 0x10e70
movq (%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x48(%rsp), %rax
movq %rax, (%rsp)
callq 0x5030
movl (%rax), %edi
callq 0x53b0
movq (%rsp), %rdi
movq 0x8(%rsp), %r8
movq %rax, %rcx
leaq 0x6dc5(%rip), %rsi      # 0xddc4
leaq 0x7047(%rip), %rdx      # 0xe04d
movb $0x0, %al
callq *%r8
jmp 0x7144
movl $0x0, 0x3c(%rsp)
movl 0x3c(%rsp), %eax
movq 0x20(%rsp), %rcx
cmpl 0x88(%rcx), %eax
jge 0x7095
movq 0x20(%rsp), %rax
movq 0x90(%rax), %rax
movslq 0x3c(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x28(%rax)
je 0x7086
movq 0x20(%rsp), %rax
movq 0x90(%rax), %rax
movslq 0x3c(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl 0x28(%rax), %edi
callq 0x5140
movq 0x20(%rsp), %rax
movq 0x90(%rax), %rax
movslq 0x3c(%rsp), %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0x28(%rax)
jmp 0x7088
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x7018
movq 0x20(%rsp), %rax
movl 0x28(%rax), %edi
callq 0x5140
movq 0x20(%rsp), %rax
movl $0x0, 0x28(%rax)
movq 0x20(%rsp), %rax
movl 0x60(%rax), %edi
callq 0x5140
movq 0x20(%rsp), %rax
movl $0x0, 0x60(%rax)
movl $0x0, 0x3c(%rsp)
movl 0x3c(%rsp), %eax
movq 0x20(%rsp), %rcx
cmpl 0x78(%rcx), %eax
jge 0x7134
movq 0x20(%rsp), %rax
movq 0x80(%rax), %rax
movslq 0x3c(%rsp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x7125
movq 0x20(%rsp), %rax
movq 0x80(%rax), %rax
movslq 0x3c(%rsp), %rcx
movl (%rax,%rcx,4), %edi
callq 0x5140
movq 0x20(%rsp), %rax
movq 0x80(%rax), %rax
movslq 0x3c(%rsp), %rcx
movl $0x0, (%rax,%rcx,4)
jmp 0x7127
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x70cf
jmp 0x7136
jmp 0x7138
movq 0x20(%rsp), %rax
movq %rax, 0x50(%rsp)
jmp 0x7161
movq 0x48(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq 0x20(%rsp), %rdx
callq 0x8060
movq $0x0, 0x50(%rsp)
movq 0x50(%rsp), %rax
addq $0x58, %rsp
retq
nopl (%rax,%rax)