#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
unsigned long crc32(unsigned char, int, int);
int /*<<< orphan*/ dump_jreg(char *, unsigned char *, int);
int /*<<< orphan*/ free(unsigned char *);
unsigned char *malloc(int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
double or1ksim_jtag_shift_dr(unsigned char *, int);
int /*<<< orphan*/ printf(char *, ...);
void *reverse_bits(unsigned long, int);
int strlen(char *);
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;
}


x86 assembly (clang, -O0):
<process_go_command_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jl     11d9 <process_go_command_write+0x49>
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    17cc <process_go_command_write+0x63c>
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%edi
call   10a0 <malloc@plt>
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
cmp    -0x38(%rbp),%rax
jne    123d <process_go_command_write+0xad>
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    17cc <process_go_command_write+0x63c>
mov    -0x2c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    $0x1,%eax
cmp    %edx,%eax
jne    1263 <process_go_command_write+0xd3>
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    13ef <process_go_command_write+0x25f>
mov    -0x3c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x40(%rbp)
mov    -0x3c(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x40(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0x44(%rbp),%eax
jg     13dc <process_go_command_write+0x24c>
mov    -0x28(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x49(%rbp)
movsbl -0x49(%rbp),%ecx
mov    $0x30,%eax
cmp    %ecx,%eax
jg     12e7 <process_go_command_write+0x157>
movsbl -0x49(%rbp),%eax
cmp    $0x39,%eax
jg     12e7 <process_go_command_write+0x157>
movsbl -0x49(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x8c(%rbp)
jmp    1375 <process_go_command_write+0x1e5>
movsbl -0x49(%rbp),%ecx
mov    $0x61,%eax
cmp    %ecx,%eax
jg     131a <process_go_command_write+0x18a>
movsbl -0x49(%rbp),%eax
cmp    $0x66,%eax
jg     131a <process_go_command_write+0x18a>
movsbl -0x49(%rbp),%eax
sub    $0x61,%eax
add    $0xa,%eax
mov    %eax,-0x90(%rbp)
jmp    1369 <process_go_command_write+0x1d9>
movsbl -0x49(%rbp),%ecx
mov    $0x41,%eax
cmp    %ecx,%eax
jg     134d <process_go_command_write+0x1bd>
movsbl -0x49(%rbp),%eax
cmp    $0x46,%eax
jg     134d <process_go_command_write+0x1bd>
movsbl -0x49(%rbp),%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %eax,-0x94(%rbp)
jmp    135d <process_go_command_write+0x1cd>
mov    $0xffffffff,%eax
mov    %eax,-0x94(%rbp)
jmp    135d <process_go_command_write+0x1cd>
mov    -0x94(%rbp),%eax
mov    %eax,-0x90(%rbp)
mov    -0x90(%rbp),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x8c(%rbp),%eax
mov    %eax,-0x50(%rbp)
cmpl   $0x0,-0x50(%rbp)
jge    13af <process_go_command_write+0x21f>
movsbl -0x49(%rbp),%esi
lea    0xd23(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    17cc <process_go_command_write+0x63c>
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
shl    $0x4,%eax
or     -0x50(%rbp),%eax
mov    %al,%dl
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    129d <process_go_command_write+0x10d>
jmp    13e1 <process_go_command_write+0x251>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    126a <process_go_command_write+0xda>
xor    %edi,%edi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   1040 <crc32@plt>
mov    %rax,-0x58(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x58(%rbp),%rcx
mov    %ecx,%edx
mov    $0x4,%esi
movzbl %al,%edi
call   1040 <crc32@plt>
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    1462 <process_go_command_write+0x2d2>
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x58(%rbp),%rcx
mov    %ecx,%edx
mov    $0x8,%esi
movzbl %al,%edi
call   1040 <crc32@plt>
mov    %rax,-0x58(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1426 <process_go_command_write+0x296>
mov    -0x20(%rbp),%rdi
mov    $0x4,%esi
call   1060 <reverse_bits@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    14ba <process_go_command_write+0x32a>
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,%edi
mov    $0x8,%esi
call   1060 <reverse_bits@plt>
mov    %al,%dl
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    147b <process_go_command_write+0x2eb>
mov    -0x58(%rbp),%rdi
mov    $0x20,%esi
call   1060 <reverse_bits@plt>
mov    %rax,-0x58(%rbp)
mov    -0x30(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%edi
call   10a0 <malloc@plt>
mov    %rax,-0x68(%rbp)
xor    %eax,%eax
cmp    -0x68(%rbp),%rax
jne    1510 <process_go_command_write+0x380>
lea    0xbe4(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    17cc <process_go_command_write+0x63c>
mov    -0x68(%rbp),%rdi
mov    -0x5c(%rbp),%edx
xor    %esi,%esi
call   1090 <memset@plt>
mov    -0x68(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdx
shl    $0x1,%rdx
mov    -0x68(%rbp),%rax
movzbl (%rax),%ecx
or     %rdx,%rcx
mov    %cl,(%rax)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    159b <process_go_command_write+0x40b>
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
shl    $0x5,%esi
mov    -0x68(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
or     %esi,%edx
mov    %dl,(%rax,%rcx,1)
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
sar    $0x3,%eax
mov    %al,%dl
mov    -0x68(%rbp),%rax
mov    -0x3c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1540 <process_go_command_write+0x3b0>
mov    -0x58(%rbp),%rsi
shl    $0x5,%rsi
mov    -0x68(%rbp),%rax
movslq -0x30(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
or     %rsi,%rdx
mov    %dl,(%rax,%rcx,1)
mov    -0x58(%rbp),%rax
shr    $0x3,%rax
mov    %al,%dl
mov    -0x68(%rbp),%rax
mov    -0x30(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x58(%rbp),%rax
shr    $0xb,%rax
mov    %al,%dl
mov    -0x68(%rbp),%rax
mov    -0x30(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x58(%rbp),%rax
shr    $0x13,%rax
mov    %al,%dl
mov    -0x68(%rbp),%rax
mov    -0x30(%rbp),%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x58(%rbp),%rax
shr    $0x1b,%rax
mov    %al,%dl
mov    -0x68(%rbp),%rax
mov    -0x30(%rbp),%ecx
add    $0x4,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x68(%rbp),%rsi
mov    -0x5c(%rbp),%edx
lea    0xae7(%rip),%rdi
call   1050 <dump_jreg@plt>
mov    -0x68(%rbp),%rdi
mov    -0x30(%rbp),%esi
shl    $0x3,%esi
add    $0x44,%esi
add    $0x4,%esi
add    $0x1,%esi
call   10b0 <or1ksim_jtag_shift_dr@plt>
movsd  %xmm0,-0x70(%rbp)
mov    -0x68(%rbp),%rsi
mov    -0x5c(%rbp),%edx
lea    0xac5(%rip),%rdi
call   1050 <dump_jreg@plt>
mov    -0x68(%rbp),%rax
mov    -0x30(%rbp),%ecx
add    $0x4,%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
sar    $0x5,%eax
mov    -0x68(%rbp),%rcx
mov    -0x30(%rbp),%edx
add    $0x5,%edx
movslq %edx,%rdx
movzbl (%rcx,%rdx,1),%ecx
shl    $0x3,%ecx
or     %ecx,%eax
and    $0xf,%eax
mov    %al,-0x71(%rbp)
mov    -0x68(%rbp),%rax
mov    -0x30(%rbp),%ecx
add    $0x5,%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
shr    $0x1,%rax
mov    -0x68(%rbp),%rcx
mov    -0x30(%rbp),%edx
add    $0x6,%edx
movslq %edx,%rdx
movzbl (%rcx,%rdx,1),%ecx
shl    $0x7,%rcx
or     %rcx,%rax
mov    -0x68(%rbp),%rcx
mov    -0x30(%rbp),%edx
add    $0x7,%edx
movslq %edx,%rdx
movzbl (%rcx,%rdx,1),%ecx
shl    $0xf,%rcx
or     %rcx,%rax
mov    -0x68(%rbp),%rcx
mov    -0x30(%rbp),%edx
add    $0x8,%edx
movslq %edx,%rdx
movzbl (%rcx,%rdx,1),%ecx
shl    $0x17,%rcx
or     %rcx,%rax
mov    -0x68(%rbp),%rcx
mov    -0x30(%rbp),%edx
add    $0x9,%edx
movslq %edx,%rdx
movzbl (%rcx,%rdx,1),%ecx
shl    $0x1f,%rcx
or     %rcx,%rax
mov    %rax,-0x80(%rbp)
movzbl -0x71(%rbp),%eax
mov    %eax,%edi
mov    $0x4,%esi
call   1060 <reverse_bits@plt>
mov    %al,-0x71(%rbp)
mov    -0x80(%rbp),%rdi
mov    $0x20,%esi
call   1060 <reverse_bits@plt>
mov    %rax,-0x80(%rbp)
mov    $0x4,%esi
mov    $0xffffffff,%edx
movzbl -0x71(%rbp),%edi
call   1040 <crc32@plt>
mov    %rax,-0x88(%rbp)
movzbl -0x71(%rbp),%esi
lea    0x9db(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x80(%rbp),%rax
cmp    -0x88(%rbp),%rax
je     17a0 <process_go_command_write+0x610>
lea    0x9d4(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x80(%rbp),%rsi
lea    0x9d2(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x88(%rbp),%rsi
lea    0x9d8(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movsd  -0x70(%rbp),%xmm0
lea    0x9e0(%rip),%rdi
mov    $0x1,%al
call   1080 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x68(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_go_command_write>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %esi,%ebx
mov    %edi,%ebp
lea    0xee8(%rip),%rdi
call   1040 <puts@plt>
cmp    %ebx,%ebp
jge    139e <process_go_command_write+0x1fe>
movslq %ebp,%rax
mov    (%r14,%rax,8),%rbp
mov    %rbp,%rdi
call   1080 <strlen@plt>
mov    %eax,%r15d
mov    %eax,%ebx
shr    $0x1f,%ebx
add    %eax,%ebx
mov    %ebx,%r13d
sar    %r13d
mov    %r13d,%edi
call   10b0 <malloc@plt>
test   %rax,%rax
je     13a7 <process_go_command_write+0x207>
mov    %rax,%r14
and    $0xfffffffe,%ebx
mov    %r15d,%eax
sub    %ebx,%eax
cmp    $0x1,%eax
jne    1215 <process_go_command_write+0x75>
lea    0xef9(%rip),%rdi
call   1040 <puts@plt>
cmp    $0x2,%r15d
jl     12fd <process_go_command_write+0x15d>
mov    %r13d,%eax
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movb   $0x0,(%r14,%rcx,1)
movzbl 0x0(%rbp,%rcx,2),%esi
movsbl %sil,%edx
lea    -0x30(%rdx),%edi
cmp    $0x9,%dil
ja     1260 <process_go_command_write+0xc0>
add    $0xffffffd0,%edx
test   %edx,%edx
jns    1298 <process_go_command_write+0xf8>
jmp    13c6 <process_go_command_write+0x226>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    -0x61(%rsi),%edi
cmp    $0x5,%dil
ja     1280 <process_go_command_write+0xe0>
add    $0xffffffa9,%edx
test   %edx,%edx
jns    1298 <process_go_command_write+0xf8>
jmp    13c6 <process_go_command_write+0x226>
cs nopw 0x0(%rax,%rax,1)
nop
lea    -0x41(%rsi),%edi
cmp    $0x5,%dil
ja     13c6 <process_go_command_write+0x226>
add    $0xffffffc9,%edx
test   %edx,%edx
js     13c6 <process_go_command_write+0x226>
mov    %dl,(%r14,%rcx,1)
movzbl 0x1(%rbp,%rcx,2),%esi
movsbl %sil,%edi
lea    -0x30(%rdi),%ebx
cmp    $0xa,%bl
jae    12c0 <process_go_command_write+0x120>
add    $0xffffffd0,%edi
jmp    12df <process_go_command_write+0x13f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    -0x61(%rsi),%ebx
cmp    $0x6,%bl
jae    12d0 <process_go_command_write+0x130>
add    $0xffffffa9,%edi
jmp    12df <process_go_command_write+0x13f>
nopl   (%rax)
lea    -0x41(%rsi),%ebx
cmp    $0x6,%bl
jae    13c6 <process_go_command_write+0x226>
add    $0xffffffc9,%edi
test   %edi,%edi
js     13c6 <process_go_command_write+0x226>
shl    $0x4,%edx
or     %edi,%edx
mov    %dl,(%r14,%rcx,1)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1230 <process_go_command_write+0x90>
xor    %edi,%edi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   1050 <crc32@plt>
xor    %edi,%edi
mov    $0x4,%esi
mov    %eax,%edx
call   1050 <crc32@plt>
mov    %rax,%rbx
cmp    $0x1,%r15d
mov    %r15d,0x8(%rsp)
jle    13e4 <process_go_command_write+0x244>
mov    %r13d,%r12d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%r14,%rbp,1),%edi
mov    $0x8,%esi
mov    %ebx,%edx
call   1050 <crc32@plt>
mov    %rax,%rbx
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1340 <process_go_command_write+0x1a0>
xor    %edi,%edi
mov    $0x4,%esi
call   1070 <reverse_bits@plt>
mov    %rax,%r15
cmpl   $0x2,0x8(%rsp)
jl     13f3 <process_go_command_write+0x253>
xor    %ebp,%ebp
nopl   0x0(%rax)
movzbl (%r14,%rbp,1),%edi
mov    $0x8,%esi
call   1070 <reverse_bits@plt>
mov    %al,(%r14,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1380 <process_go_command_write+0x1e0>
jmp    13f3 <process_go_command_write+0x253>
lea    0xdc8(%rip),%rdi
jmp    13ae <process_go_command_write+0x20e>
lea    0xd86(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movsbl %sil,%esi
lea    0xc2f(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1090 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
jmp    13b5 <process_go_command_write+0x215>
xor    %edi,%edi
mov    $0x4,%esi
call   1070 <reverse_bits@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    $0x20,%esi
call   1070 <reverse_bits@plt>
mov    %rax,%r12
mov    %r13,%rbp
lea    0xa(%r13),%ebx
mov    %ebx,%edi
call   10b0 <malloc@plt>
test   %rax,%rax
je     144b <process_go_command_write+0x2ab>
mov    %rax,%r13
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebx,0x14(%rsp)
mov    %ebx,%edx
call   10a0 <memset@plt>
add    %r15b,%r15b
mov    %r15b,0x0(%r13)
mov    0x8(%rsp),%eax
cmp    $0x2,%eax
jl     14ce <process_go_command_write+0x32e>
mov    %ebp,%esi
and    $0xfffffffe,%eax
cmp    $0x2,%eax
jne    1464 <process_go_command_write+0x2c4>
xor    %ecx,%ecx
jmp    14af <process_go_command_write+0x30f>
lea    0xc7e(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1030 <free@plt>
jmp    13b3 <process_go_command_write+0x213>
mov    %esi,%edx
and    $0xfffffffe,%edx
xor    %ecx,%ecx
nopl   0x0(%rax,%rax,1)
movzbl (%r14,%rcx,1),%eax
mov    %eax,%ebx
shl    $0x5,%bl
or     %r15b,%bl
mov    %bl,0x0(%r13,%rcx,1)
shr    $0x3,%al
mov    %al,0x1(%r13,%rcx,1)
movzbl 0x1(%r14,%rcx,1),%r15d
mov    %r15d,%ebx
shl    $0x5,%bl
or     %al,%bl
mov    %bl,0x1(%r13,%rcx,1)
shr    $0x3,%r15b
mov    %r15b,0x2(%r13,%rcx,1)
add    $0x2,%rcx
cmp    %rcx,%rdx
jne    1470 <process_go_command_write+0x2d0>
test   $0x1,%sil
je     14ce <process_go_command_write+0x32e>
mov    (%r14,%rcx,1),%al
mov    %eax,%edx
shl    $0x5,%dl
or     %r15b,%dl
mov    %dl,0x0(%r13,%rcx,1)
shr    $0x3,%al
mov    %al,0x1(%r13,%rcx,1)
movslq %ebp,%rbx
mov    %r12d,%eax
shl    $0x5,%al
or     %al,0x0(%r13,%rbx,1)
mov    %r12,%rax
shr    $0x3,%rax
mov    %al,0x1(%r13,%rbx,1)
mov    %r12,%rax
shr    $0xb,%rax
mov    %al,0x2(%r13,%rbx,1)
mov    %r12,%rax
shr    $0x13,%rax
mov    %al,0x3(%r13,%rbx,1)
shr    $0x1b,%r12
mov    %r12b,0x4(%r13,%rbx,1)
lea    0xb12(%rip),%rdi
mov    %r13,%rsi
mov    0x14(%rsp),%r15d
mov    %r15d,%edx
call   1060 <dump_jreg@plt>
lea    0x49(,%rbp,8),%esi
mov    %r13,%rdi
call   10c0 <or1ksim_jtag_shift_dr@plt>
movsd  %xmm0,0x8(%rsp)
lea    0xaf4(%rip),%rdi
mov    %r13,%rsi
mov    %r15d,%edx
call   1060 <dump_jreg@plt>
movzbl 0x4(%r13,%rbx,1),%eax
shr    $0x5,%rax
movzbl 0x5(%r13,%rbx,1),%ecx
mov    %ecx,%edx
and    $0x1,%edx
lea    (%rax,%rdx,8),%rdi
shr    %rcx
movzbl 0x6(%r13,%rbx,1),%eax
shl    $0x7,%rax
or     %rcx,%rax
movzbl 0x7(%r13,%rbx,1),%ecx
shl    $0xf,%rcx
or     %rax,%rcx
movzbl 0x8(%r13,%rbx,1),%eax
shl    $0x17,%rax
or     %rcx,%rax
movzbl 0x9(%r13,%rbx,1),%ebx
shl    $0x1f,%rbx
or     %rax,%rbx
mov    $0x4,%esi
call   1070 <reverse_bits@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    $0x20,%esi
call   1070 <reverse_bits@plt>
mov    %rax,%r15
movzbl %bpl,%ebx
mov    %ebx,%edi
mov    $0x4,%esi
mov    $0xffffffff,%edx
call   1050 <crc32@plt>
mov    %rax,%rbp
lea    0xa6b(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1090 <printf@plt>
cmp    %r15,%rbp
je     160f <process_go_command_write+0x46f>
lea    0xad9(%rip),%rdi
call   1040 <puts@plt>
lea    0xa62(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0xa6c(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0xa76(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1090 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    $0x1,%ebx
jmp    13b5 <process_go_command_write+0x215>

LLVM IR (-O0):
@.str = [30 x i8] c"Processing GO_COMMAND_WRITE.\0A\00"
@.str.1 = [50 x i8] c"GO_COMMAND_WRITE usage: GO_COMMAND_WRITE <data>.\0A\00"
@.str.2 = [58 x i8] c"ERROR: data malloc for GO_COMMAND_WRITE register failed.\0A\00"
@.str.3 = [44 x i8] c"Warning: GO_COMMAND_WRITE odd char ignored\0A\00"
@.str.4 = [34 x i8] c"ERROR: Non-hex digit in data: %c\0A\00"
@.str.5 = [58 x i8] c"ERROR: jreg malloc for GO_COMMAND_WRITE register failed.\0A\00"
@.str.6 = [14 x i8] c" shifting in\00"
@.str.7 = [14 x i8] c" shifted out\00"
@.str.8 = [24 x i8] c" status: 0x%01x\0A\00"
@.str.9 = [16 x i8] c" CRC mismatch\0A\00"
@.str.10 = [27 x i8] c" CRC out: 0x%08lx\0A\00"
@.str.11 = [27 x i8] c" CRC computed: 0x%08lx\0A\00"
@.str.12 = [24 x i8] c" time taken: %.12fs\0A\00"
define i32 @process_go_command_write(i32 %0, i32 %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i8
%18 = alloca i32
%19 = alloca i64
%20 = alloca i32
%21 = alloca i8*
%22 = alloca double
%23 = alloca i8
%24 = alloca i64
%25 = alloca i64
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%27 = load i32, i32* %5
%28 = load i32, i32* %6
%29 = icmp sge i32 %27, %28
br i1 %29, label %30, label %32
30: ; preds = %3
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %4
br label %412
32: ; preds = %3
store i64 0, i64* %8
%33 = load i8**, i8*** %7
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
store i8* %37, i8** %9
%38 = load i8*, i8** %9
%39 = call i32 @strlen(i8* %38)
store i32 %39, i32* %10
%40 = load i32, i32* %10
%41 = sdiv i32 %40, 2
store i32 %41, i32* %11
%42 = load i32, i32* %11
%43 = call i8* @malloc(i32 %42)
store i8* %43, i8** %12
%44 = load i8*, i8** %12
%45 = icmp eq i8* null, %44
br i1 %45, label %46, label %48
46: ; preds = %32
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %4
br label %412
48: ; preds = %32
%49 = load i32, i32* %10
%50 = srem i32 %49, 2
%51 = icmp eq i32 1, %50
br i1 %51, label %52, label %54
52: ; preds = %48
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
br label %54
54: ; preds = %52, %48
store i32 0, i32* %13
br label %55
55: ; preds = %151, %54
%56 = load i32, i32* %13
%57 = load i32, i32* %11
%58 = icmp slt i32 %56, %57
br i1 %58, label %59, label %154
59: ; preds = %55
%60 = load i32, i32* %13
%61 = mul nsw i32 %60, 2
store i32 %61, i32* %14
%62 = load i32, i32* %13
%63 = mul nsw i32 %62, 2
%64 = add nsw i32 %63, 1
store i32 %64, i32* %15
%65 = load i8*, i8** %12
%66 = load i32, i32* %13
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %65, i64 %67
store i8 0, i8* %68
%69 = load i32, i32* %14
store i32 %69, i32* %16
br label %70
70: ; preds = %147, %59
%71 = load i32, i32* %16
%72 = load i32, i32* %15
%73 = icmp sle i32 %71, %72
br i1 %73, label %74, label %150
74: ; preds = %70
%75 = load i8*, i8** %9
%76 = load i32, i32* %16
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8, i8* %75, i64 %77
%79 = load i8, i8* %78
store i8 %79, i8* %17
%80 = load i8, i8* %17
%81 = sext i8 %80 to i32
%82 = icmp sle i32 48, %81
br i1 %82, label %83, label %91
83: ; preds = %74
%84 = load i8, i8* %17
%85 = sext i8 %84 to i32
%86 = icmp sle i32 %85, 57
br i1 %86, label %87, label %91
87: ; preds = %83
%88 = load i8, i8* %17
%89 = sext i8 %88 to i32
%90 = sub nsw i32 %89, 48
br label %122
91: ; preds = %83, %74
%92 = load i8, i8* %17
%93 = sext i8 %92 to i32
%94 = icmp sle i32 97, %93
br i1 %94, label %95, label %104
95: ; preds = %91
%96 = load i8, i8* %17
%97 = sext i8 %96 to i32
%98 = icmp sle i32 %97, 102
br i1 %98, label %99, label %104
99: ; preds = %95
%100 = load i8, i8* %17
%101 = sext i8 %100 to i32
%102 = sub nsw i32 %101, 97
%103 = add nsw i32 %102, 10
br label %120
104: ; preds = %95, %91
%105 = load i8, i8* %17
%106 = sext i8 %105 to i32
%107 = icmp sle i32 65, %106
br i1 %107, label %108, label %117
108: ; preds = %104
%109 = load i8, i8* %17
%110 = sext i8 %109 to i32
%111 = icmp sle i32 %110, 70
br i1 %111, label %112, label %117
112: ; preds = %108
%113 = load i8, i8* %17
%114 = sext i8 %113 to i32
%115 = sub nsw i32 %114, 65
%116 = add nsw i32 %115, 10
br label %118
117: ; preds = %108, %104
br label %118
118: ; preds = %117, %112
%119 = phi i32 [ %116, %112 ], [ -1, %117 ]
br label %120
120: ; preds = %118, %99
%121 = phi i32 [ %103, %99 ], [ %119, %118 ]
br label %122
122: ; preds = %120, %87
%123 = phi i32 [ %90, %87 ], [ %121, %120 ]
store i32 %123, i32* %18
%124 = load i32, i32* %18
%125 = icmp slt i32 %124, 0
br i1 %125, label %126, label %132
126: ; preds = %122
%127 = load i8, i8* %17
%128 = sext i8 %127 to i32
%129 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %128)
%130 = load i8*, i8** %12
%131 = call i32 @free(i8* %130)
store i32 0, i32* %4
br label %412
132: ; preds = %122
%133 = load i8*, i8** %12
%134 = load i32, i32* %13
%135 = sext i32 %134 to i64
%136 = getelementptr inbounds i8, i8* %133, i64 %135
%137 = load i8, i8* %136
%138 = zext i8 %137 to i32
%139 = shl i32 %138, 4
%140 = load i32, i32* %18
%141 = or i32 %139, %140
%142 = trunc i32 %141 to i8
%143 = load i8*, i8** %12
%144 = load i32, i32* %13
%145 = sext i32 %144 to i64
%146 = getelementptr inbounds i8, i8* %143, i64 %145
store i8 %142, i8* %146
br label %147
147: ; preds = %132
%148 = load i32, i32* %16
%149 = add nsw i32 %148, 1
store i32 %149, i32* %16
br label %70
150: ; preds = %70
br label %151
151: ; preds = %150
%152 = load i32, i32* %13
%153 = add nsw i32 %152, 1
store i32 %153, i32* %13
br label %55
154: ; preds = %55
%155 = call i64 @crc32(i8 zeroext 0, i32 1, i32 -1)
store i64 %155, i64* %19
%156 = load i64, i64* %8
%157 = trunc i64 %156 to i8
%158 = load i64, i64* %19
%159 = trunc i64 %158 to i32
%160 = call i64 @crc32(i8 zeroext %157, i32 4, i32 %159)
store i64 %160, i64* %19
store i32 0, i32* %13
br label %161
161: ; preds = %174, %154
%162 = load i32, i32* %13
%163 = load i32, i32* %11
%164 = icmp slt i32 %162, %163
br i1 %164, label %165, label %177
165: ; preds = %161
%166 = load i8*, i8** %12
%167 = load i32, i32* %13
%168 = sext i32 %167 to i64
%169 = getelementptr inbounds i8, i8* %166, i64 %168
%170 = load i8, i8* %169
%171 = load i64, i64* %19
%172 = trunc i64 %171 to i32
%173 = call i64 @crc32(i8 zeroext %170, i32 8, i32 %172)
store i64 %173, i64* %19
br label %174
174: ; preds = %165
%175 = load i32, i32* %13
%176 = add nsw i32 %175, 1
store i32 %176, i32* %13
br label %161
177: ; preds = %161
%178 = load i64, i64* %8
%179 = call i8* @reverse_bits(i64 %178, i32 4)
%180 = ptrtoint i8* %179 to i64
store i64 %180, i64* %8
store i32 0, i32* %13
br label %181
181: ; preds = %198, %177
%182 = load i32, i32* %13
%183 = load i32, i32* %11
%184 = icmp slt i32 %182, %183
br i1 %184, label %185, label %201
185: ; preds = %181
%186 = load i8*, i8** %12
%187 = load i32, i32* %13
%188 = sext i32 %187 to i64
%189 = getelementptr inbounds i8, i8* %186, i64 %188
%190 = load i8, i8* %189
%191 = zext i8 %190 to i64
%192 = call i8* @reverse_bits(i64 %191, i32 8)
%193 = ptrtoint i8* %192 to i8
%194 = load i8*, i8** %12
%195 = load i32, i32* %13
%196 = sext i32 %195 to i64
%197 = getelementptr inbounds i8, i8* %194, i64 %196
store i8 %193, i8* %197
br label %198
198: ; preds = %185
%199 = load i32, i32* %13
%200 = add nsw i32 %199, 1
store i32 %200, i32* %13
br label %181
201: ; preds = %181
%202 = load i64, i64* %19
%203 = call i8* @reverse_bits(i64 %202, i32 32)
%204 = ptrtoint i8* %203 to i64
store i64 %204, i64* %19
%205 = load i32, i32* %11
%206 = add nsw i32 10, %205
store i32 %206, i32* %20
%207 = load i32, i32* %20
%208 = call i8* @malloc(i32 %207)
store i8* %208, i8** %21
%209 = load i8*, i8** %21
%210 = icmp eq i8* null, %209
br i1 %210, label %211, label %215
211: ; preds = %201
%212 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.5, i64 0, i64 0))
%213 = load i8*, i8** %12
%214 = call i32 @free(i8* %213)
store i32 0, i32* %4
br label %412
215: ; preds = %201
%216 = load i8*, i8** %21
%217 = load i32, i32* %20
%218 = call i32 @memset(i8* %216, i32 0, i32 %217)
%219 = load i8*, i8** %21
%220 = getelementptr inbounds i8, i8* %219, i64 0
store i8 0, i8* %220
%221 = load i64, i64* %8
%222 = shl i64 %221, 1
%223 = load i8*, i8** %21
%224 = getelementptr inbounds i8, i8* %223, i64 0
%225 = load i8, i8* %224
%226 = zext i8 %225 to i64
%227 = or i64 %226, %222
%228 = trunc i64 %227 to i8
store i8 %228, i8* %224
store i32 0, i32* %13
br label %229
229: ; preds = %262, %215
%230 = load i32, i32* %13
%231 = load i32, i32* %11
%232 = icmp slt i32 %230, %231
br i1 %232, label %233, label %265
233: ; preds = %229
%234 = load i8*, i8** %12
%235 = load i32, i32* %13
%236 = sext i32 %235 to i64
%237 = getelementptr inbounds i8, i8* %234, i64 %236
%238 = load i8, i8* %237
%239 = zext i8 %238 to i32
%240 = shl i32 %239, 5
%241 = load i8*, i8** %21
%242 = load i32, i32* %13
%243 = sext i32 %242 to i64
%244 = getelementptr inbounds i8, i8* %241, i64 %243
%245 = load i8, i8* %244
%246 = zext i8 %245 to i32
%247 = or i32 %246, %240
%248 = trunc i32 %247 to i8
store i8 %248, i8* %244
%249 = load i8*, i8** %12
%250 = load i32, i32* %13
%251 = sext i32 %250 to i64
%252 = getelementptr inbounds i8, i8* %249, i64 %251
%253 = load i8, i8* %252
%254 = zext i8 %253 to i32
%255 = ashr i32 %254, 3
%256 = trunc i32 %255 to i8
%257 = load i8*, i8** %21
%258 = load i32, i32* %13
%259 = add nsw i32 %258, 1
%260 = sext i32 %259 to i64
%261 = getelementptr inbounds i8, i8* %257, i64 %260
store i8 %256, i8* %261
br label %262
262: ; preds = %233
%263 = load i32, i32* %13
%264 = add nsw i32 %263, 1
store i32 %264, i32* %13
br label %229
265: ; preds = %229
%266 = load i64, i64* %19
%267 = shl i64 %266, 5
%268 = load i8*, i8** %21
%269 = load i32, i32* %11
%270 = sext i32 %269 to i64
%271 = getelementptr inbounds i8, i8* %268, i64 %270
%272 = load i8, i8* %271
%273 = zext i8 %272 to i64
%274 = or i64 %273, %267
%275 = trunc i64 %274 to i8
store i8 %275, i8* %271
%276 = load i64, i64* %19
%277 = lshr i64 %276, 3
%278 = trunc i64 %277 to i8
%279 = load i8*, i8** %21
%280 = load i32, i32* %11
%281 = add nsw i32 %280, 1
%282 = sext i32 %281 to i64
%283 = getelementptr inbounds i8, i8* %279, i64 %282
store i8 %278, i8* %283
%284 = load i64, i64* %19
%285 = lshr i64 %284, 11
%286 = trunc i64 %285 to i8
%287 = load i8*, i8** %21
%288 = load i32, i32* %11
%289 = add nsw i32 %288, 2
%290 = sext i32 %289 to i64
%291 = getelementptr inbounds i8, i8* %287, i64 %290
store i8 %286, i8* %291
%292 = load i64, i64* %19
%293 = lshr i64 %292, 19
%294 = trunc i64 %293 to i8
%295 = load i8*, i8** %21
%296 = load i32, i32* %11
%297 = add nsw i32 %296, 3
%298 = sext i32 %297 to i64
%299 = getelementptr inbounds i8, i8* %295, i64 %298
store i8 %294, i8* %299
%300 = load i64, i64* %19
%301 = lshr i64 %300, 27
%302 = trunc i64 %301 to i8
%303 = load i8*, i8** %21
%304 = load i32, i32* %11
%305 = add nsw i32 %304, 4
%306 = sext i32 %305 to i64
%307 = getelementptr inbounds i8, i8* %303, i64 %306
store i8 %302, i8* %307
%308 = load i8*, i8** %21
%309 = load i32, i32* %20
%310 = call i32 @dump_jreg(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* %308, i32 %309)
%311 = load i8*, i8** %21
%312 = load i32, i32* %11
%313 = mul nsw i32 %312, 8
%314 = add nsw i32 68, %313
%315 = add nsw i32 %314, 4
%316 = add nsw i32 %315, 1
%317 = call double @or1ksim_jtag_shift_dr(i8* %311, i32 %316)
store double %317, double* %22
%318 = load i8*, i8** %21
%319 = load i32, i32* %20
%320 = call i32 @dump_jreg(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* %318, i32 %319)
%321 = load i8*, i8** %21
%322 = load i32, i32* %11
%323 = add nsw i32 %322, 4
%324 = sext i32 %323 to i64
%325 = getelementptr inbounds i8, i8* %321, i64 %324
%326 = load i8, i8* %325
%327 = zext i8 %326 to i32
%328 = ashr i32 %327, 5
%329 = load i8*, i8** %21
%330 = load i32, i32* %11
%331 = add nsw i32 %330, 5
%332 = sext i32 %331 to i64
%333 = getelementptr inbounds i8, i8* %329, i64 %332
%334 = load i8, i8* %333
%335 = zext i8 %334 to i32
%336 = shl i32 %335, 3
%337 = or i32 %328, %336
%338 = and i32 %337, 15
%339 = trunc i32 %338 to i8
store i8 %339, i8* %23
%340 = load i8*, i8** %21
%341 = load i32, i32* %11
%342 = add nsw i32 %341, 5
%343 = sext i32 %342 to i64
%344 = getelementptr inbounds i8, i8* %340, i64 %343
%345 = load i8, i8* %344
%346 = zext i8 %345 to i64
%347 = lshr i64 %346, 1
%348 = load i8*, i8** %21
%349 = load i32, i32* %11
%350 = add nsw i32 %349, 6
%351 = sext i32 %350 to i64
%352 = getelementptr inbounds i8, i8* %348, i64 %351
%353 = load i8, i8* %352
%354 = zext i8 %353 to i64
%355 = shl i64 %354, 7
%356 = or i64 %347, %355
%357 = load i8*, i8** %21
%358 = load i32, i32* %11
%359 = add nsw i32 %358, 7
%360 = sext i32 %359 to i64
%361 = getelementptr inbounds i8, i8* %357, i64 %360
%362 = load i8, i8* %361
%363 = zext i8 %362 to i64
%364 = shl i64 %363, 15
%365 = or i64 %356, %364
%366 = load i8*, i8** %21
%367 = load i32, i32* %11
%368 = add nsw i32 %367, 8
%369 = sext i32 %368 to i64
%370 = getelementptr inbounds i8, i8* %366, i64 %369
%371 = load i8, i8* %370
%372 = zext i8 %371 to i64
%373 = shl i64 %372, 23
%374 = or i64 %365, %373
%375 = load i8*, i8** %21
%376 = load i32, i32* %11
%377 = add nsw i32 %376, 9
%378 = sext i32 %377 to i64
%379 = getelementptr inbounds i8, i8* %375, i64 %378
%380 = load i8, i8* %379
%381 = zext i8 %380 to i64
%382 = shl i64 %381, 31
%383 = or i64 %374, %382
store i64 %383, i64* %24
%384 = load i8, i8* %23
%385 = zext i8 %384 to i64
%386 = call i8* @reverse_bits(i64 %385, i32 4)
%387 = ptrtoint i8* %386 to i8
store i8 %387, i8* %23
%388 = load i64, i64* %24
%389 = call i8* @reverse_bits(i64 %388, i32 32)
%390 = ptrtoint i8* %389 to i64
store i64 %390, i64* %24
%391 = load i8, i8* %23
%392 = call i64 @crc32(i8 zeroext %391, i32 4, i32 -1)
store i64 %392, i64* %25
%393 = load i8, i8* %23
%394 = zext i8 %393 to i32
%395 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i32 %394)
%396 = load i64, i64* %24
%397 = load i64, i64* %25
%398 = icmp ne i64 %396, %397
br i1 %398, label %399, label %405
399: ; preds = %265
%400 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
%401 = load i64, i64* %24
%402 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i64 %401)
%403 = load i64, i64* %25
%404 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0), i64 %403)
br label %405
405: ; preds = %399, %265
%406 = load double, double* %22
%407 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.12, i64 0, i64 0), double %406)
%408 = load i8*, i8** %12
%409 = call i32 @free(i8* %408)
%410 = load i8*, i8** %21
%411 = call i32 @free(i8* %410)
store i32 1, i32* %4
br label %412
412: ; preds = %405, %211, %126, %46, %30
%413 = load i32, i32* %4
ret i32 %413
}

LLVM IR (-O2):
@.str.4 = [34 x i8] c"ERROR: Non-hex digit in data: %c\0A\00"
@.str.6 = [14 x i8] c" shifting in\00"
@.str.7 = [14 x i8] c" shifted out\00"
@.str.8 = [24 x i8] c" status: 0x%01x\0A\00"
@.str.10 = [27 x i8] c" CRC out: 0x%08lx\0A\00"
@.str.11 = [27 x i8] c" CRC computed: 0x%08lx\0A\00"
@.str.12 = [24 x i8] c" time taken: %.12fs\0A\00"
@str = [29 x i8] c"Processing GO_COMMAND_WRITE.\00"
@str.13 = [15 x i8] c" CRC mismatch\00"
@str.14 = [57 x i8] c"ERROR: jreg malloc for GO_COMMAND_WRITE register failed.\00"
@str.15 = [43 x i8] c"Warning: GO_COMMAND_WRITE odd char ignored\00"
@str.16 = [57 x i8] c"ERROR: data malloc for GO_COMMAND_WRITE register failed.\00"
@str.17 = [49 x i8] c"GO_COMMAND_WRITE usage: GO_COMMAND_WRITE <data>.\00"
define i32 @process_go_command_write(i32 %0, i32 %1, i8** nocapture %2) {
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%5 = icmp slt i32 %0, %1
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str.17, i64 0, i64 0))
br label %263
8: ; preds = %3
%9 = sext i32 %0 to i64
%10 = getelementptr inbounds i8*, i8** %2, i64 %9
%11 = load i8*, i8** %10
%12 = tail call i32 @strlen(i8* %11)
%13 = sdiv i32 %12, 2
%14 = srem i32 %12, 2
%15 = tail call i8* @malloc(i32 %13)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %8
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str.16, i64 0, i64 0))
br label %263
19: ; preds = %8
%20 = icmp eq i32 %14, 1
br i1 %20, label %21, label %23
21: ; preds = %19
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.15, i64 0, i64 0))
br label %23
23: ; preds = %21, %19
%24 = icmp sgt i32 %12, 1
br i1 %24, label %25, label %84
25: ; preds = %23
%26 = zext i32 %13 to i64
br label %27
27: ; preds = %25, %72
%28 = phi i64 [ 0, %25 ], [ %76, %72 ]
%29 = phi i64 [ 0, %25 ], [ %77, %72 ]
%30 = getelementptr inbounds i8, i8* %15, i64 %28
store i8 0, i8* %30
%31 = getelementptr inbounds i8, i8* %11, i64 %29
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = add i8 %32, -48
%35 = icmp ult i8 %34, 10
br i1 %35, label %36, label %38
36: ; preds = %27
%37 = add nsw i32 %33, -48
br label %47
38: ; preds = %27
%39 = add i8 %32, -97
%40 = icmp ult i8 %39, 6
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = add nsw i32 %33, -87
br label %47
43: ; preds = %38
%44 = add i8 %32, -65
%45 = icmp ult i8 %44, 6
%46 = add nsw i32 %33, -55
br i1 %45, label %47, label %79
47: ; preds = %43, %41, %36
%48 = phi i32 [ %37, %36 ], [ %42, %41 ], [ %46, %43 ]
%49 = icmp slt i32 %48, 0
br i1 %49, label %79, label %50
50: ; preds = %47
%51 = trunc i32 %48 to i8
store i8 %51, i8* %30
%52 = or i64 %29, 1
%53 = getelementptr inbounds i8, i8* %11, i64 %52
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = add i8 %54, -48
%57 = icmp ult i8 %56, 10
br i1 %57, label %67, label %58
58: ; preds = %50
%59 = add i8 %54, -97
%60 = icmp ult i8 %59, 6
br i1 %60, label %65, label %61
61: ; preds = %58
%62 = add i8 %54, -65
%63 = icmp ult i8 %62, 6
%64 = add nsw i32 %55, -55
br i1 %63, label %69, label %79
65: ; preds = %58
%66 = add nsw i32 %55, -87
br label %69
67: ; preds = %50
%68 = add nsw i32 %55, -48
br label %69
69: ; preds = %67, %65, %61
%70 = phi i32 [ %68, %67 ], [ %66, %65 ], [ %64, %61 ]
%71 = icmp slt i32 %70, 0
br i1 %71, label %79, label %72
72: ; preds = %69
%73 = shl nuw nsw i32 %48, 4
%74 = or i32 %73, %70
%75 = trunc i32 %74 to i8
store i8 %75, i8* %30
%76 = add nuw nsw i64 %28, 1
%77 = add nuw nsw i64 %29, 2
%78 = icmp eq i64 %76, %26
br i1 %78, label %84, label %27
79: ; preds = %47, %43, %61, %69
%80 = phi i8 [ %54, %69 ], [ %54, %61 ], [ %32, %43 ], [ %32, %47 ]
%81 = sext i8 %80 to i32
%82 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %81)
%83 = tail call i32 @free(i8* %15)
br label %263
84: ; preds = %72, %23
%85 = tail call i64 @crc32(i8 zeroext 0, i32 1, i32 -1)
%86 = trunc i64 %85 to i32
%87 = tail call i64 @crc32(i8 zeroext 0, i32 4, i32 %86)
br i1 %24, label %90, label %88
88: ; preds = %84
%89 = tail call i8* @reverse_bits(i64 0, i32 4)
br label %115
90: ; preds = %84
%91 = zext i32 %13 to i64
br label %92
92: ; preds = %90, %92
%93 = phi i64 [ 0, %90 ], [ %99, %92 ]
%94 = phi i64 [ %87, %90 ], [ %98, %92 ]
%95 = getelementptr inbounds i8, i8* %15, i64 %93
%96 = load i8, i8* %95
%97 = trunc i64 %94 to i32
%98 = tail call i64 @crc32(i8 zeroext %96, i32 8, i32 %97)
%99 = add nuw nsw i64 %93, 1
%100 = icmp eq i64 %99, %91
br i1 %100, label %101, label %92
101: ; preds = %92
%102 = tail call i8* @reverse_bits(i64 0, i32 4)
br i1 %24, label %103, label %115
103: ; preds = %101
%104 = zext i32 %13 to i64
br label %105
105: ; preds = %103, %105
%106 = phi i64 [ 0, %103 ], [ %113, %105 ]
%107 = getelementptr inbounds i8, i8* %15, i64 %106
%108 = load i8, i8* %107
%109 = zext i8 %108 to i64
%110 = tail call i8* @reverse_bits(i64 %109, i32 8)
%111 = ptrtoint i8* %110 to i64
%112 = trunc i64 %111 to i8
store i8 %112, i8* %107
%113 = add nuw nsw i64 %106, 1
%114 = icmp eq i64 %113, %104
br i1 %114, label %115, label %105
115: ; preds = %105, %88, %101
%116 = phi i8* [ %89, %88 ], [ %102, %101 ], [ %102, %105 ]
%117 = phi i64 [ %87, %88 ], [ %98, %101 ], [ %98, %105 ]
%118 = tail call i8* @reverse_bits(i64 %117, i32 32)
%119 = ptrtoint i8* %118 to i64
%120 = add nsw i32 %13, 10
%121 = tail call i8* @malloc(i32 %120)
%122 = icmp eq i8* %121, null
br i1 %122, label %123, label %126
123: ; preds = %115
%124 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str.14, i64 0, i64 0))
%125 = tail call i32 @free(i8* %15)
br label %263
126: ; preds = %115
%127 = ptrtoint i8* %116 to i64
%128 = tail call i32 @memset(i8* %121, i32 0, i32 %120)
%129 = trunc i64 %127 to i8
%130 = shl i8 %129, 1
store i8 %130, i8* %121
br i1 %24, label %131, label %173
131: ; preds = %126
%132 = zext i32 %13 to i64
%133 = and i64 %132, 1
%134 = and i32 %12, -2
%135 = icmp eq i32 %134, 2
br i1 %135, label %160, label %136
136: ; preds = %131
%137 = and i64 %132, 4294967294
br label %138
138: ; preds = %138, %136
%139 = phi i8 [ %130, %136 ], [ %155, %138 ]
%140 = phi i64 [ 0, %136 ], [ %156, %138 ]
%141 = phi i64 [ 0, %136 ], [ %158, %138 ]
%142 = getelementptr inbounds i8, i8* %15, i64 %140
%143 = load i8, i8* %142
%144 = shl i8 %143, 5
%145 = getelementptr inbounds i8, i8* %121, i64 %140
%146 = or i8 %144, %139
store i8 %146, i8* %145
%147 = lshr i8 %143, 3
%148 = or i64 %140, 1
%149 = getelementptr inbounds i8, i8* %121, i64 %148
store i8 %147, i8* %149
%150 = getelementptr inbounds i8, i8* %15, i64 %148
%151 = load i8, i8* %150
%152 = shl i8 %151, 5
%153 = getelementptr inbounds i8, i8* %121, i64 %148
%154 = or i8 %152, %147
store i8 %154, i8* %153
%155 = lshr i8 %151, 3
%156 = add nuw nsw i64 %140, 2
%157 = getelementptr inbounds i8, i8* %121, i64 %156
store i8 %155, i8* %157
%158 = add i64 %141, 2
%159 = icmp eq i64 %158, %137
br i1 %159, label %160, label %138
160: ; preds = %138, %131
%161 = phi i8 [ %130, %131 ], [ %155, %138 ]
%162 = phi i64 [ 0, %131 ], [ %156, %138 ]
%163 = icmp eq i64 %133, 0
br i1 %163, label %173, label %164
164: ; preds = %160
%165 = getelementptr inbounds i8, i8* %15, i64 %162
%166 = load i8, i8* %165
%167 = shl i8 %166, 5
%168 = getelementptr inbounds i8, i8* %121, i64 %162
%169 = or i8 %167, %161
store i8 %169, i8* %168
%170 = lshr i8 %166, 3
%171 = add nuw nsw i64 %162, 1
%172 = getelementptr inbounds i8, i8* %121, i64 %171
store i8 %170, i8* %172
br label %173
173: ; preds = %164, %160, %126
%174 = sext i32 %13 to i64
%175 = getelementptr inbounds i8, i8* %121, i64 %174
%176 = load i8, i8* %175
%177 = trunc i64 %119 to i8
%178 = shl i8 %177, 5
%179 = or i8 %176, %178
store i8 %179, i8* %175
%180 = lshr i64 %119, 3
%181 = trunc i64 %180 to i8
%182 = add nsw i32 %13, 1
%183 = sext i32 %182 to i64
%184 = getelementptr inbounds i8, i8* %121, i64 %183
store i8 %181, i8* %184
%185 = lshr i64 %119, 11
%186 = trunc i64 %185 to i8
%187 = add nsw i32 %13, 2
%188 = sext i32 %187 to i64
%189 = getelementptr inbounds i8, i8* %121, i64 %188
store i8 %186, i8* %189
%190 = lshr i64 %119, 19
%191 = trunc i64 %190 to i8
%192 = add nsw i32 %13, 3
%193 = sext i32 %192 to i64
%194 = getelementptr inbounds i8, i8* %121, i64 %193
store i8 %191, i8* %194
%195 = lshr i64 %119, 27
%196 = trunc i64 %195 to i8
%197 = add nsw i32 %13, 4
%198 = sext i32 %197 to i64
%199 = getelementptr inbounds i8, i8* %121, i64 %198
store i8 %196, i8* %199
%200 = tail call i32 @dump_jreg(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* %121, i32 %120)
%201 = shl nsw i32 %13, 3
%202 = add nsw i32 %201, 73
%203 = tail call double @or1ksim_jtag_shift_dr(i8* %121, i32 %202)
%204 = tail call i32 @dump_jreg(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* %121, i32 %120)
%205 = load i8, i8* %199
%206 = lshr i8 %205, 5
%207 = add nsw i32 %13, 5
%208 = sext i32 %207 to i64
%209 = getelementptr inbounds i8, i8* %121, i64 %208
%210 = load i8, i8* %209
%211 = shl i8 %210, 3
%212 = and i8 %211, 8
%213 = or i8 %212, %206
%214 = lshr i8 %210, 1
%215 = zext i8 %214 to i64
%216 = add nsw i32 %13, 6
%217 = sext i32 %216 to i64
%218 = getelementptr inbounds i8, i8* %121, i64 %217
%219 = load i8, i8* %218
%220 = zext i8 %219 to i64
%221 = shl nuw nsw i64 %220, 7
%222 = or i64 %221, %215
%223 = add nsw i32 %13, 7
%224 = sext i32 %223 to i64
%225 = getelementptr inbounds i8, i8* %121, i64 %224
%226 = load i8, i8* %225
%227 = zext i8 %226 to i64
%228 = shl nuw nsw i64 %227, 15
%229 = or i64 %222, %228
%230 = add nsw i32 %13, 8
%231 = sext i32 %230 to i64
%232 = getelementptr inbounds i8, i8* %121, i64 %231
%233 = load i8, i8* %232
%234 = zext i8 %233 to i64
%235 = shl nuw nsw i64 %234, 23
%236 = or i64 %229, %235
%237 = add nsw i32 %13, 9
%238 = sext i32 %237 to i64
%239 = getelementptr inbounds i8, i8* %121, i64 %238
%240 = load i8, i8* %239
%241 = zext i8 %240 to i64
%242 = shl nuw nsw i64 %241, 31
%243 = or i64 %236, %242
%244 = zext i8 %213 to i64
%245 = tail call i8* @reverse_bits(i64 %244, i32 4)
%246 = ptrtoint i8* %245 to i64
%247 = trunc i64 %246 to i8
%248 = tail call i8* @reverse_bits(i64 %243, i32 32)
%249 = ptrtoint i8* %248 to i64
%250 = tail call i64 @crc32(i8 zeroext %247, i32 4, i32 -1)
%251 = trunc i64 %246 to i32
%252 = and i32 %251, 255
%253 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i32 %252)
%254 = icmp eq i64 %250, %249
br i1 %254, label %259, label %255
255: ; preds = %173
%256 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.13, i64 0, i64 0))
%257 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i64 %249)
%258 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0), i64 %250)
br label %259
259: ; preds = %255, %173
%260 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.12, i64 0, i64 0), double %203)
%261 = tail call i32 @free(i8* %15)
%262 = tail call i32 @free(i8* %121)
br label %263
263: ; preds = %79, %17, %123, %259, %6
%264 = phi i32 [ 0, %6 ], [ 0, %17 ], [ 0, %79 ], [ 0, %123 ], [ 1, %259 ]
ret i32 %264
}