#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_select_module(int next_jreg, int argc, char *argv[]) {
  printf("Selecting module.\n");
  if (next_jreg >= argc) {
    printf("ERROR: no module specified.\n");
    return 0;
  }
  unsigned long int module_id = strtoul(argv[next_jreg], NULL, 16);
  if (module_id > 0xf) {
    printf("ERROR: module value 0x%lx too large\n", module_id);
    return 0;
  }
  unsigned long int crc_in;
  crc_in = crc32(1, 1, 0xffffffff);
  crc_in = crc32(module_id, 4, crc_in);
  module_id = reverse_bits(module_id, 4);
  crc_in = reverse_bits(crc_in, 32);
  int num_bytes = 10;
  unsigned char *jreg = malloc(num_bytes);
  if (NULL == jreg) {
    printf("ERROR: malloc for SELECT_MODULE register failed.\n");
    return 0;
  }
  memset(jreg, 0, num_bytes);
  jreg[0] = 0x01;
  jreg[0] |= module_id << 1;
  jreg[0] |= crc_in << 5;
  jreg[1] = crc_in >> 3;
  jreg[2] = crc_in >> 11;
  jreg[3] = crc_in >> 19;
  jreg[4] = crc_in >> 27;
  dump_jreg("  shifting in", jreg, num_bytes);
  double t = or1ksim_jtag_shift_dr(jreg, 32 + 4 + 32 + 4 + 1);
  dump_jreg("  shifted out", jreg, num_bytes);
  unsigned char status;
  unsigned long int crc_out;
  status = ((jreg[4] >> 5) | (jreg[5] << 3)) & 0xf;
  crc_out =
      ((unsigned long int)jreg[5] >> 1) | ((unsigned long int)jreg[6] << 7) |
      ((unsigned long int)jreg[7] << 15) | ((unsigned long int)jreg[8] << 23) |
      ((unsigned long int)jreg[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(jreg);
  return 1;
}


x86 assembly (clang, -O0):
<process_select_module>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%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
cmp    -0xc(%rbp),%eax
jl     11d6 <process_select_module+0x46>
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    147f <process_select_module+0x2ef>
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,-0x20(%rbp)
cmpq   $0xf,-0x20(%rbp)
jbe    121d <process_select_module+0x8d>
mov    -0x20(%rbp),%rsi
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    147f <process_select_module+0x2ef>
mov    $0x1,%esi
mov    $0xffffffff,%edx
mov    %esi,%edi
call   1040 <crc32@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %ecx,%edx
mov    $0x4,%esi
movzbl %al,%edi
call   1040 <crc32@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x4,%esi
call   1060 <reverse_bits@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x20,%esi
call   1060 <reverse_bits@plt>
mov    %rax,-0x28(%rbp)
movl   $0xa,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
call   1090 <malloc@plt>
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
cmp    -0x38(%rbp),%rax
jne    12aa <process_select_module+0x11a>
lea    0xdbe(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    147f <process_select_module+0x2ef>
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%edx
xor    %esi,%esi
call   1080 <memset@plt>
mov    -0x38(%rbp),%rax
movb   $0x1,(%rax)
mov    -0x20(%rbp),%rdx
shl    $0x1,%rdx
mov    -0x38(%rbp),%rax
movzbl (%rax),%ecx
or     %rdx,%rcx
mov    %cl,(%rax)
mov    -0x28(%rbp),%rdx
shl    $0x5,%rdx
mov    -0x38(%rbp),%rax
movzbl (%rax),%ecx
or     %rdx,%rcx
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
shr    $0x3,%rax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x28(%rbp),%rax
shr    $0xb,%rax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x28(%rbp),%rax
shr    $0x13,%rax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x28(%rbp),%rax
shr    $0x1b,%rax
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0x38(%rbp),%rsi
mov    -0x2c(%rbp),%edx
lea    0xd4e(%rip),%rdi
call   1050 <dump_jreg@plt>
mov    -0x38(%rbp),%rdi
mov    $0x49,%esi
call   10a0 <or1ksim_jtag_shift_dr@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x38(%rbp),%rsi
mov    -0x2c(%rbp),%edx
lea    0xd36(%rip),%rdi
call   1050 <dump_jreg@plt>
mov    -0x38(%rbp),%rax
movzbl 0x4(%rax),%eax
sar    $0x5,%eax
mov    -0x38(%rbp),%rcx
movzbl 0x5(%rcx),%ecx
shl    $0x3,%ecx
or     %ecx,%eax
and    $0xf,%eax
mov    %al,-0x41(%rbp)
mov    -0x38(%rbp),%rax
movzbl 0x5(%rax),%eax
shr    $0x1,%rax
mov    -0x38(%rbp),%rcx
movzbl 0x6(%rcx),%ecx
shl    $0x7,%rcx
or     %rcx,%rax
mov    -0x38(%rbp),%rcx
movzbl 0x7(%rcx),%ecx
shl    $0xf,%rcx
or     %rcx,%rax
mov    -0x38(%rbp),%rcx
movzbl 0x8(%rcx),%ecx
shl    $0x17,%rcx
or     %rcx,%rax
mov    -0x38(%rbp),%rcx
movzbl 0x9(%rcx),%ecx
shl    $0x1f,%rcx
or     %rcx,%rax
mov    %rax,-0x50(%rbp)
movzbl -0x41(%rbp),%eax
mov    %eax,%edi
mov    $0x4,%esi
call   1060 <reverse_bits@plt>
mov    %al,-0x41(%rbp)
mov    -0x50(%rbp),%rdi
mov    $0x20,%esi
call   1060 <reverse_bits@plt>
mov    %rax,-0x50(%rbp)
mov    $0x4,%esi
mov    $0xffffffff,%edx
movzbl -0x41(%rbp),%edi
call   1040 <crc32@plt>
mov    %rax,-0x58(%rbp)
movzbl -0x41(%rbp),%esi
lea    0xc8e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x50(%rbp),%rax
cmp    -0x58(%rbp),%rax
je     145c <process_select_module+0x2cc>
lea    0xc8a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x50(%rbp),%rsi
lea    0xc88(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x58(%rbp),%rsi
lea    0xc91(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movsd  -0x40(%rbp),%xmm0
lea    0xc99(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_select_module>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%ebx
mov    %edi,%ebp
lea    0xef2(%rip),%rdi
call   1040 <puts@plt>
cmp    %ebx,%ebp
jge    11ef <process_select_module+0x4f>
movslq %ebp,%rax
mov    (%r14,%rax,8),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0x10,%edx
call   10c0 <strtoul@plt>
mov    %rax,%r14
cmp    $0x10,%rax
jb     120a <process_select_module+0x6a>
lea    0xe1d(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    11fd <process_select_module+0x5d>
lea    0xf03(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   1050 <crc32@plt>
movzbl %r14b,%edi
mov    $0x4,%esi
mov    %eax,%edx
call   1050 <crc32@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x4,%esi
call   1070 <reverse_bits@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    $0x20,%esi
call   1070 <reverse_bits@plt>
mov    %rax,%rbx
mov    $0xa,%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     13d0 <process_select_module+0x230>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1090 <memset@plt>
add    %r15d,%r15d
mov    %ebx,%eax
shl    $0x5,%eax
or     %r15d,%eax
or     $0x1,%al
mov    %al,(%r14)
mov    %rbx,%rax
shr    $0x3,%rax
mov    %al,0x1(%r14)
mov    %rbx,%rax
shr    $0xb,%rax
mov    %al,0x2(%r14)
mov    %rbx,%rax
shr    $0x13,%rax
mov    %al,0x3(%r14)
shr    $0x1b,%rbx
mov    %bl,0x4(%r14)
lea    0xd6f(%rip),%rdi
mov    %r14,%rsi
mov    $0xa,%edx
call   1060 <dump_jreg@plt>
mov    %r14,%rdi
mov    $0x49,%esi
call   10b0 <or1ksim_jtag_shift_dr@plt>
movsd  %xmm0,(%rsp)
lea    0xd57(%rip),%rdi
mov    %r14,%rsi
mov    $0xa,%edx
call   1060 <dump_jreg@plt>
movzbl 0x4(%r14),%eax
shr    $0x5,%rax
movzbl 0x5(%r14),%ecx
mov    %ecx,%edx
and    $0x1,%edx
lea    (%rax,%rdx,8),%rdi
shr    %rcx
movzbl 0x6(%r14),%eax
shl    $0x7,%rax
or     %rcx,%rax
movzbl 0x7(%r14),%ecx
shl    $0xf,%rcx
or     %rax,%rcx
movzbl 0x8(%r14),%eax
shl    $0x17,%rax
or     %rcx,%rax
movzbl 0x9(%r14),%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,%ebp
mov    %ebp,%edi
mov    $0x4,%esi
mov    $0xffffffff,%edx
call   1050 <crc32@plt>
mov    %rax,%rbx
lea    0xcd2(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1080 <printf@plt>
cmp    %r15,%rbx
je     13ab <process_select_module+0x20b>
lea    0xd35(%rip),%rdi
call   1040 <puts@plt>
lea    0xcc9(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xcd3(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xcdd(%rip),%rdi
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1080 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0x1,%ebx
jmp    11fd <process_select_module+0x5d>
lea    0xcf1(%rip),%rdi
jmp    11f6 <process_select_module+0x56>

LLVM IR (-O0):
@.str = [19 x i8] c"Selecting module.\0A\00"
@.str.1 = [29 x i8] c"ERROR: no module specified.\0A\00"
@.str.2 = [37 x i8] c"ERROR: module value 0x%lx too large\0A\00"
@.str.3 = [50 x i8] c"ERROR: malloc for SELECT_MODULE register failed.\0A\00"
@.str.4 = [14 x i8] c" shifting in\00"
@.str.5 = [14 x i8] c" shifted out\00"
@.str.6 = [24 x i8] c" status: 0x%01x\0A\00"
@.str.7 = [16 x i8] c" CRC mismatch\0A\00"
@.str.8 = [27 x i8] c" CRC out: 0x%08lx\0A\00"
@.str.9 = [27 x i8] c" CRC computed: 0x%08lx\0A\00"
@.str.10 = [24 x i8] c" time taken: %.12fs\0A\00"
define i32 @process_select_module(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 i32
%11 = alloca i8*
%12 = alloca double
%13 = alloca i8
%14 = alloca i64
%15 = alloca i64
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* %5
%18 = load i32, i32* %6
%19 = icmp sge i32 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %3
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %4
br label %171
22: ; preds = %3
%23 = load i8**, i8*** %7
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
%28 = call i64 @strtoul(i8* %27, i32* null, i32 16)
store i64 %28, i64* %8
%29 = load i64, i64* %8
%30 = icmp ugt i64 %29, 15
br i1 %30, label %31, label %34
31: ; preds = %22
%32 = load i64, i64* %8
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i64 %32)
store i32 0, i32* %4
br label %171
34: ; preds = %22
%35 = call i64 @crc32(i8 zeroext 1, i32 1, i32 -1)
store i64 %35, i64* %9
%36 = load i64, i64* %8
%37 = trunc i64 %36 to i8
%38 = load i64, i64* %9
%39 = trunc i64 %38 to i32
%40 = call i64 @crc32(i8 zeroext %37, i32 4, i32 %39)
store i64 %40, i64* %9
%41 = load i64, i64* %8
%42 = call i8* @reverse_bits(i64 %41, i32 4)
%43 = ptrtoint i8* %42 to i64
store i64 %43, i64* %8
%44 = load i64, i64* %9
%45 = call i8* @reverse_bits(i64 %44, i32 32)
%46 = ptrtoint i8* %45 to i64
store i64 %46, i64* %9
store i32 10, i32* %10
%47 = load i32, i32* %10
%48 = call i8* @malloc(i32 %47)
store i8* %48, i8** %11
%49 = load i8*, i8** %11
%50 = icmp eq i8* null, %49
br i1 %50, label %51, label %53
51: ; preds = %34
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %4
br label %171
53: ; preds = %34
%54 = load i8*, i8** %11
%55 = load i32, i32* %10
%56 = call i32 @memset(i8* %54, i32 0, i32 %55)
%57 = load i8*, i8** %11
%58 = getelementptr inbounds i8, i8* %57, i64 0
store i8 1, i8* %58
%59 = load i64, i64* %8
%60 = shl i64 %59, 1
%61 = load i8*, i8** %11
%62 = getelementptr inbounds i8, i8* %61, i64 0
%63 = load i8, i8* %62
%64 = zext i8 %63 to i64
%65 = or i64 %64, %60
%66 = trunc i64 %65 to i8
store i8 %66, i8* %62
%67 = load i64, i64* %9
%68 = shl i64 %67, 5
%69 = load i8*, i8** %11
%70 = getelementptr inbounds i8, i8* %69, i64 0
%71 = load i8, i8* %70
%72 = zext i8 %71 to i64
%73 = or i64 %72, %68
%74 = trunc i64 %73 to i8
store i8 %74, i8* %70
%75 = load i64, i64* %9
%76 = lshr i64 %75, 3
%77 = trunc i64 %76 to i8
%78 = load i8*, i8** %11
%79 = getelementptr inbounds i8, i8* %78, i64 1
store i8 %77, i8* %79
%80 = load i64, i64* %9
%81 = lshr i64 %80, 11
%82 = trunc i64 %81 to i8
%83 = load i8*, i8** %11
%84 = getelementptr inbounds i8, i8* %83, i64 2
store i8 %82, i8* %84
%85 = load i64, i64* %9
%86 = lshr i64 %85, 19
%87 = trunc i64 %86 to i8
%88 = load i8*, i8** %11
%89 = getelementptr inbounds i8, i8* %88, i64 3
store i8 %87, i8* %89
%90 = load i64, i64* %9
%91 = lshr i64 %90, 27
%92 = trunc i64 %91 to i8
%93 = load i8*, i8** %11
%94 = getelementptr inbounds i8, i8* %93, i64 4
store i8 %92, i8* %94
%95 = load i8*, i8** %11
%96 = load i32, i32* %10
%97 = call i32 @dump_jreg(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %95, i32 %96)
%98 = load i8*, i8** %11
%99 = call double @or1ksim_jtag_shift_dr(i8* %98, i32 73)
store double %99, double* %12
%100 = load i8*, i8** %11
%101 = load i32, i32* %10
%102 = call i32 @dump_jreg(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %100, i32 %101)
%103 = load i8*, i8** %11
%104 = getelementptr inbounds i8, i8* %103, i64 4
%105 = load i8, i8* %104
%106 = zext i8 %105 to i32
%107 = ashr i32 %106, 5
%108 = load i8*, i8** %11
%109 = getelementptr inbounds i8, i8* %108, i64 5
%110 = load i8, i8* %109
%111 = zext i8 %110 to i32
%112 = shl i32 %111, 3
%113 = or i32 %107, %112
%114 = and i32 %113, 15
%115 = trunc i32 %114 to i8
store i8 %115, i8* %13
%116 = load i8*, i8** %11
%117 = getelementptr inbounds i8, i8* %116, i64 5
%118 = load i8, i8* %117
%119 = zext i8 %118 to i64
%120 = lshr i64 %119, 1
%121 = load i8*, i8** %11
%122 = getelementptr inbounds i8, i8* %121, i64 6
%123 = load i8, i8* %122
%124 = zext i8 %123 to i64
%125 = shl i64 %124, 7
%126 = or i64 %120, %125
%127 = load i8*, i8** %11
%128 = getelementptr inbounds i8, i8* %127, i64 7
%129 = load i8, i8* %128
%130 = zext i8 %129 to i64
%131 = shl i64 %130, 15
%132 = or i64 %126, %131
%133 = load i8*, i8** %11
%134 = getelementptr inbounds i8, i8* %133, i64 8
%135 = load i8, i8* %134
%136 = zext i8 %135 to i64
%137 = shl i64 %136, 23
%138 = or i64 %132, %137
%139 = load i8*, i8** %11
%140 = getelementptr inbounds i8, i8* %139, i64 9
%141 = load i8, i8* %140
%142 = zext i8 %141 to i64
%143 = shl i64 %142, 31
%144 = or i64 %138, %143
store i64 %144, i64* %14
%145 = load i8, i8* %13
%146 = zext i8 %145 to i64
%147 = call i8* @reverse_bits(i64 %146, i32 4)
%148 = ptrtoint i8* %147 to i8
store i8 %148, i8* %13
%149 = load i64, i64* %14
%150 = call i8* @reverse_bits(i64 %149, i32 32)
%151 = ptrtoint i8* %150 to i64
store i64 %151, i64* %14
%152 = load i8, i8* %13
%153 = call i64 @crc32(i8 zeroext %152, i32 4, i32 -1)
store i64 %153, i64* %15
%154 = load i8, i8* %13
%155 = zext i8 %154 to i32
%156 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 %155)
%157 = load i64, i64* %14
%158 = load i64, i64* %15
%159 = icmp ne i64 %157, %158
br i1 %159, label %160, label %166
160: ; preds = %53
%161 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
%162 = load i64, i64* %14
%163 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i64 %162)
%164 = load i64, i64* %15
%165 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), i64 %164)
br label %166
166: ; preds = %160, %53
%167 = load double, double* %12
%168 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0), double %167)
%169 = load i8*, i8** %11
%170 = call i32 @free(i8* %169)
store i32 1, i32* %4
br label %171
171: ; preds = %166, %51, %31, %20
%172 = load i32, i32* %4
ret i32 %172
}

LLVM IR (-O2):
@.str.2 = [37 x i8] c"ERROR: module value 0x%lx too large\0A\00"
@.str.4 = [14 x i8] c" shifting in\00"
@.str.5 = [14 x i8] c" shifted out\00"
@.str.6 = [24 x i8] c" status: 0x%01x\0A\00"
@.str.8 = [27 x i8] c" CRC out: 0x%08lx\0A\00"
@.str.9 = [27 x i8] c" CRC computed: 0x%08lx\0A\00"
@.str.10 = [24 x i8] c" time taken: %.12fs\0A\00"
@str = [18 x i8] c"Selecting module.\00"
@str.11 = [15 x i8] c" CRC mismatch\00"
@str.12 = [49 x i8] c"ERROR: malloc for SELECT_MODULE register failed.\00"
@str.13 = [28 x i8] c"ERROR: no module specified.\00"
define i32 @process_select_module(i32 %0, i32 %1, i8** nocapture %2) {
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 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 ([28 x i8], [28 x i8]* @str.13, i64 0, i64 0))
br label %98
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 i64 @strtoul(i8* nocapture %11, i32* null, i32 16)
%13 = icmp ugt i64 %12, 15
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i64 %12)
br label %98
16: ; preds = %8
%17 = tail call i64 @crc32(i8 zeroext 1, i32 1, i32 -1)
%18 = trunc i64 %12 to i8
%19 = trunc i64 %17 to i32
%20 = tail call i64 @crc32(i8 zeroext %18, i32 4, i32 %19)
%21 = tail call i8* @reverse_bits(i64 %12, i32 4)
%22 = tail call i8* @reverse_bits(i64 %20, i32 32)
%23 = ptrtoint i8* %22 to i64
%24 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %28
26: ; preds = %16
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str.12, i64 0, i64 0))
br label %98
28: ; preds = %16
%29 = ptrtoint i8* %21 to i64
%30 = tail call i32 @memset(i8* %24, i32 0, i32 10)
%31 = shl i64 %29, 1
%32 = shl i64 %23, 5
%33 = or i64 %32, %31
%34 = trunc i64 %33 to i8
%35 = or i8 %34, 1
store i8 %35, i8* %24
%36 = lshr i64 %23, 3
%37 = trunc i64 %36 to i8
%38 = getelementptr inbounds i8, i8* %24, i64 1
store i8 %37, i8* %38
%39 = lshr i64 %23, 11
%40 = trunc i64 %39 to i8
%41 = getelementptr inbounds i8, i8* %24, i64 2
store i8 %40, i8* %41
%42 = lshr i64 %23, 19
%43 = trunc i64 %42 to i8
%44 = getelementptr inbounds i8, i8* %24, i64 3
store i8 %43, i8* %44
%45 = lshr i64 %23, 27
%46 = trunc i64 %45 to i8
%47 = getelementptr inbounds i8, i8* %24, i64 4
store i8 %46, i8* %47
%48 = tail call i32 @dump_jreg(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %24, i32 10)
%49 = tail call double @or1ksim_jtag_shift_dr(i8* %24, i32 73)
%50 = tail call i32 @dump_jreg(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %24, i32 10)
%51 = load i8, i8* %47
%52 = lshr i8 %51, 5
%53 = getelementptr inbounds i8, i8* %24, i64 5
%54 = load i8, i8* %53
%55 = shl i8 %54, 3
%56 = and i8 %55, 8
%57 = or i8 %56, %52
%58 = lshr i8 %54, 1
%59 = zext i8 %58 to i64
%60 = getelementptr inbounds i8, i8* %24, i64 6
%61 = load i8, i8* %60
%62 = zext i8 %61 to i64
%63 = shl nuw nsw i64 %62, 7
%64 = or i64 %63, %59
%65 = getelementptr inbounds i8, i8* %24, i64 7
%66 = load i8, i8* %65
%67 = zext i8 %66 to i64
%68 = shl nuw nsw i64 %67, 15
%69 = or i64 %64, %68
%70 = getelementptr inbounds i8, i8* %24, i64 8
%71 = load i8, i8* %70
%72 = zext i8 %71 to i64
%73 = shl nuw nsw i64 %72, 23
%74 = or i64 %69, %73
%75 = getelementptr inbounds i8, i8* %24, i64 9
%76 = load i8, i8* %75
%77 = zext i8 %76 to i64
%78 = shl nuw nsw i64 %77, 31
%79 = or i64 %74, %78
%80 = zext i8 %57 to i64
%81 = tail call i8* @reverse_bits(i64 %80, i32 4)
%82 = ptrtoint i8* %81 to i64
%83 = trunc i64 %82 to i8
%84 = tail call i8* @reverse_bits(i64 %79, i32 32)
%85 = ptrtoint i8* %84 to i64
%86 = tail call i64 @crc32(i8 zeroext %83, i32 4, i32 -1)
%87 = trunc i64 %82 to i32
%88 = and i32 %87, 255
%89 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 %88)
%90 = icmp eq i64 %86, %85
br i1 %90, label %95, label %91
91: ; preds = %28
%92 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.11, i64 0, i64 0))
%93 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i64 %85)
%94 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), i64 %86)
br label %95
95: ; preds = %91, %28
%96 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0), double %49)
%97 = tail call i32 @free(i8* %24)
br label %98
98: ; preds = %14, %95, %26, %6
%99 = phi i32 [ 0, %6 ], [ 0, %14 ], [ 0, %26 ], [ 1, %95 ]
ret i32 %99
}