#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*/ WriteSpiCommand(int);
int /*<<< orphan*/ WriteSpiData(unsigned int);
void LCDPutChar(char c, int x, int y, int size, int fColor, int bColor) {
  extern const unsigned char FONT6x8[97][8];
  extern const unsigned char FONT8x8[97][8];
  extern const unsigned char FONT8x16[97][16];
  int i, j;
  unsigned int nCols;
  unsigned int nRows;
  unsigned int nBytes;
  unsigned char PixelRow;
  unsigned char Mask;
  unsigned int Word0;
  unsigned int Word1;
  unsigned char *pFont;
  unsigned char *pChar;
  unsigned char *FontTable[] = {(unsigned char *)FONT6x8,
                                (unsigned char *)FONT8x8,
                                (unsigned char *)FONT8x16};
  pFont = (unsigned char *)FontTable[size];
  nCols = *pFont;
  nRows = *(pFont + 1);
  nBytes = *(pFont + 2);
  pChar = pFont + (nBytes * (c - 0x1F)) + nBytes - 1;
  WriteSpiCommand(0x75);
  WriteSpiData(x);
  WriteSpiData(x + nRows - 1);
  WriteSpiCommand(0x15);
  WriteSpiData(y);
  WriteSpiData(y + nCols - 1);
  WriteSpiCommand(0x5C);
  for (i = nRows - 1; i >= 0; i--) {
    PixelRow = *pChar--;
    Mask = 0x80;
    for (j = 0; j < nCols; j += 2) {
      if ((PixelRow & Mask) == 0)
        Word0 = bColor;
      else
        Word0 = fColor;
      Mask = Mask >> 1;
      if ((PixelRow & Mask) == 0)
        Word1 = bColor;
      else
        Word1 = fColor;
      Mask = Mask >> 1;
      WriteSpiData((Word0 >> 4) & 0xFF);
      WriteSpiData(((Word0 & 0xF) << 4) | ((Word1 >> 8) & 0xF));
      WriteSpiData(Word1 & 0xFF);
    }
  }
  WriteSpiCommand(0x25);
}


x86 assembly (clang, -O0):
<LCDPutChar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8d,-0x14(%rbp)
mov    %r9d,-0x18(%rbp)
mov    0x2cba(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0x2cb7(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    0x2cb4(%rip),%rax
mov    %rax,-0x50(%rbp)
movslq -0x10(%rbp),%rax
mov    -0x60(%rbp,%rax,8),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x40(%rbp),%rax
movzbl 0x1(%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x40(%rbp),%rax
movzbl 0x2(%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x40(%rbp),%rax
mov    -0x2c(%rbp),%ecx
movsbl -0x1(%rbp),%edx
sub    $0x1f,%edx
imul   %edx,%ecx
mov    %ecx,%ecx
add    %rcx,%rax
mov    -0x2c(%rbp),%ecx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x48(%rbp)
mov    $0x75,%edi
call   1030 <WriteSpiCommand@plt>
mov    -0x8(%rbp),%edi
call   1040 <WriteSpiData@plt>
mov    -0x8(%rbp),%edi
add    -0x28(%rbp),%edi
sub    $0x1,%edi
call   1040 <WriteSpiData@plt>
mov    $0x15,%edi
call   1030 <WriteSpiCommand@plt>
mov    -0xc(%rbp),%edi
call   1040 <WriteSpiData@plt>
mov    -0xc(%rbp),%edi
add    -0x24(%rbp),%edi
sub    $0x1,%edi
call   1040 <WriteSpiData@plt>
mov    $0x5c,%edi
call   1030 <WriteSpiCommand@plt>
mov    -0x28(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     12ee <LCDPutChar+0x1ce>
mov    -0x48(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x48(%rbp)
mov    (%rax),%al
mov    %al,-0x2d(%rbp)
movb   $0x80,-0x2e(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jae    12db <LCDPutChar+0x1bb>
movzbl -0x2d(%rbp),%eax
movzbl -0x2e(%rbp),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
jne    1257 <LCDPutChar+0x137>
mov    -0x18(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    125d <LCDPutChar+0x13d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
movzbl -0x2e(%rbp),%eax
sar    $0x1,%eax
mov    %al,-0x2e(%rbp)
movzbl -0x2d(%rbp),%eax
movzbl -0x2e(%rbp),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
jne    1285 <LCDPutChar+0x165>
mov    -0x18(%rbp),%eax
mov    %eax,-0x38(%rbp)
jmp    128b <LCDPutChar+0x16b>
mov    -0x14(%rbp),%eax
mov    %eax,-0x38(%rbp)
movzbl -0x2e(%rbp),%eax
sar    $0x1,%eax
mov    %al,-0x2e(%rbp)
mov    -0x34(%rbp),%edi
shr    $0x4,%edi
and    $0xff,%edi
call   1040 <WriteSpiData@plt>
mov    -0x34(%rbp),%edi
and    $0xf,%edi
shl    $0x4,%edi
mov    -0x38(%rbp),%eax
shr    $0x8,%eax
and    $0xf,%eax
or     %eax,%edi
call   1040 <WriteSpiData@plt>
mov    -0x38(%rbp),%edi
and    $0xff,%edi
call   1040 <WriteSpiData@plt>
mov    -0x20(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x20(%rbp)
jmp    122d <LCDPutChar+0x10d>
jmp    12e0 <LCDPutChar+0x1c0>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1204 <LCDPutChar+0xe4>
mov    $0x25,%edi
call   1030 <WriteSpiCommand@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LCDPutChar>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9d,%r14d
mov    %r8d,0xc(%rsp)
mov    %edx,%r12d
mov    %esi,%ebx
mov    %edi,0x18(%rsp)
movslq %ecx,%rax
lea    0x2cb7(%rip),%rcx
mov    (%rcx,%rax,8),%rax
movzbl (%rax),%r13d
movzbl 0x1(%rax),%ebp
mov    %rax,0x10(%rsp)
movzbl 0x2(%rax),%r15d
mov    $0x75,%edi
call   1030 <WriteSpiCommand@plt>
mov    %ebx,%edi
call   1040 <WriteSpiData@plt>
lea    (%rbx,%rbp,1),%edi
add    $0xffffffff,%edi
call   1040 <WriteSpiData@plt>
mov    $0x15,%edi
call   1030 <WriteSpiCommand@plt>
mov    %r12d,%edi
call   1040 <WriteSpiData@plt>
mov    %r13,0x20(%rsp)
lea    (%r12,%r13,1),%edi
add    $0xffffffff,%edi
call   1040 <WriteSpiData@plt>
mov    $0x5c,%edi
call   1030 <WriteSpiCommand@plt>
test   %ebp,%ebp
je     126d <LCDPutChar+0x14d>
movsbl 0x18(%rsp),%eax
add    $0xffffffe1,%eax
mov    %r15d,%ecx
imul   %eax,%ecx
mov    0x10(%rsp),%rbx
add    %rcx,%rbx
add    %r15,%rbx
mov    %rbx,0x10(%rsp)
jmp    11e3 <LCDPutChar+0xc3>
mov    0x18(%rsp),%rcx
lea    -0x1(%rcx),%eax
cmp    $0x2,%ecx
mov    %eax,%ebp
jl     126d <LCDPutChar+0x14d>
mov    %rbp,0x18(%rsp)
addq   $0xffffffffffffffff,0x10(%rsp)
cmpb   $0x0,0x20(%rsp)
je     11d0 <LCDPutChar+0xb0>
mov    0x10(%rsp),%rax
movzbl (%rax),%ebp
xor    %r13d,%r13d
mov    $0x80,%r15d
jmp    124b <LCDPutChar+0x12b>
nopl   0x0(%rax,%rax,1)
shr    %r15d
mov    %r12d,%eax
shr    $0x4,%eax
movzbl %al,%edi
call   1040 <WriteSpiData@plt>
shl    $0x4,%r12d
movzbl %r12b,%eax
mov    %ebx,%edi
shr    $0x8,%edi
and    $0xf,%edi
or     %eax,%edi
call   1040 <WriteSpiData@plt>
movzbl %bl,%edi
call   1040 <WriteSpiData@plt>
add    $0x2,%r13d
cmp    0x20(%rsp),%r13d
jae    11d0 <LCDPutChar+0xb0>
mov    %r14d,%r12d
test   %ebp,%r15d
je     1258 <LCDPutChar+0x138>
mov    0xc(%rsp),%r12d
shr    %r15d
and    $0x7f,%r15d
mov    %r14d,%ebx
test   %ebp,%r15d
je     1210 <LCDPutChar+0xf0>
mov    0xc(%rsp),%ebx
jmp    1210 <LCDPutChar+0xf0>
mov    $0x25,%edi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <WriteSpiCommand@plt>

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

LLVM IR (-O2):
@FONT6x8 = external constant [97 x [8 x i8]]
@FONT8x8 = external constant [97 x [8 x i8]]
@FONT8x16 = external constant [97 x [16 x i8]]
@__const.LCDPutChar.FontTable = [3 x i8*] [i8* getelementptr inbounds ([97 x [8 x i8]], [97 x [8 x i8]]* @FONT6x8, i32 0, i32 0, i32 0), i8* getelementptr inbounds ([97 x [8 x i8]], [97 x [8 x i8]]* @FONT8x8, i32 0, i32 0, i32 0), i8* getelementptr inbounds ([97 x [16 x i8]], [97 x [16 x i8]]* @FONT8x16, i32 0, i32 0, i32 0)]
define void @LCDPutChar(i8 signext %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = sext i32 %3 to i64
%8 = getelementptr inbounds [3 x i8*], [3 x i8*]* @__const.LCDPutChar.FontTable, i64 0, i64 %7
%9 = load i8*, i8** %8
%10 = load i8, i8* %9
%11 = zext i8 %10 to i32
%12 = getelementptr inbounds i8, i8* %9, i64 1
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = getelementptr inbounds i8, i8* %9, i64 2
%16 = load i8, i8* %15
%17 = zext i8 %16 to i64
%18 = tail call i32 @WriteSpiCommand(i32 117)
%19 = tail call i32 @WriteSpiData(i32 %1)
%20 = add i32 %1, -1
%21 = add i32 %20, %14
%22 = tail call i32 @WriteSpiData(i32 %21)
%23 = tail call i32 @WriteSpiCommand(i32 21)
%24 = tail call i32 @WriteSpiData(i32 %2)
%25 = add i32 %2, -1
%26 = add i32 %25, %11
%27 = tail call i32 @WriteSpiData(i32 %26)
%28 = tail call i32 @WriteSpiCommand(i32 92)
%29 = icmp eq i8 %13, 0
br i1 %29, label %73, label %30
30: ; preds = %6
%31 = sext i8 %0 to i64
%32 = add nsw i64 %31, 4294967265
%33 = mul nuw nsw i64 %32, %17
%34 = and i64 %33, 4294967295
%35 = getelementptr inbounds i8, i8* %9, i64 %34
%36 = getelementptr inbounds i8, i8* %35, i64 %17
%37 = icmp eq i8 %10, 0
br label %40
38: ; preds = %48, %40
%39 = icmp sgt i32 %41, 1
br i1 %39, label %40, label %73
40: ; preds = %30, %38
%41 = phi i32 [ %14, %30 ], [ %44, %38 ]
%42 = phi i8* [ %36, %30 ], [ %43, %38 ]
%43 = getelementptr inbounds i8, i8* %42, i64 -1
%44 = add nsw i32 %41, -1
br i1 %37, label %38, label %45
45: ; preds = %40
%46 = load i8, i8* %43
%47 = zext i8 %46 to i32
br label %48
48: ; preds = %45, %48
%49 = phi i32 [ 128, %45 ], [ %59, %48 ]
%50 = phi i32 [ 0, %45 ], [ %71, %48 ]
%51 = and i32 %49, %47
%52 = icmp eq i32 %51, 0
%53 = select i1 %52, i32 %5, i32 %4
%54 = lshr i32 %49, 1
%55 = and i32 %54, 127
%56 = and i32 %55, %47
%57 = icmp eq i32 %56, 0
%58 = select i1 %57, i32 %5, i32 %4
%59 = lshr i32 %55, 1
%60 = lshr i32 %53, 4
%61 = and i32 %60, 255
%62 = tail call i32 @WriteSpiData(i32 %61)
%63 = shl i32 %53, 4
%64 = and i32 %63, 240
%65 = lshr i32 %58, 8
%66 = and i32 %65, 15
%67 = or i32 %66, %64
%68 = tail call i32 @WriteSpiData(i32 %67)
%69 = and i32 %58, 255
%70 = tail call i32 @WriteSpiData(i32 %69)
%71 = add nuw nsw i32 %50, 2
%72 = icmp ult i32 %71, %11
br i1 %72, label %48, label %38
73: ; preds = %38, %6
%74 = tail call i32 @WriteSpiCommand(i32 37)
ret void
}