user: 请从给定的汇编指令推导出C源代码：

```asm
<tty_getw_irq>:
  endbr64
  push   %r12
  xor    %r12d,%r12d
  push   %rbp
  mov    %rdi,%rbp
  push   %rbx
  sub    $0x40,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x38(%rsp)
  xor    %eax,%eax
  lea    0xf(%rsp),%ebx
  cs nopw 0x0(%rax,%rax,1)
L181:
  xor    %r8d,%r8d
  xor    %ecx,%ecx
  mov    $0x1,%edx
  mov    %ebx,%esi
  mov    $0xa,%edi
  call   <sys_call@plt>
  cmp    $0x1,%eax
  jne    L181
  movzbl 0xf(%rsp),%edi
  lea    -0x30(%rdi),%eax
  cmp    $0x9,%al
  jbe    L92
  cmp    $0xa,%dil
  je     L163
  cmp    $0xd,%dil
  je     L163
  cmp    $0x7f,%dil
  je     L27
  cmp    $0x20,%r12d
  jne    L181
L97:
  mov    $0x20,%ebx
  nopl   0x0(%rax)
L112:
  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    L112
L179:
  mov    $0x30,%edi
  xor    %r12d,%r12d
  call   <tty_putc@plt>
L139:
  mov    %r12d,0x0(%rbp)
  mov    0x38(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L49
  add    $0x40,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
  nopl   0x0(%rax,%rax,1)
L163:
  cmp    $0x20,%r12d
  je     L97
  test   %r12d,%r12d
  je     L139
  lea    -0x1(%r12),%edx
  lea    0x10(%rsp),%rax
  xor    %esi,%esi
  xor    %ecx,%ecx
  lea    0x11(%rsp,%rdx,1),%r9
  mov    $0x1,%r8d
L23:
  mov    %ecx,%edx
  lea    (%rcx,%rcx,4),%edi
  movzbl (%rax),%ecx
  lea    -0x30(%rcx,%rdi,2),%ecx
  cmp    %edx,%ecx
  cmovb  %r8d,%esi
  add    $0x1,%rax
  cmp    %rax,%r9
  jne    L23
  xor    %ebx,%ebx
  test   %esi,%esi
  je     L126
  nopl   0x0(%rax)
L135:
  mov    $0x8,%edi
  add    $0x1,%ebx
  call   <tty_putc@plt>
  mov    $0x20,%edi
  call   <tty_putc@plt>
  mov    $0x8,%edi
  call   <tty_putc@plt>
  cmp    %r12d,%ebx
  jne    L135
  jmp    L179
  nopl   0x0(%rax,%rax,1)
L92:
  mov    %r12d,%eax
  add    $0x1,%r12d
  mov    %dil,0x10(%rsp,%rax,1)
  call   <tty_putc@plt>
  cmp    $0x20,%r12d
  jne    L181
  jmp    L97
  nopl   0x0(%rax,%rax,1)
L27:
  test   %r12d,%r12d
  je     L181
  mov    $0x8,%edi
  sub    $0x1,%r12d
  call   <tty_putc@plt>
  mov    $0x20,%edi
  call   <tty_putc@plt>
  mov    $0x8,%edi
  call   <tty_putc@plt>
  cmp    $0x20,%r12d
  jne    L181
  jmp    L97
L126:
  mov    %ecx,%r12d
  jmp    L139
L49:
  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;
}
```