#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);
unsigned long strtoul(char *, int /*<<< orphan*/ *, int);
int process_write_control(int next_jreg, int argc, char *argv[]) {
  printf("Processing WRITE_CONTROL.\n");
  if (next_jreg + 2 > argc) {
    printf("WRITE_CONTROL usage: WRITE_CONTROL <reset> <status>\n");
    return 0;
  }
  unsigned long int cmd = 4;
  unsigned long int reset = strtoul(argv[next_jreg], NULL, 16);
  unsigned long int stall = strtoul(argv[next_jreg + 1], NULL, 16);
  if (reset > 0x1) {
    printf("ERROR: invalid WRITE_CONTROL reset value 0x%lx.\n", reset);
    return 0;
  }
  if (stall > 0x1) {
    printf("ERROR: invalid WRITE_CONTROL stall value 0x%lx.\n", stall);
    return 0;
  }
  unsigned long long int creg = ((unsigned long long int)reset << 51) |
                                ((unsigned long long int)stall << 50);
  unsigned long int crc_in;
  crc_in = crc32(0, 1, 0xffffffff);
  crc_in = crc32(cmd, 4, crc_in);
  crc_in = crc32(creg, 52, crc_in);
  cmd = reverse_bits(cmd, 4);
  creg = reverse_bits(creg, 52);
  crc_in = reverse_bits(crc_in, 32);
  int num_bytes = 16;
  unsigned char *jreg = malloc(num_bytes);
  if (NULL == jreg) {
    printf("ERROR: malloc for WRITE_CONTROL register failed.\n");
    return 0;
  }
  memset(jreg, 0, num_bytes);
  jreg[0] = 0x0;
  jreg[0] |= cmd << 1;
  jreg[0] |= creg << 5;
  jreg[1] = creg >> 3;
  jreg[2] = creg >> 11;
  jreg[3] = creg >> 19;
  jreg[4] = creg >> 27;
  jreg[5] = creg >> 35;
  jreg[6] = creg >> 43;
  jreg[7] = creg >> 51;
  jreg[7] |= crc_in << 1;
  jreg[8] = crc_in >> 7;
  jreg[9] = crc_in >> 15;
  jreg[10] = crc_in >> 23;
  jreg[11] = crc_in >> 31;
  dump_jreg("  shifting in", jreg, num_bytes);
  double t = or1ksim_jtag_shift_dr(jreg, 32 + 4 + 32 + 52 + 4 + 1);
  dump_jreg("  shifted out", jreg, num_bytes);
  unsigned char status;
  unsigned long int crc_out;
  status = (jreg[11] >> 1) & 0xf;
  crc_out =
      ((unsigned long int)jreg[11] >> 5) | ((unsigned long int)jreg[12] << 3) |
      ((unsigned long int)jreg[13] << 11) |
      ((unsigned long int)jreg[14] << 19) | ((unsigned long int)jreg[15] << 27);
  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(jreg);
  return 1;
}


x86 assembly (clang, -O0):
<process_write_control>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x2,%eax
cmp    -0xc(%rbp),%eax
jle    11d9 <process_write_control+0x49>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    159a <process_write_control+0x40a>
movq   $0x4,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   10b0 <strtoul@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   10b0 <strtoul@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x1,-0x28(%rbp)
jbe    124b <process_write_control+0xbb>
mov    -0x28(%rbp),%rsi
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    159a <process_write_control+0x40a>
cmpq   $0x1,-0x30(%rbp)
jbe    1274 <process_write_control+0xe4>
mov    -0x30(%rbp),%rsi
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    159a <process_write_control+0x40a>
mov    -0x28(%rbp),%rax
shl    $0x33,%rax
mov    -0x30(%rbp),%rcx
shl    $0x32,%rcx
or     %rcx,%rax
mov    %rax,-0x38(%rbp)
xor    %edi,%edi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   1040 <crc32@plt>
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    %ecx,%edx
mov    $0x4,%esi
movzbl %al,%edi
call   1040 <crc32@plt>
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    %ecx,%edx
mov    $0x34,%esi
movzbl %al,%edi
call   1040 <crc32@plt>
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x4,%esi
call   1060 <reverse_bits@plt>
mov    %rax,-0x20(%rbp)
mov    -0x38(%rbp),%rdi
mov    $0x34,%esi
call   1060 <reverse_bits@plt>
mov    %rax,-0x38(%rbp)
mov    -0x40(%rbp),%rdi
mov    $0x20,%esi
call   1060 <reverse_bits@plt>
mov    %rax,-0x40(%rbp)
movl   $0x10,-0x44(%rbp)
mov    -0x44(%rbp),%edi
call   1090 <malloc@plt>
mov    %rax,-0x50(%rbp)
xor    %eax,%eax
cmp    -0x50(%rbp),%rax
jne    1345 <process_write_control+0x1b5>
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    159a <process_write_control+0x40a>
mov    -0x50(%rbp),%rdi
mov    -0x44(%rbp),%edx
xor    %esi,%esi
call   1080 <memset@plt>
mov    -0x50(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdx
shl    $0x1,%rdx
mov    -0x50(%rbp),%rax
movzbl (%rax),%ecx
or     %rdx,%rcx
mov    %cl,(%rax)
mov    -0x38(%rbp),%rdx
shl    $0x5,%rdx
mov    -0x50(%rbp),%rax
movzbl (%rax),%ecx
or     %rdx,%rcx
mov    %cl,(%rax)
mov    -0x38(%rbp),%rax
shr    $0x3,%rax
mov    %al,%cl
mov    -0x50(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x38(%rbp),%rax
shr    $0xb,%rax
mov    %al,%cl
mov    -0x50(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x38(%rbp),%rax
shr    $0x13,%rax
mov    %al,%cl
mov    -0x50(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x38(%rbp),%rax
shr    $0x1b,%rax
mov    %al,%cl
mov    -0x50(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0x38(%rbp),%rax
shr    $0x23,%rax
mov    %al,%cl
mov    -0x50(%rbp),%rax
mov    %cl,0x5(%rax)
mov    -0x38(%rbp),%rax
shr    $0x2b,%rax
mov    %al,%cl
mov    -0x50(%rbp),%rax
mov    %cl,0x6(%rax)
mov    -0x38(%rbp),%rax
shr    $0x33,%rax
mov    %al,%cl
mov    -0x50(%rbp),%rax
mov    %cl,0x7(%rax)
mov    -0x40(%rbp),%rdx
shl    $0x1,%rdx
mov    -0x50(%rbp),%rax
movzbl 0x7(%rax),%ecx
or     %rdx,%rcx
mov    %cl,0x7(%rax)
mov    -0x40(%rbp),%rax
shr    $0x7,%rax
mov    %al,%cl
mov    -0x50(%rbp),%rax
mov    %cl,0x8(%rax)
mov    -0x40(%rbp),%rax
shr    $0xf,%rax
mov    %al,%cl
mov    -0x50(%rbp),%rax
mov    %cl,0x9(%rax)
mov    -0x40(%rbp),%rax
shr    $0x17,%rax
mov    %al,%cl
mov    -0x50(%rbp),%rax
mov    %cl,0xa(%rax)
mov    -0x40(%rbp),%rax
shr    $0x1f,%rax
mov    %al,%cl
mov    -0x50(%rbp),%rax
mov    %cl,0xb(%rax)
mov    -0x50(%rbp),%rsi
mov    -0x44(%rbp),%edx
lea    0xc83(%rip),%rdi
call   1050 <dump_jreg@plt>
mov    -0x50(%rbp),%rdi
mov    $0x7d,%esi
call   10a0 <or1ksim_jtag_shift_dr@plt>
movsd  %xmm0,-0x58(%rbp)
mov    -0x50(%rbp),%rsi
mov    -0x44(%rbp),%edx
lea    0xc6b(%rip),%rdi
call   1050 <dump_jreg@plt>
mov    -0x50(%rbp),%rax
movzbl 0xb(%rax),%eax
sar    $0x1,%eax
and    $0xf,%eax
mov    %al,-0x59(%rbp)
mov    -0x50(%rbp),%rax
movzbl 0xb(%rax),%eax
shr    $0x5,%rax
mov    -0x50(%rbp),%rcx
movzbl 0xc(%rcx),%ecx
shl    $0x3,%rcx
or     %rcx,%rax
mov    -0x50(%rbp),%rcx
movzbl 0xd(%rcx),%ecx
shl    $0xb,%rcx
or     %rcx,%rax
mov    -0x50(%rbp),%rcx
movzbl 0xe(%rcx),%ecx
shl    $0x13,%rcx
or     %rcx,%rax
mov    -0x50(%rbp),%rcx
movzbl 0xf(%rcx),%ecx
shl    $0x1b,%rcx
or     %rcx,%rax
mov    %rax,-0x68(%rbp)
movzbl -0x59(%rbp),%eax
mov    %eax,%edi
mov    $0x4,%esi
call   1060 <reverse_bits@plt>
mov    %al,-0x59(%rbp)
mov    -0x68(%rbp),%rdi
mov    $0x20,%esi
call   1060 <reverse_bits@plt>
mov    %rax,-0x68(%rbp)
mov    $0x4,%esi
mov    $0xffffffff,%edx
movzbl -0x59(%rbp),%edi
call   1040 <crc32@plt>
mov    %rax,-0x70(%rbp)
movzbl -0x59(%rbp),%esi
lea    0xbd0(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x68(%rbp),%rax
cmp    -0x70(%rbp),%rax
je     1577 <process_write_control+0x3e7>
lea    0xbcc(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x68(%rbp),%rsi
lea    0xbca(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x70(%rbp),%rsi
lea    0xbd3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movsd  -0x58(%rbp),%xmm0
lea    0xbdb(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_write_control>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%ebx
mov    %edi,%ebp
lea    0xf2b(%rip),%rdi
call   1040 <puts@plt>
lea    0x2(%rbp),%eax
cmp    %ebx,%eax
jle    11d6 <process_write_control+0x36>
lea    0xf72(%rip),%rdi
call   1040 <puts@plt>
xor    %r13d,%r13d
jmp    122f <process_write_control+0x8f>
movslq %ebp,%rbx
mov    (%r14,%rbx,8),%rdi
xor    %r13d,%r13d
xor    %esi,%esi
mov    $0x10,%edx
call   10c0 <strtoul@plt>
mov    %rax,%rbp
mov    0x8(%r14,%rbx,8),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   10c0 <strtoul@plt>
cmp    $0x2,%rbp
jb     1212 <process_write_control+0x72>
lea    0xdf3(%rip),%rdi
mov    %rbp,%rsi
jmp    1228 <process_write_control+0x88>
mov    %rax,%rbx
cmp    $0x2,%rax
jb     1241 <process_write_control+0xa1>
lea    0xe0f(%rip),%rdi
xor    %r13d,%r13d
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
shl    $0x33,%rbp
shl    $0x32,%rbx
or     %rbp,%rbx
xor    %r13d,%r13d
xor    %edi,%edi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   1050 <crc32@plt>
mov    $0x4,%edi
mov    $0x4,%esi
mov    %eax,%edx
call   1050 <crc32@plt>
xor    %edi,%edi
mov    $0x34,%esi
mov    %eax,%edx
call   1050 <crc32@plt>
mov    %rax,%rbp
mov    $0x4,%edi
mov    $0x4,%esi
call   1070 <reverse_bits@plt>
mov    %rax,(%rsp)
mov    %rbx,%rdi
mov    $0x34,%esi
call   1070 <reverse_bits@plt>
mov    %rax,%r12
mov    %rbp,%rdi
mov    $0x20,%esi
call   1070 <reverse_bits@plt>
mov    %rax,%r15
mov    $0x10,%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     147c <process_write_control+0x2dc>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1090 <memset@plt>
mov    (%rsp),%rcx
add    %ecx,%ecx
mov    %r12d,%eax
shl    $0x5,%eax
or     %ecx,%eax
mov    %al,(%r14)
mov    %r12,%rax
shr    $0x3,%rax
mov    %al,0x1(%r14)
mov    %r12,%rax
shr    $0xb,%rax
mov    %al,0x2(%r14)
mov    %r12,%rax
shr    $0x13,%rax
mov    %al,0x3(%r14)
mov    %r12,%rax
shr    $0x1b,%rax
mov    %al,0x4(%r14)
mov    %r12,%rax
shr    $0x23,%rax
mov    %al,0x5(%r14)
mov    %r12,%rax
shr    $0x2b,%rax
mov    %al,0x6(%r14)
shr    $0x33,%r12
lea    (%r15,%r15,1),%eax
or     %eax,%r12d
mov    %r12b,0x7(%r14)
mov    %r15,%rax
shr    $0x7,%rax
mov    %al,0x8(%r14)
mov    %r15,%rax
shr    $0xf,%rax
mov    %al,0x9(%r14)
mov    %r15,%rax
shr    $0x17,%rax
mov    %al,0xa(%r14)
shr    $0x1f,%r15
mov    %r15b,0xb(%r14)
lea    0xcf6(%rip),%rdi
mov    %r14,%rsi
mov    $0x10,%edx
call   1060 <dump_jreg@plt>
mov    %r14,%rdi
mov    $0x7d,%esi
call   10b0 <or1ksim_jtag_shift_dr@plt>
movsd  %xmm0,(%rsp)
lea    0xcde(%rip),%rdi
mov    %r14,%rsi
mov    $0x10,%edx
call   1060 <dump_jreg@plt>
movzbl 0xb(%r14),%edi
movzbl %dil,%eax
shr    %edi
and    $0xf,%edi
shr    $0x5,%rax
movzbl 0xc(%r14),%ecx
lea    (%rax,%rcx,8),%rax
movzbl 0xd(%r14),%ecx
shl    $0xb,%rcx
or     %rax,%rcx
movzbl 0xe(%r14),%eax
shl    $0x13,%rax
or     %rcx,%rax
movzbl 0xf(%r14),%ebx
shl    $0x1b,%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    0xc64(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1080 <printf@plt>
cmp    %r15,%rbp
je     1456 <process_write_control+0x2b6>
lea    0xccf(%rip),%rdi
call   1040 <puts@plt>
lea    0xc5b(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xc65(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xc6f(%rip),%rdi
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1080 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0x1,%r13d
jmp    122f <process_write_control+0x8f>
lea    0xc8a(%rip),%rdi
call   1040 <puts@plt>
jmp    122f <process_write_control+0x8f>

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

LLVM IR (-O2):
@.str.2 = [49 x i8] c"ERROR: invalid WRITE_CONTROL reset value 0x%lx.\0A\00"
@.str.3 = [49 x i8] c"ERROR: invalid WRITE_CONTROL stall value 0x%lx.\0A\00"
@.str.5 = [14 x i8] c" shifting in\00"
@.str.6 = [14 x i8] c" shifted out\00"
@.str.7 = [24 x i8] c" status: 0x%01x\0A\00"
@.str.9 = [27 x i8] c" CRC out: 0x%08lx\0A\00"
@.str.10 = [27 x i8] c" CRC computed: 0x%08lx\0A\00"
@.str.11 = [24 x i8] c" time taken: %.12fs\0A\00"
@str = [26 x i8] c"Processing WRITE_CONTROL.\00"
@str.12 = [15 x i8] c" CRC mismatch\00"
@str.13 = [49 x i8] c"ERROR: malloc for WRITE_CONTROL register failed.\00"
@str.14 = [52 x i8] c"WRITE_CONTROL usage: WRITE_CONTROL <reset> <status>\00"
define i32 @process_write_control(i32 %0, i32 %1, i8** nocapture %2) {
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%5 = add nsw i32 %0, 2
%6 = icmp sgt i32 %5, %1
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.14, i64 0, i64 0))
br label %132
9: ; preds = %3
%10 = sext i32 %0 to i64
%11 = getelementptr inbounds i8*, i8** %2, i64 %10
%12 = load i8*, i8** %11
%13 = tail call i64 @strtoul(i8* nocapture %12, i32* null, i32 16)
%14 = add nsw i32 %0, 1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8*, i8** %2, i64 %15
%17 = load i8*, i8** %16
%18 = tail call i64 @strtoul(i8* nocapture %17, i32* null, i32 16)
%19 = icmp ugt i64 %13, 1
br i1 %19, label %20, label %22
20: ; preds = %9
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i64 %13)
br label %132
22: ; preds = %9
%23 = icmp ugt i64 %18, 1
br i1 %23, label %24, label %26
24: ; preds = %22
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i64 %18)
br label %132
26: ; preds = %22
%27 = shl nuw nsw i64 %13, 51
%28 = shl nuw nsw i64 %18, 50
%29 = or i64 %28, %27
%30 = tail call i64 @crc32(i8 zeroext 0, i32 1, i32 -1)
%31 = trunc i64 %30 to i32
%32 = tail call i64 @crc32(i8 zeroext 4, i32 4, i32 %31)
%33 = trunc i64 %32 to i32
%34 = tail call i64 @crc32(i8 zeroext 0, i32 52, i32 %33)
%35 = tail call i8* @reverse_bits(i64 4, i32 4)
%36 = tail call i8* @reverse_bits(i64 %29, i32 52)
%37 = ptrtoint i8* %36 to i64
%38 = tail call i8* @reverse_bits(i64 %34, i32 32)
%39 = ptrtoint i8* %38 to i64
%40 = tail call dereferenceable_or_null(16) i8* @malloc(i32 16)
%41 = icmp eq i8* %40, null
br i1 %41, label %42, label %44
42: ; preds = %26
%43 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str.13, i64 0, i64 0))
br label %132
44: ; preds = %26
%45 = ptrtoint i8* %35 to i64
%46 = tail call i32 @memset(i8* %40, i32 0, i32 16)
%47 = shl i64 %45, 1
%48 = shl i64 %37, 5
%49 = or i64 %48, %47
%50 = trunc i64 %49 to i8
store i8 %50, i8* %40
%51 = lshr i64 %37, 3
%52 = trunc i64 %51 to i8
%53 = getelementptr inbounds i8, i8* %40, i64 1
store i8 %52, i8* %53
%54 = lshr i64 %37, 11
%55 = trunc i64 %54 to i8
%56 = getelementptr inbounds i8, i8* %40, i64 2
store i8 %55, i8* %56
%57 = lshr i64 %37, 19
%58 = trunc i64 %57 to i8
%59 = getelementptr inbounds i8, i8* %40, i64 3
store i8 %58, i8* %59
%60 = lshr i64 %37, 27
%61 = trunc i64 %60 to i8
%62 = getelementptr inbounds i8, i8* %40, i64 4
store i8 %61, i8* %62
%63 = lshr i64 %37, 35
%64 = trunc i64 %63 to i8
%65 = getelementptr inbounds i8, i8* %40, i64 5
store i8 %64, i8* %65
%66 = lshr i64 %37, 43
%67 = trunc i64 %66 to i8
%68 = getelementptr inbounds i8, i8* %40, i64 6
store i8 %67, i8* %68
%69 = lshr i64 %37, 51
%70 = getelementptr inbounds i8, i8* %40, i64 7
%71 = shl i64 %39, 1
%72 = or i64 %71, %69
%73 = trunc i64 %72 to i8
store i8 %73, i8* %70
%74 = lshr i64 %39, 7
%75 = trunc i64 %74 to i8
%76 = getelementptr inbounds i8, i8* %40, i64 8
store i8 %75, i8* %76
%77 = lshr i64 %39, 15
%78 = trunc i64 %77 to i8
%79 = getelementptr inbounds i8, i8* %40, i64 9
store i8 %78, i8* %79
%80 = lshr i64 %39, 23
%81 = trunc i64 %80 to i8
%82 = getelementptr inbounds i8, i8* %40, i64 10
store i8 %81, i8* %82
%83 = lshr i64 %39, 31
%84 = trunc i64 %83 to i8
%85 = getelementptr inbounds i8, i8* %40, i64 11
store i8 %84, i8* %85
%86 = tail call i32 @dump_jreg(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %40, i32 16)
%87 = tail call double @or1ksim_jtag_shift_dr(i8* %40, i32 125)
%88 = tail call i32 @dump_jreg(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* %40, i32 16)
%89 = load i8, i8* %85
%90 = lshr i8 %89, 1
%91 = and i8 %90, 15
%92 = lshr i8 %89, 5
%93 = zext i8 %92 to i64
%94 = getelementptr inbounds i8, i8* %40, i64 12
%95 = load i8, i8* %94
%96 = zext i8 %95 to i64
%97 = shl nuw nsw i64 %96, 3
%98 = or i64 %97, %93
%99 = getelementptr inbounds i8, i8* %40, i64 13
%100 = load i8, i8* %99
%101 = zext i8 %100 to i64
%102 = shl nuw nsw i64 %101, 11
%103 = or i64 %98, %102
%104 = getelementptr inbounds i8, i8* %40, i64 14
%105 = load i8, i8* %104
%106 = zext i8 %105 to i64
%107 = shl nuw nsw i64 %106, 19
%108 = or i64 %103, %107
%109 = getelementptr inbounds i8, i8* %40, i64 15
%110 = load i8, i8* %109
%111 = zext i8 %110 to i64
%112 = shl nuw nsw i64 %111, 27
%113 = or i64 %108, %112
%114 = zext i8 %91 to i64
%115 = tail call i8* @reverse_bits(i64 %114, i32 4)
%116 = ptrtoint i8* %115 to i64
%117 = trunc i64 %116 to i8
%118 = tail call i8* @reverse_bits(i64 %113, i32 32)
%119 = ptrtoint i8* %118 to i64
%120 = tail call i64 @crc32(i8 zeroext %117, i32 4, i32 -1)
%121 = trunc i64 %116 to i32
%122 = and i32 %121, 255
%123 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i32 %122)
%124 = icmp eq i64 %120, %119
br i1 %124, label %129, label %125
125: ; preds = %44
%126 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.12, i64 0, i64 0))
%127 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), i64 %119)
%128 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i64 %120)
br label %129
129: ; preds = %125, %44
%130 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0), double %87)
%131 = tail call i32 @free(i8* %40)
br label %132
132: ; preds = %20, %24, %129, %42, %7
%133 = phi i32 [ 0, %7 ], [ 0, %20 ], [ 0, %24 ], [ 0, %42 ], [ 1, %129 ]
ret i32 %133
}