#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 */
struct gpiohandle_data {
  int *values;
};

/* Variables and functions */
int /*<<< orphan*/ GPIOHANDLE_SET_LINE_VALUES_IOCTL;
int ioctl(int, int /*<<< orphan*/, struct gpiohandle_data *);
int ws2801_byte(int req_fd, unsigned char byte) {
  int ret;
  unsigned char mask;
  struct gpiohandle_data data;
  for (mask = 0x80; mask; mask >>= 1) {
    data.values[0] = 0;
    data.values[1] = (byte & mask) ? 1 : 0;
    ret = ioctl(req_fd, GPIOHANDLE_SET_LINE_VALUES_IOCTL, &data);
    if (ret == -1)
      return ret;
    data.values[0] = 1;
    ret = ioctl(req_fd, GPIOHANDLE_SET_LINE_VALUES_IOCTL, &data);
    if (ret == -1)
      return ret;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ws2801_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %edi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movb   $0x80,-0x11(%rbp)
cmpb   $0x0,-0x11(%rbp)
je     11cf <ws2801_byte+0xbf>
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
movzbl -0x9(%rbp),%edx
movzbl -0x11(%rbp),%eax
and    %eax,%edx
xor    %ecx,%ecx
mov    $0x1,%eax
cmp    $0x0,%edx
cmovne %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x8(%rbp),%edi
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    1184 <ws2801_byte+0x74>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d6 <ws2801_byte+0xc6>
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x8(%rbp),%edi
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    11bb <ws2801_byte+0xab>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d6 <ws2801_byte+0xc6>
jmp    11c0 <ws2801_byte+0xb0>
movzbl -0x11(%rbp),%eax
sar    $0x1,%eax
mov    %al,-0x11(%rbp)
jmp    1125 <ws2801_byte+0x15>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
LLVM IR (-O0):
%struct.gpiohandle_data = type { i32* }
@GPIOHANDLE_SET_LINE_VALUES_IOCTL = global i32 0
define i32 @ws2801_byte(i32 %0, i8 zeroext %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = alloca i32
%7 = alloca i8
%8 = alloca %struct.gpiohandle_data
store i32 %0, i32* %4
store i8 %1, i8* %5
store i8 -128, i8* %7
br label %9
9: ; preds = %46, %2
%10 = load i8, i8* %7
%11 = icmp ne i8 %10, 0
br i1 %11, label %12, label %51
12: ; preds = %9
%13 = getelementptr inbounds %struct.gpiohandle_data, %struct.gpiohandle_data* %8, i32 0, i32 0
%14 = load i32*, i32** %13
%15 = getelementptr inbounds i32, i32* %14, i64 0
store i32 0, i32* %15
%16 = load i8, i8* %5
%17 = zext i8 %16 to i32
%18 = load i8, i8* %7
%19 = zext i8 %18 to i32
%20 = and i32 %17, %19
%21 = icmp ne i32 %20, 0
%22 = zext i1 %21 to i64
%23 = select i1 %21, i32 1, i32 0
%24 = getelementptr inbounds %struct.gpiohandle_data, %struct.gpiohandle_data* %8, i32 0, i32 0
%25 = load i32*, i32** %24
%26 = getelementptr inbounds i32, i32* %25, i64 1
store i32 %23, i32* %26
%27 = load i32, i32* %4
%28 = load i32, i32* @GPIOHANDLE_SET_LINE_VALUES_IOCTL
%29 = call i32 @ioctl(i32 %27, i32 %28, %struct.gpiohandle_data* %8)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %12
%33 = load i32, i32* %6
store i32 %33, i32* %3
br label %52
34: ; preds = %12
%35 = getelementptr inbounds %struct.gpiohandle_data, %struct.gpiohandle_data* %8, i32 0, i32 0
%36 = load i32*, i32** %35
%37 = getelementptr inbounds i32, i32* %36, i64 0
store i32 1, i32* %37
%38 = load i32, i32* %4
%39 = load i32, i32* @GPIOHANDLE_SET_LINE_VALUES_IOCTL
%40 = call i32 @ioctl(i32 %38, i32 %39, %struct.gpiohandle_data* %8)
store i32 %40, i32* %6
%41 = load i32, i32* %6
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %45
43: ; preds = %34
%44 = load i32, i32* %6
store i32 %44, i32* %3
br label %52
45: ; preds = %34
br label %46
46: ; preds = %45
%47 = load i8, i8* %7
%48 = zext i8 %47 to i32
%49 = ashr i32 %48, 1
%50 = trunc i32 %49 to i8
store i8 %50, i8* %7
br label %9
51: ; preds = %9
store i32 0, i32* %3
br label %52
52: ; preds = %51, %43, %32
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):