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

/* Variables and functions */
int /*<<< orphan*/ SendCMD(int);
int /*<<< orphan*/ SendData(int);
void rawFillRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h,
                 uint16_t fillcolor) {
  uint16_t i;
  if ((x >= 128) || (y >= 128)) {
    return;
  }
  if (y + h > 128) {
    h = 128 - y - 1;
  }
  if ((x + w) > 128) {
    w = 128 - x - 1;
  }
  SendCMD(0x15);
  SendData(x);
  SendData(x + w - 1);
  SendCMD(0x75);
  SendData(y);
  SendData(y + h - 1);
  SendCMD(0x5C);
  for (i = 0; i < (w * h); i++) {
    SendData(fillcolor >> 8);
    SendData(fillcolor);
  }
}


x86 assembly (clang, -O0):
<rawFillRect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8d,-0x14(%rbp)
cmpl   $0x80,-0x4(%rbp)
jge    1152 <rawFillRect+0x32>
cmpl   $0x80,-0x8(%rbp)
jl     1157 <rawFillRect+0x37>
jmp    1219 <rawFillRect+0xf9>
mov    -0x8(%rbp),%eax
add    -0x10(%rbp),%eax
cmp    $0x80,%eax
jle    1176 <rawFillRect+0x56>
mov    $0x80,%eax
sub    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    -0xc(%rbp),%eax
cmp    $0x80,%eax
jle    1195 <rawFillRect+0x75>
mov    $0x80,%eax
sub    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    $0x15,%edi
call   1030 <SendCMD@plt>
mov    -0x4(%rbp),%edi
call   1040 <SendData@plt>
mov    -0x4(%rbp),%edi
add    -0xc(%rbp),%edi
sub    $0x1,%edi
call   1040 <SendData@plt>
mov    $0x75,%edi
call   1030 <SendCMD@plt>
mov    -0x8(%rbp),%edi
call   1040 <SendData@plt>
mov    -0x8(%rbp),%edi
add    -0x10(%rbp),%edi
sub    $0x1,%edi
call   1040 <SendData@plt>
mov    $0x5c,%edi
call   1030 <SendCMD@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0xc(%rbp),%ecx
imul   -0x10(%rbp),%ecx
cmp    %ecx,%eax
jge    1219 <rawFillRect+0xf9>
mov    -0x14(%rbp),%edi
sar    $0x8,%edi
call   1040 <SendData@plt>
mov    -0x14(%rbp),%edi
call   1040 <SendData@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11e6 <rawFillRect+0xc6>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rawFillRect>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x7f,%edi
jg     11d4 <rawFillRect+0xb4>
mov    %esi,%r14d
cmp    $0x7f,%esi
jg     11d4 <rawFillRect+0xb4>
mov    %r8d,%r12d
mov    %edi,%r15d
lea    (%rcx,%r14,1),%eax
mov    $0x7f,%ebx
mov    $0x7f,%ebp
sub    %r14d,%ebp
cmp    $0x81,%eax
cmovl  %ecx,%ebp
lea    (%rdx,%r15,1),%eax
sub    %edi,%ebx
cmp    $0x81,%eax
cmovl  %edx,%ebx
mov    $0x15,%edi
call   1030 <SendCMD@plt>
mov    %r15d,%edi
call   1040 <SendData@plt>
lea    (%r15,%rbx,1),%edi
add    $0xffffffff,%edi
call   1040 <SendData@plt>
mov    $0x75,%edi
call   1030 <SendCMD@plt>
mov    %r14d,%edi
call   1040 <SendData@plt>
lea    (%r14,%rbp,1),%edi
add    $0xffffffff,%edi
call   1040 <SendData@plt>
mov    $0x5c,%edi
call   1030 <SendCMD@plt>
imul   %ebp,%ebx
test   %ebx,%ebx
jle    11d4 <rawFillRect+0xb4>
mov    %r12d,%ebp
sar    $0x8,%ebp
nopl   (%rax)
mov    %ebp,%edi
call   1040 <SendData@plt>
mov    %r12d,%edi
call   1040 <SendData@plt>
add    $0xffffffff,%ebx
jne    11c0 <rawFillRect+0xa0>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @rawFillRect(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%12 = load i32, i32* %6
%13 = icmp sge i32 %12, 128
br i1 %13, label %17, label %14
14: ; preds = %5
%15 = load i32, i32* %7
%16 = icmp sge i32 %15, 128
br i1 %16, label %17, label %18
17: ; preds = %14, %5
br label %69
18: ; preds = %14
%19 = load i32, i32* %7
%20 = load i32, i32* %9
%21 = add nsw i32 %19, %20
%22 = icmp sgt i32 %21, 128
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = load i32, i32* %7
%25 = sub nsw i32 128, %24
%26 = sub nsw i32 %25, 1
store i32 %26, i32* %9
br label %27
27: ; preds = %23, %18
%28 = load i32, i32* %6
%29 = load i32, i32* %8
%30 = add nsw i32 %28, %29
%31 = icmp sgt i32 %30, 128
br i1 %31, label %32, label %36
32: ; preds = %27
%33 = load i32, i32* %6
%34 = sub nsw i32 128, %33
%35 = sub nsw i32 %34, 1
store i32 %35, i32* %8
br label %36
36: ; preds = %32, %27
%37 = call i32 @SendCMD(i32 21)
%38 = load i32, i32* %6
%39 = call i32 @SendData(i32 %38)
%40 = load i32, i32* %6
%41 = load i32, i32* %8
%42 = add nsw i32 %40, %41
%43 = sub nsw i32 %42, 1
%44 = call i32 @SendData(i32 %43)
%45 = call i32 @SendCMD(i32 117)
%46 = load i32, i32* %7
%47 = call i32 @SendData(i32 %46)
%48 = load i32, i32* %7
%49 = load i32, i32* %9
%50 = add nsw i32 %48, %49
%51 = sub nsw i32 %50, 1
%52 = call i32 @SendData(i32 %51)
%53 = call i32 @SendCMD(i32 92)
store i32 0, i32* %11
br label %54
54: ; preds = %66, %36
%55 = load i32, i32* %11
%56 = load i32, i32* %8
%57 = load i32, i32* %9
%58 = mul nsw i32 %56, %57
%59 = icmp slt i32 %55, %58
br i1 %59, label %60, label %69
60: ; preds = %54
%61 = load i32, i32* %10
%62 = ashr i32 %61, 8
%63 = call i32 @SendData(i32 %62)
%64 = load i32, i32* %10
%65 = call i32 @SendData(i32 %64)
br label %66
66: ; preds = %60
%67 = load i32, i32* %11
%68 = add nsw i32 %67, 1
store i32 %68, i32* %11
br label %54
69: ; preds = %17, %54
ret void
}

LLVM IR (-O2):
define void @rawFillRect(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = icmp sgt i32 %0, 127
%7 = icmp sgt i32 %1, 127
%8 = or i1 %6, %7
br i1 %8, label %39, label %9
9: ; preds = %5
%10 = add nsw i32 %3, %1
%11 = icmp sgt i32 %10, 128
%12 = sub i32 127, %1
%13 = select i1 %11, i32 %12, i32 %3
%14 = add nsw i32 %2, %0
%15 = icmp sgt i32 %14, 128
%16 = sub i32 127, %0
%17 = select i1 %15, i32 %16, i32 %2
%18 = tail call i32 @SendCMD(i32 21)
%19 = tail call i32 @SendData(i32 %0)
%20 = add i32 %0, -1
%21 = add i32 %20, %17
%22 = tail call i32 @SendData(i32 %21)
%23 = tail call i32 @SendCMD(i32 117)
%24 = tail call i32 @SendData(i32 %1)
%25 = add i32 %1, -1
%26 = add i32 %25, %13
%27 = tail call i32 @SendData(i32 %26)
%28 = tail call i32 @SendCMD(i32 92)
%29 = mul i32 %13, %17
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %39
31: ; preds = %9
%32 = ashr i32 %4, 8
br label %33
33: ; preds = %31, %33
%34 = phi i32 [ 0, %31 ], [ %37, %33 ]
%35 = tail call i32 @SendData(i32 %32)
%36 = tail call i32 @SendData(i32 %4)
%37 = add nuw nsw i32 %34, 1
%38 = icmp eq i32 %37, %29
br i1 %38, label %39, label %33
39: ; preds = %33, %9, %5
ret void
}