#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;
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ lcd_init();
int /*<<< orphan*/ lcd_startStream();
int /*<<< orphan*/ lcd_stopStream();
int /*<<< orphan*/ lcd_stream(int, int, int);
int /*<<< orphan*/ lcdhal_deselect();
int /*<<< orphan*/ lcdhal_init();
int /*<<< orphan*/ lcdhal_select();
int /*<<< orphan*/ lcdhal_write(int, int);
void display_data(uint8_t channel, uint8_t *data, uint8_t len) {
  uint16_t x, r, g, b;
  if (channel == 0xFE) {
    if (len > 0) {
      switch (data[0]) {
      case 0x01:
        lcd_startStream();
        break;
      case 0x02:
        lcd_stopStream();
        break;
      case 0x03:
        if (len == 6) {
          x = data[0] << 8;
          x |= data[1];
          r = data[2];
          g = data[3];
          b = data[4];
          while (x--) {
            lcd_stream(r, g, b);
          }
        }
        break;
      case 0x04:
        lcd_init();
        break;
      case 0x05:
        lcdhal_write(data[1], data[2]);
        break;
      case 0x06:
        lcdhal_select();
        break;
      case 0x07:
        lcdhal_deselect();
        break;
      case 0x08:
        lcdhal_init();
        break;
      };
    }
  } else if (channel == 0xFF) {
    while (len >= 2) {
      uint8_t count = data[0] >> 4;
      uint8_t r = data[0] << 4;
      uint8_t g = data[1] & 0xF0;
      uint8_t b = data[1] << 4;
      do {
        lcd_stream(r, g, b);
      } while (count--);
      data += 2;
      len -= 2;
    }
  }
}


x86 assembly (clang, -O0):
<display_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0xfe,-0x4(%rbp)
jne    12ac <display_data+0x12c>
cmpl   $0x0,-0x14(%rbp)
jle    12a7 <display_data+0x127>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x40(%rbp)
sub    $0x7,%eax
ja     12a2 <display_data+0x122>
mov    -0x40(%rbp),%rax
lea    0xe34(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1060 <lcd_startStream@plt>
jmp    12a2 <display_data+0x122>
mov    $0x0,%al
call   1040 <lcd_stopStream@plt>
jmp    12a2 <display_data+0x122>
cmpl   $0x6,-0x14(%rbp)
jne    125a <display_data+0xda>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
shl    $0x8,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x18(%rbp)
cmp    $0x0,%eax
je     1255 <display_data+0xd5>
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1050 <lcd_stream@plt>
jmp    122e <display_data+0xae>
jmp    125a <display_data+0xda>
jmp    12a2 <display_data+0x122>
mov    $0x0,%al
call   1080 <lcd_init@plt>
jmp    12a2 <display_data+0x122>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%esi
call   1070 <lcdhal_write@plt>
jmp    12a2 <display_data+0x122>
mov    $0x0,%al
call   10a0 <lcdhal_select@plt>
jmp    12a2 <display_data+0x122>
mov    $0x0,%al
call   1090 <lcdhal_deselect@plt>
jmp    12a2 <display_data+0x122>
mov    $0x0,%al
call   1030 <lcdhal_init@plt>
jmp    12a7 <display_data+0x127>
jmp    1342 <display_data+0x1c2>
cmpl   $0xff,-0x4(%rbp)
jne    133d <display_data+0x1bd>
jmp    12be <display_data+0x13e>
cmpl   $0x2,-0x14(%rbp)
jl     1338 <display_data+0x1b8>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
sar    $0x4,%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
shl    $0x4,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
and    $0xf0,%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
shl    $0x4,%eax
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    -0x34(%rbp),%edx
call   1050 <lcd_stream@plt>
mov    -0x28(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x28(%rbp)
cmp    $0x0,%eax
jne    12fc <display_data+0x17c>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    12be <display_data+0x13e>
jmp    133d <display_data+0x1bd>
jmp    1342 <display_data+0x1c2>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<display_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
cmp    $0xfe,%edi
jne    11d6 <display_data+0x56>
test   %r14d,%r14d
jle    1243 <display_data+0xc3>
mov    (%r15),%eax
add    $0xffffffff,%eax
cmp    $0x7,%eax
ja     1243 <display_data+0xc3>
lea    0xe48(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <lcd_startStream@plt>
cmp    $0xff,%edi
jne    1243 <display_data+0xc3>
cmp    $0x2,%r14d
jl     1243 <display_data+0xc3>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r15),%r12d
mov    0x4(%r15),%r13d
mov    %r12d,%ebp
sar    $0x4,%ebp
shl    $0x4,%r12d
mov    %r13d,%ebx
and    $0xf0,%ebx
shl    $0x4,%r13d
add    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12d,%edi
mov    %ebx,%esi
mov    %r13d,%edx
call   1050 <lcd_stream@plt>
add    $0xffffffff,%ebp
jne    1220 <display_data+0xa0>
add    $0x8,%r15
lea    -0x2(%r14),%eax
cmp    $0x3,%r14d
mov    %eax,%r14d
jg     11f0 <display_data+0x70>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    $0x6,%r14d
jne    1243 <display_data+0xc3>
mov    $0x300,%ebp
or     0x4(%r15),%ebp
mov    0x8(%r15),%r14d
mov    0xc(%r15),%r12d
mov    0x10(%r15),%ebx
nopl   (%rax)
mov    %r14d,%edi
mov    %r12d,%esi
mov    %ebx,%edx
call   1050 <lcd_stream@plt>
add    $0xffffffff,%ebp
jne    1270 <display_data+0xf0>
jmp    1243 <display_data+0xc3>
mov    0x4(%r15),%edi
mov    0x8(%r15),%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <lcdhal_write@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <lcd_stopStream@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <lcd_init@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10a0 <lcdhal_select@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <lcdhal_deselect@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <lcdhal_init@plt>

LLVM IR (-O0):
define void @display_data(i32 %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 254
br i1 %16, label %17, label %79
17: ; preds = %3
%18 = load i32, i32* %6
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %78
20: ; preds = %17
%21 = load i32*, i32** %5
%22 = getelementptr inbounds i32, i32* %21, i64 0
%23 = load i32, i32* %22
switch i32 %23, label %77 [
i32 1, label %24
i32 2, label %26
i32 3, label %28
i32 4, label %61
i32 5, label %63
i32 6, label %71
i32 7, label %73
i32 8, label %75
]
24: ; preds = %20
%25 = call i32 (...) @lcd_startStream()
br label %77
26: ; preds = %20
%27 = call i32 (...) @lcd_stopStream()
br label %77
28: ; preds = %20
%29 = load i32, i32* %6
%30 = icmp eq i32 %29, 6
br i1 %30, label %31, label %60
31: ; preds = %28
%32 = load i32*, i32** %5
%33 = getelementptr inbounds i32, i32* %32, i64 0
%34 = load i32, i32* %33
%35 = shl i32 %34, 8
store i32 %35, i32* %7
%36 = load i32*, i32** %5
%37 = getelementptr inbounds i32, i32* %36, i64 1
%38 = load i32, i32* %37
%39 = load i32, i32* %7
%40 = or i32 %39, %38
store i32 %40, i32* %7
%41 = load i32*, i32** %5
%42 = getelementptr inbounds i32, i32* %41, i64 2
%43 = load i32, i32* %42
store i32 %43, i32* %8
%44 = load i32*, i32** %5
%45 = getelementptr inbounds i32, i32* %44, i64 3
%46 = load i32, i32* %45
store i32 %46, i32* %9
%47 = load i32*, i32** %5
%48 = getelementptr inbounds i32, i32* %47, i64 4
%49 = load i32, i32* %48
store i32 %49, i32* %10
br label %50
50: ; preds = %54, %31
%51 = load i32, i32* %7
%52 = add nsw i32 %51, -1
store i32 %52, i32* %7
%53 = icmp ne i32 %51, 0
br i1 %53, label %54, label %59
54: ; preds = %50
%55 = load i32, i32* %8
%56 = load i32, i32* %9
%57 = load i32, i32* %10
%58 = call i32 @lcd_stream(i32 %55, i32 %56, i32 %57)
br label %50
59: ; preds = %50
br label %60
60: ; preds = %59, %28
br label %77
61: ; preds = %20
%62 = call i32 (...) @lcd_init()
br label %77
63: ; preds = %20
%64 = load i32*, i32** %5
%65 = getelementptr inbounds i32, i32* %64, i64 1
%66 = load i32, i32* %65
%67 = load i32*, i32** %5
%68 = getelementptr inbounds i32, i32* %67, i64 2
%69 = load i32, i32* %68
%70 = call i32 @lcdhal_write(i32 %66, i32 %69)
br label %77
71: ; preds = %20
%72 = call i32 (...) @lcdhal_select()
br label %77
73: ; preds = %20
%74 = call i32 (...) @lcdhal_deselect()
br label %77
75: ; preds = %20
%76 = call i32 (...) @lcdhal_init()
br label %77
77: ; preds = %20, %75, %73, %71, %63, %61, %60, %26, %24
br label %78
78: ; preds = %77, %17
br label %119
79: ; preds = %3
%80 = load i32, i32* %4
%81 = icmp eq i32 %80, 255
br i1 %81, label %82, label %118
82: ; preds = %79
br label %83
83: ; preds = %112, %82
%84 = load i32, i32* %6
%85 = icmp sge i32 %84, 2
br i1 %85, label %86, label %117
86: ; preds = %83
%87 = load i32*, i32** %5
%88 = getelementptr inbounds i32, i32* %87, i64 0
%89 = load i32, i32* %88
%90 = ashr i32 %89, 4
store i32 %90, i32* %11
%91 = load i32*, i32** %5
%92 = getelementptr inbounds i32, i32* %91, i64 0
%93 = load i32, i32* %92
%94 = shl i32 %93, 4
store i32 %94, i32* %12
%95 = load i32*, i32** %5
%96 = getelementptr inbounds i32, i32* %95, i64 1
%97 = load i32, i32* %96
%98 = and i32 %97, 240
store i32 %98, i32* %13
%99 = load i32*, i32** %5
%100 = getelementptr inbounds i32, i32* %99, i64 1
%101 = load i32, i32* %100
%102 = shl i32 %101, 4
store i32 %102, i32* %14
br label %103
103: ; preds = %108, %86
%104 = load i32, i32* %12
%105 = load i32, i32* %13
%106 = load i32, i32* %14
%107 = call i32 @lcd_stream(i32 %104, i32 %105, i32 %106)
br label %108
108: ; preds = %103
%109 = load i32, i32* %11
%110 = add nsw i32 %109, -1
store i32 %110, i32* %11
%111 = icmp ne i32 %109, 0
br i1 %111, label %103, label %112
112: ; preds = %108
%113 = load i32*, i32** %5
%114 = getelementptr inbounds i32, i32* %113, i64 2
store i32* %114, i32** %5
%115 = load i32, i32* %6
%116 = sub nsw i32 %115, 2
store i32 %116, i32* %6
br label %83
117: ; preds = %83
br label %118
118: ; preds = %117, %79
br label %119
119: ; preds = %118, %78
ret void
}

LLVM IR (-O2):
define void @display_data(i32 %0, i32* nocapture %1, i32 %2) {
%4 = icmp eq i32 %0, 254
br i1 %4, label %5, label %44
5: ; preds = %3
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %67
7: ; preds = %5
%8 = load i32, i32* %1
switch i32 %8, label %67 [
i32 1, label %9
i32 2, label %11
i32 3, label %13
i32 4, label %30
i32 5, label %32
i32 6, label %38
i32 7, label %40
i32 8, label %42
]
9: ; preds = %7
%10 = tail call i32 (...) @lcd_startStream()
br label %67
11: ; preds = %7
%12 = tail call i32 (...) @lcd_stopStream()
br label %67
13: ; preds = %7
%14 = icmp eq i32 %2, 6
br i1 %14, label %15, label %67
15: ; preds = %13
%16 = getelementptr inbounds i32, i32* %1, i64 1
%17 = load i32, i32* %16
%18 = or i32 %17, 768
%19 = getelementptr inbounds i32, i32* %1, i64 2
%20 = load i32, i32* %19
%21 = getelementptr inbounds i32, i32* %1, i64 3
%22 = load i32, i32* %21
%23 = getelementptr inbounds i32, i32* %1, i64 4
%24 = load i32, i32* %23
br label %25
25: ; preds = %15, %25
%26 = phi i32 [ %18, %15 ], [ %27, %25 ]
%27 = add nsw i32 %26, -1
%28 = tail call i32 @lcd_stream(i32 %20, i32 %22, i32 %24)
%29 = icmp eq i32 %27, 0
br i1 %29, label %67, label %25
30: ; preds = %7
%31 = tail call i32 (...) @lcd_init()
br label %67
32: ; preds = %7
%33 = getelementptr inbounds i32, i32* %1, i64 1
%34 = load i32, i32* %33
%35 = getelementptr inbounds i32, i32* %1, i64 2
%36 = load i32, i32* %35
%37 = tail call i32 @lcdhal_write(i32 %34, i32 %36)
br label %67
38: ; preds = %7
%39 = tail call i32 (...) @lcdhal_select()
br label %67
40: ; preds = %7
%41 = tail call i32 (...) @lcdhal_deselect()
br label %67
42: ; preds = %7
%43 = tail call i32 (...) @lcdhal_init()
br label %67
44: ; preds = %3
%45 = icmp eq i32 %0, 255
%46 = icmp sgt i32 %2, 1
%47 = and i1 %45, %46
br i1 %47, label %48, label %67
48: ; preds = %44, %63
%49 = phi i32 [ %65, %63 ], [ %2, %44 ]
%50 = phi i32* [ %64, %63 ], [ %1, %44 ]
%51 = load i32, i32* %50
%52 = ashr i32 %51, 4
%53 = shl i32 %51, 4
%54 = getelementptr inbounds i32, i32* %50, i64 1
%55 = load i32, i32* %54
%56 = and i32 %55, 240
%57 = shl i32 %55, 4
br label %58
58: ; preds = %58, %48
%59 = phi i32 [ %52, %48 ], [ %61, %58 ]
%60 = tail call i32 @lcd_stream(i32 %53, i32 %56, i32 %57)
%61 = add nsw i32 %59, -1
%62 = icmp eq i32 %59, 0
br i1 %62, label %63, label %58
63: ; preds = %58
%64 = getelementptr inbounds i32, i32* %50, i64 2
%65 = add nsw i32 %49, -2
%66 = icmp sgt i32 %49, 3
br i1 %66, label %48, label %67
67: ; preds = %63, %25, %44, %5, %13, %7, %42, %40, %38, %32, %30, %11, %9
ret void
}