#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*/ printk(char *, unsigned int);
unsigned int read_data_cmd();
int /*<<< orphan*/ send_ctrl_cmd(int);
int /*<<< orphan*/ send_data_cmd(short);
void lcm_read_fb(unsigned char *buffer) {
  int i = 0;
  short x0, y0, x1, y1;
  short h_X_start, l_X_start, h_X_end, l_X_end, h_Y_start, l_Y_start, h_Y_end,
      l_Y_end;
  unsigned int readData;
  x0 = 0;
  y0 = 0;
  x1 = (480) - 1;
  y1 = (800) - 1;
  h_X_start = ((x0 & 0x0300) >> 8);
  l_X_start = (x0 & 0x00FF);
  h_X_end = ((x1 & 0x0300) >> 8);
  l_X_end = (x1 & 0x00FF);
  h_Y_start = ((y0 & 0x0300) >> 8);
  l_Y_start = (y0 & 0x00FF);
  h_Y_end = ((y1 & 0x0300) >> 8);
  l_Y_end = (y1 & 0x00FF);
  send_ctrl_cmd(0x2A00);
  send_data_cmd(h_X_start);
  send_ctrl_cmd(0x2A01);
  send_data_cmd(l_X_start);
  send_ctrl_cmd(0x2A02);
  send_data_cmd(h_X_end);
  send_ctrl_cmd(0x2A03);
  send_data_cmd(l_X_end);
  send_ctrl_cmd(0x2B00);
  send_data_cmd(h_Y_start);
  send_ctrl_cmd(0x2B01);
  send_data_cmd(l_Y_start);
  send_ctrl_cmd(0x2B02);
  send_data_cmd(h_Y_end);
  send_ctrl_cmd(0x2B03);
  send_data_cmd(l_Y_end);
  send_ctrl_cmd(0x2E00);
  readData = read_data_cmd();
  for (i = 0; i < 60; i += 3) {
    readData = read_data_cmd();
    printk("Read data: 0x%04X \n", readData);
    buffer[i] = (readData >> 8) & 0xFF;
    buffer[i + 1] = readData & 0xFF;
    readData = read_data_cmd();
    printk("Read data: 0x%04X \n", readData);
    buffer[i + 2] = (readData >> 8) & 0xFF;
  }
}


x86 assembly (clang, -O0):
<lcm_read_fb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movw   $0x0,-0xe(%rbp)
movw   $0x0,-0x10(%rbp)
movw   $0x1df,-0x12(%rbp)
movw   $0x31f,-0x14(%rbp)
movswl -0xe(%rbp),%eax
and    $0x300,%eax
sar    $0x8,%eax
mov    %ax,-0x16(%rbp)
movswl -0xe(%rbp),%eax
and    $0xff,%eax
mov    %ax,-0x18(%rbp)
movswl -0x12(%rbp),%eax
and    $0x300,%eax
sar    $0x8,%eax
mov    %ax,-0x1a(%rbp)
movswl -0x12(%rbp),%eax
and    $0xff,%eax
mov    %ax,-0x1c(%rbp)
movswl -0x10(%rbp),%eax
and    $0x300,%eax
sar    $0x8,%eax
mov    %ax,-0x1e(%rbp)
movswl -0x10(%rbp),%eax
and    $0xff,%eax
mov    %ax,-0x20(%rbp)
movswl -0x14(%rbp),%eax
and    $0x300,%eax
sar    $0x8,%eax
mov    %ax,-0x22(%rbp)
movswl -0x14(%rbp),%eax
and    $0xff,%eax
mov    %ax,-0x24(%rbp)
mov    $0x2a00,%edi
call   1060 <send_ctrl_cmd@plt>
movswl -0x16(%rbp),%edi
call   1050 <send_data_cmd@plt>
mov    $0x2a01,%edi
call   1060 <send_ctrl_cmd@plt>
movswl -0x18(%rbp),%edi
call   1050 <send_data_cmd@plt>
mov    $0x2a02,%edi
call   1060 <send_ctrl_cmd@plt>
movswl -0x1a(%rbp),%edi
call   1050 <send_data_cmd@plt>
mov    $0x2a03,%edi
call   1060 <send_ctrl_cmd@plt>
movswl -0x1c(%rbp),%edi
call   1050 <send_data_cmd@plt>
mov    $0x2b00,%edi
call   1060 <send_ctrl_cmd@plt>
movswl -0x1e(%rbp),%edi
call   1050 <send_data_cmd@plt>
mov    $0x2b01,%edi
call   1060 <send_ctrl_cmd@plt>
movswl -0x20(%rbp),%edi
call   1050 <send_data_cmd@plt>
mov    $0x2b02,%edi
call   1060 <send_ctrl_cmd@plt>
movswl -0x22(%rbp),%edi
call   1050 <send_data_cmd@plt>
mov    $0x2b03,%edi
call   1060 <send_ctrl_cmd@plt>
movswl -0x24(%rbp),%edi
call   1050 <send_data_cmd@plt>
mov    $0x2e00,%edi
call   1060 <send_ctrl_cmd@plt>
mov    $0x0,%al
call   1040 <read_data_cmd@plt>
mov    %eax,-0x28(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x3c,-0xc(%rbp)
jge    132b <lcm_read_fb+0x1eb>
mov    $0x0,%al
call   1040 <read_data_cmd@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%esi
lea    0xd50(%rip),%rdi
call   1030 <printk@plt>
mov    -0x28(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%eax
and    $0xff,%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    $0x0,%al
call   1040 <read_data_cmd@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%esi
lea    0xd05(%rip),%rdi
call   1030 <printk@plt>
mov    -0x28(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0xc(%rbp)
jmp    1292 <lcm_read_fb+0x152>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lcm_read_fb>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r15
mov    $0x2a00,%edi
call   1060 <send_ctrl_cmd@plt>
xor    %edi,%edi
call   1050 <send_data_cmd@plt>
mov    $0x2a01,%edi
call   1060 <send_ctrl_cmd@plt>
xor    %edi,%edi
call   1050 <send_data_cmd@plt>
mov    $0x2a02,%edi
call   1060 <send_ctrl_cmd@plt>
mov    $0x1,%edi
call   1050 <send_data_cmd@plt>
mov    $0x2a03,%edi
call   1060 <send_ctrl_cmd@plt>
mov    $0xdf,%edi
call   1050 <send_data_cmd@plt>
mov    $0x2b00,%edi
call   1060 <send_ctrl_cmd@plt>
xor    %edi,%edi
call   1050 <send_data_cmd@plt>
mov    $0x2b01,%edi
call   1060 <send_ctrl_cmd@plt>
xor    %edi,%edi
call   1050 <send_data_cmd@plt>
mov    $0x2b02,%edi
call   1060 <send_ctrl_cmd@plt>
mov    $0x3,%edi
call   1050 <send_data_cmd@plt>
mov    $0x2b03,%edi
call   1060 <send_ctrl_cmd@plt>
mov    $0x1f,%edi
call   1050 <send_data_cmd@plt>
mov    $0x2e00,%edi
call   1060 <send_ctrl_cmd@plt>
xor    %eax,%eax
call   1040 <read_data_cmd@plt>
mov    $0xfffffffffffffffd,%rbx
lea    0xe02(%rip),%r14
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <read_data_cmd@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <printk@plt>
rol    $0x8,%bp
mov    %bp,0x3(%r15,%rbx,1)
mov    %r15,%r12
xor    %eax,%eax
call   1040 <read_data_cmd@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    %eax,%ebp
call   1030 <printk@plt>
mov    %ebp,%eax
mov    %r15,%rcx
mov    %ah,0x5(%rcx,%rbx,1)
add    $0x3,%rbx
cmp    $0x39,%rbx
jb     1200 <lcm_read_fb+0xc0>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Read data: 0x%04X \0A\00"
define void @lcm_read_fb(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i16
%5 = alloca i16
%6 = alloca i16
%7 = alloca i16
%8 = alloca i16
%9 = alloca i16
%10 = alloca i16
%11 = alloca i16
%12 = alloca i16
%13 = alloca i16
%14 = alloca i16
%15 = alloca i16
%16 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i16 0, i16* %4
store i16 0, i16* %5
store i16 479, i16* %6
store i16 799, i16* %7
%17 = load i16, i16* %4
%18 = sext i16 %17 to i32
%19 = and i32 %18, 768
%20 = ashr i32 %19, 8
%21 = trunc i32 %20 to i16
store i16 %21, i16* %8
%22 = load i16, i16* %4
%23 = sext i16 %22 to i32
%24 = and i32 %23, 255
%25 = trunc i32 %24 to i16
store i16 %25, i16* %9
%26 = load i16, i16* %6
%27 = sext i16 %26 to i32
%28 = and i32 %27, 768
%29 = ashr i32 %28, 8
%30 = trunc i32 %29 to i16
store i16 %30, i16* %10
%31 = load i16, i16* %6
%32 = sext i16 %31 to i32
%33 = and i32 %32, 255
%34 = trunc i32 %33 to i16
store i16 %34, i16* %11
%35 = load i16, i16* %5
%36 = sext i16 %35 to i32
%37 = and i32 %36, 768
%38 = ashr i32 %37, 8
%39 = trunc i32 %38 to i16
store i16 %39, i16* %12
%40 = load i16, i16* %5
%41 = sext i16 %40 to i32
%42 = and i32 %41, 255
%43 = trunc i32 %42 to i16
store i16 %43, i16* %13
%44 = load i16, i16* %7
%45 = sext i16 %44 to i32
%46 = and i32 %45, 768
%47 = ashr i32 %46, 8
%48 = trunc i32 %47 to i16
store i16 %48, i16* %14
%49 = load i16, i16* %7
%50 = sext i16 %49 to i32
%51 = and i32 %50, 255
%52 = trunc i32 %51 to i16
store i16 %52, i16* %15
%53 = call i32 @send_ctrl_cmd(i32 10752)
%54 = load i16, i16* %8
%55 = call i32 @send_data_cmd(i16 signext %54)
%56 = call i32 @send_ctrl_cmd(i32 10753)
%57 = load i16, i16* %9
%58 = call i32 @send_data_cmd(i16 signext %57)
%59 = call i32 @send_ctrl_cmd(i32 10754)
%60 = load i16, i16* %10
%61 = call i32 @send_data_cmd(i16 signext %60)
%62 = call i32 @send_ctrl_cmd(i32 10755)
%63 = load i16, i16* %11
%64 = call i32 @send_data_cmd(i16 signext %63)
%65 = call i32 @send_ctrl_cmd(i32 11008)
%66 = load i16, i16* %12
%67 = call i32 @send_data_cmd(i16 signext %66)
%68 = call i32 @send_ctrl_cmd(i32 11009)
%69 = load i16, i16* %13
%70 = call i32 @send_data_cmd(i16 signext %69)
%71 = call i32 @send_ctrl_cmd(i32 11010)
%72 = load i16, i16* %14
%73 = call i32 @send_data_cmd(i16 signext %72)
%74 = call i32 @send_ctrl_cmd(i32 11011)
%75 = load i16, i16* %15
%76 = call i32 @send_data_cmd(i16 signext %75)
%77 = call i32 @send_ctrl_cmd(i32 11776)
%78 = call i32 (...) @read_data_cmd()
store i32 %78, i32* %16
store i32 0, i32* %3
br label %79
79: ; preds = %114, %1
%80 = load i32, i32* %3
%81 = icmp slt i32 %80, 60
br i1 %81, label %82, label %117
82: ; preds = %79
%83 = call i32 (...) @read_data_cmd()
store i32 %83, i32* %16
%84 = load i32, i32* %16
%85 = call i32 @printk(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %84)
%86 = load i32, i32* %16
%87 = lshr i32 %86, 8
%88 = and i32 %87, 255
%89 = trunc i32 %88 to i8
%90 = load i8*, i8** %2
%91 = load i32, i32* %3
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds i8, i8* %90, i64 %92
store i8 %89, i8* %93
%94 = load i32, i32* %16
%95 = and i32 %94, 255
%96 = trunc i32 %95 to i8
%97 = load i8*, i8** %2
%98 = load i32, i32* %3
%99 = add nsw i32 %98, 1
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds i8, i8* %97, i64 %100
store i8 %96, i8* %101
%102 = call i32 (...) @read_data_cmd()
store i32 %102, i32* %16
%103 = load i32, i32* %16
%104 = call i32 @printk(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %103)
%105 = load i32, i32* %16
%106 = lshr i32 %105, 8
%107 = and i32 %106, 255
%108 = trunc i32 %107 to i8
%109 = load i8*, i8** %2
%110 = load i32, i32* %3
%111 = add nsw i32 %110, 2
%112 = sext i32 %111 to i64
%113 = getelementptr inbounds i8, i8* %109, i64 %112
store i8 %108, i8* %113
br label %114
114: ; preds = %82
%115 = load i32, i32* %3
%116 = add nsw i32 %115, 3
store i32 %116, i32* %3
br label %79
117: ; preds = %79
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"Read data: 0x%04X \0A\00"
define void @lcm_read_fb(i8* nocapture writeonly %0) {
%2 = tail call i32 @send_ctrl_cmd(i32 10752)
%3 = tail call i32 @send_data_cmd(i16 signext 0)
%4 = tail call i32 @send_ctrl_cmd(i32 10753)
%5 = tail call i32 @send_data_cmd(i16 signext 0)
%6 = tail call i32 @send_ctrl_cmd(i32 10754)
%7 = tail call i32 @send_data_cmd(i16 signext 1)
%8 = tail call i32 @send_ctrl_cmd(i32 10755)
%9 = tail call i32 @send_data_cmd(i16 signext 223)
%10 = tail call i32 @send_ctrl_cmd(i32 11008)
%11 = tail call i32 @send_data_cmd(i16 signext 0)
%12 = tail call i32 @send_ctrl_cmd(i32 11009)
%13 = tail call i32 @send_data_cmd(i16 signext 0)
%14 = tail call i32 @send_ctrl_cmd(i32 11010)
%15 = tail call i32 @send_data_cmd(i16 signext 3)
%16 = tail call i32 @send_ctrl_cmd(i32 11011)
%17 = tail call i32 @send_data_cmd(i16 signext 31)
%18 = tail call i32 @send_ctrl_cmd(i32 11776)
%19 = tail call i32 (...) @read_data_cmd()
br label %20
20: ; preds = %1, %20
%21 = phi i64 [ 0, %1 ], [ %36, %20 ]
%22 = tail call i32 (...) @read_data_cmd()
%23 = tail call i32 @printk(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = lshr i32 %22, 8
%25 = trunc i32 %24 to i8
%26 = getelementptr inbounds i8, i8* %0, i64 %21
store i8 %25, i8* %26
%27 = trunc i32 %22 to i8
%28 = add nuw nsw i64 %21, 1
%29 = getelementptr inbounds i8, i8* %0, i64 %28
store i8 %27, i8* %29
%30 = tail call i32 (...) @read_data_cmd()
%31 = tail call i32 @printk(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %30)
%32 = lshr i32 %30, 8
%33 = trunc i32 %32 to i8
%34 = add nuw nsw i64 %21, 2
%35 = getelementptr inbounds i8, i8* %0, i64 %34
store i8 %33, i8* %35
%36 = add nuw nsw i64 %21, 3
%37 = icmp ult i64 %21, 57
br i1 %37, label %20, label %38
38: ; preds = %20
ret void
}