// File: /workspace/github_c_makefile_star2_O2/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 0x168a
movq 0x8(%rbx), %rax
cmpb $0x2d, (%rax)
jne 0x168a
cmpb $0x62, 0x1(%rax)
jne 0x1652
cmpb $0x0, 0x2(%rax)
jne 0x1652
movq 0x10(%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x1190
movl %eax, 0x2daf(%rip)      # 0x4108
testl %eax, %eax
je 0x1675
andq $0x0, 0x30(%rsp)
andq $0x0, 0x28(%rsp)
movl $0x200000, 0x1c(%rsp)   # imm = 0x200000
pushq $0x10
popq %rdi
pushq $0x2
popq %rsi
pushq $0xf
popq %rdx
callq 0x11d0
testl %eax, %eax
js 0x16ad
movl %eax, %r15d
pushq $0x1
popq %rbx
pushq $0x7
popq %rdx
leaq 0x1c(%rsp), %r14
pushq $0x4
popq %rbp
movl %eax, %edi
movl %ebx, %esi
movq %r14, %rcx
movl %ebp, %r8d
callq 0x10a0
pushq $0x20
popq %rdx
movl %r15d, %edi
movl %ebx, %esi
movq %r14, %rcx
movl %ebp, %r8d
callq 0x10a0
leaq 0x2d3b(%rip), %rsi      # 0x4100
pushq $0xc
popq %rdx
movl %r15d, 0x4(%rsp)
movl %r15d, %edi
callq 0x11c0
testl %eax, %eax
js 0x1692
movq 0x2bf4(%rip), %r14      # 0x3fd8
xorl %eax, %eax
xorl %ebp, %ebp
xorl %ecx, %ecx
xorl %r13d, %r13d
xorl %edx, %edx
movq %rdx, %r12
movq %rcx, %r15
movq %rax, 0x8(%rsp)
movq (%r14), %rdx
leaq 0x30(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x11a0
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rax, %rax
jg 0x1422
testq %r15, %r15
je 0x1610
testq %rbx, %rbx
setle %al
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0x143f
xorl %eax, %eax
cmpb $0xa, -0x1(%rdi,%rbx)
sete %al
subq %rax, %rbx
testq %rdi, %rdi
je 0x144d
testq %rbx, %rbx
jg 0x14cd
movl $0x0, %eax
movl $0x0, %ecx
movl $0x0, %edx
testq %r12, %r12
je 0x13ef
movl $0x0, %eax
movl $0x0, %ecx
movl $0x0, %edx
cmpq $0x0, 0x8(%rsp)
je 0x13ef
movq %r12, %rdi
callq 0x10b0
movq %rax, %rbx
movq 0x8(%rsp), %rdi
callq 0x10b0
leaq (%rbx,%rax), %rcx
leaq (%rbx,%rax), %r14
addq $0x2, %r14
leaq (%r15,%rcx), %rbx
addq $0x2, %rbx
cmpq %rbx, %r13
jae 0x1548
addq $0x1000, %r13           # imm = 0x1000
movq %rbp, %rdi
movq %r13, %rsi
callq 0x1160
movq %rax, %rbp
testq %rax, %rax
jne 0x14a5
jmp 0x1641
leaq (%rbx,%r15), %rax
movq %rax, 0x20(%rsp)
leaq (%rbx,%r15), %r14
incq %r14
cmpq %r14, %r13
jae 0x1501
addq $0x1000, %r13           # imm = 0x1000
movq %rbp, %rdi
movq %r13, %rsi
callq 0x1160
movq %rax, %rbp
testq %rax, %rax
jne 0x14dd
jmp 0x1641
leaq (%r15,%rbp), %rdi
movq 0x30(%rsp), %rsi
movq %rdi, 0x10(%rsp)
movq %rbx, %rdx
callq 0x1130
movq 0x20(%rsp), %rdx
movb $0x0, (%rbp,%rdx)
movq %r15, %rax
movq 0x2aad(%rip), %r14      # 0x3fd8
cmpq %rdx, %rax
jae 0x15bb
movzbl (%rbp,%rax), %ecx
cmpl $0x3d, %ecx
je 0x15b6
cmpl $0x20, %ecx
je 0x15b6
incq %rax
jmp 0x152b
leaq (%r14,%rbp), %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x1180
addq %r14, %r12
movq 0x8(%rsp), %r8
addq %r14, %r8
movq %rbp, %rdi
movq %r14, %rsi
leaq 0xb80(%rip), %rdx       # 0x20ef
movq %r12, %rcx
xorl %eax, %eax
callq 0x1100
movl 0x4(%rsp), %r14d
movl %r14d, %edi
movq %rbp, %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x10d0
testq %rax, %rax
jns 0x15a4
callq 0x1060
movl (%rax), %eax
cmpl $0x4, %eax
je 0x157e
cmpl $0xb, %eax
je 0x157e
xorl %eax, %eax
xorl %ecx, %ecx
xorl %edx, %edx
movq 0x2a27(%rip), %r14      # 0x3fd8
jmp 0x13ef
movb $0x3d, (%rbp,%rax)
movq 0x10(%rsp), %rdi
leaq 0xb17(%rip), %rsi       # 0x20de
pushq $0x7
popq %rdx
callq 0x1070
movq 0x10(%rsp), %rdi
leaq 0x7(%rdi), %rcx
testl %eax, %eax
cmoveq %rcx, %r12
leaq 0xb01(%rip), %rsi       # 0x20e6
pushq $0x8
popq %rdx
callq 0x1070
movq 0x10(%rsp), %rcx
addq $0x8, %rcx
testl %eax, %eax
movq 0x8(%rsp), %rax
cmoveq %rcx, %rax
leaq (%r15,%rbx), %rcx
incq %rcx
movq %r12, %rdx
jmp 0x13ef
callq 0x1030
movl 0x4(%rsp), %edi
callq 0x1110
movq (%r14), %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 0xa8e(%rip), %rsi       # 0x20d6
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x1140
cmpb $0x6c, 0x1(%rax)
jne 0x168a
cmpb $0x0, 0x2(%rax)
jne 0x168a
movq 0x10(%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x1190
movl %eax, 0x2a97(%rip)      # 0x4108
testl %eax, %eax
jne 0x169b
movq 0x10(%rbx), %rdx
leaq 0xa07(%rip), %rsi       # 0x2087
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x10c0
movq (%rbx), %rdi
callq 0x12dc
leaq 0xa35(%rip), %rsi       # 0x20ce
jmp 0x1648
pushq $0x10
popq %rdi
pushq $0x2
popq %rsi
pushq $0xf
popq %rdx
callq 0x11d0
testl %eax, %eax
jns 0x16b6
leaq 0x9f2(%rip), %rsi       # 0x20a6
jmp 0x1648
movl %eax, %ebx
pushq $0x1
popq %rbp
pushq $0x8
popq %rdx
leaq 0x18(%rsp), %r14
pushq $0x4
popq %r15
movl %eax, %edi
movl %ebp, %esi
movq %r14, %rcx
movl %r15d, %r8d
callq 0x10a0
pushq $0x21
popq %rdx
movl %ebx, %edi
movl %ebp, %esi
movq %r14, %rcx
movl %r15d, %r8d
callq 0x10a0
leaq 0x2a11(%rip), %rsi      # 0x4100
pushq $0xc
popq %rdx
movl %ebx, %edi
callq 0x1170
testl %eax, %eax
jns 0x1709
leaq 0x9a9(%rip), %rsi       # 0x20ad
jmp 0x1648
pushq $0xa
popq %rdi
callq 0x1050
movq 0x28b8(%rip), %r13      # 0x3fd0
leaq 0x30(%rsp), %r14
pushq $0x3d
popq %r12
movq (%r13), %rdi
callq 0x1150
movl $0x1000, %edx           # imm = 0x1000
movl %ebx, %edi
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x1040
testq %rax, %rax
jns 0x1768
callq 0x1060
movl (%rax), %eax
cmpl $0x4, %eax
je 0x172a
cmpl $0xb, %eax
je 0x172a
cmpl $0x69, %eax
jne 0x1818
leaq 0x994(%rip), %rdi       # 0x20f5
callq 0x1080
jmp 0x1721
movq %rax, %r15
leaq (%rsp,%rax), %rbp
addq $0x30, %rbp
movb $0x0, 0x30(%rsp,%rax)
movq %r14, %rax
cmpq %rbp, %rax
jae 0x178d
cmpb $0xa, (%rax)
jne 0x1788
movb $0x20, (%rax)
incq %rax
jmp 0x177b
movq %r14, %rdi
callq 0x10b0
decq %r15
cmpq %r15, %rax
jae 0x17d0
movq %r14, %r15
movq %r15, %rdi
callq 0x10b0
addq %rax, %r15
incq %r15
cmpq %rbp, %r15
jae 0x180b
movq %r15, %rdi
movl %r12d, %esi
callq 0x10e0
testq %rax, %rax
je 0x17c6
movb $0x20, (%rax)
movq %r15, %rdi
callq 0x1080
jmp 0x17a0
movq %r14, %rdi
pushq $0x40
popq %rsi
callq 0x10e0
testq %rax, %rax
je 0x180b
movq %rax, %r15
incq %r15
movb $0x0, (%rax)
leaq 0x8c7(%rip), %rdi       # 0x20b7
movq %r14, %rsi
xorl %eax, %eax
callq 0x10f0
leaq 0x8c1(%rip), %rdi       # 0x20c2
movq %r15, %rsi
xorl %eax, %eax
callq 0x10f0
pushq $0xa
popq %rdi
callq 0x1050
jmp 0x1721
leaq 0x893(%rip), %rsi       # 0x20b2
jmp 0x1648