// File: /workspace/github_c_makefile_star2_O0/canboat[P]canboat/n2kd/main.c
// Function: handleClientRequest
static void handleClientRequest(int i)
{
  ssize_t r;
  char   *p;
  size_t  remain;

  if (stream[i].len >= sizeof(stream[i].buffer) - 2)
  {
    logAbort("Input line on stream %d too long: %s\n", i, stream[i].buffer);
  }
  remain = sizeof(stream[i].buffer) - stream[i].len - 2;

  logDebug("handleClientRequest: read i=%d\n", i);
  logDebug("read %s i=%d fd=%d len=%u remain=%u\n", streamTypeName[stream[i].type], i, stream[i].fd, stream[i].len, remain);
  r = read(stream[i].fd, stream[i].buffer + stream[i].len, remain);

  if (r <= 0)
  {
    logDebug("read %s i=%d fd=%d r=%d\n", streamTypeName[stream[i].type], i, stream[i].fd, r);
    if (stream[i].type == DATA_INPUT_STREAM)
    {
      stop = true;
    }
    else
    {
      closeStream(i);
      return;
    }
  }
  logDebug("processing stream %d\n", i);

  stream[i].len += r;
  stream[i].buffer[stream[i].len] = 0;

  while (stream[i].len > 0)
  {
    size_t len;

    logDebug("processing stream %d buffer '%-1.20s...' len=%zu\n", i, stream[i].buffer, stream[i].len);
    p = strchr(stream[i].buffer, '\n');
    if (!p)
    {
      break;
    }
    len = p - stream[i].buffer;
    if (stream[i].type == CLIENT_INPUT_STREAM)
    {
      write(stdoutfd, stream[i].buffer, len + 1);
    }
    else
    {
      sbAppendData(&tcpMessage, stream[i].buffer, len + 1);
      if (stream[i].type != DATA_INPUT_STREAM || stream[outputIdx].type == DATA_OUTPUT_COPY)
      {
        /* Send all TCP client input and the main stdin stream if the mode is -o */
        /* directly to stdout */
        sbAppendData(&outMessage, stream[i].buffer, len + 1);
      }
    }
    *p = 0;
    if (storeMessage(stream[i].buffer, len) && haveNMEA0183Client)
    {
      convertJSONToNMEA0183(&nmeaMessage, stream[i].buffer);
    }
    p++, len++;
    stream[i].len -= len;

    /* Now remove [buffer..p> == the entire line */
    memmove(stream[i].buffer, p, stream[i].len + 1);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0x4(%rbp)
movslq -0x4(%rbp), %rcx
leaq 0xf0ba(%rip), %rax      # 0x115a0
imulq $0x8038, %rcx, %rcx     # imm = 0x8038
addq %rcx, %rax
cmpq $0x7ffe, 0x8030(%rax) # imm = 0x7FFE
jb 0x2527
movl -0x4(%rbp), %esi
movslq -0x4(%rbp), %rax
leaq 0xf095(%rip), %rdx      # 0x115a0
imulq $0x8038, %rax, %rax     # imm = 0x8038
addq %rax, %rdx
addq $0x18, %rdx
leaq 0xa34f(%rip), %rdi      # 0xc86f
movb $0x0, %al
callq 0x9c40
movslq -0x4(%rbp), %rax
leaq 0xf06e(%rip), %rcx      # 0x115a0
imulq $0x8038, %rax, %rax     # imm = 0x8038
addq %rax, %rcx
movl $0x8000, %eax           # imm = 0x8000
subq 0x8030(%rcx), %rax
subq $0x2, %rax
movq %rax, -0x20(%rbp)
movl -0x4(%rbp), %esi
leaq 0xa33b(%rip), %rdi      # 0xc895
movb $0x0, %al
callq 0x9ae0
movslq -0x4(%rbp), %rcx
leaq 0xf034(%rip), %rax      # 0x115a0
imulq $0x8038, %rcx, %rcx     # imm = 0x8038
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, %ecx
leaq 0xec8e(%rip), %rax      # 0x11210
movq (%rax,%rcx,8), %rsi
movl -0x4(%rbp), %edx
movslq -0x4(%rbp), %rcx
leaq 0xf00c(%rip), %rax      # 0x115a0
imulq $0x8038, %rcx, %rcx     # imm = 0x8038
addq %rcx, %rax
movl (%rax), %ecx
movslq -0x4(%rbp), %rdi
leaq 0xeff5(%rip), %rax      # 0x115a0
imulq $0x8038, %rdi, %rdi     # imm = 0x8038
addq %rdi, %rax
movq 0x8030(%rax), %r8
movq -0x20(%rbp), %r9
leaq 0xa2ee(%rip), %rdi      # 0xc8b5
movb $0x0, %al
callq 0x9ae0
movslq -0x4(%rbp), %rcx
leaq 0xefc7(%rip), %rax      # 0x115a0
imulq $0x8038, %rcx, %rcx     # imm = 0x8038
addq %rcx, %rax
movl (%rax), %edi
movslq -0x4(%rbp), %rax
leaq 0xefb0(%rip), %rsi      # 0x115a0
imulq $0x8038, %rax, %rax     # imm = 0x8038
addq %rax, %rsi
addq $0x18, %rsi
movslq -0x4(%rbp), %rcx
leaq 0xef97(%rip), %rax      # 0x115a0
imulq $0x8038, %rcx, %rcx     # imm = 0x8038
addq %rcx, %rax
addq 0x8030(%rax), %rsi
movq -0x20(%rbp), %rdx
callq 0x21c0
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jg 0x26b6
movslq -0x4(%rbp), %rcx
leaq 0xef63(%rip), %rax      # 0x115a0
imulq $0x8038, %rcx, %rcx     # imm = 0x8038
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, %ecx
leaq 0xebbd(%rip), %rax      # 0x11210
movq (%rax,%rcx,8), %rsi
movl -0x4(%rbp), %edx
movslq -0x4(%rbp), %rcx
leaq 0xef3b(%rip), %rax      # 0x115a0
imulq $0x8038, %rcx, %rcx     # imm = 0x8038
addq %rcx, %rax
movl (%rax), %ecx
movq -0x10(%rbp), %r8
leaq 0xa25e(%rip), %rdi      # 0xc8da
movb $0x0, %al
callq 0x9ae0
movslq -0x4(%rbp), %rcx
leaq 0xef12(%rip), %rax      # 0x115a0
imulq $0x8038, %rcx, %rcx     # imm = 0x8038
addq %rcx, %rax
cmpl $0xe, 0x4(%rax)
jne 0x26a7
movb $0x1, 0xeeed(%rip)      # 0x11592
jmp 0x26b4
movl -0x4(%rbp), %edi
callq 0x3a30
jmp 0x29aa
jmp 0x26b6
movl -0x4(%rbp), %esi
leaq 0xa233(%rip), %rdi      # 0xc8f3
movb $0x0, %al
callq 0x9ae0
movq -0x10(%rbp), %rcx
movslq -0x4(%rbp), %rdx
leaq 0xeeca(%rip), %rax      # 0x115a0
imulq $0x8038, %rdx, %rdx     # imm = 0x8038
addq %rdx, %rax
addq 0x8030(%rax), %rcx
movq %rcx, 0x8030(%rax)
movslq -0x4(%rbp), %rcx
leaq 0xeea7(%rip), %rax      # 0x115a0
imulq $0x8038, %rcx, %rcx     # imm = 0x8038
addq %rcx, %rax
movslq -0x4(%rbp), %rdx
leaq 0xee92(%rip), %rcx      # 0x115a0
imulq $0x8038, %rdx, %rdx     # imm = 0x8038
addq %rdx, %rcx
movq 0x8030(%rcx), %rcx
movb $0x0, 0x18(%rax,%rcx)
movslq -0x4(%rbp), %rcx
leaq 0xee71(%rip), %rax      # 0x115a0
imulq $0x8038, %rcx, %rcx     # imm = 0x8038
addq %rcx, %rax
cmpq $0x0, 0x8030(%rax)
jbe 0x29aa
movl -0x4(%rbp), %esi
movslq -0x4(%rbp), %rax
leaq 0xee4b(%rip), %rdx      # 0x115a0
imulq $0x8038, %rax, %rax     # imm = 0x8038
addq %rax, %rdx
addq $0x18, %rdx
movslq -0x4(%rbp), %rcx
leaq 0xee32(%rip), %rax      # 0x115a0
imulq $0x8038, %rcx, %rcx     # imm = 0x8038
addq %rcx, %rax
movq 0x8030(%rax), %rcx
leaq 0xa183(%rip), %rdi      # 0xc909
movb $0x0, %al
callq 0x9ae0
movslq -0x4(%rbp), %rax
leaq 0xee08(%rip), %rdi      # 0x115a0
imulq $0x8038, %rax, %rax     # imm = 0x8038
addq %rax, %rdi
addq $0x18, %rdi
movl $0xa, %esi
callq 0x2110
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x27c0
jmp 0x29aa
movq -0x18(%rbp), %rax
movslq -0x4(%rbp), %rdx
leaq 0xedd1(%rip), %rcx      # 0x115a0
imulq $0x8038, %rdx, %rdx     # imm = 0x8038
addq %rdx, %rcx
addq $0x18, %rcx
subq %rcx, %rax
movq %rax, -0x28(%rbp)
movslq -0x4(%rbp), %rcx
leaq 0xedb1(%rip), %rax      # 0x115a0
imulq $0x8038, %rcx, %rcx     # imm = 0x8038
addq %rcx, %rax
cmpl $0x2, 0x4(%rax)
jne 0x282f
movslq -0x4(%rbp), %rax
leaq 0xed96(%rip), %rsi      # 0x115a0
imulq $0x8038, %rax, %rax     # imm = 0x8038
addq %rax, %rsi
addq $0x18, %rsi
movq -0x28(%rbp), %rdx
addq $0x1, %rdx
movl $0x1, %edi
callq 0x20d0
jmp 0x28c4
movslq -0x4(%rbp), %rax
leaq 0xed66(%rip), %rsi      # 0x115a0
imulq $0x8038, %rax, %rax     # imm = 0x8038
addq %rax, %rsi
addq $0x18, %rsi
movq -0x28(%rbp), %rdx
addq $0x1, %rdx
leaq 0x201cd51(%rip), %rdi   # 0x201f5a8
callq 0xa130
movslq -0x4(%rbp), %rcx
leaq 0xed39(%rip), %rax      # 0x115a0
imulq $0x8038, %rcx, %rcx     # imm = 0x8038
addq %rcx, %rax
cmpl $0xe, 0x4(%rax)
jne 0x2895
movslq 0xeaca(%rip), %rcx      # 0x11348
leaq 0xed1b(%rip), %rax      # 0x115a0
imulq $0x8038, %rcx, %rcx     # imm = 0x8038
addq %rcx, %rax
cmpl $0x10, 0x4(%rax)
jne 0x28c2
movslq -0x4(%rbp), %rax
leaq 0xed00(%rip), %rsi      # 0x115a0
imulq $0x8038, %rax, %rax     # imm = 0x8038
addq %rax, %rsi
addq $0x18, %rsi
movq -0x28(%rbp), %rdx
addq $0x1, %rdx
leaq 0x201cd03(%rip), %rdi   # 0x201f5c0
callq 0xa130
jmp 0x28c4
movq -0x18(%rbp), %rax
movb $0x0, (%rax)
movslq -0x4(%rbp), %rax
leaq 0xecca(%rip), %rdi      # 0x115a0
imulq $0x8038, %rax, %rax     # imm = 0x8038
addq %rax, %rdi
addq $0x18, %rdi
movq -0x28(%rbp), %rsi
callq 0x3d70
testb $0x1, %al
jne 0x28f3
jmp 0x2921
testb $0x1, 0xeafe(%rip)      # 0x113f8
je 0x2921
movslq -0x4(%rbp), %rax
leaq 0xec99(%rip), %rsi      # 0x115a0
imulq $0x8038, %rax, %rax     # imm = 0x8038
addq %rax, %rsi
addq $0x18, %rsi
leaq 0x201ccbc(%rip), %rdi   # 0x201f5d8
callq 0x8b60
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdx
movslq -0x4(%rbp), %rcx
leaq 0xec58(%rip), %rax      # 0x115a0
imulq $0x8038, %rcx, %rcx     # imm = 0x8038
addq %rcx, %rax
movq 0x8030(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0x8030(%rax)
movslq -0x4(%rbp), %rax
leaq 0xec32(%rip), %rdi      # 0x115a0
imulq $0x8038, %rax, %rax     # imm = 0x8038
addq %rax, %rdi
addq $0x18, %rdi
movq -0x18(%rbp), %rsi
movslq -0x4(%rbp), %rcx
leaq 0xec15(%rip), %rax      # 0x115a0
imulq $0x8038, %rcx, %rcx     # imm = 0x8038
addq %rcx, %rax
movq 0x8030(%rax), %rdx
addq $0x1, %rdx
callq 0x22b0
jmp 0x2724
addq $0x30, %rsp
popq %rbp
retq