#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*/ CC2500_clearLamps();
int /*<<< orphan*/ CC2500_sendBurstCommand(int, unsigned char *, unsigned char);
unsigned char CC2500_sendCommand(int, int);
int /*<<< orphan*/ CC2500_sendStrobeCommand(int);
int /*<<< orphan*/ checkAddress(unsigned char *);
int /*<<< orphan*/ delay(int);
unsigned long millis();
void LivingColors_learnLamps() {
  CC2500_clearLamps();
  CC2500_sendStrobeCommand(0x36);
  unsigned char result = CC2500_sendCommand(0xFB, 0x00);
  for (int i = 0; i < result; ++i) {
    CC2500_sendCommand(0xBF, 0x00);
  }
  unsigned long startTime = millis();
  while ((millis() - startTime) < 5000) {
    CC2500_sendStrobeCommand(0x34);
    delay(10);
    result = CC2500_sendCommand(0xFB, 0x00);
    if (result >= 0x11) {
      result = CC2500_sendCommand(0xBF, 0x00);
      if (result == 0x0E) {
        unsigned char data[15];
        CC2500_sendBurstCommand(0xFF, data, result);
        if ((data[9] == 0x03) || (data[9] == 0x05) || (data[9] == 0x07)) {
          checkAddress(data);
        }
        CC2500_sendCommand(0xBF, 0x00);
        CC2500_sendCommand(0xBF, 0x00);
      } else {
        result = CC2500_sendCommand(0xFB, 0x00);
        for (int i = 0; i < result; ++i) {
          CC2500_sendCommand(0xBF, 0x00);
        }
      }
    }
    CC2500_sendStrobeCommand(0x36);
    delay(2);
  }
  CC2500_sendStrobeCommand(0x36);
  result = CC2500_sendCommand(0xFB, 0x00);
  for (int i = 0; i < result; ++i) {
    CC2500_sendCommand(0xBF, 0x00);
  }
}


x86 assembly (clang, -O0):
<LivingColors_learnLamps>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x0,%al
call   1090 <CC2500_clearLamps@plt>
mov    $0x36,%edi
call   1040 <CC2500_sendStrobeCommand@plt>
mov    $0xfb,%edi
xor    %esi,%esi
call   1060 <CC2500_sendCommand@plt>
mov    %al,-0x1(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
movzbl -0x1(%rbp),%ecx
cmp    %ecx,%eax
jge    11c8 <LivingColors_learnLamps+0x58>
mov    $0xbf,%edi
xor    %esi,%esi
call   1060 <CC2500_sendCommand@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    119f <LivingColors_learnLamps+0x2f>
mov    $0x0,%al
call   1080 <millis@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1080 <millis@plt>
sub    -0x10(%rbp),%rax
cmp    $0x1388,%rax
jae    12f7 <LivingColors_learnLamps+0x187>
mov    $0x34,%edi
call   1040 <CC2500_sendStrobeCommand@plt>
mov    $0xa,%edi
call   1050 <delay@plt>
mov    $0xfb,%edi
xor    %esi,%esi
call   1060 <CC2500_sendCommand@plt>
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
cmp    $0x11,%eax
jl     12de <LivingColors_learnLamps+0x16e>
mov    $0xbf,%edi
xor    %esi,%esi
call   1060 <CC2500_sendCommand@plt>
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
cmp    $0xe,%eax
jne    1295 <LivingColors_learnLamps+0x125>
lea    -0x1f(%rbp),%rsi
mov    $0xff,%edi
movzbl -0x1(%rbp),%edx
call   1070 <CC2500_sendBurstCommand@plt>
movzbl -0x16(%rbp),%eax
cmp    $0x3,%eax
je     126f <LivingColors_learnLamps+0xff>
movzbl -0x16(%rbp),%eax
cmp    $0x5,%eax
je     126f <LivingColors_learnLamps+0xff>
movzbl -0x16(%rbp),%eax
cmp    $0x7,%eax
jne    1278 <LivingColors_learnLamps+0x108>
lea    -0x1f(%rbp),%rdi
call   1030 <checkAddress@plt>
mov    $0xbf,%edi
xor    %esi,%esi
call   1060 <CC2500_sendCommand@plt>
mov    $0xbf,%edi
xor    %esi,%esi
call   1060 <CC2500_sendCommand@plt>
jmp    12d9 <LivingColors_learnLamps+0x169>
mov    $0xfb,%edi
xor    %esi,%esi
call   1060 <CC2500_sendCommand@plt>
mov    %al,-0x1(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
movzbl -0x1(%rbp),%ecx
cmp    %ecx,%eax
jge    12d4 <LivingColors_learnLamps+0x164>
mov    $0xbf,%edi
xor    %esi,%esi
call   1060 <CC2500_sendCommand@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    12ab <LivingColors_learnLamps+0x13b>
jmp    12d9 <LivingColors_learnLamps+0x169>
jmp    12de <LivingColors_learnLamps+0x16e>
mov    $0x36,%edi
call   1040 <CC2500_sendStrobeCommand@plt>
mov    $0x2,%edi
call   1050 <delay@plt>
jmp    11d3 <LivingColors_learnLamps+0x63>
mov    $0x36,%edi
call   1040 <CC2500_sendStrobeCommand@plt>
mov    $0xfb,%edi
xor    %esi,%esi
call   1060 <CC2500_sendCommand@plt>
mov    %al,-0x1(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
movzbl -0x1(%rbp),%ecx
cmp    %ecx,%eax
jge    1340 <LivingColors_learnLamps+0x1d0>
mov    $0xbf,%edi
xor    %esi,%esi
call   1060 <CC2500_sendCommand@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1317 <LivingColors_learnLamps+0x1a7>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LivingColors_learnLamps>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
call   1090 <CC2500_clearLamps@plt>
mov    $0x36,%edi
call   1040 <CC2500_sendStrobeCommand@plt>
mov    $0xfb,%edi
xor    %esi,%esi
call   1060 <CC2500_sendCommand@plt>
test   %al,%al
je     11b1 <LivingColors_learnLamps+0x41>
movzbl %al,%ebx
xchg   %ax,%ax
mov    $0xbf,%edi
xor    %esi,%esi
call   1060 <CC2500_sendCommand@plt>
add    $0xffffffff,%ebx
jne    11a0 <LivingColors_learnLamps+0x30>
xor    %eax,%eax
call   1080 <millis@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1080 <millis@plt>
sub    %rbx,%rax
cmp    $0x1387,%rax
ja     12c6 <LivingColors_learnLamps+0x156>
lea    0x9(%rsp),%r14
mov    $0xa8,%r15d
jmp    1222 <LivingColors_learnLamps+0xb2>
xchg   %ax,%ax
mov    $0xbf,%edi
xor    %esi,%esi
call   1060 <CC2500_sendCommand@plt>
mov    $0xbf,%edi
xor    %esi,%esi
call   1060 <CC2500_sendCommand@plt>
mov    $0x36,%edi
call   1040 <CC2500_sendStrobeCommand@plt>
mov    $0x2,%edi
call   1050 <delay@plt>
xor    %eax,%eax
call   1080 <millis@plt>
sub    %rbx,%rax
cmp    $0x1388,%rax
jae    12c6 <LivingColors_learnLamps+0x156>
mov    $0x34,%edi
call   1040 <CC2500_sendStrobeCommand@plt>
mov    $0xa,%edi
call   1050 <delay@plt>
mov    $0xfb,%edi
xor    %esi,%esi
call   1060 <CC2500_sendCommand@plt>
cmp    $0x11,%al
jb     11f8 <LivingColors_learnLamps+0x88>
mov    $0xbf,%edi
xor    %esi,%esi
call   1060 <CC2500_sendCommand@plt>
cmp    $0xe,%al
jne    1290 <LivingColors_learnLamps+0x120>
mov    $0xff,%edi
mov    %r14,%rsi
mov    $0xe,%edx
call   1070 <CC2500_sendBurstCommand@plt>
mov    0x12(%rsp),%al
cmp    $0x7,%al
ja     11e0 <LivingColors_learnLamps+0x70>
movzbl %al,%eax
bt     %eax,%r15d
jae    11e0 <LivingColors_learnLamps+0x70>
mov    %r14,%rdi
call   1030 <checkAddress@plt>
jmp    11e0 <LivingColors_learnLamps+0x70>
xchg   %ax,%ax
mov    $0xfb,%edi
xor    %esi,%esi
call   1060 <CC2500_sendCommand@plt>
test   %al,%al
je     11f8 <LivingColors_learnLamps+0x88>
movzbl %al,%ebp
nopw   0x0(%rax,%rax,1)
mov    $0xbf,%edi
xor    %esi,%esi
call   1060 <CC2500_sendCommand@plt>
add    $0xffffffff,%ebp
jne    12b0 <LivingColors_learnLamps+0x140>
jmp    11f8 <LivingColors_learnLamps+0x88>
mov    $0x36,%edi
call   1040 <CC2500_sendStrobeCommand@plt>
mov    $0xfb,%edi
xor    %esi,%esi
call   1060 <CC2500_sendCommand@plt>
test   %al,%al
je     1301 <LivingColors_learnLamps+0x191>
movzbl %al,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0xbf,%edi
xor    %esi,%esi
call   1060 <CC2500_sendCommand@plt>
add    $0xffffffff,%ebx
jne    12f0 <LivingColors_learnLamps+0x180>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @LivingColors_learnLamps() {
%1 = alloca i8
%2 = alloca i32
%3 = alloca i64
%4 = alloca [15 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = call i32 (...) @CC2500_clearLamps()
%8 = call i32 @CC2500_sendStrobeCommand(i32 54)
%9 = call zeroext i8 @CC2500_sendCommand(i32 251, i32 0)
store i8 %9, i8* %1
store i32 0, i32* %2
br label %10
10: ; preds = %17, %0
%11 = load i32, i32* %2
%12 = load i8, i8* %1
%13 = zext i8 %12 to i32
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = call zeroext i8 @CC2500_sendCommand(i32 191, i32 0)
br label %17
17: ; preds = %15
%18 = load i32, i32* %2
%19 = add nsw i32 %18, 1
store i32 %19, i32* %2
br label %10
20: ; preds = %10
%21 = call i64 (...) @millis()
store i64 %21, i64* %3
br label %22
22: ; preds = %77, %20
%23 = call i64 (...) @millis()
%24 = load i64, i64* %3
%25 = sub i64 %23, %24
%26 = icmp ult i64 %25, 5000
br i1 %26, label %27, label %80
27: ; preds = %22
%28 = call i32 @CC2500_sendStrobeCommand(i32 52)
%29 = call i32 @delay(i32 10)
%30 = call zeroext i8 @CC2500_sendCommand(i32 251, i32 0)
store i8 %30, i8* %1
%31 = load i8, i8* %1
%32 = zext i8 %31 to i32
%33 = icmp sge i32 %32, 17
br i1 %33, label %34, label %77
34: ; preds = %27
%35 = call zeroext i8 @CC2500_sendCommand(i32 191, i32 0)
store i8 %35, i8* %1
%36 = load i8, i8* %1
%37 = zext i8 %36 to i32
%38 = icmp eq i32 %37, 14
br i1 %38, label %39, label %63
39: ; preds = %34
%40 = getelementptr inbounds [15 x i8], [15 x i8]* %4, i64 0, i64 0
%41 = load i8, i8* %1
%42 = call i32 @CC2500_sendBurstCommand(i32 255, i8* %40, i8 zeroext %41)
%43 = getelementptr inbounds [15 x i8], [15 x i8]* %4, i64 0, i64 9
%44 = load i8, i8* %43
%45 = zext i8 %44 to i32
%46 = icmp eq i32 %45, 3
br i1 %46, label %57, label %47
47: ; preds = %39
%48 = getelementptr inbounds [15 x i8], [15 x i8]* %4, i64 0, i64 9
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
%51 = icmp eq i32 %50, 5
br i1 %51, label %57, label %52
52: ; preds = %47
%53 = getelementptr inbounds [15 x i8], [15 x i8]* %4, i64 0, i64 9
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = icmp eq i32 %55, 7
br i1 %56, label %57, label %60
57: ; preds = %52, %47, %39
%58 = getelementptr inbounds [15 x i8], [15 x i8]* %4, i64 0, i64 0
%59 = call i32 @checkAddress(i8* %58)
br label %60
60: ; preds = %57, %52
%61 = call zeroext i8 @CC2500_sendCommand(i32 191, i32 0)
%62 = call zeroext i8 @CC2500_sendCommand(i32 191, i32 0)
br label %76
63: ; preds = %34
%64 = call zeroext i8 @CC2500_sendCommand(i32 251, i32 0)
store i8 %64, i8* %1
store i32 0, i32* %5
br label %65
65: ; preds = %72, %63
%66 = load i32, i32* %5
%67 = load i8, i8* %1
%68 = zext i8 %67 to i32
%69 = icmp slt i32 %66, %68
br i1 %69, label %70, label %75
70: ; preds = %65
%71 = call zeroext i8 @CC2500_sendCommand(i32 191, i32 0)
br label %72
72: ; preds = %70
%73 = load i32, i32* %5
%74 = add nsw i32 %73, 1
store i32 %74, i32* %5
br label %65
75: ; preds = %65
br label %76
76: ; preds = %75, %60
br label %77
77: ; preds = %76, %27
%78 = call i32 @CC2500_sendStrobeCommand(i32 54)
%79 = call i32 @delay(i32 2)
br label %22
80: ; preds = %22
%81 = call i32 @CC2500_sendStrobeCommand(i32 54)
%82 = call zeroext i8 @CC2500_sendCommand(i32 251, i32 0)
store i8 %82, i8* %1
store i32 0, i32* %6
br label %83
83: ; preds = %90, %80
%84 = load i32, i32* %6
%85 = load i8, i8* %1
%86 = zext i8 %85 to i32
%87 = icmp slt i32 %84, %86
br i1 %87, label %88, label %93
88: ; preds = %83
%89 = call zeroext i8 @CC2500_sendCommand(i32 191, i32 0)
br label %90
90: ; preds = %88
%91 = load i32, i32* %6
%92 = add nsw i32 %91, 1
store i32 %92, i32* %6
br label %83
93: ; preds = %83
ret void
}

LLVM IR (-O2):
define void @LivingColors_learnLamps() {
%1 = alloca [15 x i8]
%2 = tail call i32 (...) @CC2500_clearLamps()
%3 = tail call i32 @CC2500_sendStrobeCommand(i32 54)
%4 = tail call zeroext i8 @CC2500_sendCommand(i32 251, i32 0)
%5 = zext i8 %4 to i32
%6 = icmp eq i8 %4, 0
br i1 %6, label %7, label %15
7: ; preds = %15, %0
%8 = tail call i64 (...) @millis()
%9 = call i64 (...) @millis()
%10 = sub i64 %9, %8
%11 = icmp ult i64 %10, 5000
br i1 %11, label %12, label %51
12: ; preds = %7
%13 = getelementptr inbounds [15 x i8], [15 x i8]* %1, i64 0, i64 0
%14 = getelementptr inbounds [15 x i8], [15 x i8]* %1, i64 0, i64 9
br label %20
15: ; preds = %0, %15
%16 = phi i32 [ %18, %15 ], [ 0, %0 ]
%17 = tail call zeroext i8 @CC2500_sendCommand(i32 191, i32 0)
%18 = add nuw nsw i32 %16, 1
%19 = icmp eq i32 %18, %5
br i1 %19, label %7, label %15
20: ; preds = %12, %45
%21 = call i32 @CC2500_sendStrobeCommand(i32 52)
%22 = call i32 @delay(i32 10)
%23 = call zeroext i8 @CC2500_sendCommand(i32 251, i32 0)
%24 = icmp ugt i8 %23, 16
br i1 %24, label %25, label %45
25: ; preds = %20
%26 = call zeroext i8 @CC2500_sendCommand(i32 191, i32 0)
%27 = icmp eq i8 %26, 14
br i1 %27, label %28, label %36
28: ; preds = %25
%29 = call i32 @CC2500_sendBurstCommand(i32 255, i8* %13, i8 zeroext 14)
%30 = load i8, i8* %14
switch i8 %30, label %33 [
i8 7, label %31
i8 5, label %31
i8 3, label %31
]
31: ; preds = %28, %28, %28
%32 = call i32 @checkAddress(i8* %13)
br label %33
33: ; preds = %28, %31
%34 = call zeroext i8 @CC2500_sendCommand(i32 191, i32 0)
%35 = call zeroext i8 @CC2500_sendCommand(i32 191, i32 0)
br label %45
36: ; preds = %25
%37 = call zeroext i8 @CC2500_sendCommand(i32 251, i32 0)
%38 = zext i8 %37 to i32
%39 = icmp eq i8 %37, 0
br i1 %39, label %45, label %40
40: ; preds = %36, %40
%41 = phi i32 [ %43, %40 ], [ 0, %36 ]
%42 = call zeroext i8 @CC2500_sendCommand(i32 191, i32 0)
%43 = add nuw nsw i32 %41, 1
%44 = icmp eq i32 %43, %38
br i1 %44, label %45, label %40
45: ; preds = %40, %36, %33, %20
%46 = call i32 @CC2500_sendStrobeCommand(i32 54)
%47 = call i32 @delay(i32 2)
%48 = call i64 (...) @millis()
%49 = sub i64 %48, %8
%50 = icmp ult i64 %49, 5000
br i1 %50, label %20, label %51
51: ; preds = %45, %7
%52 = call i32 @CC2500_sendStrobeCommand(i32 54)
%53 = call zeroext i8 @CC2500_sendCommand(i32 251, i32 0)
%54 = zext i8 %53 to i32
%55 = icmp eq i8 %53, 0
br i1 %55, label %56, label %57
56: ; preds = %57, %51
ret void
57: ; preds = %51, %57
%58 = phi i32 [ %60, %57 ], [ 0, %51 ]
%59 = call zeroext i8 @CC2500_sendCommand(i32 191, i32 0)
%60 = add nuw nsw i32 %58, 1
%61 = icmp eq i32 %60, %54
br i1 %61, label %56, label %57
}