// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x1040, %rsp           # imm = 0x1040
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x200000, -0x1038(%rbp) # imm = 0x200000
cmpl $0x3, -0x8(%rbp)
jne 0x13bd
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xd1f(%rip), %rsi       # 0x2087
callq 0x1120
cmpl $0x0, %eax
jne 0x13bd
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x11a0
movl %eax, 0x2d85(%rip)      # 0x4110
cmpl $0x0, 0x2d7e(%rip)      # 0x4110
jne 0x13af
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdx
movl $0x1, %edi
leaq 0xce2(%rip), %rsi       # 0x208a
movb $0x0, %al
callq 0x10c0
callq 0x16e0
addq $0x1040, %rsp           # imm = 0x1040
popq %rbp
retq
cmpl $0x3, -0x8(%rbp)
jne 0x141b
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xcd7(%rip), %rsi       # 0x20a9
callq 0x1120
cmpl $0x0, %eax
jne 0x141b
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x11a0
movl %eax, 0x2d1b(%rip)      # 0x4110
cmpl $0x0, 0x2d14(%rip)      # 0x4110
jne 0x1419
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdx
movl $0x1, %edi
leaq 0xc78(%rip), %rsi       # 0x208a
movb $0x0, %al
callq 0x10c0
jmp 0x1427
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x12f0
movl $0x10, %edi
movl $0x2, %esi
movl $0xf, %edx
callq 0x11e0
movl %eax, -0x1034(%rbp)
cmpl $0x0, %eax
jge 0x1459
movl $0x1, %edi
leaq 0xc5a(%rip), %rsi       # 0x20ac
movb $0x0, %al
callq 0x1150
movl -0x1034(%rbp), %edi
movl $0x1, %esi
movl $0x8, %edx
leaq -0x1038(%rbp), %rcx
movl $0x4, %r8d
callq 0x10a0
movl -0x1034(%rbp), %edi
movl $0x1, %esi
movl $0x21, %edx
leaq -0x1038(%rbp), %rcx
movl $0x4, %r8d
callq 0x10a0
movl -0x1034(%rbp), %edi
leaq 0x2c5e(%rip), %rsi      # 0x4108
movl $0xc, %edx
callq 0x1180
cmpl $0x0, %eax
jge 0x14cc
movl $0x1, %edi
leaq 0xbee(%rip), %rsi       # 0x20b3
movb $0x0, %al
callq 0x1150
movl $0xa, %edi
callq 0x1050
movq 0x2af3(%rip), %rax      # 0x3fd0
movq (%rax), %rdi
callq 0x1160
movl -0x1034(%rbp), %edi
leaq -0x1020(%rbp), %rsi
movl $0x1000, %edx           # imm = 0x1000
xorl %ecx, %ecx
callq 0x1040
movq %rax, -0x1040(%rbp)
cmpq $0x0, %rax
jge 0x155f
callq 0x1060
cmpl $0x69, (%rax)
jne 0x1534
leaq 0xb9c(%rip), %rdi       # 0x20b8
movb $0x0, %al
callq 0x10f0
movq 0x2aa6(%rip), %rax      # 0x3fd0
movq (%rax), %rdi
callq 0x1160
jmp 0x155d
callq 0x1060
cmpl $0xb, (%rax)
je 0x155b
callq 0x1060
cmpl $0x4, (%rax)
je 0x155b
movl $0x1, %edi
leaq 0xb76(%rip), %rsi       # 0x20ca
movb $0x0, %al
callq 0x1150
jmp 0x155d
jmp 0x14e5
movq -0x1040(%rbp), %rax
movb $0x0, -0x1020(%rbp,%rax)
leaq -0x1020(%rbp), %rax
movq %rax, -0x1028(%rbp)
movq -0x1028(%rbp), %rax
leaq -0x1020(%rbp), %rcx
addq -0x1040(%rbp), %rcx
cmpq %rcx, %rax
jae 0x15c5
movq -0x1028(%rbp), %rax
movsbl (%rax), %eax
cmpl $0xa, %eax
jne 0x15af
movq -0x1028(%rbp), %rax
movb $0x20, (%rax)
jmp 0x15b1
movq -0x1028(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1028(%rbp)
jmp 0x157c
leaq -0x1020(%rbp), %rdi
callq 0x10b0
movq -0x1040(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jb 0x1643
leaq -0x1020(%rbp), %rdi
movl $0x40, %esi
callq 0x10e0
movq %rax, -0x1028(%rbp)
cmpq $0x0, %rax
je 0x1641
movq -0x1028(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x1028(%rbp)
movb $0x0, (%rax)
leaq -0x1020(%rbp), %rsi
leaq 0xaaa(%rip), %rdi       # 0x20cf
movb $0x0, %al
callq 0x10f0
movq -0x1028(%rbp), %rsi
leaq 0xaa0(%rip), %rdi       # 0x20da
movb $0x0, %al
callq 0x10f0
jmp 0x16c1
leaq -0x1020(%rbp), %rax
movq %rax, -0x1028(%rbp)
movq -0x1028(%rbp), %rdi
callq 0x10b0
addq $0x1, %rax
addq -0x1028(%rbp), %rax
movq %rax, -0x1028(%rbp)
movq -0x1028(%rbp), %rax
leaq -0x1020(%rbp), %rcx
addq -0x1040(%rbp), %rcx
cmpq %rcx, %rax
jae 0x16bf
movq -0x1028(%rbp), %rdi
movl $0x3d, %esi
callq 0x10e0
movq %rax, -0x1030(%rbp)
cmpq $0x0, %rax
je 0x16b1
movq -0x1030(%rbp), %rax
movb $0x20, (%rax)
movq -0x1028(%rbp), %rdi
callq 0x1080
jmp 0x1651
jmp 0x16c1
movl $0xa, %edi
callq 0x1050
movq 0x28fe(%rip), %rax      # 0x3fd0
movq (%rax), %rdi
callq 0x1160
jmp 0x14e5
nop