// File: /workspace/github_c_makefile_star2_O3/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 0x16c5
movq 0x8(%rbx), %rax
cmpb $0x2d, (%rax)
jne 0x16c5
cmpb $0x62, 0x1(%rax)
jne 0x168b
cmpb $0x0, 0x2(%rax)
jne 0x168b
movq 0x10(%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x1190
movl %eax, 0x2dad(%rip)      # 0x4108
testl %eax, %eax
je 0x16ae
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 0x11d0
testl %eax, %eax
js 0x16ee
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 0x2d2b(%rip), %rsi      # 0x4100
movl %ebp, 0xc(%rsp)
movl %ebp, %edi
movl $0xc, %edx
callq 0x11c0
testl %eax, %eax
js 0x16cd
movq 0x2be4(%rip), %rax      # 0x3fd8
movq (%rax), %rdx
leaq 0x30(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x11a0
testq %rax, %rax
jle 0x163b
movq %rax, %rbx
movb $0x1, %al
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 0x1442
xorl %eax, %eax
cmpb $0xa, -0x1(%rcx,%rbx)
sete %al
subq %rax, %rbx
testq %rcx, %rcx
je 0x1489
testq %rbx, %rbx
jle 0x1489
movq %r15, 0x10(%rsp)
movq %r12, 0x28(%rsp)
leaq (%rbx,%r13), %r12
leaq (%rbx,%r13), %r15
incq %r15
cmpq %r15, %rbp
jae 0x14eb
addq $0x1000, %rbp           # imm = 0x1000
movq %r14, %rdi
movq %rbp, %rsi
callq 0x1160
movq %rax, %r14
testq %rax, %rax
jne 0x1461
jmp 0x1678
testq %r15, %r15
je 0x15a8
testq %r12, %r12
je 0x15a8
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 0x1533
addq $0x1000, %rbp           # imm = 0x1000
movq %r14, %rdi
movq %rbp, %rsi
callq 0x1160
movq %rax, %r14
testq %rax, %rax
jne 0x14c7
jmp 0x1678
leaq (%r14,%r13), %r15
movq 0x30(%rsp), %rsi
movq %r15, %rdi
movq %rbx, %rdx
callq 0x1130
movb $0x0, (%r14,%r12)
cmpq %r12, %r13
jae 0x15b8
xorl %eax, %eax
movzbl (%r15,%rax), %ecx
cmpl $0x3d, %ecx
je 0x15b3
cmpl $0x20, %ecx
je 0x15b3
incq %rax
cmpq %rax, %rbx
jne 0x150f
jmp 0x15b8
leaq (%r14,%r15), %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x1180
movq 0x10(%rsp), %rcx
addq %r15, %rcx
addq %r15, %r12
movq %r14, %rdi
movq %r15, %rsi
leaq 0xb95(%rip), %rdx       # 0x20ef
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 0x15a8
callq 0x1060
movq %rax, %r15
movl (%r15), %eax
cmpl $0xb, %eax
je 0x1593
cmpl $0x4, %eax
jne 0x15a8
movl %r12d, %edi
movq %r14, %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x10d0
testq %rax, %rax
js 0x1586
xorl %r12d, %r12d
xorl %r13d, %r13d
xorl %r15d, %r15d
jmp 0x160a
movb $0x3d, (%rax,%r15)
movl $0x7, %edx
movq %r15, %rdi
leaq 0xb17(%rip), %rsi       # 0x20de
callq 0x1070
leaq 0x7(%r15), %rcx
testl %eax, %eax
movq 0x10(%rsp), %r12
cmoveq %rcx, %r12
movl $0x8, %edx
movq %r15, %rdi
leaq 0xafc(%rip), %rsi       # 0x20e6
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 0x29c7(%rip), %rax      # 0x3fd8
movq (%rax), %rdx
leaq 0x30(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x11a0
movq %rax, %rbx
testq %rax, %rax
setg %al
jg 0x1422
testq %r13, %r13
jne 0x1422
movq 0x30(%rsp), %rdi
callq 0x1030
movl 0xc(%rsp), %edi
callq 0x1110
movq 0x2983(%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 0xa57(%rip), %rsi       # 0x20d6
movl $0x1, %edi
xorl %eax, %eax
callq 0x1140
cmpb $0x6c, 0x1(%rax)
jne 0x16c5
cmpb $0x0, 0x2(%rax)
jne 0x16c5
movq 0x10(%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x1190
movl %eax, 0x2a5e(%rip)      # 0x4108
testl %eax, %eax
jne 0x16d6
movq 0x10(%rbx), %rdx
leaq 0x9ce(%rip), %rsi       # 0x2087
movl $0x1, %edi
xorl %eax, %eax
callq 0x10c0
movq (%rbx), %rdi
callq 0x12dc
leaq 0x9fa(%rip), %rsi       # 0x20ce
jmp 0x167f
movl $0x10, %edi
movl $0x2, %esi
movl $0xf, %edx
callq 0x11d0
testl %eax, %eax
jns 0x16f7
leaq 0x9b1(%rip), %rsi       # 0x20a6
jmp 0x167f
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 0x29c7(%rip), %rsi      # 0x4100
movl %ebx, %edi
movl $0xc, %edx
callq 0x1170
testl %eax, %eax
jns 0x1755
leaq 0x95d(%rip), %rsi       # 0x20ad
jmp 0x167f
movl $0xa, %edi
callq 0x1050
movq 0x286a(%rip), %r12      # 0x3fd0
movq (%r12), %rdi
callq 0x1150
leaq 0x30(%rsp), %r14
movl $0x1000, %edx           # imm = 0x1000
movl %ebx, %edi
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x1040
testq %rax, %rax
js 0x17fd
movq %rax, %r15
leaq 0x30(%rsp,%rax), %r13
movb $0x0, 0x30(%rsp,%rax)
je 0x17ac
movq %r14, %rax
cmpb $0xa, (%rax)
jne 0x17a4
movb $0x20, (%rax)
incq %rax
cmpq %r13, %rax
jb 0x179c
movq %r14, %rdi
callq 0x10b0
decq %r15
cmpq %r15, %rax
jae 0x1829
movq %rax, %rbp
leaq 0x31(%rsp), %rax
addq %rax, %rbp
cmpq %r13, %rbp
jae 0x1866
movq %rbp, %rdi
movl $0x3d, %esi
callq 0x10e0
testq %rax, %rax
je 0x17e5
movb $0x20, (%rax)
movq %rbp, %rdi
callq 0x1080
movq %rbp, %rdi
callq 0x10b0
addq %rax, %rbp
incq %rbp
jmp 0x17c7
callq 0x1060
movl (%rax), %eax
cmpl $0x4, %eax
je 0x1774
cmpl $0xb, %eax
je 0x1774
cmpl $0x69, %eax
jne 0x187e
leaq 0x8d3(%rip), %rdi       # 0x20f5
callq 0x1080
jmp 0x1870
movq %r14, %rdi
movl $0x40, %esi
callq 0x10e0
testq %rax, %rax
je 0x1866
movq %rax, %r15
incq %r15
movb $0x0, (%rax)
leaq 0x86c(%rip), %rdi       # 0x20b7
movq %r14, %rsi
xorl %eax, %eax
callq 0x10f0
leaq 0x866(%rip), %rdi       # 0x20c2
movq %r15, %rsi
xorl %eax, %eax
callq 0x10f0
movl $0xa, %edi
callq 0x1050
movq (%r12), %rdi
callq 0x1150
jmp 0x1774
leaq 0x82d(%rip), %rsi       # 0x20b2
jmp 0x167f