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

```asm
<process_go_command_write>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  mov    %rdx,%r12
  push   %rbp
  mov    %esi,%ebp
  push   %rbx
  movslq %edi,%rbx
  lea    D84(%rip),%rdi
  sub    $0x18,%rsp
  call   <puts@plt>
  cmp    %ebp,%ebx
  jge    L162
  mov    (%r12,%rbx,8),%r12
  mov    %r12,%rdi
  call   <strlen@plt>
  mov    %eax,%ebx
  mov    %eax,%r13d
  shr    $0x1f,%ebx
  add    %eax,%ebx
  sar    %ebx
  mov    %ebx,%edi
  call   <malloc@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  je     L51
  mov    %r13d,%edx
  shr    $0x1f,%edx
  lea    0x0(%r13,%rdx,1),%eax
  and    $0x1,%eax
  sub    %edx,%eax
  cmp    $0x1,%eax
  je     L29
L92:
  cmp    $0x1,%r13d
  jle    L101
  mov    %rbp,%rsi
  xor    %r8d,%r8d
  mov    $0x2,%edi
  xor    %r9d,%r9d
L49:
  movb   $0x0,(%rsi)
  mov    %r8,%rdx
  jmp    L36
  nopw   0x0(%rax,%rax,1)
L145:
  lea    -0x57(%rcx),%eax
L157:
  movzbl (%rsi),%ecx
  add    $0x1,%rdx
  shl    $0x4,%ecx
  or     %ecx,%eax
  mov    %al,(%rsi)
  cmp    %rdx,%rdi
  je     L128
L36:
  movzbl (%r12,%rdx,1),%ecx
  lea    -0x30(%rcx),%eax
  cmp    $0x9,%al
  jbe    L157
  lea    -0x61(%rcx),%eax
  cmp    $0x5,%al
  jbe    L145
  lea    -0x41(%rcx),%eax
  cmp    $0x5,%al
  ja     L32
  lea    -0x37(%rcx),%eax
  jmp    L157
  nopl   0x0(%rax)
L128:
  add    $0x1,%r9d
  add    $0x1,%rsi
  add    $0x2,%rdi
  add    $0x2,%r8
  cmp    %r9d,%ebx
  jg     L49
  mov    $0xffffffff,%edx
  mov    $0x1,%esi
  xor    %edi,%edi
  xor    %r13d,%r13d
  call   <crc32@plt>
  mov    $0x4,%esi
  xor    %edi,%edi
  mov    %eax,%edx
  call   <crc32@plt>
  mov    %rax,%r12
  nopw   0x0(%rax,%rax,1)
L210:
  movzbl 0x0(%rbp,%r13,1),%edi
  mov    %r12d,%edx
  mov    $0x8,%esi
  add    $0x1,%r13
  call   <crc32@plt>
  mov    %rax,%r12
  cmp    %r13d,%ebx
  jg     L210
  mov    $0x4,%esi
  xor    %edi,%edi
  xor    %r13d,%r13d
  call   <reverse_bits@plt>
  mov    %rax,%r14
  nopl   0x0(%rax)
L27:
  movzbl 0x0(%rbp,%r13,1),%edi
  mov    $0x8,%esi
  call   <reverse_bits@plt>
  mov    %al,0x0(%rbp,%r13,1)
  add    $0x1,%r13
  cmp    %r13d,%ebx
  jg     L27
  mov    %r12,%rdi
  mov    $0x20,%esi
  lea    0xa(%rbx),%r15d
  call   <reverse_bits@plt>
  mov    %r15d,%edi
  mov    %rax,%r13
  call   <malloc@plt>
  mov    %rax,%r12
  test   %rax,%rax
  je     L202
  mov    %r15d,%edx
  xor    %esi,%esi
  mov    %r12,%rdi
  call   <memset@plt>
  lea    (%r14,%r14,1),%edx
  xor    %eax,%eax
  mov    %dl,(%r12)
  jmp    L217
  nop
L28:
  movzbl (%r12,%rax,1),%edx
L217:
  movzbl 0x0(%rbp,%rax,1),%ecx
  shl    $0x5,%ecx
  or     %ecx,%edx
  mov    %dl,(%r12,%rax,1)
  movzbl 0x0(%rbp,%rax,1),%edx
  shr    $0x3,%dl
  mov    %dl,0x1(%r12,%rax,1)
  add    $0x1,%rax
  cmp    %eax,%ebx
  jg     L28
L21:
  movslq %ebx,%rcx
  mov    %r13d,%eax
  mov    %r15d,%edx
  mov    %r12,%rsi
  shl    $0x5,%eax
  or     %al,(%r12,%rcx,1)
  mov    %r13,%rax
  shr    $0x3,%rax
  lea    0x4(%r12,%rcx,1),%r14
  mov    %rcx,0x8(%rsp)
  lea    D61(%rip),%rdi
  mov    %al,0x1(%r12,%rcx,1)
  mov    %r13,%rax
  shr    $0xb,%rax
  mov    %al,0x2(%r12,%rcx,1)
  mov    %r13,%rax
  shr    $0x1b,%r13
  shr    $0x13,%rax
  mov    %al,0x3(%r12,%rcx,1)
  mov    %r13b,(%r14)
  call   <dump_jreg@plt>
  lea    0x49(,%rbx,8),%esi
  mov    %r12,%rdi
  call   <or1ksim_jtag_shift_dr@plt>
  mov    %r15d,%edx
  mov    %r12,%rsi
  lea    D100(%rip),%rdi
  movsd  %xmm0,(%rsp)
  call   <dump_jreg@plt>
  mov    0x8(%rsp),%rcx
  mov    $0x4,%esi
  movzbl 0x5(%r12,%rcx,1),%eax
  movzbl 0x6(%r12,%rcx,1),%r13d
  mov    %eax,%edx
  shl    $0x7,%r13
  lea    0x0(,%rax,8),%edi
  shr    %dl
  movzbl %dl,%edx
  or     %rdx,%r13
  movzbl 0x7(%r12,%rcx,1),%edx
  shl    $0xf,%rdx
  or     %rdx,%r13
  movzbl 0x8(%r12,%rcx,1),%edx
  shl    $0x17,%rdx
  or     %rdx,%r13
  movzbl 0x9(%r12,%rcx,1),%edx
  shl    $0x1f,%rdx
  or     %rdx,%r13
  movzbl (%r14),%edx
  shr    $0x5,%dl
  or     %edx,%edi
  and    $0xf,%edi
  call   <reverse_bits@plt>
  mov    %r13,%rdi
  mov    $0x20,%esi
  mov    %rax,%rbx
  call   <reverse_bits@plt>
  movzbl %bl,%r13d
  mov    $0xffffffff,%edx
  mov    $0x4,%esi
  mov    %r13d,%edi
  mov    %rax,%r15
  call   <crc32@plt>
  mov    %r13d,%esi
  lea    D31(%rip),%rdi
  mov    %rax,%r14
  xor    %eax,%eax
  call   <printf@plt>
  cmp    %r14,%r15
  movsd  (%rsp),%xmm0
  je     L198
  lea    D0(%rip),%rdi
  call   <puts@plt>
  mov    %r15,%rsi
  lea    D119(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  mov    %r14,%rsi
  lea    D32(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  movsd  (%rsp),%xmm0
L198:
  lea    D43(%rip),%rdi
  mov    $0x1,%eax
  call   <printf@plt>
  mov    %rbp,%rdi
  call   <free@plt>
  mov    %r12,%rdi
  call   <free@plt>
  add    $0x18,%rsp
  mov    $0x1,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L32:
  movsbl %cl,%esi
  lea    D24(%rip),%rdi
  xor    %eax,%eax
  call   <printf@plt>
  mov    %rbp,%rdi
  call   <free@plt>
  xor    %eax,%eax
L26:
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L162:
  lea    D95(%rip),%rdi
  call   <puts@plt>
  add    $0x18,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L29:
  lea    D14(%rip),%rdi
  call   <puts@plt>
  jmp    L92
L51:
  lea    D120(%rip),%rdi
  call   <puts@plt>
  xor    %eax,%eax
  jmp    L26
L202:
  lea    D124(%rip),%rdi
  call   <puts@plt>
  mov    %rbp,%rdi
  call   <free@plt>
  xor    %eax,%eax
  jmp    L26
L101:
  mov    $0xffffffff,%edx
  mov    $0x1,%esi
  lea    0xa(%rbx),%r15d
  xor    %edi,%edi
  call   <crc32@plt>
  mov    $0x4,%esi
  xor    %edi,%edi
  mov    %eax,%edx
  call   <crc32@plt>
  mov    $0x4,%esi
  xor    %edi,%edi
  mov    %rax,%r12
  call   <reverse_bits@plt>
  mov    %r12,%rdi
  mov    $0x20,%esi
  mov    %rax,%r14
  call   <reverse_bits@plt>
  mov    %r15d,%edi
  mov    %rax,%r13
  call   <malloc@plt>
  mov    %rax,%r12
  test   %rax,%rax
  je     L202
  mov    %r15d,%edx
  xor    %esi,%esi
  mov    %r12,%rdi
  add    %r14d,%r14d
  call   <memset@plt>
  mov    %r14b,(%r12)
  jmp    L21
```

tool_calls: name: parse_data
arguments: data_tag: D84
data_type: string
name: parse_data
arguments: data_tag: D61
data_type: string
name: parse_data
arguments: data_tag: D100
data_type: string
name: parse_data
arguments: data_tag: D31
data_type: string
name: parse_data
arguments: data_tag: D0
data_type: string
name: parse_data
arguments: data_tag: D119
data_type: string
name: parse_data
arguments: data_tag: D32
data_type: string
name: parse_data
arguments: data_tag: D43
data_type: string
name: parse_data
arguments: data_tag: D24
data_type: string
name: parse_data
arguments: data_tag: D95
data_type: string
name: parse_data
arguments: data_tag: D14
data_type: string
name: parse_data
arguments: data_tag: D120
data_type: string
name: parse_data
arguments: data_tag: D124
data_type: string

tool: D84: Processing GO_COMMAND_WRITE.

tool: D61:   shifting in

tool: D100:   shifted out

tool: D31:   status:       0x%01x


tool: D0:   CRC mismatch

tool: D119:     CRC out:      0x%08lx


tool: D32:     CRC computed: 0x%08lx


tool: D43:   time taken:   %.12fs


tool: D24: ERROR: Non-hex digit in data: %c


tool: D95: GO_COMMAND_WRITE usage: GO_COMMAND_WRITE <data>.

tool: D14: Warning: GO_COMMAND_WRITE odd char ignored

tool: D120: ERROR: data malloc for GO_COMMAND_WRITE register failed.

tool: D124: ERROR: jreg malloc for GO_COMMAND_WRITE register failed.

assistant: ```c
int process_go_command_write(int next_jreg, int argc, char *argv[]) {
  printf("Processing GO_COMMAND_WRITE.\n");
  if (next_jreg >= argc) {
    printf("GO_COMMAND_WRITE usage: GO_COMMAND_WRITE <data>.\n");
    return 0;
  }
  unsigned long int cmd = 0;
  char *data_str = argv[next_jreg];
  int data_len = strlen(data_str);
  int data_bytes = data_len / 2;
  unsigned char *data = malloc(data_bytes);
  if (NULL == data) {
    printf("ERROR: data malloc for GO_COMMAND_WRITE register failed.\n");
    return 0;
  }
  if (1 == (data_len % 2)) {
    printf("Warning: GO_COMMAND_WRITE odd char ignored\n");
  }
  int i;
  for (i = 0; i < data_bytes; i++) {
    int ch_off_ms = i * 2;
    int ch_off_ls = i * 2 + 1;
    data[i] = 0;
    int j;
    for (j = ch_off_ms; j <= ch_off_ls; j++) {
      char c = data_str[j];
      int dig_val = (('0' <= c) && (c <= '9')) ? c - '0' : (('a' <= c) && (c <= 'f')) ? c - 'a' + 10 : (('A' <= c) && (c <= 'F')) ? c - 'A' + 10 : -1;
      if (dig_val < 0) {
        printf("ERROR: Non-hex digit in data: %c\n", c);
        free(data);
        return 0;
      }
      data[i] = (data[i] << 4) | dig_val;
    }
  }
  unsigned long int crc_in;
  crc_in = crc32(0, 1, 0xffffffff);
  crc_in = crc32(cmd, 4, crc_in);
  for (i = 0; i < data_bytes; i++) {
    crc_in = crc32(data[i], 8, crc_in);
  }
  cmd = reverse_bits(cmd, 4);
  for (i = 0; i < data_bytes; i++) {
    data[i] = reverse_bits(data[i], 8);
  }
  crc_in = reverse_bits(crc_in, 32);
  int num_bytes = 10 + data_bytes;
  unsigned char *jreg = malloc(num_bytes);
  if (NULL == jreg) {
    printf("ERROR: jreg malloc for GO_COMMAND_WRITE register failed.\n");
    free(data);
    return 0;
  }
  memset(jreg, 0, num_bytes);
  jreg[0] = 0x0;
  jreg[0] |= cmd << 1;
  for (i = 0; i < data_bytes; i++) {
    jreg[i] |= data[i] << 5;
    jreg[i + 1] = data[i] >> 3;
  }
  jreg[data_bytes] |= crc_in << 5;
  jreg[data_bytes + 1] = crc_in >> 3;
  jreg[data_bytes + 2] = crc_in >> 11;
  jreg[data_bytes + 3] = crc_in >> 19;
  jreg[data_bytes + 4] = crc_in >> 27;
  dump_jreg("  shifting in", jreg, num_bytes);
  double t = or1ksim_jtag_shift_dr(jreg, 32 + 4 + 32 + data_bytes * 8 + 4 + 1);
  dump_jreg("  shifted out", jreg, num_bytes);
  unsigned char status;
  unsigned long int crc_out;
  status = ((jreg[data_bytes + 4] >> 5) | (jreg[data_bytes + 5] << 3)) & 0xf;
  crc_out = ((unsigned long int)jreg[data_bytes + 5] >> 1) | ((unsigned long int)jreg[data_bytes + 6] << 7) | ((unsigned long int)jreg[data_bytes + 7] << 15) | ((unsigned long int)jreg[data_bytes + 8] << 23) | ((unsigned long int)jreg[data_bytes + 9] << 31);
  status = reverse_bits(status, 4);
  crc_out = reverse_bits(crc_out, 32);
  unsigned long int crc_computed = crc32(status, 4, 0xffffffff);
  printf("  status:       0x%01x\n", status);
  if (crc_out != crc_computed) {
    printf("  CRC mismatch\n");
    printf("    CRC out:      0x%08lx\n", crc_out);
    printf("    CRC computed: 0x%08lx\n", crc_computed);
  }
  printf("  time taken:   %.12fs\n", t);
  free(data);
  free(jreg);
  return 1;
}
```