#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*/ led_write_1(int);
int /*<<< orphan*/ led_write_2(char);
int /*<<< orphan*/ usleep(int);
void led_spi_write(char data) {
  int i;
  for (i = 7; i >= 0; i--) {
    led_write_1(0);
    usleep(2);
    led_write_2((data >> i) & 1);
    usleep(2);
    led_write_1(1);
    usleep(4);
  }
}


x86 assembly (clang, -O0):
<led_spi_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movl   $0x7,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     11a0 <led_spi_write+0x70>
xor    %edi,%edi
call   1030 <led_write_1@plt>
mov    $0x2,%edi
call   1050 <usleep@plt>
movsbl -0x1(%rbp),%eax
mov    -0x8(%rbp),%ecx
sar    %cl,%eax
and    $0x1,%eax
movsbl %al,%edi
call   1040 <led_write_2@plt>
mov    $0x2,%edi
call   1050 <usleep@plt>
mov    $0x1,%edi
call   1030 <led_write_1@plt>
mov    $0x4,%edi
call   1050 <usleep@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1145 <led_spi_write+0x15>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<led_spi_write>:
push   %rbx
mov    %edi,%ebx
xor    %edi,%edi
call   1030 <led_write_1@plt>
mov    $0x2,%edi
call   1050 <usleep@plt>
mov    %ebx,%eax
shr    $0x7,%al
movzbl %al,%edi
call   1040 <led_write_2@plt>
mov    $0x2,%edi
call   1050 <usleep@plt>
mov    $0x1,%edi
call   1030 <led_write_1@plt>
mov    $0x4,%edi
call   1050 <usleep@plt>
xor    %edi,%edi
call   1030 <led_write_1@plt>
mov    $0x2,%edi
call   1050 <usleep@plt>
mov    %ebx,%eax
shr    $0x6,%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <led_write_2@plt>
mov    $0x2,%edi
call   1050 <usleep@plt>
mov    $0x1,%edi
call   1030 <led_write_1@plt>
mov    $0x4,%edi
call   1050 <usleep@plt>
xor    %edi,%edi
call   1030 <led_write_1@plt>
mov    $0x2,%edi
call   1050 <usleep@plt>
mov    %ebx,%eax
shr    $0x5,%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <led_write_2@plt>
mov    $0x2,%edi
call   1050 <usleep@plt>
mov    $0x1,%edi
call   1030 <led_write_1@plt>
mov    $0x4,%edi
call   1050 <usleep@plt>
xor    %edi,%edi
call   1030 <led_write_1@plt>
mov    $0x2,%edi
call   1050 <usleep@plt>
mov    %ebx,%eax
shr    $0x4,%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <led_write_2@plt>
mov    $0x2,%edi
call   1050 <usleep@plt>
mov    $0x1,%edi
call   1030 <led_write_1@plt>
mov    $0x4,%edi
call   1050 <usleep@plt>
xor    %edi,%edi
call   1030 <led_write_1@plt>
mov    $0x2,%edi
call   1050 <usleep@plt>
mov    %ebx,%eax
shr    $0x3,%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <led_write_2@plt>
mov    $0x2,%edi
call   1050 <usleep@plt>
mov    $0x1,%edi
call   1030 <led_write_1@plt>
mov    $0x4,%edi
call   1050 <usleep@plt>
xor    %edi,%edi
call   1030 <led_write_1@plt>
mov    $0x2,%edi
call   1050 <usleep@plt>
mov    %ebx,%eax
shr    $0x2,%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <led_write_2@plt>
mov    $0x2,%edi
call   1050 <usleep@plt>
mov    $0x1,%edi
call   1030 <led_write_1@plt>
mov    $0x4,%edi
call   1050 <usleep@plt>
xor    %edi,%edi
call   1030 <led_write_1@plt>
mov    $0x2,%edi
call   1050 <usleep@plt>
mov    %ebx,%eax
shr    %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <led_write_2@plt>
mov    $0x2,%edi
call   1050 <usleep@plt>
mov    $0x1,%edi
call   1030 <led_write_1@plt>
mov    $0x4,%edi
call   1050 <usleep@plt>
xor    %edi,%edi
call   1030 <led_write_1@plt>
mov    $0x2,%edi
call   1050 <usleep@plt>
and    $0x1,%ebx
mov    %ebx,%edi
call   1040 <led_write_2@plt>
mov    $0x2,%edi
call   1050 <usleep@plt>
mov    $0x1,%edi
call   1030 <led_write_1@plt>
mov    $0x4,%edi
pop    %rbx
jmp    1050 <usleep@plt>

LLVM IR (-O0):
define void @led_spi_write(i8 signext %0) {
%2 = alloca i8
%3 = alloca i32
store i8 %0, i8* %2
store i32 7, i32* %3
br label %4
4: ; preds = %20, %1
%5 = load i32, i32* %3
%6 = icmp sge i32 %5, 0
br i1 %6, label %7, label %23
7: ; preds = %4
%8 = call i32 @led_write_1(i32 0)
%9 = call i32 @usleep(i32 2)
%10 = load i8, i8* %2
%11 = sext i8 %10 to i32
%12 = load i32, i32* %3
%13 = ashr i32 %11, %12
%14 = and i32 %13, 1
%15 = trunc i32 %14 to i8
%16 = call i32 @led_write_2(i8 signext %15)
%17 = call i32 @usleep(i32 2)
%18 = call i32 @led_write_1(i32 1)
%19 = call i32 @usleep(i32 4)
br label %20
20: ; preds = %7
%21 = load i32, i32* %3
%22 = add nsw i32 %21, -1
store i32 %22, i32* %3
br label %4
23: ; preds = %4
ret void
}

LLVM IR (-O2):
define void @led_spi_write(i8 signext %0) {
%2 = tail call i32 @led_write_1(i32 0)
%3 = tail call i32 @usleep(i32 2)
%4 = lshr i8 %0, 7
%5 = tail call i32 @led_write_2(i8 signext %4)
%6 = tail call i32 @usleep(i32 2)
%7 = tail call i32 @led_write_1(i32 1)
%8 = tail call i32 @usleep(i32 4)
%9 = tail call i32 @led_write_1(i32 0)
%10 = tail call i32 @usleep(i32 2)
%11 = lshr i8 %0, 6
%12 = and i8 %11, 1
%13 = tail call i32 @led_write_2(i8 signext %12)
%14 = tail call i32 @usleep(i32 2)
%15 = tail call i32 @led_write_1(i32 1)
%16 = tail call i32 @usleep(i32 4)
%17 = tail call i32 @led_write_1(i32 0)
%18 = tail call i32 @usleep(i32 2)
%19 = lshr i8 %0, 5
%20 = and i8 %19, 1
%21 = tail call i32 @led_write_2(i8 signext %20)
%22 = tail call i32 @usleep(i32 2)
%23 = tail call i32 @led_write_1(i32 1)
%24 = tail call i32 @usleep(i32 4)
%25 = tail call i32 @led_write_1(i32 0)
%26 = tail call i32 @usleep(i32 2)
%27 = lshr i8 %0, 4
%28 = and i8 %27, 1
%29 = tail call i32 @led_write_2(i8 signext %28)
%30 = tail call i32 @usleep(i32 2)
%31 = tail call i32 @led_write_1(i32 1)
%32 = tail call i32 @usleep(i32 4)
%33 = tail call i32 @led_write_1(i32 0)
%34 = tail call i32 @usleep(i32 2)
%35 = lshr i8 %0, 3
%36 = and i8 %35, 1
%37 = tail call i32 @led_write_2(i8 signext %36)
%38 = tail call i32 @usleep(i32 2)
%39 = tail call i32 @led_write_1(i32 1)
%40 = tail call i32 @usleep(i32 4)
%41 = tail call i32 @led_write_1(i32 0)
%42 = tail call i32 @usleep(i32 2)
%43 = lshr i8 %0, 2
%44 = and i8 %43, 1
%45 = tail call i32 @led_write_2(i8 signext %44)
%46 = tail call i32 @usleep(i32 2)
%47 = tail call i32 @led_write_1(i32 1)
%48 = tail call i32 @usleep(i32 4)
%49 = tail call i32 @led_write_1(i32 0)
%50 = tail call i32 @usleep(i32 2)
%51 = lshr i8 %0, 1
%52 = and i8 %51, 1
%53 = tail call i32 @led_write_2(i8 signext %52)
%54 = tail call i32 @usleep(i32 2)
%55 = tail call i32 @led_write_1(i32 1)
%56 = tail call i32 @usleep(i32 4)
%57 = tail call i32 @led_write_1(i32 0)
%58 = tail call i32 @usleep(i32 2)
%59 = and i8 %0, 1
%60 = tail call i32 @led_write_2(i8 signext %59)
%61 = tail call i32 @usleep(i32 2)
%62 = tail call i32 @led_write_1(i32 1)
%63 = tail call i32 @usleep(i32 4)
ret void
}