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

```asm
<factorial>:
  endbr64
  push   %r12
  push   %rbp
  push   %rbx
  lea    -0x7a1000(%rsp),%r11
L149:
  sub    $0x1000,%rsp
  orq    $0x0,(%rsp)
  cmp    %r11,%rsp
  jne    L149
  sub    $0x200,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x7a11f8(%rsp)
  xor    %eax,%eax
  test   %rdi,%rdi
  je     L129
  mov    %rdi,%r10
  mov    %rdi,%rcx
  xor    %ebx,%ebx
  mov    %rsp,%rbp
  movabs $0xcccccccccccccccd,%rdi
  nopl   0x0(%rax)
L175:
  mov    %rcx,%rax
  mov    %rcx,%rsi
  add    $0x1,%rbx
  mul    %rdi
  shr    $0x3,%rdx
  lea    (%rdx,%rdx,4),%rax
  add    %rax,%rax
  sub    %rax,%rsi
  mov    %rcx,%rax
  mov    %rdx,%rcx
  mov    %rsi,-0x8(%rbp,%rbx,8)
  cmp    $0x9,%rax
  ja     L175
  movabs $0xcccccccccccccccd,%r8
  mov    %r10,%r9
  cmp    $0x1,%r10
  je     L133
  nopl   0x0(%rax,%rax,1)
L154:
  sub    $0x1,%r9
  test   %rbx,%rbx
  je     L140
  mov    %rbp,%rdi
  lea    0x0(%rbp,%rbx,8),%r11
  xor    %ecx,%ecx
  nop
L163:
  mov    (%rdi),%rsi
  add    $0x8,%rdi
  imul   %r9,%rsi
  add    %rcx,%rsi
  mov    %rsi,%rax
  mul    %r8
  mov    %rdx,%rcx
  mov    %rsi,%rdx
  shr    $0x3,%rcx
  lea    (%rcx,%rcx,4),%rax
  add    %rax,%rax
  sub    %rax,%rdx
  mov    %rdx,-0x8(%rdi)
  cmp    %rdi,%r11
  jne    L163
  cmp    $0x9,%rsi
  jbe    L142
  nopw   0x0(%rax,%rax,1)
L77:
  mov    %rcx,%rax
  mov    %rcx,%rsi
  mul    %r8
  shr    $0x3,%rdx
  lea    (%rdx,%rdx,4),%rax
  add    %rax,%rax
  sub    %rax,%rsi
  mov    %rcx,%rax
  mov    %rdx,%rcx
  mov    %rsi,0x0(%rbp,%rbx,8)
  add    $0x1,%rbx
  cmp    $0x9,%rax
  ja     L77
L142:
  cmp    $0x1,%r9
  jne    L154
  xor    %eax,%eax
  mov    %r10,%rsi
  lea    D25(%rip),%rdi
  call   <printf@plt>
  test   %rbx,%rbx
  je     L51
L85:
  lea    D58(%rip),%r12
  nopl   0x0(%rax,%rax,1)
L62:
  sub    $0x1,%rbx
  xor    %eax,%eax
  mov    %r12,%rdi
  mov    0x0(%rbp,%rbx,8),%rsi
  call   <printf@plt>
  test   %rbx,%rbx
  jne    L62
L51:
  mov    0x7a11f8(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L61
  add    $0x7a1200,%rsp
  lea    D24(%rip),%rdi
  pop    %rbx
  pop    %rbp
  pop    %r12
  jmp    1070 <puts@plt>
L140:
  cmp    $0x1,%r9
  je     L69
L125:
  cmp    $0x2,%r9
  je     L69
  sub    $0x2,%r9
  cmp    $0x1,%r9
  jne    L125
L69:
  mov    %r10,%rsi
  lea    D25(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  jmp    L51
L129:
  mov    0x7a11f8(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L61
  add    $0x7a1200,%rsp
  lea    D5(%rip),%rdi
  pop    %rbx
  pop    %rbp
  pop    %r12
  jmp    1070 <puts@plt>
L133:
  mov    $0x1,%esi
  lea    D25(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  jmp    L85
L61:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: parse_data
arguments: data_label: D25
data_type: string
name: parse_data
arguments: data_label: D58
data_type: string
name: parse_data
arguments: data_label: D24
data_type: string
name: parse_data
arguments: data_label: D5
data_type: string

tool: D25: 
	%lu! = 

tool: D58: %lu

tool: D24: 


tool: D5: 
	0! = 1


assistant: ```c
void factorial(unsigned long n) {
  if (n == 0) {
    printf("\n\t0! = 1\n\n");
    return;
  }
  unsigned long a[(999999L)];
  unsigned long index = 0;
  unsigned long tmp = n;
  unsigned long digits = 0;
  unsigned long carry = 0;
  while (tmp > 0) {
    a[index++] = tmp % 10;
    tmp /= 10;
    digits++;
  }
  unsigned long m;
  for (m = n; m > 1; --m) {
    for (index = 0; index < digits; ++index) {
      tmp = a[index] * (m - 1) + carry;
      a[index] = tmp % 10;
      carry = tmp / 10;
    }
    while (carry > 0) {
      a[index++] = carry % 10;
      carry /= 10;
      digits++;
    }
  }
  printf("\n\t%lu! = ", n);
  for (index = digits; index > 0; --index)
    printf("%lu", a[index - 1]);
  printf("\n\n");
}
```