#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 */
int /*<<< orphan*/ dump_jreg(char *, unsigned char *, int);
int /*<<< orphan*/ free(unsigned char *);
int hexch2val(char);
unsigned char *malloc(int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
double or1ksim_jtag_shift_dr(unsigned char *, int);
double or1ksim_jtag_shift_ir(unsigned char *, int);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int strtol(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int process_jreg(const char type, int next_jreg, int argc, char *argv[]) {
  const char *long_name = ('D' == type) ? "data" : "instruction";
  if ((next_jreg + 1) > argc) {
    printf("ERROR: no %s register found.\n", long_name);
    return 0;
  }
  int bit_len = strtol(argv[next_jreg++], NULL, 0);
  if (0 == bit_len) {
    printf("ERROR: invalid register length\n");
    return 0;
  }
  char *hex_str = argv[next_jreg];
  int num_chars = strlen(hex_str);
  int num_bytes = (bit_len + 7) / 8;
  if (num_chars > (2 * num_bytes)) {
    printf("Warning: Too many digits for register: truncated.\n");
  }
  unsigned char *jreg = malloc(num_bytes);
  if (NULL == jreg) {
    printf("ERROR: malloc for %s register failed.\n", long_name);
    return 0;
  }
  memset(jreg, 0, num_bytes);
  int i;
  for (i = num_chars - 1; i >= 0; i--) {
    int dig_num = num_chars - 1 - i;
    int dig_val = hexch2val(hex_str[i]);
    if (dig_val < 0) {
      printf("ERROR: %c not valid hex digit.\n", hex_str[i]);
      free(jreg);
      return 0;
    }
    jreg[dig_num / 2] |= (0 == (dig_num % 2)) ? dig_val : dig_val << 4;
  }
  dump_jreg("  shifting in", jreg, num_bytes);
  double t;
  if ('D' == type) {
    t = or1ksim_jtag_shift_dr(jreg, bit_len);
  } else {
    t = or1ksim_jtag_shift_ir(jreg, bit_len);
  }
  dump_jreg("  shifted out", jreg, num_bytes);
  printf("  time taken %.12fs\n", t);
  free(jreg);
  return 1;
}


x86 assembly (clang, -O0):
<process_jreg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movsbl -0x5(%rbp),%esi
mov    $0x44,%edx
lea    0xe3d(%rip),%rax
lea    0xe31(%rip),%rcx
cmp    %esi,%edx
cmove  %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cmp    -0x10(%rbp),%eax
jle    1206 <process_jreg+0x66>
mov    -0x20(%rbp),%rsi
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    142b <process_jreg+0x28b>
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0xc(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1090 <strtol@plt>
mov    %eax,-0x24(%rbp)
xor    %eax,%eax
cmp    -0x24(%rbp),%eax
jne    124f <process_jreg+0xaf>
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    142b <process_jreg+0x28b>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x34(%rbp)
mov    -0x24(%rbp),%eax
add    $0x7,%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%eax
mov    -0x38(%rbp),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
jle    129b <process_jreg+0xfb>
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%edi
call   10b0 <malloc@plt>
mov    %rax,-0x40(%rbp)
xor    %eax,%eax
cmp    -0x40(%rbp),%rax
jne    12d1 <process_jreg+0x131>
mov    -0x20(%rbp),%rsi
lea    0xdc4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    142b <process_jreg+0x28b>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jl     13aa <process_jreg+0x20a>
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
sub    -0x44(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1080 <hexch2val@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jge    134b <process_jreg+0x1ab>
mov    -0x30(%rbp),%rax
movslq -0x44(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xd7a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    142b <process_jreg+0x28b>
mov    -0x48(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
xor    %eax,%eax
cmp    %edx,%eax
jne    136b <process_jreg+0x1cb>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x5c(%rbp)
jmp    1374 <process_jreg+0x1d4>
mov    -0x4c(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%esi
mov    -0x40(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x48(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x68(%rbp),%rax
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%edx
or     %esi,%edx
mov    %dl,(%rax,%rcx,1)
mov    -0x44(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x44(%rbp)
jmp    12e8 <process_jreg+0x148>
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%edx
lea    0xd11(%rip),%rdi
call   1040 <dump_jreg@plt>
movsbl -0x5(%rbp),%ecx
mov    $0x44,%eax
cmp    %ecx,%eax
jne    13e4 <process_jreg+0x244>
mov    -0x40(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   10c0 <or1ksim_jtag_shift_dr@plt>
movsd  %xmm0,-0x58(%rbp)
jmp    13f5 <process_jreg+0x255>
mov    -0x40(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   10a0 <or1ksim_jtag_shift_ir@plt>
movsd  %xmm0,-0x58(%rbp)
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%edx
lea    0xcd4(%rip),%rdi
call   1040 <dump_jreg@plt>
movsd  -0x58(%rbp),%xmm0
lea    0xcd1(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    -0x40(%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_jreg>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r13d
cmp    $0x44,%r13b
lea    0xe34(%rip),%rax
lea    0xe32(%rip),%r15
cmove  %rax,%r15
cmp    %edx,%esi
jge    12cb <process_jreg+0x11b>
mov    %rcx,%r14
mov    %esi,%ebx
movslq %esi,%rax
mov    (%rcx,%rax,8),%rdi
xor    %r12d,%r12d
xor    %esi,%esi
xor    %edx,%edx
call   10a0 <strtol@plt>
test   %eax,%eax
je     12e4 <process_jreg+0x134>
mov    %eax,%ebp
mov    %r13d,0x8(%rsp)
add    $0x1,%ebx
movslq %ebx,%rax
mov    (%r14,%rax,8),%r14
mov    %r14,%rdi
call   1060 <strlen@plt>
lea    0x7(%rbp),%ecx
mov    %rbp,0x10(%rsp)
lea    0xe(%rbp),%r12d
test   %ecx,%ecx
cmovns %ecx,%r12d
mov    %eax,%ebx
sar    $0x3,%r12d
lea    (%r12,%r12,1),%eax
cmp    %eax,%ebx
jle    1244 <process_jreg+0x94>
lea    0xe68(%rip),%rdi
call   1040 <puts@plt>
mov    %r12d,%edi
call   10c0 <malloc@plt>
test   %rax,%rax
je     12f2 <process_jreg+0x142>
mov    %rax,%r13
xor    %ebp,%ebp
mov    %rax,%rdi
xor    %esi,%esi
mov    %r12d,%edx
call   1080 <memset@plt>
test   %ebx,%ebx
jle    12a3 <process_jreg+0xf3>
add    $0xffffffff,%ebx
xchg   %ax,%ax
movsbl (%r14,%rbx,1),%edi
call   1090 <hexch2val@plt>
test   %eax,%eax
js     12fb <process_jreg+0x14b>
mov    %eax,%ecx
shl    $0x4,%ecx
mov    %ebp,%edx
shr    %rdx
test   $0x1,%bpl
cmove  %eax,%ecx
or     %cl,0x0(%r13,%rdx,1)
lea    -0x1(%rbx),%rax
add    $0x1,%ebp
test   %rbx,%rbx
mov    %rax,%rbx
jg     1270 <process_jreg+0xc0>
lea    0xdcc(%rip),%rdi
mov    %r13,%rsi
mov    %r12d,%edx
call   1050 <dump_jreg@plt>
cmpb   $0x44,0x8(%rsp)
jne    131d <process_jreg+0x16d>
mov    %r13,%rdi
mov    0x10(%rsp),%rsi
call   10d0 <or1ksim_jtag_shift_dr@plt>
jmp    132a <process_jreg+0x17a>
lea    0xd3f(%rip),%rdi
xor    %r12d,%r12d
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1364 <process_jreg+0x1b4>
lea    0xdee(%rip),%rdi
call   1040 <puts@plt>
jmp    1364 <process_jreg+0x1b4>
lea    0xd36(%rip),%rdi
jmp    12d2 <process_jreg+0x122>
mov    %ebx,%eax
movsbl (%r14,%rax,1),%esi
lea    0xd4d(%rip),%rdi
xor    %r12d,%r12d
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r13,%rdi
call   1030 <free@plt>
jmp    1364 <process_jreg+0x1b4>
mov    %r13,%rdi
mov    0x10(%rsp),%rsi
call   10b0 <or1ksim_jtag_shift_ir@plt>
movsd  %xmm0,0x8(%rsp)
lea    0xd4d(%rip),%rdi
mov    %r13,%rsi
mov    %r12d,%edx
call   1050 <dump_jreg@plt>
lea    0xd49(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1070 <printf@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    $0x1,%r12d
mov    %r12d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"data\00"
@.str.1 = [12 x i8] c"instruction\00"
@.str.2 = [30 x i8] c"ERROR: no %s register found.\0A\00"
@.str.3 = [32 x i8] c"ERROR: invalid register length\0A\00"
@.str.4 = [51 x i8] c"Warning: Too many digits for register: truncated.\0A\00"
@.str.5 = [39 x i8] c"ERROR: malloc for %s register failed.\0A\00"
@.str.6 = [32 x i8] c"ERROR: %c not valid hex digit.\0A\00"
@.str.7 = [14 x i8] c" shifting in\00"
@.str.8 = [14 x i8] c" shifted out\00"
@.str.9 = [21 x i8] c" time taken %.12fs\0A\00"
define i32 @process_jreg(i8 signext %0, i32 %1, i32 %2, i8** %3) {
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8**
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca double
store i8 %0, i8* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8** %3, i8*** %9
%20 = load i8, i8* %6
%21 = sext i8 %20 to i32
%22 = icmp eq i32 68, %21
%23 = zext i1 %22 to i64
%24 = select i1 %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0)
store i8* %24, i8** %10
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
%27 = load i32, i32* %8
%28 = icmp sgt i32 %26, %27
br i1 %28, label %29, label %32
29: ; preds = %4
%30 = load i8*, i8** %10
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %30)
store i32 0, i32* %5
br label %147
32: ; preds = %4
%33 = load i8**, i8*** %9
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 1
store i32 %35, i32* %7
%36 = sext i32 %34 to i64
%37 = getelementptr inbounds i8*, i8** %33, i64 %36
%38 = load i8*, i8** %37
%39 = call i32 @strtol(i8* %38, i32* null, i32 0)
store i32 %39, i32* %11
%40 = load i32, i32* %11
%41 = icmp eq i32 0, %40
br i1 %41, label %42, label %44
42: ; preds = %32
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %5
br label %147
44: ; preds = %32
%45 = load i8**, i8*** %9
%46 = load i32, i32* %7
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %45, i64 %47
%49 = load i8*, i8** %48
store i8* %49, i8** %12
%50 = load i8*, i8** %12
%51 = call i32 @strlen(i8* %50)
store i32 %51, i32* %13
%52 = load i32, i32* %11
%53 = add nsw i32 %52, 7
%54 = sdiv i32 %53, 8
store i32 %54, i32* %14
%55 = load i32, i32* %13
%56 = load i32, i32* %14
%57 = mul nsw i32 2, %56
%58 = icmp sgt i32 %55, %57
br i1 %58, label %59, label %61
59: ; preds = %44
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0))
br label %61
61: ; preds = %59, %44
%62 = load i32, i32* %14
%63 = call i8* @malloc(i32 %62)
store i8* %63, i8** %15
%64 = load i8*, i8** %15
%65 = icmp eq i8* null, %64
br i1 %65, label %66, label %69
66: ; preds = %61
%67 = load i8*, i8** %10
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* %67)
store i32 0, i32* %5
br label %147
69: ; preds = %61
%70 = load i8*, i8** %15
%71 = load i32, i32* %14
%72 = call i32 @memset(i8* %70, i32 0, i32 %71)
%73 = load i32, i32* %13
%74 = sub nsw i32 %73, 1
store i32 %74, i32* %16
br label %75
75: ; preds = %121, %69
%76 = load i32, i32* %16
%77 = icmp sge i32 %76, 0
br i1 %77, label %78, label %124
78: ; preds = %75
%79 = load i32, i32* %13
%80 = sub nsw i32 %79, 1
%81 = load i32, i32* %16
%82 = sub nsw i32 %80, %81
store i32 %82, i32* %17
%83 = load i8*, i8** %12
%84 = load i32, i32* %16
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i8, i8* %83, i64 %85
%87 = load i8, i8* %86
%88 = call i32 @hexch2val(i8 signext %87)
store i32 %88, i32* %18
%89 = load i32, i32* %18
%90 = icmp slt i32 %89, 0
br i1 %90, label %91, label %101
91: ; preds = %78
%92 = load i8*, i8** %12
%93 = load i32, i32* %16
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds i8, i8* %92, i64 %94
%96 = load i8, i8* %95
%97 = sext i8 %96 to i32
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i32 %97)
%99 = load i8*, i8** %15
%100 = call i32 @free(i8* %99)
store i32 0, i32* %5
br label %147
101: ; preds = %78
%102 = load i32, i32* %17
%103 = srem i32 %102, 2
%104 = icmp eq i32 0, %103
br i1 %104, label %105, label %107
105: ; preds = %101
%106 = load i32, i32* %18
br label %110
107: ; preds = %101
%108 = load i32, i32* %18
%109 = shl i32 %108, 4
br label %110
110: ; preds = %107, %105
%111 = phi i32 [ %106, %105 ], [ %109, %107 ]
%112 = load i8*, i8** %15
%113 = load i32, i32* %17
%114 = sdiv i32 %113, 2
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds i8, i8* %112, i64 %115
%117 = load i8, i8* %116
%118 = zext i8 %117 to i32
%119 = or i32 %118, %111
%120 = trunc i32 %119 to i8
store i8 %120, i8* %116
br label %121
121: ; preds = %110
%122 = load i32, i32* %16
%123 = add nsw i32 %122, -1
store i32 %123, i32* %16
br label %75
124: ; preds = %75
%125 = load i8*, i8** %15
%126 = load i32, i32* %14
%127 = call i32 @dump_jreg(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* %125, i32 %126)
%128 = load i8, i8* %6
%129 = sext i8 %128 to i32
%130 = icmp eq i32 68, %129
br i1 %130, label %131, label %135
131: ; preds = %124
%132 = load i8*, i8** %15
%133 = load i32, i32* %11
%134 = call double @or1ksim_jtag_shift_dr(i8* %132, i32 %133)
store double %134, double* %19
br label %139
135: ; preds = %124
%136 = load i8*, i8** %15
%137 = load i32, i32* %11
%138 = call double @or1ksim_jtag_shift_ir(i8* %136, i32 %137)
store double %138, double* %19
br label %139
139: ; preds = %135, %131
%140 = load i8*, i8** %15
%141 = load i32, i32* %14
%142 = call i32 @dump_jreg(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8* %140, i32 %141)
%143 = load double, double* %19
%144 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0), double %143)
%145 = load i8*, i8** %15
%146 = call i32 @free(i8* %145)
store i32 1, i32* %5
br label %147
147: ; preds = %139, %91, %66, %42, %29
%148 = load i32, i32* %5
ret i32 %148
}

LLVM IR (-O2):
@.str = [5 x i8] c"data\00"
@.str.1 = [12 x i8] c"instruction\00"
@.str.2 = [30 x i8] c"ERROR: no %s register found.\0A\00"
@.str.5 = [39 x i8] c"ERROR: malloc for %s register failed.\0A\00"
@.str.6 = [32 x i8] c"ERROR: %c not valid hex digit.\0A\00"
@.str.7 = [14 x i8] c" shifting in\00"
@.str.8 = [14 x i8] c" shifted out\00"
@.str.9 = [21 x i8] c" time taken %.12fs\0A\00"
@str = [50 x i8] c"Warning: Too many digits for register: truncated.\00"
@str.10 = [31 x i8] c"ERROR: invalid register length\00"
define i32 @process_jreg(i8 signext %0, i32 %1, i32 %2, i8** nocapture %3) {
%5 = icmp eq i8 %0, 68
%6 = select i1 %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0)
%7 = add nsw i32 %1, 1
%8 = icmp slt i32 %1, %2
br i1 %8, label %11, label %9
9: ; preds = %4
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i8* %6)
br label %80
11: ; preds = %4
%12 = sext i32 %1 to i64
%13 = getelementptr inbounds i8*, i8** %3, i64 %12
%14 = load i8*, i8** %13
%15 = tail call i32 @strtol(i8* nocapture %14, i32* null, i32 0)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.10, i64 0, i64 0))
br label %80
19: ; preds = %11
%20 = sext i32 %7 to i64
%21 = getelementptr inbounds i8*, i8** %3, i64 %20
%22 = load i8*, i8** %21
%23 = tail call i32 @strlen(i8* %22)
%24 = add nsw i32 %15, 7
%25 = sdiv i32 %24, 8
%26 = shl nsw i32 %25, 1
%27 = icmp sgt i32 %23, %26
br i1 %27, label %28, label %30
28: ; preds = %19
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str, i64 0, i64 0))
br label %30
30: ; preds = %28, %19
%31 = tail call i8* @malloc(i32 %25)
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* %6)
br label %80
35: ; preds = %30
%36 = tail call i32 @memset(i8* %31, i32 0, i32 %25)
%37 = icmp sgt i32 %23, 0
br i1 %37, label %38, label %69
38: ; preds = %35
%39 = add nsw i32 %23, -1
%40 = zext i32 %39 to i64
br label %41
41: ; preds = %38, %54
%42 = phi i64 [ %40, %38 ], [ %67, %54 ]
%43 = getelementptr inbounds i8, i8* %22, i64 %42
%44 = load i8, i8* %43
%45 = tail call i32 @hexch2val(i8 signext %44)
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %54
47: ; preds = %41
%48 = and i64 %42, 4294967295
%49 = getelementptr inbounds i8, i8* %22, i64 %48
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i32 %51)
%53 = tail call i32 @free(i8* %31)
br label %80
54: ; preds = %41
%55 = trunc i64 %42 to i32
%56 = sub i32 %39, %55
%57 = and i32 %56, 1
%58 = icmp eq i32 %57, 0
%59 = shl i32 %45, 4
%60 = select i1 %58, i32 %45, i32 %59
%61 = lshr i32 %56, 1
%62 = zext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %31, i64 %62
%64 = load i8, i8* %63
%65 = trunc i32 %60 to i8
%66 = or i8 %64, %65
store i8 %66, i8* %63
%67 = add nsw i64 %42, -1
%68 = icmp sgt i64 %42, 0
br i1 %68, label %41, label %69
69: ; preds = %54, %35
%70 = tail call i32 @dump_jreg(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* %31, i32 %25)
br i1 %5, label %71, label %73
71: ; preds = %69
%72 = tail call double @or1ksim_jtag_shift_dr(i8* %31, i32 %15)
br label %75
73: ; preds = %69
%74 = tail call double @or1ksim_jtag_shift_ir(i8* %31, i32 %15)
br label %75
75: ; preds = %73, %71
%76 = phi double [ %72, %71 ], [ %74, %73 ]
%77 = tail call i32 @dump_jreg(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8* %31, i32 %25)
%78 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0), double %76)
%79 = tail call i32 @free(i8* %31)
br label %80
80: ; preds = %47, %17, %75, %33, %9
%81 = phi i32 [ 0, %9 ], [ 0, %17 ], [ 0, %33 ], [ 1, %75 ], [ 0, %47 ]
ret i32 %81
}