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

```asm
<main>:
  endbr64
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x8(%rsp)
  xor    %eax,%eax
  cmp    $0x1,%edi
  je     L148
  cmp    $0x3,%edi
  je     L146
  cmp    $0x2,%edi
  je     L100
  lea    D67(%rip),%rdi
  call   <puts@plt>
  mov    $0x1,%edi
  call   <exit@plt>
L14:
  mov    %rsp,%rsi
  mov    %rbp,%rdi
  call   <loadfile2@plt>
  mov    %rax,%r12
  test   %rax,%rax
  je     L123
L91:
  mov    (%rsp),%rcx
  mov    %rbp,%rsi
  movabs $0xaaaaaaaaaaaaaaab,%rdx
  lea    D54(%rip),%rdi
  mov    %rcx,%rax
  mul    %rdx
  xor    %eax,%eax
  shr    %rdx
  call   <printf@plt>
  mov    %r13,%rdi
  lea    D94(%rip),%rsi
  call   <fopen@plt>
  mov    %rax,%r13
  test   %rax,%rax
  je     L64
L66:
  mov    %r13,%rcx
  mov    $0x1c,%edx
  mov    $0x1,%esi
  lea    D86(%rip),%rdi
  call   <fwrite@plt>
  cmpq   $0x0,(%rsp)
  je     L133
  xor    %ebp,%ebp
  xor    %eax,%eax
  lea    D84(%rip),%rbx
  nopl   0x0(%rax)
L103:
  movzbl (%r12,%rax,1),%esi
  lea    0x1(%rbp),%eax
  mov    %r13,%rdi
  movzbl (%r12,%rax,1),%ecx
  lea    0x2(%rbp),%eax
  movzbl (%r12,%rax,1),%r8d
  mov    %ecx,%edx
  shl    $0x2,%ecx
  shr    $0x4,%dl
  mov    %r8d,%eax
  shl    $0x2,%r8d
  movzbl %dl,%edx
  shr    $0x4,%al
  or     %edx,%ecx
  movzbl %sil,%edx
  shr    $0x4,%sil
  movzbl %al,%eax
  movzbl %sil,%esi
  shl    $0x2,%edx
  or     %eax,%r8d
  xor    %eax,%eax
  or     %esi,%edx
  mov    %rbx,%rsi
  call   <fprintf@plt>
  lea    0x3(%rbp),%eax
  mov    %rax,%rbp
  cmp    (%rsp),%rax
  jb     L103
L133:
  mov    %r13,%rdi
  call   <fclose@plt>
  mov    %r12,%rdi
  call   <free@plt>
  xor    %edi,%edi
  call   <exit@plt>
  mov    0x8(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L17
  add    $0x18,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  ret
L146:
  mov    0x8(%rsi),%rbp
  mov    0x10(%rsi),%r13
  jmp    L14
L148:
  lea    D32(%rip),%rdi
  call   <puts@plt>
  lea    D44(%rip),%rdi
  call   <puts@plt>
  lea    D25(%rip),%rdi
  call   <puts@plt>
  xor    %edi,%edi
  call   <exit@plt>
  jmp    L14
L100:
  mov    $0x9,%edi
  mov    0x8(%rsi),%rbp
  call   <malloc@plt>
  mov    %rax,%r13
  test   %rax,%rax
  je     L76
L7:
  mov    %rbp,%rsi
  mov    %r13,%rdi
  call   <strcpy@plt>
  lea    D10(%rip),%rsi
  mov    %r13,%rdi
  call   <changefileext@plt>
  jmp    L14
L64:
  lea    D13(%rip),%rdi
  call   <perror@plt>
  mov    $0x1,%edi
  call   <exit@plt>
  jmp    L66
L123:
  mov    $0x1,%edi
  call   <exit@plt>
  jmp    L91
L76:
  lea    D59(%rip),%rdi
  call   <perror@plt>
  mov    $0x1,%edi
  call   <exit@plt>
  jmp    L7
L17:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: extract_symbolic_data
arguments: label: D67
type_infered: string
name: extract_symbolic_data
arguments: label: D54
type_infered: string
name: extract_symbolic_data
arguments: label: D94
type_infered: string
name: extract_symbolic_data
arguments: label: D86
type_infered: string
name: extract_symbolic_data
arguments: label: D84
type_infered: string
name: extract_symbolic_data
arguments: label: D32
type_infered: string
name: extract_symbolic_data
arguments: label: D44
type_infered: string
name: extract_symbolic_data
arguments: label: D25
type_infered: string
name: extract_symbolic_data
arguments: label: D10
type_infered: string
name: extract_symbolic_data
arguments: label: D13
type_infered: string
name: extract_symbolic_data
arguments: label: D59
type_infered: string

tool: D67: Too many arguments!

tool: D54: '%s' has %d colors, file size is %li.


tool: D94: wb

tool: D86: GIMP Palette
Name: eracha
#


tool: D84: %3d %3d %3d


tool: D32: pal2gpl

tool: D44: ----------------------------------

tool: D25: usage: pal2gpl file.pal [file.gpl]

tool: D10: .gpl

tool: D13: create file

tool: D59: malloc

assistant: ```c
int main(int argc, char *argv[]) {
  char *filename_from, *filename_to;
  unsigned int count;
  unsigned long size;
  unsigned char *buf;
  if (argc == 1) {
    printf("pal2gpl\n");
    printf("----------------------------------\n");
    printf("usage: pal2gpl file.pal [file.gpl]\n");
    exit(0);
  } else if (argc == 3) {
    filename_from = argv[1];
    filename_to = argv[2];
  } else if (argc == 2) {
    filename_from = argv[1];
    filename_to = (char *)malloc(sizeof(filename_from) + 1);
    if (filename_to == NULL) {
      perror("malloc");
      exit(1);
    }
    strcpy(filename_to, filename_from);
    changefileext(filename_to, ".gpl");
  } else {
    printf("Too many arguments!\n");
    exit(1);
  }
  buf = loadfile2(filename_from, &size);
  if (buf == NULL)
    exit(1);
  count = size / 3;
  printf("'%s' has %d colors, file size is %li.\n", filename_from, count, size);
  FILE *des = fopen(filename_to, "wb");
  if (des == NULL) {
    perror("create file");
    exit(1);
  }
  fprintf(des, "GIMP Palette\nName: eracha\n#\n");
  unsigned int i, r, g, b;
  for (i = 0; i < size; i = i + 3) {
    r = (buf[i] << 2) | (buf[i] >> 4);
    g = (buf[i + 1] << 2) | (buf[i + 1] >> 4);
    b = (buf[i + 2] << 2) | (buf[i + 2] >> 4);
    fprintf(des, "%3d %3d %3d\n", r, g, b);
  }
  fclose(des);
  free(buf);
  exit(0);
}
```