user: Converte this assembly snippet into its equivalent C code:

```asm
<open_pty_master>:
  endbr64
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x8,%rsp
  mov    %rdi,%rbx
  movzbl D113(%rip),%eax
  test   %al,%al
  je     L1
  lea    D113(%rip),%rbp
  lea    D173(%rip),%r12
L39:
  mov    %al,0xa(%r12)
  mov    $0x0,%edx
  mov    D46(%rip),%rax
  mov    (%rax),%esi
  mov    %r12,%rdi
  call   <open@plt>
  test   %eax,%eax
  jns    L176
  add    $0x1,%rbp
  movzbl 0x0(%rbp),%eax
  test   %al,%al
  jne    L39
L1:
  movzbl D47(%rip),%eax
  test   %al,%al
  je     L104
  lea    D47(%rip),%r13
L97:
  mov    %al,D130(%rip)
  movzbl D113(%rip),%eax
  test   %al,%al
  je     L43
  lea    D113(%rip),%rbp
  lea    D168(%rip),%r12
L2:
  mov    %al,0xe(%r12)
  mov    $0x0,%edx
  mov    D46(%rip),%rax
  mov    (%rax),%esi
  mov    %r12,%rdi
  call   <open@plt>
  test   %eax,%eax
  jns    L16
  add    $0x1,%rbp
  movzbl 0x0(%rbp),%eax
  test   %al,%al
  jne    L2
L43:
  add    $0x1,%r13
  movzbl 0x0(%r13),%eax
  test   %al,%al
  jne    L97
  movzbl D47(%rip),%eax
  test   %al,%al
  je     L84
  lea    D47(%rip),%r13
L167:
  mov    %al,D126(%rip)
  movzbl D113(%rip),%eax
  test   %al,%al
  je     L56
  lea    D113(%rip),%rbp
  lea    D195(%rip),%r12
L120:
  mov    %al,0x9(%r12)
  mov    $0x0,%edx
  mov    D46(%rip),%rax
  mov    (%rax),%esi
  mov    %r12,%rdi
  call   <open@plt>
  test   %eax,%eax
  jns    L31
  add    $0x1,%rbp
  movzbl 0x0(%rbp),%eax
  test   %al,%al
  jne    L120
L56:
  add    $0x1,%r13
  movzbl 0x0(%r13),%eax
  test   %al,%al
  jne    L167
  mov    $0xffffffff,%eax
  jmp    L132
L176:
  movb   $0x73,D159(%rip)
  lea    D173(%rip),%rcx
  mov    %rcx,(%rbx)
L132:
  add    $0x8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  ret
L16:
  movzbl 0x0(%r13),%edx
  mov    %dl,D160(%rip)
  movzbl 0x0(%rbp),%edx
  mov    %dl,D243(%rip)
  lea    D234(%rip),%rcx
  mov    %rcx,(%rbx)
  jmp    L132
L31:
  movb   $0x74,D21(%rip)
  lea    D195(%rip),%rcx
  mov    %rcx,(%rbx)
  jmp    L132
L104:
  mov    $0xffffffff,%eax
  jmp    L132
L84:
  mov    $0xffffffff,%eax
  jmp    L132
```

assistant: ```c
int open_pty_master(char **ptyslave) {
  int mfd;
  char *major, *minor;
  static char majorchars[] = "pqrstuvwxyzabcdePQRSTUVWXYZABCDE";
  static char minorchars[] = "0123456789abcdefghijklmnopqrstuv"
                             "wxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_+";
  {
    static char ptyname[] = "/dev/pty/mX";
    for (minor = minorchars; *minor; minor++) {
      ptyname[10] = *minor;
      if ((mfd = open(ptyname, O_RDWR, 0)) >= 0) {
        ptyname[9] = 's';
        *ptyslave = ptyname;
        return mfd;
      }
    }
  }
  {
    static char ptyname[] = "/dev/ptym/ptyXY";
    static char ttyname[] = "/dev/pty/ttyXY";
    for (major = majorchars; *major; major++) {
      ptyname[13] = *major;
      for (minor = minorchars; *minor; minor++) {
        ptyname[14] = *minor;
        if ((mfd = open(ptyname, O_RDWR, 0)) >= 0) {
          ttyname[12] = *major;
          ttyname[13] = *minor;
          *ptyslave = ttyname;
          return mfd;
        }
      }
    }
  }
  {
    static char ptyname[] = "/dev/ptyXY";
    for (major = majorchars; *major; major++) {
      ptyname[8] = *major;
      for (minor = minorchars; *minor; minor++) {
        ptyname[9] = *minor;
        if ((mfd = open(ptyname, O_RDWR, 0)) >= 0) {
          ptyname[5] = 't';
          *ptyslave = ptyname;
          return mfd;
        }
      }
    }
  }
  return -1;
}
```