// File: /workspace/github_c_makefile_star2_O1/arachsys[P]init/uevent.c
// Function: main
int main(int argc, char **argv) {
  char buffer[BUFFER + 1], *cursor, *separator;
  int sock, socksize = 1 << 21;
  ssize_t length;

  if (argc == 3 && strcmp(argv[1], "-b") == 0) {
    netlink.nl_groups = strtoul(argv[2], NULL, 0);
    if (netlink.nl_groups == 0)
      errx(EXIT_FAILURE, "Invalid netlink group mask: %s", argv[2]);
    return broadcast();
  }

  if (argc == 3 && strcmp(argv[1], "-l") == 0) {
    netlink.nl_groups = strtoul(argv[2], NULL, 0);
    if (netlink.nl_groups == 0)
      errx(EXIT_FAILURE, "Invalid netlink group mask: %s", argv[2]);
  } else {
    usage(argv[0]);
  }

  if ((sock = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT)) < 0)
    err(EXIT_FAILURE, "socket");

  setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &socksize, sizeof(int));
  setsockopt(sock, SOL_SOCKET, SO_RCVBUFFORCE, &socksize, sizeof(int));

  if (bind(sock, (struct sockaddr *) &netlink, sizeof(netlink)) < 0)
    err(EXIT_FAILURE, "bind");

  putchar('\n');
  fflush(stdout);

  while (1) {
    if ((length = recv(sock, &buffer, sizeof(buffer) - 1, 0)) < 0) {
      if (errno == ENOBUFS) {
        printf("ACTION overflow\n\n");
        fflush(stdout);
      } else if (errno != EAGAIN && errno != EINTR) {
        err(EXIT_FAILURE, "recv");
      }
      continue;
    }

    /* Null-terminate the uevent and replace stray newlines with spaces. */
    buffer[length] = 0;
    for (cursor = buffer; cursor < buffer + length; cursor++)
      if (*cursor == '\n')
        *cursor = ' ';

    if (strlen(buffer) >= length - 1) {
      /* No properties; fake a simple environment based on the header. */
      if ((cursor = strchr(buffer, '@'))) {
        *cursor++ = 0;
        printf("ACTION %s\n", buffer);
        printf("DEVPATH %s\n", cursor);
      }
    } else {
      /* Ignore header as properties will include ACTION and DEVPATH. */
      cursor = buffer;
      while (cursor += strlen(cursor) + 1, cursor < buffer + length) {
        if ((separator = strchr(cursor, '=')))
          *separator = ' ';
        puts(cursor);
      }
    }
    putchar('\n');
    fflush(stdout);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1038, %rsp           # imm = 0x1038
movq %rsi, %rbx
movl $0x200000, 0x18(%rsp)   # imm = 0x200000
cmpl $0x3, %edi
jne 0x16d7
movq 0x8(%rbx), %r14
leaq 0xd45(%rip), %rsi       # 0x2087
movq %r14, %rdi
callq 0x1120
testl %eax, %eax
jne 0x1696
movq 0x10(%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x11a0
movl %eax, 0x2dab(%rip)      # 0x4110
testl %eax, %eax
je 0x16c0
xorl %eax, %eax
movq %rax, 0x30(%rsp)
movq %rax, 0x20(%rsp)
movl $0x200000, 0x1c(%rsp)   # imm = 0x200000
movl $0x10, %edi
movl $0x2, %esi
movl $0xf, %edx
callq 0x11e0
testl %eax, %eax
js 0x1700
movl %eax, %ebp
leaq 0x1c(%rsp), %rbx
movl %eax, %edi
movl $0x1, %esi
movl $0x7, %edx
movq %rbx, %rcx
movl $0x4, %r8d
callq 0x10a0
movl %ebp, %edi
movl $0x1, %esi
movl $0x20, %edx
movq %rbx, %rcx
movl $0x4, %r8d
callq 0x10a0
leaq 0x2d29(%rip), %rsi      # 0x4108
movl %ebp, 0xc(%rsp)
movl %ebp, %edi
movl $0xc, %edx
callq 0x11d0
testl %eax, %eax
js 0x16df
movq 0x2bda(%rip), %rax      # 0x3fd8
movq (%rax), %rdx
leaq 0x30(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x11b0
movq %rax, %rbx
testq %rax, %rax
setg %al
jle 0x1646
xorl %r15d, %r15d
xorl %ebp, %ebp
xorl %r13d, %r13d
xorl %r14d, %r14d
xorl %r12d, %r12d
movq 0x30(%rsp), %rcx
testq %rcx, %rcx
sete %dl
notb %al
orb %dl, %al
testb $0x1, %al
jne 0x144d
xorl %eax, %eax
cmpb $0xa, -0x1(%rcx,%rbx)
sete %al
subq %rax, %rbx
testq %rcx, %rcx
je 0x1494
testq %rbx, %rbx
jle 0x1494
movq %r15, 0x10(%rsp)
movq %r12, 0x28(%rsp)
leaq (%rbx,%r13), %r12
leaq (%rbx,%r13), %r15
incq %r15
cmpq %r15, %rbp
jae 0x14f6
addq $0x1000, %rbp           # imm = 0x1000
movq %r14, %rdi
movq %rbp, %rsi
callq 0x1170
movq %rax, %r14
testq %rax, %rax
jne 0x146c
jmp 0x1683
testq %r15, %r15
je 0x15b3
testq %r12, %r12
je 0x15b3
movq %r15, 0x10(%rsp)
movq %r15, %rdi
callq 0x10b0
movq %rax, %rbx
movq %r12, %rdi
callq 0x10b0
leaq (%rbx,%rax), %rcx
leaq (%rbx,%rax), %r15
addq $0x2, %r15
leaq (%rcx,%r13), %rbx
addq $0x2, %rbx
cmpq %rbx, %rbp
jae 0x153e
addq $0x1000, %rbp           # imm = 0x1000
movq %r14, %rdi
movq %rbp, %rsi
callq 0x1170
movq %rax, %r14
testq %rax, %rax
jne 0x14d2
jmp 0x1683
leaq (%r14,%r13), %r15
movq 0x30(%rsp), %rsi
movq %r15, %rdi
movq %rbx, %rdx
callq 0x1140
movb $0x0, (%r14,%r12)
cmpq %r12, %r13
jae 0x15c3
xorl %eax, %eax
movzbl (%r15,%rax), %ecx
cmpl $0x3d, %ecx
je 0x15be
cmpl $0x20, %ecx
je 0x15be
incq %rax
cmpq %rax, %rbx
jne 0x151a
jmp 0x15c3
leaq (%r14,%r15), %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x1190
movq 0x10(%rsp), %rcx
addq %r15, %rcx
addq %r15, %r12
movq %r14, %rdi
movq %r15, %rsi
leaq 0xb90(%rip), %rdx       # 0x20f5
movq %r12, %r8
xorl %eax, %eax
callq 0x1100
movl 0xc(%rsp), %r12d
movl %r12d, %edi
movq %r14, %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x10d0
testq %rax, %rax
jns 0x15b3
callq 0x1060
movq %rax, %r15
movl (%r15), %eax
cmpl $0xb, %eax
je 0x159e
cmpl $0x4, %eax
jne 0x15b3
movl %r12d, %edi
movq %r14, %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x10d0
testq %rax, %rax
js 0x1591
xorl %r12d, %r12d
xorl %r13d, %r13d
xorl %r15d, %r15d
jmp 0x1615
movb $0x3d, (%rax,%r15)
movl $0x7, %edx
movq %r15, %rdi
leaq 0xb12(%rip), %rsi       # 0x20e4
callq 0x1070
leaq 0x7(%r15), %rcx
testl %eax, %eax
movq 0x10(%rsp), %r12
cmoveq %rcx, %r12
movl $0x8, %edx
movq %r15, %rdi
leaq 0xaf7(%rip), %rsi       # 0x20ec
callq 0x1070
addq $0x8, %r15
testl %eax, %eax
movq 0x28(%rsp), %rax
cmoveq %r15, %rax
movq %r12, %r15
movq %rax, %r12
addq %rbx, %r13
incq %r13
movq 0x29bc(%rip), %rax      # 0x3fd8
movq (%rax), %rdx
leaq 0x30(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x11b0
movq %rax, %rbx
testq %rax, %rax
setg %al
jg 0x142d
testq %r13, %r13
jne 0x142d
movq 0x30(%rsp), %rdi
callq 0x1030
movl 0xc(%rsp), %edi
callq 0x1110
movq 0x2978(%rip), %rax      # 0x3fd8
movq (%rax), %rdi
callq 0x1090
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
movl %ecx, %eax
addq $0x1038, %rsp           # imm = 0x1038
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xa52(%rip), %rsi       # 0x20dc
movl $0x1, %edi
xorl %eax, %eax
callq 0x1150
leaq 0xa0c(%rip), %rsi       # 0x20a9
movq %r14, %rdi
callq 0x1120
testl %eax, %eax
jne 0x16d7
movq 0x10(%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x11a0
movl %eax, 0x2a54(%rip)      # 0x4110
testl %eax, %eax
jne 0x16e8
movq 0x10(%rbx), %rdx
leaq 0x9bf(%rip), %rsi       # 0x208a
movl $0x1, %edi
xorl %eax, %eax
callq 0x10c0
movq (%rbx), %rdi
callq 0x12ec
leaq 0x9ee(%rip), %rsi       # 0x20d4
jmp 0x168a
movl $0x10, %edi
movl $0x2, %esi
movl $0xf, %edx
callq 0x11e0
testl %eax, %eax
jns 0x1709
leaq 0x9a5(%rip), %rsi       # 0x20ac
jmp 0x168a
movl %eax, %ebx
leaq 0x18(%rsp), %r14
movl %eax, %edi
movl $0x1, %esi
movl $0x8, %edx
movq %r14, %rcx
movl $0x4, %r8d
callq 0x10a0
movl %ebx, %edi
movl $0x1, %esi
movl $0x21, %edx
movq %r14, %rcx
movl $0x4, %r8d
callq 0x10a0
leaq 0x29bd(%rip), %rsi      # 0x4108
movl %ebx, %edi
movl $0xc, %edx
callq 0x1180
testl %eax, %eax
jns 0x1767
leaq 0x951(%rip), %rsi       # 0x20b3
jmp 0x168a
movl $0xa, %edi
callq 0x1050
movq 0x2858(%rip), %r13      # 0x3fd0
leaq 0x30(%rsp), %r14
leaq 0x977(%rip), %r15       # 0x20fb
movq (%r13), %rdi
callq 0x1160
movl $0x1000, %edx           # imm = 0x1000
movl %ebx, %edi
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x1040
testq %rax, %rax
jns 0x17c7
callq 0x1060
movl (%rax), %eax
cmpl $0x4, %eax
je 0x178d
cmpl $0xb, %eax
je 0x178d
cmpl $0x69, %eax
jne 0x1887
movq %r15, %rdi
callq 0x1080
jmp 0x1784
movq %rax, %rbp
leaq 0x30(%rsp,%rax), %r12
movb $0x0, 0x30(%rsp,%rax)
je 0x17e9
movq %r14, %rax
cmpb $0xa, (%rax)
jne 0x17e1
movb $0x20, (%rax)
incq %rax
cmpq %r12, %rax
jb 0x17d9
movq %r14, %rdi
callq 0x10b0
decq %rbp
movq %r14, %rdi
cmpq %rbp, %rax
jae 0x183e
callq 0x10b0
movq %rax, %rbp
leaq 0x31(%rsp), %rax
addq %rax, %rbp
cmpq %r12, %rbp
jae 0x1878
movq %rbp, %rdi
movl $0x3d, %esi
callq 0x10e0
testq %rax, %rax
je 0x1826
movb $0x20, (%rax)
movq %rbp, %rdi
callq 0x1080
movq %rbp, %rdi
callq 0x10b0
addq %rax, %rbp
incq %rbp
jmp 0x180c
movl $0x40, %esi
callq 0x10e0
testq %rax, %rax
je 0x1878
movq %rax, %rbp
incq %rbp
movb $0x0, (%rax)
leaq 0x860(%rip), %rdi       # 0x20bd
movq %r14, %rsi
xorl %eax, %eax
callq 0x10f0
leaq 0x85a(%rip), %rdi       # 0x20c8
movq %rbp, %rsi
xorl %eax, %eax
callq 0x10f0
movl $0xa, %edi
callq 0x1050
jmp 0x1784
leaq 0x82a(%rip), %rsi       # 0x20b8
jmp 0x168a