// File: /workspace/github_c_makefile_star2_O0/arachsys[P]init/daemon.c
// Function: await
static void await(const char *path, int inotify, int parent) {
  struct pollfd fd = { .fd = inotify, .events = POLLIN };
  struct stat test;
  char *slash;
  int watch;

  /* Take a short-cut if path already exists and is a parent dir. */
  if (parent) {
    if (chdir(path) >= 0)
      return;
    if (errno != ENOENT)
      err(EXIT_FAILURE, "chdir %s", path);
  }

  /* If leading slashes are present, chdir to the root and remove them. */
  if (*path == '/') {
    if (chdir("/") < 0)
      err(EXIT_FAILURE, "chdir /");
    while (*path == '/')
      path++;
  }

  /* Remove any stray trailing slashes. */
  slash = strrchr(path, '/');
  if (slash && slash[1] == 0) {
    while (*slash == '/')
      *slash-- = 0;
    slash = strrchr(path, '/');
  }

  /* Recurse to await the parent dir if necessary. */
  if (slash) {
    *slash = 0;
    await(path, inotify, 1);
    path = slash + 1;
  }

  if (*path == 0)
    return;

  /* Now wait for the correct leaf name to arrive in our working dir. */
  watch = inotify_add_watch(inotify, ".", IN_CREATE | IN_MOVED_TO);
  if (watch < 0)
    err(EXIT_FAILURE, "inotify_add_watch");

  while (1) {
    /* Check if it already exists after setting watch to avoid a race. */
    if (parent) {
      if (chdir(path) >= 0)
        goto out;
      if (errno != ENOENT)
        err(EXIT_FAILURE, "chdir %s", path);
    } else {
      if (lstat(path, &test) >= 0)
        goto out;
      if (errno != ENOENT)
        err(EXIT_FAILURE, "lstat %s", path);
    }

    if (event == NULL)
      event = malloc(sizeof(*event) + PATH_MAX + 1);
    if (event == NULL)
      err(EXIT_FAILURE, "malloc");

    /* Otherwise, wait one second for a matching create/move-into event. */
    while (1) {
      while (poll(&fd, 1, 1000) < 0)
        if (errno != EAGAIN && errno != EINTR)
          err(EXIT_FAILURE, "poll");
      if (fd.revents == 0)
        break;

      if (read(inotify, event, sizeof(*event) + PATH_MAX + 1) < 0) {
        if (errno != EAGAIN && errno != EINTR)
          err(EXIT_FAILURE, "read");
        break;
      }

      /* Read only succeeds if it can fill the entire struct. */
      if (!strcmp(path, event->name))
        break;
    }
  }

out:
  inotify_rm_watch(inotify, watch);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x18(%rbp)
movw $0x1, -0x14(%rbp)
movw $0x0, -0x12(%rbp)
cmpl $0x0, -0x10(%rbp)
je 0x35e3
movq -0x8(%rbp), %rdi
callq 0x20d0
cmpl $0x0, %eax
jl 0x35c0
jmp 0x3894
callq 0x2040
cmpl $0x2, (%rax)
je 0x35e1
movq -0x8(%rbp), %rdx
movl $0x1, %edi
leaq 0x10e9(%rip), %rsi      # 0x46c3
movb $0x0, %al
callq 0x2230
jmp 0x35e3
movq -0x8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
jne 0x3631
leaq 0x10dc(%rip), %rdi      # 0x46d2
callq 0x20d0
cmpl $0x0, %eax
jge 0x3613
movl $0x1, %edi
leaq 0x10c0(%rip), %rsi      # 0x46cc
movb $0x0, %al
callq 0x2230
jmp 0x3615
movq -0x8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
jne 0x362f
movq -0x8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x8(%rbp)
jmp 0x3615
jmp 0x3631
movq -0x8(%rbp), %rdi
movl $0x2f, %esi
callq 0x2130
movq %rax, -0xb0(%rbp)
cmpq $0x0, -0xb0(%rbp)
je 0x36a0
movq -0xb0(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
jne 0x36a0
jmp 0x3662
movq -0xb0(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
jne 0x368b
movq -0xb0(%rbp), %rax
movq %rax, %rcx
addq $-0x1, %rcx
movq %rcx, -0xb0(%rbp)
movb $0x0, (%rax)
jmp 0x3662
movq -0x8(%rbp), %rdi
movl $0x2f, %esi
callq 0x2130
movq %rax, -0xb0(%rbp)
cmpq $0x0, -0xb0(%rbp)
je 0x36d4
movq -0xb0(%rbp), %rax
movb $0x0, (%rax)
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl $0x1, %edx
callq 0x3580
movq -0xb0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x36e5
jmp 0x3894
movl -0xc(%rbp), %edi
leaq 0x9de(%rip), %rsi       # 0x40cd
movl $0x180, %edx            # imm = 0x180
callq 0x2250
movl %eax, -0xb4(%rbp)
cmpl $0x0, -0xb4(%rbp)
jge 0x371b
movl $0x1, %edi
leaq 0xfc0(%rip), %rsi       # 0x46d4
movb $0x0, %al
callq 0x2230
jmp 0x371d
cmpl $0x0, -0x10(%rbp)
je 0x3759
movq -0x8(%rbp), %rdi
callq 0x20d0
cmpl $0x0, %eax
jl 0x3736
jmp 0x3886
callq 0x2040
cmpl $0x2, (%rax)
je 0x3757
movq -0x8(%rbp), %rdx
movl $0x1, %edi
leaq 0xf73(%rip), %rsi       # 0x46c3
movb $0x0, %al
callq 0x2230
jmp 0x3796
movq -0x8(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x21b0
cmpl $0x0, %eax
jl 0x3773
jmp 0x3886
callq 0x2040
cmpl $0x2, (%rax)
je 0x3794
movq -0x8(%rbp), %rdx
movl $0x1, %edi
leaq 0xf59(%rip), %rsi       # 0x46e6
movb $0x0, %al
callq 0x2230
jmp 0x3796
cmpq $0x0, 0x2ab2(%rip)      # 0x6250
jne 0x37b1
movl $0x1011, %edi           # imm = 0x1011
callq 0x2240
movq %rax, 0x2a9f(%rip)      # 0x6250
cmpq $0x0, 0x2a97(%rip)      # 0x6250
jne 0x37ce
movl $0x1, %edi
leaq 0xf28(%rip), %rsi       # 0x46ef
movb $0x0, %al
callq 0x2230
jmp 0x37d0
jmp 0x37d2
leaq -0x18(%rbp), %rdi
movl $0x1, %esi
movl $0x3e8, %edx            # imm = 0x3E8
callq 0x22a0
cmpl $0x0, %eax
jge 0x3813
callq 0x2040
cmpl $0xb, (%rax)
je 0x3811
callq 0x2040
cmpl $0x4, (%rax)
je 0x3811
movl $0x1, %edi
leaq 0xeec(%rip), %rsi       # 0x46f6
movb $0x0, %al
callq 0x2230
jmp 0x37d2
movswl -0x12(%rbp), %eax
cmpl $0x0, %eax
jne 0x381e
jmp 0x3881
movl -0xc(%rbp), %edi
movq 0x2a28(%rip), %rsi      # 0x6250
movl $0x1011, %edx           # imm = 0x1011
callq 0x21a0
cmpq $0x0, %rax
jge 0x3861
callq 0x2040
cmpl $0xb, (%rax)
je 0x385f
callq 0x2040
cmpl $0x4, (%rax)
je 0x385f
movl $0x1, %edi
leaq 0xea3(%rip), %rsi       # 0x46fb
movb $0x0, %al
callq 0x2230
jmp 0x3881
movq -0x8(%rbp), %rdi
movq 0x29e4(%rip), %rsi      # 0x6250
addq $0x10, %rsi
callq 0x21c0
cmpl $0x0, %eax
jne 0x387c
jmp 0x3881
jmp 0x37d0
jmp 0x371d
movl -0xc(%rbp), %edi
movl -0xb4(%rbp), %esi
callq 0x23a0
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax)