// File: /workspace/github_c_makefile_star2_O0/arachsys[P]init/daemon.c
// Function: serve
static int serve(char **argv, size_t limit) {
  int connection;
  size_t count = 0;

  listen_add(signals[0]);
  pollfd[listeners - 1].events = POLLIN;

  while (1) {
    /* Only listen for new connections when below the connection limit. */
    for (size_t i = 0; i + 1 < listeners; i++)
      pollfd[i].events = count < limit ? POLLIN : 0;

    if (poll(pollfd, listeners, -1) < 0) {
      if (errno != EINTR && errno != EAGAIN)
        err(EXIT_FAILURE, "poll");
      continue;
    }

    /* Deal with signals first in case they free additional slots. */
    if (pollfd[listeners - 1].revents & POLLIN)
      switch (signal_get()) {
        case SIGCHLD:
          while (reap(NULL) > 0)
            if (count > 0)
              count--;
          break;
        case SIGINT:
        case SIGTERM:
          return EXIT_SUCCESS;
      }

    /* Accept connections from ready listeners until we hit our limit. */
    for (size_t i = 0; i + 1 < listeners; i++)
      if (pollfd[i].revents & POLLIN && count < limit)
        if ((connection = accept(pollfd[i].fd, NULL, NULL)) >= 0) {
          switch (fork()) {
            case -1:
              break;
            case 0:
              if (dup2(connection, STDIN_FILENO) < 0)
                err(EXIT_FAILURE, "dup2");
              if (dup2(connection, STDOUT_FILENO) < 0)
                err(EXIT_FAILURE, "dup2");
              close(connection);
              execute(argv);
            default:
              count++;
          }
          close(connection);
        }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x20(%rbp)
movl 0x289a(%rip), %edi      # 0x6228
callq 0x3d40
movq 0x28ae(%rip), %rax      # 0x6248
movq 0x287f(%rip), %rcx      # 0x6220
subq $0x1, %rcx
movw $0x1, 0x4(%rax,%rcx,8)
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
addq $0x1, %rax
cmpq 0x285d(%rip), %rax      # 0x6220
jae 0x39fb
movq -0x20(%rbp), %rdx
movq -0x10(%rbp), %rsi
xorl %eax, %eax
movl $0x1, %ecx
cmpq %rsi, %rdx
cmovbl %ecx, %eax
movw %ax, %dx
movq 0x2864(%rip), %rax      # 0x6248
movq -0x28(%rbp), %rcx
movw %dx, 0x4(%rax,%rcx,8)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x39b4
movq 0x2846(%rip), %rdi      # 0x6248
movq 0x2817(%rip), %rsi      # 0x6220
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x22a0
cmpl $0x0, %eax
jge 0x3a44
callq 0x2040
cmpl $0x4, (%rax)
je 0x3a3f
callq 0x2040
cmpl $0xb, (%rax)
je 0x3a3f
movl $0x1, %edi
leaq 0xcbe(%rip), %rsi       # 0x46f6
movb $0x0, %al
callq 0x2230
jmp 0x39ac
movq 0x27fd(%rip), %rax      # 0x6248
movq 0x27ce(%rip), %rcx      # 0x6220
subq $0x1, %rcx
movswl 0x6(%rax,%rcx,8), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x3ab9
callq 0x3dd0
movl %eax, %ecx
movl %ecx, -0x3c(%rbp)
subl $0x2, %eax
je 0x3aaf
jmp 0x3a74
movl -0x3c(%rbp), %eax
subl $0xf, %eax
je 0x3aaf
jmp 0x3a7e
movl -0x3c(%rbp), %eax
subl $0x11, %eax
jne 0x3ab7
jmp 0x3a88
jmp 0x3a8a
xorl %eax, %eax
movl %eax, %edi
callq 0x3e10
cmpl $0x0, %eax
jle 0x3aad
cmpq $0x0, -0x20(%rbp)
jbe 0x3aab
movq -0x20(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x3a8a
jmp 0x3ab7
xorl %eax, %eax
addq $0x40, %rsp
popq %rbp
retq
jmp 0x3ab9
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
cmpq 0x2750(%rip), %rax      # 0x6220
jae 0x3bcc
movq 0x276b(%rip), %rax      # 0x6248
movq -0x30(%rbp), %rcx
movswl 0x6(%rax,%rcx,8), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x3bb9
movq -0x20(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x3bb9
movq 0x2741(%rip), %rax      # 0x6248
movq -0x30(%rbp), %rcx
movl (%rax,%rcx,8), %edi
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x2300
movl %eax, -0x14(%rbp)
cmpl $0x0, %eax
jl 0x3bb7
callq 0x23c0
movl %eax, %ecx
movl %ecx, -0x40(%rbp)
subl $-0x1, %eax
je 0x3b49
jmp 0x3b40
movl -0x40(%rbp), %eax
testl %eax, %eax
je 0x3b4b
jmp 0x3ba3
jmp 0x3baf
movl -0x14(%rbp), %edi
xorl %esi, %esi
callq 0x20f0
cmpl $0x0, %eax
jge 0x3b6d
movl $0x1, %edi
leaq 0x501(%rip), %rsi       # 0x4067
movb $0x0, %al
callq 0x2230
movl -0x14(%rbp), %edi
movl $0x1, %esi
callq 0x20f0
cmpl $0x0, %eax
jge 0x3b92
movl $0x1, %edi
leaq 0x4dc(%rip), %rsi       # 0x4067
movb $0x0, %al
callq 0x2230
movl -0x14(%rbp), %edi
callq 0x2160
movq -0x8(%rbp), %rdi
callq 0x38a0
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movl -0x14(%rbp), %edi
callq 0x2160
jmp 0x3bb9
jmp 0x3bbb
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x3ac1
jmp 0x39ac
nopw %cs:(%rax,%rax)