// File: /workspace/github_c_makefile_star2_O2/hilbix[P]unbuffered/unbuffered.c
// Function: unbuffered
static void
unbuffered(const char *arg0, int argc, char **argv)
{
  TINO_BUF	buf;
  int		fd_target;

  if (!line_cont_suffix && !flag_hexdump)
    line_cont_suffix = (flag_localtime || flag_linecount || flag_utc || flag_verbose) ? "\n" : "";
  producer	= 0;
  fd_target	= fd_write<0 ? 1 : fd_write;
  if (argc)
    {
      int	fds[2], redir[TINO_OPEN_MAX], fdmax, i;

      if (tino_file_pipeE(fds))
        tino_exit("cannot create pipe");

      fdmax = fd_in<3 ? 3 : fd_in+1;

      for (i=fdmax; --i>=0; )
        redir[i] = -1;				/* preserve all FDs	*/

      if (fd_in<0)
        fd_in = 1;

      redir[2] = flag_both ? fds[1] : 2;	/* catch stderr on -d, too	*/
      if (fd_in==2)
        redir[1] = redir[2];			/* swap stdin/stderr on -i2	*/
      redir[fd_in] = fds[!!fd_in];		/* catch 0:input else:output of producer	*/

      tino_file_close_on_exec_setE(fds[!fd_in]);	/* we do not want to keep the other one	*/

      /* catch the child's 0:input else:output for preprocessing
       */
      producer = tino_fork_execO(redir, fdmax, argv, NULL, 0, NULL);
      tino_file_closeE(fds[!!fd_in]);		/* close the used side of pipe	*/
      if (fd_in)
        fd_in = fds[0];
      else
        fd_target = fds[1];			/* write input to producer	*/

      if (flag_killme)
        {
          /* Following is a mess.  It is only needed for a consumer, though.
           * With a producer we see EOF on the pipe.
           * Shall be handled implicitely by a library somehow:
           */
          consumer	= producer;		/* it's a static, so 0 if not set here */
          tino_sigset(SIGCHLD, terminate);
          terminate();	/* catch early terminated childs	*/
        }
    }

  tino_buf_initO(&buf);
  if (producer && flag_verbose)
    {
      start_line(1, 1);
      add_prefix("start");
      for (; *argv; argv++)
        add_prefix(" '%s'", *argv);	/* XXX TODO sadly, escape is implemented in tino_io, not in tino_buf	*/
      add_prefix("\n");
      out_open();
      tino_data_putsA(&out, tino_buf_get_sN(&prefix));
    }

  if (fd_in<0)
    fd_in = 0;
  tino_file_blockE(fd_in);
  while (tino_buf_readE(&buf, fd_in, -1))
    {
      size_t		n;

      out_open();
      /* XXX TODO MISSING:
       * for flag_buffer==1 or flag_buffer==2
       * immediately write STDOUT(1),
       * but buffer STDERR(dump_line)
       */
      while ((n=tino_buf_get_lenO(&buf))>0)
        {
          const char	*ptr;
          size_t	k, p;

          ptr	= tino_buf_getN(&buf);
          p	= 0;
          for (k=0; k<n; k++)
            if (ptr[k]==line_terminator)
              {
                dump_line(ptr+p, k-p, 1);
                p	= k+1;
              }
          /* k=n	*/
          if (flag_buffer && p)
            n = p;	/* do not output incomplete line	*/
          else if ((flag_buffer>1 && n<=99999) || flag_buffer>2)
            break;		/* buffer fragments	*/

          /* We shall, nonblockingly, read additional input data here,
           * if available.  Leave this to future.
           */
          TINO_XXX;

          if (p<n)
            dump_line(ptr+p, n-p, 0);
          if (flag_cat)
            tino_buf_advanceO(&buf, n);
          else if (tino_buf_write_away_allE(&buf, fd_target, n))
            {
              /* silently drop out	*/
              *tino_main_errflag	= 1;
              break;
            }
          if (flag_buffer)
            break;
        }
      out_flush();
    }
  {
      size_t		n;

      /* in case of flag_buffer: send the rest	*/
      if ((n=tino_buf_get_lenO(&buf))>0)
        {
          const char	*ptr;

          out_open();
          ptr	= tino_buf_getN(&buf);
          dump_line(ptr, n, 0);
          if (!flag_cat && tino_buf_write_away_allE(&buf, fd_target, n))
            *tino_main_errflag	= 1;
        }
  }
  if (producer)
    {
      char *cause;

      if (consumer)
        tino_sigdummy(SIGCHLD);	/* prevent reentrance of waitpid()	*/

      /* wait for child to finish after the pipe was closed,
       * so give the child the chance to terminate.
       */
      tino_file_closeE(fd_in);
      if (fd_out != fd_target)
        tino_file_closeE(fd_target);
      *tino_main_errflag	= tino_wait_child_exact(producer, &cause);
      if (flag_verbose)
        {
          start_line(1, 1);
          add_prefix("end %s\n", cause);
          out_open();
          tino_data_putsA(&out, tino_buf_get_sN(&prefix));
        }
    }
  out_close();			/* close(2)	*/
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2018, %rsp           # imm = 0x2018
movq %rdx, %r14
cmpq $0x0, 0x999d(%rip)      # 0xd280
jne 0x3924
cmpl $0x0, 0x99bc(%rip)      # 0xd2a8
jne 0x3924
movl 0x9978(%rip), %eax      # 0xd26c
orl 0x996a(%rip), %eax      # 0xd264
cmpl $0x0, 0x999f(%rip)      # 0xd2a0
leaq 0x58bc(%rip), %rcx      # 0x91c4
leaq 0x56e8(%rip), %rdx      # 0x8ff7
cmovneq %rdx, %rcx
orl 0x9983(%rip), %eax      # 0xd29c
cmovneq %rdx, %rcx
movq %rcx, 0x995c(%rip)      # 0xd280
andl $0x0, 0x9995(%rip)      # 0xd2c0
movl 0x9973(%rip), %eax      # 0xd2a4
testl %eax, %eax
pushq $0x1
popq %rbx
cmovsl %ebx, %eax
testl %esi, %esi
movl %eax, 0x4(%rsp)
je 0x3a6e
leaq 0x8(%rsp), %rdi
callq 0x2180
testl %eax, %eax
jne 0x3d8b
movl 0x98ff(%rip), %eax      # 0xd25c
leal 0x1(%rax), %ecx
cmpl $0x3, %eax
pushq $0x3
popq %r13
cmovgel %ecx, %r13d
movq %r13, %rcx
testl %ecx, %ecx
jle 0x397f
orl $-0x1, 0x100c(%rsp,%rcx,4)
decq %rcx
jmp 0x396e
testl %eax, %eax
jns 0x398f
movl $0x1, 0x98cf(%rip)      # 0xd25c
movl %ebx, %eax
cmpl $0x0, 0x98c2(%rip)      # 0xd258
je 0x399e
movl 0xc(%rsp), %ecx
jmp 0x39a1
pushq $0x2
popq %rcx
movl %ecx, 0x1018(%rsp)
cmpl $0x2, %eax
jne 0x39b4
movl %ecx, 0x1014(%rsp)
xorl %ecx, %ecx
xorl %edx, %edx
testl %eax, %eax
setne %cl
movl 0x8(%rsp,%rcx,4), %ecx
movl %eax, %eax
movl %ecx, 0x1010(%rsp,%rax,4)
sete %dl
movl 0x8(%rsp,%rdx,4), %r15d
pushq $0x1
popq %rsi
movl %r15d, %edi
xorl %eax, %eax
callq 0x2250
cmpl $-0x1, %eax
je 0x39fa
movl %eax, %edx
orl $0x1, %edx
cmpl %edx, %eax
je 0x39fa
pushq $0x2
popq %rsi
movl %r15d, %edi
xorl %eax, %eax
callq 0x2250
callq 0x2300
cmpl $-0x1, %eax
je 0x3d94
testl %eax, %eax
je 0x3da2
movl %eax, 0x98aa(%rip)      # 0xd2c0
xorl %eax, %eax
cmpl $0x0, 0x983d(%rip)      # 0xd25c
setne %al
movl 0x8(%rsp,%rax,4), %edi
callq 0x4717
cmpl $0x0, 0x982a(%rip)      # 0xd25c
je 0x3a40
movl 0x8(%rsp), %eax
movl %eax, 0x981e(%rip)      # 0xd25c
jmp 0x3a48
movl 0xc(%rsp), %eax
movl %eax, 0x4(%rsp)
cmpl $0x0, 0x9811(%rip)      # 0xd260
je 0x3a6e
movl 0x9869(%rip), %eax      # 0xd2c0
movl %eax, 0x9867(%rip)      # 0xd2c4
leaq 0x36b6(%rip), %rdi      # 0x711a
callq 0x69a2
callq 0x711a
leaq 0x10(%rsp), %rdi
callq 0x6a4f
cmpl $0x0, 0x9841(%rip)      # 0xd2c0
je 0x3ae1
cmpl $0x0, 0x9818(%rip)      # 0xd2a0
je 0x3ae1
pushq $0x1
popq %rdi
movl %edi, %esi
callq 0x6a64
leaq 0x5f56(%rip), %rdi      # 0x99f1
xorl %eax, %eax
callq 0x6b82
leaq 0x5efe(%rip), %r15      # 0x99a7
movq (%r14), %rsi
testq %rsi, %rsi
je 0x3ac1
movq %r15, %rdi
xorl %eax, %eax
callq 0x6b82
addq $0x8, %r14
jmp 0x3aa9
leaq 0x552f(%rip), %rdi      # 0x8ff7
xorl %eax, %eax
callq 0x6b82
callq 0x6c71
callq 0x6cf5
movq %rax, %rdi
callq 0x6ce0
movl 0x9775(%rip), %ebp      # 0xd25c
testl %ebp, %ebp
jns 0x3af4
andl $0x0, 0x976a(%rip)      # 0xd25c
xorl %ebp, %ebp
pushq $0x3
popq %rsi
movl %ebp, %edi
xorl %edx, %edx
xorl %eax, %eax
callq 0x2250
cmpl $-0x1, %eax
je 0x3b1f
movl %eax, %edx
andl $0xfffff7ff, %edx       # imm = 0xFFFFF7FF
cmpl %edx, %eax
je 0x3b1f
pushq $0x4
popq %rsi
movl %ebp, %edi
xorl %eax, %eax
callq 0x2250
leaq 0x10(%rsp), %r14
movl 0x9731(%rip), %r15d     # 0xd25c
movl $0x14000, %esi          # imm = 0x14000
movq %r14, %rdi
callq 0x4055
movq %rax, %r12
movl $0x14000, %edx          # imm = 0x14000
movl %r15d, %edi
movq %r12, %rsi
callq 0x21a0
testl %eax, %eax
jns 0x3b5b
callq 0x2060
cmpl $0x4, (%rax)
je 0x3b3b
jmp 0x3b6b
je 0x3c73
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addq %rax, 0x10(%rsp)
callq 0x6c71
movq 0x10(%rsp), %rax
movq 0x20(%rsp), %rbx
movq %rax, %r12
subq %rbx, %r12
je 0x3c5c
movq 0x28(%rsp), %r15
addq %rbx, %r15
subq %rax, %rbx
xorl %r13d, %r13d
movb 0x96fe(%rip), %al       # 0xd298
leaq (%rbx,%r13), %rcx
movq %r15, %rdx
xorl %ebp, %ebp
cmpq %rbp, %rcx
je 0x3bd0
cmpb %al, (%rdx,%r13)
je 0x3bb6
decq %rbp
incq %rdx
jmp 0x3ba3
leaq (%r15,%r13), %rdi
movq %rbp, %rsi
negq %rsi
pushq $0x1
popq %rdx
callq 0x6d47
subq %rbp, %r13
incq %r13
jmp 0x3b94
movl 0x967a(%rip), %eax      # 0xd250
testl %eax, %eax
setne %cl
testq %r13, %r13
setne %dl
movq %r13, %rbx
testb %dl, %cl
jne 0x3c04
cmpl $0x2, %eax
setge %cl
cmpq $0x186a0, %r12          # imm = 0x186A0
setb %dl
cmpl $0x2, %eax
jg 0x3c5c
movq %r12, %rbx
andb %cl, %dl
jne 0x3c5c
movq %rbx, %rsi
subq %r13, %rsi
jbe 0x3c19
addq %r13, %r15
movq %r15, %rdi
xorl %edx, %edx
callq 0x6d47
cmpl $0x0, 0x9634(%rip)      # 0xd254
je 0x3c2e
movq %r14, %rdi
movl %ebx, %esi
callq 0x6f45
jmp 0x3c40
movq %r14, %rdi
movl 0x4(%rsp), %esi
movl %ebx, %edx
callq 0x6fa4
testl %eax, %eax
jne 0x3c4f
cmpl $0x0, 0x9609(%rip)      # 0xd250
je 0x3b70
jmp 0x3c5c
movq 0x9662(%rip), %rax      # 0xd2b8
movl $0x1, (%rax)
cmpl $0x0, 0x96dd(%rip)      # 0xd340
jle 0x3b24
callq 0x7031
jmp 0x3b24
movq 0x10(%rsp), %r14
subq 0x20(%rsp), %r14
je 0x3cc3
callq 0x6c71
movq 0x28(%rsp), %rdi
addq 0x20(%rsp), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x6d47
cmpl $0x0, 0x95b5(%rip)      # 0xd254
jne 0x3cc3
leaq 0x10(%rsp), %rdi
movl 0x4(%rsp), %esi
movl %r14d, %edx
callq 0x6fa4
testl %eax, %eax
je 0x3cc3
movq 0x95fb(%rip), %rax      # 0xd2b8
movl $0x1, (%rax)
cmpl $0x0, 0x95f6(%rip)      # 0xd2c0
je 0x3d74
cmpl $0x0, 0x95ed(%rip)      # 0xd2c4
je 0x3ce5
leaq 0x3aa3(%rip), %rdi      # 0x7783
callq 0x69a2
movl 0x9571(%rip), %edi      # 0xd25c
callq 0x4717
movl 0x4(%rsp), %edi
cmpl %edi, 0x9576(%rip)      # 0xd270
je 0x3d01
callq 0x4717
movl 0x95b9(%rip), %eax      # 0xd2c0
leaq 0x1010(%rsp), %rdi
movl %eax, (%rdi)
pushq $-0x1
popq %rsi
leaq 0x8(%rsp), %rbx
movq %rbx, %rdx
callq 0x7164
movl (%rbx), %edi
leaq 0x1010(%rsp), %rsi
callq 0x71ee
movq 0x9581(%rip), %rcx      # 0xd2b8
movl %eax, (%rcx)
cmpl $0x0, 0x9560(%rip)      # 0xd2a0
je 0x3d74
pushq $0x1
popq %rdi
movl %edi, %esi
callq 0x6a64
movq 0x1010(%rsp), %rsi
leaq 0x5c9c(%rip), %rdi      # 0x99f7
xorl %eax, %eax
callq 0x6b82
callq 0x6c71
callq 0x6cf5
movq %rax, %rdi
callq 0x6ce0
callq 0x7031
addq $0x2018, %rsp           # imm = 0x2018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5c4c(%rip), %rdi      # 0x99de
jmp 0x3d9b
leaq 0x5c64(%rip), %rdi      # 0x99ff
xorl %eax, %eax
callq 0x691c
cmpl $0x401, %r13d           # imm = 0x401
jl 0x3dd4
leaq 0x5c5d(%rip), %rdi      # 0x9a0f
leaq 0x5c64(%rip), %rdx      # 0x9a1d
pushq $0x72
popq %rsi
callq 0x45e8
leaq 0x5c62(%rip), %rdi      # 0x9a2a
leaq 0x5c69(%rip), %rsi      # 0x9a38
jmp 0x3feb
leaq 0x10(%rsp), %rdi
movl $0x1000, %edx           # imm = 0x1000
xorl %esi, %esi
callq 0x2160
movq %r13, %rax
testl %eax, %eax
jle 0x3e0e
movslq 0x100c(%rsp,%rax,4), %rcx
testq %rcx, %rcx
js 0x3e09
cmpl $0x400, %ecx            # imm = 0x400
jae 0x3f37
incl 0x10(%rsp,%rcx,4)
decq %rax
jmp 0x3de8
pushq $-0x1
popq %rdx
xorl %esi, %esi
movq %r13, %r15
movl %edx, %eax
movl %eax, %ebx
movq %r15, %rax
testl %eax, %eax
jle 0x3e8d
movq %rax, %r15
decq %r15
decl %eax
movl %r15d, %ebp
movl 0x1010(%rsp,%rbp,4), %r12d
testl %r12d, %r12d
sets %cl
cmpl %r12d, %eax
sete %al
orb %cl, %al
movq %r15, %rax
jne 0x3e1d
cmpl $0x0, 0x10(%rsp,%rbp,4)
movl %r15d, %eax
jne 0x3e18
movl %r12d, %edi
movl %esi, 0x4(%rsp)
movl %r15d, %esi
callq 0x20f0
movl 0x4(%rsp), %esi
movl $0x1, 0x10(%rsp,%rbp,4)
decl 0x10(%rsp,%r12,4)
jne 0x3e7e
movl %r12d, %edi
callq 0x2170
pushq $0x1
popq %rsi
movl %r15d, 0x1010(%rsp,%rbp,4)
movl %ebx, %eax
pushq $-0x1
popq %rdx
jmp 0x3e18
movq %r13, %r15
movl %edx, %eax
testl %esi, %esi
movl $0x0, %esi
jne 0x3e18
testl %ebx, %ebx
js 0x3f60
movl %ebx, %edi
callq 0x2130
testl %eax, %eax
js 0x3f75
cmpl $0x400, %eax            # imm = 0x400
jae 0x3f9d
movl %eax, %ecx
cmpl $0x0, 0x10(%rsp,%rcx,4)
jne 0x3fc5
movl %ebx, %edx
movq %r13, %rsi
testl %esi, %esi
jle 0x3ef4
cmpl %ebx, 0x100c(%rsp,%rsi,4)
jne 0x3eef
incl 0x10(%rsp,%rcx,4)
movl %eax, 0x100c(%rsp,%rsi,4)
decl 0x10(%rsp,%rdx,4)
decq %rsi
jmp 0x3ed3
cmpl $0x0, 0x10(%rsp,%rdx,4)
movq %r13, %r15
movl $0x0, %esi
pushq $-0x1
popq %rdx
movl %edx, %eax
je 0x3e18
leaq 0x5afc(%rip), %rdi      # 0x9a0f
leaq 0x5b03(%rip), %rdx      # 0x9a1d
movl $0xba, %esi
callq 0x45e8
leaq 0x5aff(%rip), %rdi      # 0x9a2a
leaq 0x5b66(%rip), %rsi      # 0x9a98
jmp 0x3feb
leaq 0x5ad1(%rip), %rdi      # 0x9a0f
leaq 0x5ad8(%rip), %rdx      # 0x9a1d
pushq $0x7a
popq %rsi
callq 0x45e8
leaq 0x5ad6(%rip), %rdi      # 0x9a2a
leaq 0x5aef(%rip), %rsi      # 0x9a4a
jmp 0x3feb
movq (%r14), %rdi
movq %r14, %rsi
callq 0x2290
movq (%r14), %rdx
xorl %eax, %eax
callq 0x7090
leaq 0x5a93(%rip), %rdi      # 0x9a0f
leaq 0x5a9a(%rip), %rdx      # 0x9a1d
movl $0xb0, %esi
callq 0x45e8
leaq 0x5acc(%rip), %rdi      # 0x9a60
movl %ebx, %esi
xorl %eax, %eax
callq 0x409d
leaq 0x5a6b(%rip), %rdi      # 0x9a0f
leaq 0x5a72(%rip), %rdx      # 0x9a1d
movl $0xb1, %esi
callq 0x45e8
leaq 0x5a6e(%rip), %rdi      # 0x9a2a
leaq 0x5aba(%rip), %rsi      # 0x9a7d
jmp 0x3feb
leaq 0x5a43(%rip), %rdi      # 0x9a0f
leaq 0x5a4a(%rip), %rdx      # 0x9a1d
movl $0xb2, %esi
callq 0x45e8
leaq 0x5a46(%rip), %rdi      # 0x9a2a
leaq 0x5aa4(%rip), %rsi      # 0x9a8f
xorl %eax, %eax
callq 0x409d