#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*/ LCDSetLine(int, int, int, int, int);
int /*<<< orphan*/ WriteSpiCommand(int);
int /*<<< orphan*/ WriteSpiData(int);
void LCDSetRect(int x0, int y0, int x1, int y1, unsigned char fill, int color) {
  int xmin, xmax, ymin, ymax;
  int i;
  if (fill == 1) {
    xmin = (x0 <= x1) ? x0 : x1;
    xmax = (x0 > x1) ? x0 : x1;
    ymin = (y0 <= y1) ? y0 : y1;
    ymax = (y0 > y1) ? y0 : y1;
    WriteSpiCommand(0x75);
    WriteSpiData(xmin);
    WriteSpiData(xmax);
    WriteSpiCommand(0x15);
    WriteSpiData(ymin);
    WriteSpiData(ymax);
    WriteSpiCommand(0x5C);
    for (i = 0; i < ((((xmax - xmin + 1) * (ymax - ymin + 1)) / 2) + 130);
         i++) {
      WriteSpiData((color >> 4) & 0xFF);
      WriteSpiData(((color & 0xF) << 4) | ((color >> 8) & 0xF));
      WriteSpiData(color & 0xFF);
    }
  } else {
    LCDSetLine(x0, y0, x1, y0, color);
    LCDSetLine(x0, y1, x1, y1, color);
    LCDSetLine(x0, y0, x0, y1, color);
    LCDSetLine(x1, y0, x1, y1, color);
  }
}


x86 assembly (clang, -O0):
<LCDSetRect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %r8b,%al
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %r9d,-0x18(%rbp)
movzbl -0x11(%rbp),%eax
cmp    $0x1,%eax
jne    12ad <LCDSetRect+0x17d>
mov    -0x4(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1172 <LCDSetRect+0x42>
mov    -0x4(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    1178 <LCDSetRect+0x48>
mov    -0xc(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    1195 <LCDSetRect+0x65>
mov    -0x4(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    119b <LCDSetRect+0x6b>
mov    -0xc(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11b8 <LCDSetRect+0x88>
mov    -0x8(%rbp),%eax
mov    %eax,-0x38(%rbp)
jmp    11be <LCDSetRect+0x8e>
mov    -0x10(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    11db <LCDSetRect+0xab>
mov    -0x8(%rbp),%eax
mov    %eax,-0x3c(%rbp)
jmp    11e1 <LCDSetRect+0xb1>
mov    -0x10(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    $0x75,%edi
call   1040 <WriteSpiCommand@plt>
mov    -0x1c(%rbp),%edi
call   1050 <WriteSpiData@plt>
mov    -0x20(%rbp),%edi
call   1050 <WriteSpiData@plt>
mov    $0x15,%edi
call   1040 <WriteSpiCommand@plt>
mov    -0x24(%rbp),%edi
call   1050 <WriteSpiData@plt>
mov    -0x28(%rbp),%edi
call   1050 <WriteSpiData@plt>
mov    $0x5c,%edi
call   1040 <WriteSpiCommand@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x20(%rbp),%eax
sub    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    -0x28(%rbp),%ecx
sub    -0x24(%rbp),%ecx
add    $0x1,%ecx
imul   %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
add    $0x82,%ecx
cmp    %ecx,%eax
jge    12a8 <LCDSetRect+0x178>
mov    -0x18(%rbp),%edi
sar    $0x4,%edi
and    $0xff,%edi
call   1050 <WriteSpiData@plt>
mov    -0x18(%rbp),%edi
and    $0xf,%edi
shl    $0x4,%edi
mov    -0x18(%rbp),%eax
sar    $0x8,%eax
and    $0xf,%eax
or     %eax,%edi
call   1050 <WriteSpiData@plt>
mov    -0x18(%rbp),%edi
and    $0xff,%edi
call   1050 <WriteSpiData@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    122c <LCDSetRect+0xfc>
jmp    1301 <LCDSetRect+0x1d1>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%ecx
mov    -0x18(%rbp),%r8d
call   1030 <LCDSetLine@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x18(%rbp),%r8d
call   1030 <LCDSetLine@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x4(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x18(%rbp),%r8d
call   1030 <LCDSetLine@plt>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x18(%rbp),%r8d
call   1030 <LCDSetLine@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LCDSetRect>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%ebp
mov    %ecx,%r12d
mov    %edx,%r14d
mov    %esi,%r15d
mov    %edi,%ebx
cmp    $0x1,%r8b
jne    122b <LCDSetRect+0xfb>
mov    %ebp,0x4(%rsp)
cmp    %r14d,%ebx
mov    %ebx,%ebp
cmovg  %r14d,%ebp
cmovg  %ebx,%r14d
cmp    %r12d,%r15d
mov    %r15d,%r13d
cmovg  %r12d,%r13d
cmovg  %r15d,%r12d
mov    $0x75,%edi
call   1040 <WriteSpiCommand@plt>
mov    %ebp,%edi
call   1050 <WriteSpiData@plt>
mov    %r14d,%edi
call   1050 <WriteSpiData@plt>
mov    $0x15,%edi
call   1040 <WriteSpiCommand@plt>
mov    %r13d,%edi
call   1050 <WriteSpiData@plt>
mov    %r12d,%edi
call   1050 <WriteSpiData@plt>
mov    $0x5c,%edi
call   1040 <WriteSpiCommand@plt>
sub    %ebp,%r14d
add    $0x1,%r14d
sub    %r13d,%r12d
add    $0x1,%r12d
imul   %r14d,%r12d
cmp    $0xfffffefd,%r12d
jl     121c <LCDSetRect+0xec>
mov    %r12d,%ebp
shr    $0x1f,%ebp
add    %r12d,%ebp
sar    %ebp
mov    0x4(%rsp),%ecx
mov    %ecx,%eax
shr    $0x4,%eax
movzbl %al,%r14d
mov    %ecx,%eax
shl    $0x4,%eax
movzbl %al,%eax
mov    %ecx,%ebx
shr    $0x8,%ebx
and    $0xf,%ebx
or     %eax,%ebx
movzbl %cl,%r15d
add    $0x82,%ebp
xchg   %ax,%ax
mov    %r14d,%edi
call   1050 <WriteSpiData@plt>
mov    %ebx,%edi
call   1050 <WriteSpiData@plt>
mov    %r15d,%edi
call   1050 <WriteSpiData@plt>
add    $0xffffffff,%ebp
jne    1200 <LCDSetRect+0xd0>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebx,%edi
mov    %r15d,%esi
mov    %r14d,%edx
mov    %r15d,%ecx
mov    %ebp,%r8d
call   1030 <LCDSetLine@plt>
mov    %ebx,%edi
mov    %r12d,%esi
mov    %r14d,%edx
mov    %r12d,%ecx
mov    %ebp,%r8d
call   1030 <LCDSetLine@plt>
mov    %ebx,%edi
mov    %r15d,%esi
mov    %ebx,%edx
mov    %r12d,%ecx
mov    %ebp,%r8d
call   1030 <LCDSetLine@plt>
mov    %r14d,%edi
mov    %r15d,%esi
mov    %r14d,%edx
mov    %r12d,%ecx
mov    %ebp,%r8d
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <LCDSetLine@plt>

LLVM IR (-O0):
define void @LCDSetRect(i32 %0, i32 %1, i32 %2, i32 %3, i8 zeroext %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i8 %4, i8* %11
store i32 %5, i32* %12
%18 = load i8, i8* %11
%19 = zext i8 %18 to i32
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %103
21: ; preds = %6
%22 = load i32, i32* %7
%23 = load i32, i32* %9
%24 = icmp sle i32 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = load i32, i32* %7
br label %29
27: ; preds = %21
%28 = load i32, i32* %9
br label %29
29: ; preds = %27, %25
%30 = phi i32 [ %26, %25 ], [ %28, %27 ]
store i32 %30, i32* %13
%31 = load i32, i32* %7
%32 = load i32, i32* %9
%33 = icmp sgt i32 %31, %32
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = load i32, i32* %7
br label %38
36: ; preds = %29
%37 = load i32, i32* %9
br label %38
38: ; preds = %36, %34
%39 = phi i32 [ %35, %34 ], [ %37, %36 ]
store i32 %39, i32* %14
%40 = load i32, i32* %8
%41 = load i32, i32* %10
%42 = icmp sle i32 %40, %41
br i1 %42, label %43, label %45
43: ; preds = %38
%44 = load i32, i32* %8
br label %47
45: ; preds = %38
%46 = load i32, i32* %10
br label %47
47: ; preds = %45, %43
%48 = phi i32 [ %44, %43 ], [ %46, %45 ]
store i32 %48, i32* %15
%49 = load i32, i32* %8
%50 = load i32, i32* %10
%51 = icmp sgt i32 %49, %50
br i1 %51, label %52, label %54
52: ; preds = %47
%53 = load i32, i32* %8
br label %56
54: ; preds = %47
%55 = load i32, i32* %10
br label %56
56: ; preds = %54, %52
%57 = phi i32 [ %53, %52 ], [ %55, %54 ]
store i32 %57, i32* %16
%58 = call i32 @WriteSpiCommand(i32 117)
%59 = load i32, i32* %13
%60 = call i32 @WriteSpiData(i32 %59)
%61 = load i32, i32* %14
%62 = call i32 @WriteSpiData(i32 %61)
%63 = call i32 @WriteSpiCommand(i32 21)
%64 = load i32, i32* %15
%65 = call i32 @WriteSpiData(i32 %64)
%66 = load i32, i32* %16
%67 = call i32 @WriteSpiData(i32 %66)
%68 = call i32 @WriteSpiCommand(i32 92)
store i32 0, i32* %17
br label %69
69: ; preds = %99, %56
%70 = load i32, i32* %17
%71 = load i32, i32* %14
%72 = load i32, i32* %13
%73 = sub nsw i32 %71, %72
%74 = add nsw i32 %73, 1
%75 = load i32, i32* %16
%76 = load i32, i32* %15
%77 = sub nsw i32 %75, %76
%78 = add nsw i32 %77, 1
%79 = mul nsw i32 %74, %78
%80 = sdiv i32 %79, 2
%81 = add nsw i32 %80, 130
%82 = icmp slt i32 %70, %81
br i1 %82, label %83, label %102
83: ; preds = %69
%84 = load i32, i32* %12
%85 = ashr i32 %84, 4
%86 = and i32 %85, 255
%87 = call i32 @WriteSpiData(i32 %86)
%88 = load i32, i32* %12
%89 = and i32 %88, 15
%90 = shl i32 %89, 4
%91 = load i32, i32* %12
%92 = ashr i32 %91, 8
%93 = and i32 %92, 15
%94 = or i32 %90, %93
%95 = call i32 @WriteSpiData(i32 %94)
%96 = load i32, i32* %12
%97 = and i32 %96, 255
%98 = call i32 @WriteSpiData(i32 %97)
br label %99
99: ; preds = %83
%100 = load i32, i32* %17
%101 = add nsw i32 %100, 1
store i32 %101, i32* %17
br label %69
102: ; preds = %69
br label %128
103: ; preds = %6
%104 = load i32, i32* %7
%105 = load i32, i32* %8
%106 = load i32, i32* %9
%107 = load i32, i32* %8
%108 = load i32, i32* %12
%109 = call i32 @LCDSetLine(i32 %104, i32 %105, i32 %106, i32 %107, i32 %108)
%110 = load i32, i32* %7
%111 = load i32, i32* %10
%112 = load i32, i32* %9
%113 = load i32, i32* %10
%114 = load i32, i32* %12
%115 = call i32 @LCDSetLine(i32 %110, i32 %111, i32 %112, i32 %113, i32 %114)
%116 = load i32, i32* %7
%117 = load i32, i32* %8
%118 = load i32, i32* %7
%119 = load i32, i32* %10
%120 = load i32, i32* %12
%121 = call i32 @LCDSetLine(i32 %116, i32 %117, i32 %118, i32 %119, i32 %120)
%122 = load i32, i32* %9
%123 = load i32, i32* %8
%124 = load i32, i32* %9
%125 = load i32, i32* %10
%126 = load i32, i32* %12
%127 = call i32 @LCDSetLine(i32 %122, i32 %123, i32 %124, i32 %125, i32 %126)
br label %128
128: ; preds = %103, %102
ret void
}

LLVM IR (-O2):
define void @LCDSetRect(i32 %0, i32 %1, i32 %2, i32 %3, i8 zeroext %4, i32 %5) {
%7 = icmp eq i8 %4, 1
br i1 %7, label %8, label %46
8: ; preds = %6
%9 = icmp sgt i32 %0, %2
%10 = select i1 %9, i32 %2, i32 %0
%11 = select i1 %9, i32 %0, i32 %2
%12 = icmp sgt i32 %1, %3
%13 = select i1 %12, i32 %3, i32 %1
%14 = select i1 %12, i32 %1, i32 %3
%15 = tail call i32 @WriteSpiCommand(i32 117)
%16 = tail call i32 @WriteSpiData(i32 %10)
%17 = tail call i32 @WriteSpiData(i32 %11)
%18 = tail call i32 @WriteSpiCommand(i32 21)
%19 = tail call i32 @WriteSpiData(i32 %13)
%20 = tail call i32 @WriteSpiData(i32 %14)
%21 = tail call i32 @WriteSpiCommand(i32 92)
%22 = sub i32 1, %10
%23 = add i32 %22, %11
%24 = sub i32 1, %13
%25 = add i32 %24, %14
%26 = mul nsw i32 %25, %23
%27 = icmp sgt i32 %26, -260
br i1 %27, label %28, label %51
28: ; preds = %8
%29 = sdiv i32 %26, 2
%30 = lshr i32 %5, 4
%31 = and i32 %30, 255
%32 = shl i32 %5, 4
%33 = and i32 %32, 240
%34 = lshr i32 %5, 8
%35 = and i32 %34, 15
%36 = or i32 %33, %35
%37 = and i32 %5, 255
%38 = add nsw i32 %29, 129
br label %39
39: ; preds = %28, %39
%40 = phi i32 [ 0, %28 ], [ %44, %39 ]
%41 = tail call i32 @WriteSpiData(i32 %31)
%42 = tail call i32 @WriteSpiData(i32 %36)
%43 = tail call i32 @WriteSpiData(i32 %37)
%44 = add nuw nsw i32 %40, 1
%45 = icmp eq i32 %40, %38
br i1 %45, label %51, label %39
46: ; preds = %6
%47 = tail call i32 @LCDSetLine(i32 %0, i32 %1, i32 %2, i32 %1, i32 %5)
%48 = tail call i32 @LCDSetLine(i32 %0, i32 %3, i32 %2, i32 %3, i32 %5)
%49 = tail call i32 @LCDSetLine(i32 %0, i32 %1, i32 %0, i32 %3, i32 %5)
%50 = tail call i32 @LCDSetLine(i32 %2, i32 %1, i32 %2, i32 %3, i32 %5)
br label %51
51: ; preds = %39, %8, %46
ret void
}