user: 请将以下的汇编代码转换成C语言代码：

```asm
<tty_getw_irq>:
  endbr64
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x40,%rsp
  mov    %rdi,%r12
  mov    %fs:0x28,%rax
  mov    %rax,0x38(%rsp)
  xor    %eax,%eax
  mov    $0x0,%ebp
  lea    0xf(%rsp),%ebx
  jmp    L183
L91:
  mov    %ebp,%eax
  mov    %dil,0x10(%rsp,%rax,1)
  add    $0x1,%ebp
  movzbl %dil,%edi
  call   <tty_putc@plt>
  cmp    $0x20,%ebp
  jne    L183
L128:
  mov    $0x20,%ebx
L100:
  mov    $0x8,%edi
  call   <tty_putc@plt>
  mov    $0x20,%edi
  call   <tty_putc@plt>
  mov    $0x8,%edi
  call   <tty_putc@plt>
  sub    $0x1,%ebx
  jne    L100
  mov    $0x30,%edi
  call   <tty_putc@plt>
L170:
  mov    %ebx,(%r12)
  mov    0x38(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L175
  mov    $0x0,%eax
  add    $0x40,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
L90:
  mov    $0x0,%eax
L21:
  cmp    $0x20,%ebp
  je     L128
  test   %eax,%eax
  jne    L12
L183:
  mov    $0x0,%r8d
  mov    $0x0,%ecx
  mov    $0x1,%edx
  mov    %ebx,%esi
  mov    $0xa,%edi
  call   <sys_call@plt>
  cmp    $0x1,%eax
  jne    L183
  movzbl 0xf(%rsp),%edi
  lea    -0x30(%rdi),%edx
  cmp    $0x9,%dl
  jbe    L91
  cmp    $0xa,%dil
  je     L21
  cmp    $0xd,%dil
  je     L21
  test   %ebp,%ebp
  je     L90
  cmp    $0x7f,%dil
  jne    L90
  sub    $0x1,%ebp
  mov    $0x8,%edi
  call   <tty_putc@plt>
  mov    $0x20,%edi
  call   <tty_putc@plt>
  mov    $0x8,%edi
  call   <tty_putc@plt>
  mov    $0x0,%eax
  jmp    L21
L12:
  mov    %ebp,%ebx
  test   %ebp,%ebp
  je     L170
  movzbl 0x10(%rsp),%ebx
  sub    $0x30,%ebx
  lea    0x11(%rsp),%rdx
  lea    -0x1(%rbp),%r8d
  add    %rdx,%r8
  mov    $0x0,%esi
  jmp    L24
L52:
  lea    (%rbx,%rbx,4),%edi
  movzbl (%rdx),%ecx
  lea    -0x30(%rcx,%rdi,2),%ecx
  cmp    %ebx,%ecx
  cmovb  %eax,%esi
  add    $0x1,%rdx
  mov    %ecx,%ebx
L24:
  cmp    %r8,%rdx
  jne    L52
  test   %esi,%esi
  je     L170
  mov    $0x0,%ebx
L84:
  mov    $0x8,%edi
  call   <tty_putc@plt>
  mov    $0x20,%edi
  call   <tty_putc@plt>
  mov    $0x8,%edi
  call   <tty_putc@plt>
  add    $0x1,%ebx
  cmp    %ebx,%ebp
  jne    L84
  mov    $0x30,%edi
  call   <tty_putc@plt>
  mov    $0x0,%ebx
  jmp    L170
L175:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
unsigned int tty_getw_irq(unsigned int *val) {
  unsigned char buf[32];
  unsigned char byte;
  unsigned int save = 0;
  unsigned int dec = 0;
  unsigned int done = 0;
  unsigned int overflow = 0;
  unsigned int max = 0;
  unsigned int i;
  unsigned int ret;
  while (done == 0) {
    do {
      ret = sys_call(0x0A, (unsigned int)(&byte), 1, 0, 0);
    } while (ret != 1);
    if ((byte > 0x2F) && (byte < 0x3A)) {
      buf[max] = byte;
      max++;
      tty_putc(byte);
    } else if ((byte == 0x0A) || (byte == 0x0D)) {
      done = 1;
    } else if (byte == 0x7F) {
      if (max > 0) {
        max--;
        tty_putc(0x08);
        tty_putc(0x20);
        tty_putc(0x08);
      }
    }
    if (max == 32) {
      for (i = 0; i < max; i++) {
        tty_putc(0x08);
        tty_putc(0x20);
        tty_putc(0x08);
      }
      tty_putc(0x30);
      *val = 0;
      return 0;
    }
  }
  for (i = 0; i < max; i++) {
    dec = dec * 10 + (buf[i] - 0x30);
    if (dec < save)
      overflow = 1;
    save = dec;
  }
  if (overflow == 0) {
    *val = dec;
  } else {
    for (i = 0; i < max; i++) {
      tty_putc(0x08);
      tty_putc(0x20);
      tty_putc(0x08);
    }
    tty_putc(0x30);
    *val = 0;
  }
  return 0;
}
```