#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 jam_jtag_io(int, char, int);
int jam_jtag_irscan(int start_state, int count, char *tdi, char *tdo) {
  int i = 0;
  int tdo_bit = 0;
  int status = 1;
  switch (start_state) {
  case 0:
    jam_jtag_io(1, 0, 0);
    jam_jtag_io(1, 0, 0);
    jam_jtag_io(0, 0, 0);
    jam_jtag_io(0, 0, 0);
    break;
  case 1:
    jam_jtag_io(1, 0, 0);
    jam_jtag_io(1, 0, 0);
    jam_jtag_io(1, 0, 0);
    jam_jtag_io(1, 0, 0);
    jam_jtag_io(0, 0, 0);
    jam_jtag_io(0, 0, 0);
    break;
  case 2:
    jam_jtag_io(1, 0, 0);
    jam_jtag_io(0, 0, 0);
    break;
  default:
    status = 0;
  }
  if (status) {
    for (i = 0; i < count; i++) {
      tdo_bit = jam_jtag_io((i == count - 1), tdi[i >> 3] & (1 << (i & 7)),
                            (tdo != (0)));
      if (tdo != (0)) {
        if (tdo_bit) {
          tdo[i >> 3] |= (1 << (i & 7));
        } else {
          tdo[i >> 3] &= ~(unsigned int)(1 << (i & 7));
        }
      }
    }
    jam_jtag_io(0, 0, 0);
  }
  return (status);
}


x86 assembly (clang, -O0):
<jam_jtag_irscan>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x28(%rbp)
test   %eax,%eax
je     1170 <jam_jtag_irscan+0x60>
jmp    114e <jam_jtag_irscan+0x3e>
mov    -0x28(%rbp),%eax
sub    $0x1,%eax
je     11a7 <jam_jtag_irscan+0x97>
jmp    115f <jam_jtag_irscan+0x4f>
mov    -0x28(%rbp),%eax
sub    $0x2,%eax
je     11fa <jam_jtag_irscan+0xea>
jmp    1218 <jam_jtag_irscan+0x108>
mov    $0x1,%edi
xor    %edx,%edx
mov    %edx,%esi
call   1030 <jam_jtag_io@plt>
mov    $0x1,%edi
xor    %edx,%edx
mov    %edx,%esi
call   1030 <jam_jtag_io@plt>
xor    %edx,%edx
mov    %edx,%edi
mov    %edx,%esi
call   1030 <jam_jtag_io@plt>
xor    %edx,%edx
mov    %edx,%edi
mov    %edx,%esi
call   1030 <jam_jtag_io@plt>
jmp    121f <jam_jtag_irscan+0x10f>
mov    $0x1,%edi
xor    %edx,%edx
mov    %edx,%esi
call   1030 <jam_jtag_io@plt>
mov    $0x1,%edi
xor    %edx,%edx
mov    %edx,%esi
call   1030 <jam_jtag_io@plt>
mov    $0x1,%edi
xor    %edx,%edx
mov    %edx,%esi
call   1030 <jam_jtag_io@plt>
mov    $0x1,%edi
xor    %edx,%edx
mov    %edx,%esi
call   1030 <jam_jtag_io@plt>
xor    %edx,%edx
mov    %edx,%edi
mov    %edx,%esi
call   1030 <jam_jtag_io@plt>
xor    %edx,%edx
mov    %edx,%edi
mov    %edx,%esi
call   1030 <jam_jtag_io@plt>
jmp    121f <jam_jtag_irscan+0x10f>
mov    $0x1,%edi
xor    %edx,%edx
mov    %edx,%esi
call   1030 <jam_jtag_io@plt>
xor    %edx,%edx
mov    %edx,%edi
mov    %edx,%esi
call   1030 <jam_jtag_io@plt>
jmp    121f <jam_jtag_irscan+0x10f>
movl   $0x0,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1310 <jam_jtag_irscan+0x200>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1305 <jam_jtag_irscan+0x1f5>
mov    -0x1c(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sar    $0x3,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x1c(%rbp),%ecx
and    $0x7,%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmpq   $0x0,-0x18(%rbp)
setne  %cl
and    $0x1,%cl
movzbl %cl,%edx
movsbl %al,%esi
call   1030 <jam_jtag_io@plt>
mov    %eax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12f2 <jam_jtag_irscan+0x1e2>
cmpl   $0x0,-0x20(%rbp)
je     12c7 <jam_jtag_irscan+0x1b7>
mov    -0x1c(%rbp),%ecx
and    $0x7,%ecx
mov    $0x1,%esi
shl    %cl,%esi
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sar    $0x3,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edx
or     %esi,%edx
mov    %dl,(%rax,%rcx,1)
jmp    12ed <jam_jtag_irscan+0x1dd>
mov    -0x1c(%rbp),%ecx
and    $0x7,%ecx
mov    $0x1,%esi
shl    %cl,%esi
xor    $0xffffffff,%esi
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sar    $0x3,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edx
and    %esi,%edx
mov    %dl,(%rax,%rcx,1)
jmp    12f2 <jam_jtag_irscan+0x1e2>
jmp    12f7 <jam_jtag_irscan+0x1e7>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1230 <jam_jtag_irscan+0x120>
xor    %edx,%edx
mov    %edx,%edi
mov    %edx,%esi
call   1030 <jam_jtag_io@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jam_jtag_irscan>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r13
mov    %rdx,(%rsp)
mov    %esi,%r15d
test   %edi,%edi
je     1155 <jam_jtag_irscan+0x45>
cmp    $0x2,%edi
je     1176 <jam_jtag_irscan+0x66>
xor    %eax,%eax
cmp    $0x1,%edi
jne    1228 <jam_jtag_irscan+0x118>
mov    $0x1,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1030 <jam_jtag_io@plt>
mov    $0x1,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1030 <jam_jtag_io@plt>
xor    %r12d,%r12d
mov    $0x1,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1030 <jam_jtag_io@plt>
mov    $0x1,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1030 <jam_jtag_io@plt>
jmp    117c <jam_jtag_irscan+0x6c>
mov    $0x1,%r12d
xor    %ebp,%ebp
mov    %r12d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1030 <jam_jtag_io@plt>
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1030 <jam_jtag_io@plt>
test   %r15d,%r15d
jle    1218 <jam_jtag_irscan+0x108>
xor    %r12d,%r12d
test   %r13,%r13
setne  %r12b
neg    %r15d
jmp    11ba <jam_jtag_irscan+0xaa>
nopl   (%rax)
add    $0x1,%ebp
mov    %r15d,%eax
add    %ebp,%eax
je     1218 <jam_jtag_irscan+0x108>
lea    (%r15,%rbp,1),%eax
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
mov    %ebp,%ebx
mov    %ebp,%ecx
and    $0x7,%cl
mov    $0x1,%r14d
shl    %cl,%r14d
shr    $0x3,%rbx
mov    (%rsp),%rax
movzbl (%rax,%rbx,1),%eax
and    %r14b,%al
movsbl %al,%esi
mov    %r12d,%edx
call   1030 <jam_jtag_io@plt>
test   %r13,%r13
je     11b0 <jam_jtag_irscan+0xa0>
movzbl 0x0(%r13,%rbx,1),%ecx
mov    %r14d,%edx
not    %dl
and    %cl,%dl
or     %r14b,%cl
test   %eax,%eax
movzbl %dl,%eax
movzbl %cl,%ecx
cmove  %eax,%ecx
mov    %cl,0x0(%r13,%rbx,1)
jmp    11b0 <jam_jtag_irscan+0xa0>
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1030 <jam_jtag_io@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @jam_jtag_irscan(i32 %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 1, i32* %11
%12 = load i32, i32* %5
switch i32 %12, label %28 [
i32 0, label %13
i32 1, label %18
i32 2, label %25
]
13: ; preds = %4
%14 = call i32 @jam_jtag_io(i32 1, i8 signext 0, i32 0)
%15 = call i32 @jam_jtag_io(i32 1, i8 signext 0, i32 0)
%16 = call i32 @jam_jtag_io(i32 0, i8 signext 0, i32 0)
%17 = call i32 @jam_jtag_io(i32 0, i8 signext 0, i32 0)
br label %29
18: ; preds = %4
%19 = call i32 @jam_jtag_io(i32 1, i8 signext 0, i32 0)
%20 = call i32 @jam_jtag_io(i32 1, i8 signext 0, i32 0)
%21 = call i32 @jam_jtag_io(i32 1, i8 signext 0, i32 0)
%22 = call i32 @jam_jtag_io(i32 1, i8 signext 0, i32 0)
%23 = call i32 @jam_jtag_io(i32 0, i8 signext 0, i32 0)
%24 = call i32 @jam_jtag_io(i32 0, i8 signext 0, i32 0)
br label %29
25: ; preds = %4
%26 = call i32 @jam_jtag_io(i32 1, i8 signext 0, i32 0)
%27 = call i32 @jam_jtag_io(i32 0, i8 signext 0, i32 0)
br label %29
28: ; preds = %4
store i32 0, i32* %11
br label %29
29: ; preds = %28, %25, %18, %13
%30 = load i32, i32* %11
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %98
32: ; preds = %29
store i32 0, i32* %9
br label %33
33: ; preds = %93, %32
%34 = load i32, i32* %9
%35 = load i32, i32* %6
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %96
37: ; preds = %33
%38 = load i32, i32* %9
%39 = load i32, i32* %6
%40 = sub nsw i32 %39, 1
%41 = icmp eq i32 %38, %40
%42 = zext i1 %41 to i32
%43 = load i8*, i8** %7
%44 = load i32, i32* %9
%45 = ashr i32 %44, 3
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %43, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = load i32, i32* %9
%51 = and i32 %50, 7
%52 = shl i32 1, %51
%53 = and i32 %49, %52
%54 = trunc i32 %53 to i8
%55 = load i8*, i8** %8
%56 = icmp ne i8* %55, null
%57 = zext i1 %56 to i32
%58 = call i32 @jam_jtag_io(i32 %42, i8 signext %54, i32 %57)
store i32 %58, i32* %10
%59 = load i8*, i8** %8
%60 = icmp ne i8* %59, null
br i1 %60, label %61, label %92
61: ; preds = %37
%62 = load i32, i32* %10
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %77
64: ; preds = %61
%65 = load i32, i32* %9
%66 = and i32 %65, 7
%67 = shl i32 1, %66
%68 = load i8*, i8** %8
%69 = load i32, i32* %9
%70 = ashr i32 %69, 3
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %68, i64 %71
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = or i32 %74, %67
%76 = trunc i32 %75 to i8
store i8 %76, i8* %72
br label %91
77: ; preds = %61
%78 = load i32, i32* %9
%79 = and i32 %78, 7
%80 = shl i32 1, %79
%81 = xor i32 %80, -1
%82 = load i8*, i8** %8
%83 = load i32, i32* %9
%84 = ashr i32 %83, 3
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i8, i8* %82, i64 %85
%87 = load i8, i8* %86
%88 = sext i8 %87 to i32
%89 = and i32 %88, %81
%90 = trunc i32 %89 to i8
store i8 %90, i8* %86
br label %91
91: ; preds = %77, %64
br label %92
92: ; preds = %91, %37
br label %93
93: ; preds = %92
%94 = load i32, i32* %9
%95 = add nsw i32 %94, 1
store i32 %95, i32* %9
br label %33
96: ; preds = %33
%97 = call i32 @jam_jtag_io(i32 0, i8 signext 0, i32 0)
br label %98
98: ; preds = %96, %29
%99 = load i32, i32* %11
ret i32 %99
}

LLVM IR (-O2):
define i32 @jam_jtag_irscan(i32 %0, i32 %1, i8* nocapture %2, i8* %3) {
switch i32 %0, label %46 [
i32 0, label %8
i32 1, label %5
i32 2, label %11
]
5: ; preds = %4
%6 = tail call i32 @jam_jtag_io(i32 1, i8 signext 0, i32 0)
%7 = tail call i32 @jam_jtag_io(i32 1, i8 signext 0, i32 0)
br label %8
8: ; preds = %4, %5
%9 = tail call i32 @jam_jtag_io(i32 1, i8 signext 0, i32 0)
%10 = tail call i32 @jam_jtag_io(i32 1, i8 signext 0, i32 0)
br label %11
11: ; preds = %8, %4
%12 = phi i32 [ 1, %4 ], [ 0, %8 ]
%13 = tail call i32 @jam_jtag_io(i32 %12, i8 signext 0, i32 0)
%14 = tail call i32 @jam_jtag_io(i32 0, i8 signext 0, i32 0)
%15 = icmp sgt i32 %1, 0
br i1 %15, label %16, label %44
16: ; preds = %11
%17 = add nsw i32 %1, -1
%18 = icmp ne i8* %3, null
%19 = zext i1 %18 to i32
br label %20
20: ; preds = %16, %41
%21 = phi i32 [ 0, %16 ], [ %42, %41 ]
%22 = icmp eq i32 %21, %17
%23 = zext i1 %22 to i32
%24 = lshr i32 %21, 3
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %2, i64 %25
%27 = load i8, i8* %26
%28 = and i32 %21, 7
%29 = shl nuw nsw i32 1, %28
%30 = trunc i32 %29 to i8
%31 = and i8 %27, %30
%32 = tail call i32 @jam_jtag_io(i32 %23, i8 signext %31, i32 %19)
br i1 %18, label %33, label %41
33: ; preds = %20
%34 = icmp eq i32 %32, 0
%35 = getelementptr inbounds i8, i8* %3, i64 %25
%36 = load i8, i8* %35
%37 = xor i8 %30, -1
%38 = and i8 %36, %37
%39 = or i8 %36, %30
%40 = select i1 %34, i8 %38, i8 %39
store i8 %40, i8* %35
br label %41
41: ; preds = %33, %20
%42 = add nuw nsw i32 %21, 1
%43 = icmp eq i32 %42, %1
br i1 %43, label %44, label %20
44: ; preds = %41, %11
%45 = tail call i32 @jam_jtag_io(i32 0, i8 signext 0, i32 0)
br label %46
46: ; preds = %4, %44
%47 = phi i32 [ 1, %44 ], [ 0, %4 ]
ret i32 %47
}