#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*/ CLEAR_TMS();
int /*<<< orphan*/ JTAG_SPEED();
int /*<<< orphan*/ SET_TDI();
int /*<<< orphan*/ SET_TMS();
void bit_out_tms(uint8_t byte, int length, int tdi) {
  if (tdi == 1)
    SET_TDI();
  else
    CLEAR_TDI();
  for (length; length > 0; length--) {
    if (byte & 1)
      SET_TMS();
    else
      CLEAR_TMS();
    byte = byte >> 1;
    JTAG_SPEED();
  }
}


x86 assembly (clang, -O0):
<bit_out_tms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    1177 <bit_out_tms+0x27>
mov    $0x0,%al
call   1050 <SET_TDI@plt>
jmp    117e <bit_out_tms+0x2e>
mov    $0x0,%al
call   1070 <CLEAR_TDI@plt>
cmpl   $0x0,-0x8(%rbp)
jle    11c8 <bit_out_tms+0x78>
mov    -0x4(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11a3 <bit_out_tms+0x53>
mov    $0x0,%al
call   1060 <SET_TMS@plt>
jmp    11aa <bit_out_tms+0x5a>
mov    $0x0,%al
call   1040 <CLEAR_TMS@plt>
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1030 <JTAG_SPEED@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    117e <bit_out_tms+0x2e>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bit_out_tms>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
xor    %eax,%eax
cmp    $0x1,%edx
jne    1169 <bit_out_tms+0x19>
call   1050 <SET_TDI@plt>
test   %ebx,%ebx
jg     1172 <bit_out_tms+0x22>
jmp    11a5 <bit_out_tms+0x55>
call   1070 <CLEAR_TDI@plt>
test   %ebx,%ebx
jle    11a5 <bit_out_tms+0x55>
add    $0x1,%ebx
jmp    1196 <bit_out_tms+0x46>
nopw   0x0(%rax,%rax,1)
call   1040 <CLEAR_TMS@plt>
sar    %ebp
xor    %eax,%eax
call   1030 <JTAG_SPEED@plt>
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
jle    11a5 <bit_out_tms+0x55>
xor    %eax,%eax
test   $0x1,%bpl
je     1180 <bit_out_tms+0x30>
call   1060 <SET_TMS@plt>
jmp    1185 <bit_out_tms+0x35>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @bit_out_tms(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%7 = load i32, i32* %6
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = call i32 (...) @SET_TDI()
br label %13
11: ; preds = %3
%12 = call i32 (...) @CLEAR_TDI()
br label %13
13: ; preds = %11, %9
%14 = load i32, i32* %5
br label %15
15: ; preds = %30, %13
%16 = load i32, i32* %5
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %33
18: ; preds = %15
%19 = load i32, i32* %4
%20 = and i32 %19, 1
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 (...) @SET_TMS()
br label %26
24: ; preds = %18
%25 = call i32 (...) @CLEAR_TMS()
br label %26
26: ; preds = %24, %22
%27 = load i32, i32* %4
%28 = ashr i32 %27, 1
store i32 %28, i32* %4
%29 = call i32 (...) @JTAG_SPEED()
br label %30
30: ; preds = %26
%31 = load i32, i32* %5
%32 = add nsw i32 %31, -1
store i32 %32, i32* %5
br label %15
33: ; preds = %15
ret void
}

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