// File: /workspace/github_c_makefile_star2_O3/redis-force[P]rpm/module/rpm.c
// Function: rpm_worker_upstream_read
static void rpm_worker_upstream_read(RedisModuleCtx *ctx, int fd, void *client_data, int mask) {
  int rd;
  rpm_context *rpm;
  redis_response_status st = REDIS_RESPONSE_OK;
  worker_pipe *pipe = client_data;
  worker_process *worker = pipe->worker;
  redis_response_reader *reader = pipe->user_data;
  char *buf = worker->buf;
  redis_response *reply = NULL;
  REDISMODULE_NOT_USED(mask);
  while ((rd = read(fd, buf, sizeof(worker->buf))) > 0) {
    redis_response_reader_feed(reader, buf, rd);
    while (st == REDIS_RESPONSE_OK && (st = redis_response_reader_next(reader, &reply)) == REDIS_RESPONSE_OK && reply != NULL) {
      st = rpm_worker_upstream_on_reply(ctx, reply);
    }
    if (st != REDIS_RESPONSE_OK) {
      /* protocol error, kill worker and restart to fix the channel */
      RedisModule_Log(ctx, "warning", "worker process respond invalid response and will be restarted to fix the state. %s",
          redis_response_reader_strerr(reader));
      rpm_worker_suicide(ctx, worker);
    }
  }
  if (rd == 0) {
    /* upstream eof, worker process must be died, restart it automatically */
    RedisModule_DeleteFileEvent(ctx, fd, REDISMODULE_READ);
    RedisModule_Log(ctx, "warning", "Upstream connection with fd %d was closed", fd);
    rpm = rpm_context_get(ctx);
    if (--worker->active_upstreams <= 0) {
      RedisModule_Log(ctx, "warning", "All upstream connections were closed, restart worker process now");
      rpm_worker_destroy(ctx, rpm, worker);
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, 0x10(%rsp)
movq (%rdx), %rax
movq 0x30(%rdx), %r15
movq %rax, 0x20(%rsp)
leaq 0xa8(%rax), %r12
movq $0x0, 0x18(%rsp)
movl $0x100000, %edx         # imm = 0x100000
movl %esi, 0xc(%rsp)
movl %esi, %edi
movq %r12, %rsi
callq 0x5170
testl %eax, %eax
jle 0x6f6c
xorl %r13d, %r13d
movq %r15, %rdi
movq %r12, %rsi
movl %eax, %edx
callq 0x5400
testl %r13d, %r13d
je 0x6e41
movq 0x707c(%rip), %rax      # 0xde68
movq (%rax), %rbx
movq %r15, %rdi
callq 0x5300
movq 0x10(%rsp), %r14
movq %r14, %rdi
leaq 0x3fce(%rip), %rsi      # 0xadd4
leaq 0x428d(%rip), %rdx      # 0xb09a
movq %rax, %rcx
xorl %eax, %eax
callq *%rbx
movq %r14, %rdi
movq 0x20(%rsp), %rsi
callq 0x7569
movl %r13d, %ebx
movl $0x100000, %edx         # imm = 0x100000
movl 0xc(%rsp), %edi
movq %r12, %rsi
callq 0x5170
movl %ebx, %r13d
testl %eax, %eax
jg 0x6dd3
jmp 0x6f6c
movq %r15, %rdi
leaq 0x18(%rsp), %rsi
callq 0x5120
movl %eax, %r13d
testl %eax, %eax
sete %al
movq 0x18(%rsp), %rbx
testq %rbx, %rbx
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x6f5d
movq 0x10(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
movq 0x6d8c(%rip), %rax      # 0xdc08
callq *(%rax)
movl $0x2, %r13d
cmpl $0x2, (%rbx)
jne 0x6de5
cmpq $0x3, 0x18(%rbx)
jne 0x6de5
movq 0x10(%rbx), %rdx
movq (%rdx), %rcx
cmpl $0x3, (%rcx)
jne 0x6de5
movq 0x8(%rdx), %rdx
cmpl $0x3, (%rdx)
jne 0x6de5
movq %r12, %r14
movq 0x10(%rcx), %rbp
movq 0x10(%rdx), %r13
movq 0x10(%rax), %r12
movq $0x0, 0x28(%rsp)
movq 0x98(%r12), %rdi
movl $0x8, %edx
movq %r13, %rsi
leaq 0x28(%rsp), %rcx
leaq 0x30(%rsp), %r8
callq 0x51c0
testl %eax, %eax
je 0x6efa
movq %rbx, %rdi
callq 0x5250
jmp 0x6f35
movq 0xa0(%r12), %rdi
movl $0x8, %edx
movq %rbp, %rsi
callq 0x53f0
movq 0x98(%r12), %rdi
movl $0x8, %edx
movq %r13, %rsi
callq 0x53f0
movq 0x28(%rsp), %rdi
movq %rbx, %rsi
movq 0x6f3d(%rip), %rax      # 0xde70
callq *(%rax)
movq %r15, %rdi
leaq 0x18(%rsp), %rsi
callq 0x5120
movl %eax, %r13d
testl %eax, %eax
sete %al
movq %r14, %r12
jne 0x6f5d
movq 0x18(%rsp), %rbx
testq %rbx, %rbx
jne 0x6e6c
xorl %ebx, %ebx
testb %al, %al
je 0x6de5
jmp 0x6e24
testl %eax, %eax
jne 0x7006
movq 0x6c95(%rip), %rax      # 0xdc10
movq 0x10(%rsp), %r14
movq %r14, %rdi
movl 0xc(%rsp), %ebx
movl %ebx, %esi
movl $0x1, %edx
callq *(%rax)
movq 0x6ed1(%rip), %r15      # 0xde68
leaq 0x3e36(%rip), %rsi      # 0xadd4
leaq 0x4148(%rip), %rdx      # 0xb0ed
movq %r14, %rdi
movl %ebx, %ecx
xorl %eax, %eax
callq *(%r15)
movq 0x6c52(%rip), %rax      # 0xdc08
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq *(%rax)
movq %rax, %rbx
movq 0x20(%rsp), %rdx
movl 0x8c(%rdx), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x8c(%rdx)
cmpl $0x1, %eax
jg 0x7006
leaq 0x3df2(%rip), %rsi      # 0xadd4
leaq 0x412e(%rip), %rdx      # 0xb117
movq 0x10(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq *(%r15)
movq %r14, %rdi
movq %rbx, %rsi
movq 0x20(%rsp), %rdx
callq 0x72ef
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq