// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x10a0, %rsp           # imm = 0x10A0
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
cmpq $0x0, 0xe4f2(%rip)      # 0x112a0
jne 0x2e1e
cmpl $0x0, 0xe511(%rip)      # 0x112c8
jne 0x2e1e
movb $0x1, %al
cmpl $0x0, 0xe4c2(%rip)      # 0x11284
movb %al, -0x1091(%rbp)
jne 0x2dfc
movb $0x1, %al
cmpl $0x0, 0xe4b9(%rip)      # 0x1128c
movb %al, -0x1091(%rbp)
jne 0x2dfc
movb $0x1, %al
cmpl $0x0, 0xe4d8(%rip)      # 0x112bc
movb %al, -0x1091(%rbp)
jne 0x2dfc
cmpl $0x0, 0xe4cd(%rip)      # 0x112c0
setne %al
movb %al, -0x1091(%rbp)
movb -0x1091(%rbp), %dl
leaq 0xa6ea(%rip), %rax      # 0xd4f3
leaq 0xa401(%rip), %rcx      # 0xd211
testb $0x1, %dl
cmovneq %rcx, %rax
movq %rax, 0xe482(%rip)      # 0x112a0
movl $0x0, 0xe4b8(%rip)      # 0x112e0
cmpl $0x0, 0xe495(%rip)      # 0x112c4
jge 0x2e3e
movl $0x1, %eax
movl %eax, -0x1098(%rbp)
jmp 0x2e4a
movl 0xe480(%rip), %eax      # 0x112c4
movl %eax, -0x1098(%rbp)
movl -0x1098(%rbp), %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0xc(%rbp)
je 0x3002
leaq -0x44(%rbp), %rdi
callq 0x9770
cmpl $0x0, %eax
je 0x2e79
leaq 0xadc7(%rip), %rdi      # 0xdc39
movb $0x0, %al
callq 0x9790
cmpl $0x3, 0xe3fc(%rip)      # 0x1127c
jge 0x2e8f
movl $0x3, %eax
movl %eax, -0x109c(%rbp)
jmp 0x2e9e
movl 0xe3e7(%rip), %eax      # 0x1127c
addl $0x1, %eax
movl %eax, -0x109c(%rbp)
movl -0x109c(%rbp), %eax
movl %eax, -0x1054(%rbp)
movl -0x1054(%rbp), %eax
movl %eax, -0x1058(%rbp)
movl -0x1058(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1058(%rbp)
cmpl $0x0, %eax
jl 0x2ede
movslq -0x1058(%rbp), %rax
movl $0xffffffff, -0x1050(%rbp,%rax,4) # imm = 0xFFFFFFFF
jmp 0x2eb6
cmpl $0x0, 0xe397(%rip)      # 0x1127c
jge 0x2ef1
movl $0x1, 0xe38b(%rip)      # 0x1127c
cmpl $0x0, 0xe380(%rip)      # 0x11278
je 0x2f05
movl -0x40(%rbp), %eax
movl %eax, -0x10a0(%rbp)
jmp 0x2f12
movl $0x2, %eax
movl %eax, -0x10a0(%rbp)
jmp 0x2f12
movl -0x10a0(%rbp), %eax
movl %eax, -0x1048(%rbp)
cmpl $0x2, 0xe357(%rip)      # 0x1127c
jne 0x2f33
movl -0x1048(%rbp), %eax
movl %eax, -0x104c(%rbp)
cmpl $0x0, 0xe342(%rip)      # 0x1127c
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
movl -0x44(%rbp,%rax,4), %ecx
movslq 0xe329(%rip), %rax      # 0x1127c
movl %ecx, -0x1050(%rbp,%rax,4)
cmpl $0x0, 0xe31b(%rip)      # 0x1127c
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
movl -0x44(%rbp,%rax,4), %edi
callq 0x9840
leaq -0x1050(%rbp), %rdi
movl -0x1054(%rbp), %esi
movq -0x18(%rbp), %rdx
xorl %eax, %eax
movl %eax, %r9d
xorl %r8d, %r8d
movq %r9, %rcx
callq 0x9860
movl %eax, 0xe343(%rip)      # 0x112e0
cmpl $0x0, 0xe2d8(%rip)      # 0x1127c
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
movl -0x44(%rbp,%rax,4), %edi
callq 0x4420
cmpl $0x0, 0xe2ba(%rip)      # 0x1127c
je 0x2fcf
movl -0x44(%rbp), %eax
movl %eax, 0xe2af(%rip)      # 0x1127c
jmp 0x2fd5
movl -0x40(%rbp), %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, 0xe2a4(%rip)      # 0x11280
je 0x3000
movl 0xe2fc(%rip), %eax      # 0x112e0
movl %eax, 0xe2fa(%rip)      # 0x112e4
movl $0x11, %edi
leaq 0x7a2a(%rip), %rsi      # 0xaa20
callq 0x98c0
callq 0xaa20
jmp 0x3002
leaq -0x38(%rbp), %rdi
callq 0x98f0
cmpl $0x0, 0xe2ce(%rip)      # 0x112e0
je 0x3092
cmpl $0x0, 0xe2a5(%rip)      # 0x112c0
je 0x3092
movl $0x1, %esi
movl %esi, %edi
callq 0x9930
leaq 0xac1c(%rip), %rdi      # 0xdc4c
movb $0x0, %al
callq 0x9a90
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
je 0x3064
movq -0x18(%rbp), %rax
movq (%rax), %rsi
leaq 0xabb3(%rip), %rdi      # 0xdc02
movb $0x0, %al
callq 0x9a90
movq -0x18(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x18(%rbp)
jmp 0x3037
leaq 0xa1a6(%rip), %rdi      # 0xd211
movb $0x0, %al
callq 0x9a90
callq 0x9bb0
leaq 0xe2aa(%rip), %rdi      # 0x11328
callq 0x9c90
movq %rax, %rsi
leaq 0xe25b(%rip), %rdi      # 0x112e8
callq 0x9c50
cmpl $0x0, 0xe1e3(%rip)      # 0x1127c
jge 0x30a5
movl $0x0, 0xe1d7(%rip)      # 0x1127c
movl 0xe1d1(%rip), %edi      # 0x1127c
callq 0x9d20
movl 0xe1c6(%rip), %esi      # 0x1127c
leaq -0x38(%rbp), %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x9d40
cmpl $0x0, %eax
je 0x326b
callq 0x9bb0
leaq -0x38(%rbp), %rdi
callq 0x3410
movq %rax, -0x1060(%rbp)
cmpq $0x0, %rax
jbe 0x3261
leaq -0x38(%rbp), %rdi
callq 0x3450
movq %rax, -0x1068(%rbp)
movq $0x0, -0x1078(%rbp)
movq $0x0, -0x1070(%rbp)
movq -0x1070(%rbp), %rax
cmpq -0x1060(%rbp), %rax
jae 0x318d
movq -0x1068(%rbp), %rax
movq -0x1070(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movsbl 0xe17d(%rip), %ecx      # 0x112b8
cmpl %ecx, %eax
jne 0x3177
movq -0x1068(%rbp), %rdi
addq -0x1078(%rbp), %rdi
movq -0x1070(%rbp), %rsi
subq -0x1078(%rbp), %rsi
movl $0x1, %edx
callq 0x9db0
movq -0x1070(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1078(%rbp)
jmp 0x3179
movq -0x1070(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1070(%rbp)
jmp 0x3112
cmpl $0x0, 0xe0dc(%rip)      # 0x11270
je 0x31b0
cmpq $0x0, -0x1078(%rbp)
je 0x31b0
movq -0x1078(%rbp), %rax
movq %rax, -0x1060(%rbp)
jmp 0x31d6
cmpl $0x1, 0xe0b9(%rip)      # 0x11270
jle 0x31c6
cmpq $0x1869f, -0x1060(%rbp) # imm = 0x1869F
jbe 0x31cf
cmpl $0x2, 0xe0a3(%rip)      # 0x11270
jle 0x31d4
jmp 0x3261
jmp 0x31d6
movq -0x1078(%rbp), %rax
cmpq -0x1060(%rbp), %rax
jae 0x3209
movq -0x1068(%rbp), %rdi
addq -0x1078(%rbp), %rdi
movq -0x1060(%rbp), %rsi
subq -0x1078(%rbp), %rsi
xorl %edx, %edx
callq 0x9db0
cmpl $0x0, 0xe064(%rip)      # 0x11274
je 0x3226
movq -0x1060(%rbp), %rax
movl %eax, %esi
leaq -0x38(%rbp), %rdi
callq 0x9ef0
jmp 0x3251
movl -0x3c(%rbp), %esi
movq -0x1060(%rbp), %rax
movl %eax, %edx
leaq -0x38(%rbp), %rdi
callq 0x9f40
cmpl $0x0, %eax
je 0x324f
movq 0xe091(%rip), %rax      # 0x112d8
movl $0x1, (%rax)
jmp 0x3261
jmp 0x3251
cmpl $0x0, 0xe018(%rip)      # 0x11270
je 0x325c
jmp 0x3261
jmp 0x30d2
callq 0xa020
jmp 0x30b0
leaq -0x38(%rbp), %rdi
callq 0x3410
movq %rax, -0x1080(%rbp)
cmpq $0x0, %rax
jbe 0x32dd
callq 0x9bb0
leaq -0x38(%rbp), %rdi
callq 0x3450
movq %rax, -0x1088(%rbp)
movq -0x1088(%rbp), %rdi
movq -0x1080(%rbp), %rsi
xorl %edx, %edx
callq 0x9db0
cmpl $0x0, 0xdfc2(%rip)      # 0x11274
jne 0x32db
movl -0x3c(%rbp), %esi
movq -0x1080(%rbp), %rax
movl %eax, %edx
leaq -0x38(%rbp), %rdi
callq 0x9f40
cmpl $0x0, %eax
je 0x32db
movq 0xe003(%rip), %rax      # 0x112d8
movl $0x1, (%rax)
jmp 0x32dd
cmpl $0x0, 0xdffc(%rip)      # 0x112e0
je 0x3384
cmpl $0x0, 0xdff3(%rip)      # 0x112e4
je 0x32fd
movl $0x11, %edi
callq 0xa040
movl 0xdf79(%rip), %edi      # 0x1127c
callq 0x4420
movl 0xdf82(%rip), %eax      # 0x11290
cmpl -0x3c(%rbp), %eax
je 0x331b
movl -0x3c(%rbp), %edi
callq 0x4420
movl 0xdfbf(%rip), %edi      # 0x112e0
leaq -0x1090(%rbp), %rsi
callq 0xa060
movl %eax, %ecx
movq 0xdfa2(%rip), %rax      # 0x112d8
movl %ecx, (%rax)
cmpl $0x0, 0xdf81(%rip)      # 0x112c0
je 0x3382
movl $0x1, %esi
movl %esi, %edi
callq 0x9930
movq -0x1090(%rbp), %rsi
leaq 0xa8f7(%rip), %rdi      # 0xdc52
movb $0x0, %al
callq 0x9a90
callq 0x9bb0
leaq 0xdfba(%rip), %rdi      # 0x11328
callq 0x9c90
movq %rax, %rsi
leaq 0xdf6b(%rip), %rdi      # 0x112e8
callq 0x9c50
jmp 0x3384
callq 0xa0a0
addq $0x10a0, %rsp           # imm = 0x10A0
popq %rbp
retq
nopw %cs:(%rax,%rax)