#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 */
typedef int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ CLEAR_TDI();
int /*<<< orphan*/ JTAG_SPEED();
int /*<<< orphan*/ SET_TDI();
scalar_t__ SET_TDO();
void bit_out_in(uint8_t byte, int length, char *in) {
  for (length; length > 0; length--) {
    if (byte & 1)
      SET_TDI();
    else
      CLEAR_TDI();
    byte = byte >> 1;
    if (SET_TDO())
      in[0] |= 1;
    in[0] = in[0] << 1;
    JTAG_SPEED();
  }
}


x86 assembly (clang, -O0):
<bit_out_in>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    11cb <bit_out_in+0x8b>
mov    -0x4(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1177 <bit_out_in+0x37>
mov    $0x0,%al
call   1050 <SET_TDI@plt>
jmp    117e <bit_out_in+0x3e>
mov    $0x0,%al
call   1060 <CLEAR_TDI@plt>
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1040 <SET_TDO@plt>
cmp    $0x0,%rax
je     11a4 <bit_out_in+0x64>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
or     $0x1,%ecx
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
shl    $0x1,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    $0x0,%al
call   1030 <JTAG_SPEED@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1152 <bit_out_in+0x12>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bit_out_in>:
push   %rbp
push   %r14
push   %rbx
test   %esi,%esi
jle    1199 <bit_out_in+0x59>
mov    %rdx,%r14
mov    %esi,%ebp
mov    %edi,%ebx
add    $0x1,%ebp
jmp    118b <bit_out_in+0x4b>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
call   1060 <CLEAR_TDI@plt>
sar    %ebx
xor    %eax,%eax
call   1040 <SET_TDO@plt>
test   %rax,%rax
setne  %al
or     (%r14),%al
add    %al,%al
mov    %al,(%r14)
xor    %eax,%eax
call   1030 <JTAG_SPEED@plt>
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
jle    1199 <bit_out_in+0x59>
xor    %eax,%eax
test   $0x1,%bl
je     1160 <bit_out_in+0x20>
call   1050 <SET_TDI@plt>
jmp    1165 <bit_out_in+0x25>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @bit_out_in(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%7 = load i32, i32* %5
br label %8
8: ; preds = %41, %3
%9 = load i32, i32* %5
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %44
11: ; preds = %8
%12 = load i32, i32* %4
%13 = and i32 %12, 1
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 (...) @SET_TDI()
br label %19
17: ; preds = %11
%18 = call i32 (...) @CLEAR_TDI()
br label %19
19: ; preds = %17, %15
%20 = load i32, i32* %4
%21 = ashr i32 %20, 1
store i32 %21, i32* %4
%22 = call i64 (...) @SET_TDO()
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %19
%25 = load i8*, i8** %6
%26 = getelementptr inbounds i8, i8* %25, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = or i32 %28, 1
%30 = trunc i32 %29 to i8
store i8 %30, i8* %26
br label %31
31: ; preds = %24, %19
%32 = load i8*, i8** %6
%33 = getelementptr inbounds i8, i8* %32, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = shl i32 %35, 1
%37 = trunc i32 %36 to i8
%38 = load i8*, i8** %6
%39 = getelementptr inbounds i8, i8* %38, i64 0
store i8 %37, i8* %39
%40 = call i32 (...) @JTAG_SPEED()
br label %41
41: ; preds = %31
%42 = load i32, i32* %5
%43 = add nsw i32 %42, -1
store i32 %43, i32* %5
br label %8
44: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @bit_out_in(i32 %0, i32 %1, i8* nocapture %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %25
5: ; preds = %3, %14
%6 = phi i32 [ %15, %14 ], [ %0, %3 ]
%7 = phi i32 [ %23, %14 ], [ %1, %3 ]
%8 = and i32 %6, 1
%9 = icmp eq i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %5
%11 = tail call i32 (...) @SET_TDI()
br label %14
12: ; preds = %5
%13 = tail call i32 (...) @CLEAR_TDI()
br label %14
14: ; preds = %12, %10
%15 = ashr i32 %6, 1
%16 = tail call i64 (...) @SET_TDO()
%17 = icmp ne i64 %16, 0
%18 = load i8, i8* %2
%19 = zext i1 %17 to i8
%20 = or i8 %18, %19
%21 = shl i8 %20, 1
store i8 %21, i8* %2
%22 = tail call i32 (...) @JTAG_SPEED()
%23 = add nsw i32 %7, -1
%24 = icmp sgt i32 %7, 1
br i1 %24, label %5, label %25
25: ; preds = %14, %3
ret void
}