#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*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ memset(unsigned char *, char, int);
int /*<<< orphan*/ tyan_lcdm_set_rampos(int, unsigned char);
int /*<<< orphan*/ write(int, unsigned char *, int);
void tyan_lcdm_write_str(int fd, unsigned char *str, unsigned char start_addr,
                         int length) {
  unsigned char cmd_str[20] = {0xF1, 0x70, 0x02};
  tyan_lcdm_set_rampos(fd, start_addr);
  memset(cmd_str, ' ', 20);
  cmd_str[0] = 0xF1;
  cmd_str[1] = 0x70;
  cmd_str[2] = 0x02;
  cmd_str[19] = 0xF2;
  memcpy(cmd_str + 3, str, (length < 16) ? length : 16);
  write(fd, cmd_str, 20);
}


x86 assembly (clang, -O0):
<tyan_lcdm_write_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %dl,%al
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %ecx,-0x18(%rbp)
mov    0xea2(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe9f(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe9d(%rip),%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
movzbl -0x11(%rbp),%esi
call   1030 <tyan_lcdm_set_rampos@plt>
lea    -0x30(%rbp),%rdi
mov    $0x20,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
movb   $0xf1,-0x30(%rbp)
movb   $0x70,-0x2f(%rbp)
movb   $0x2,-0x2e(%rbp)
movb   $0xf2,-0x1d(%rbp)
lea    -0x30(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpl   $0x10,-0x18(%rbp)
jge    11ce <tyan_lcdm_write_str+0x8e>
mov    -0x18(%rbp),%eax
mov    %eax,-0x44(%rbp)
jmp    11db <tyan_lcdm_write_str+0x9b>
mov    $0x10,%eax
mov    %eax,-0x44(%rbp)
jmp    11db <tyan_lcdm_write_str+0x9b>
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x14,%edx
call   1040 <write@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tyan_lcdm_write_str>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%ebp
mov    %rsi,%r14
mov    %edi,%ebx
mov    0xeb9(%rip),%eax
mov    %eax,0x10(%rsp)
movaps 0xe9e(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %edx,%esi
call   1030 <tyan_lcdm_set_rampos@plt>
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x20,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
movw   $0x70f1,(%rsp)
movb   $0x2,0x2(%rsp)
movb   $0xf2,0x13(%rsp)
lea    0x3(%rsp),%rdi
cmp    $0x10,%ebp
mov    $0x10,%edx
cmovl  %ebp,%edx
mov    %r14,%rsi
call   1060 <memcpy@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x14,%edx
call   1040 <write@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.tyan_lcdm_write_str.cmd_str = <{ i8, i8, i8, [17 x i8] }> <{ i8 -15, i8 112, i8 2, [17 x i8] zeroinitializer }>
define void @tyan_lcdm_write_str(i32 %0, i8* %1, i8 zeroext %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i32
%9 = alloca [20 x i8]
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8 %2, i8* %7
store i32 %3, i32* %8
%10 = bitcast [20 x i8]* %9 to i8*
%11 = load i32, i32* %5
%12 = load i8, i8* %7
%13 = call i32 @tyan_lcdm_set_rampos(i32 %11, i8 zeroext %12)
%14 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%15 = call i32 @memset(i8* %14, i8 signext 32, i32 20)
%16 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
store i8 -15, i8* %16
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 1
store i8 112, i8* %17
%18 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 2
store i8 2, i8* %18
%19 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 19
store i8 -14, i8* %19
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%21 = getelementptr inbounds i8, i8* %20, i64 3
%22 = load i8*, i8** %6
%23 = load i32, i32* %8
%24 = icmp slt i32 %23, 16
br i1 %24, label %25, label %27
25: ; preds = %4
%26 = load i32, i32* %8
br label %28
27: ; preds = %4
br label %28
28: ; preds = %27, %25
%29 = phi i32 [ %26, %25 ], [ 16, %27 ]
%30 = call i32 @memcpy(i8* %21, i8* %22, i32 %29)
%31 = load i32, i32* %5
%32 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%33 = call i32 @write(i32 %31, i8* %32, i32 20)
ret void
}

LLVM IR (-O2):
@__const.tyan_lcdm_write_str.cmd_str = <{ i8, i8, i8, [17 x i8] }> <{ i8 -15, i8 112, i8 2, [17 x i8] zeroinitializer }>
define void @tyan_lcdm_write_str(i32 %0, i8* %1, i8 zeroext %2, i32 %3) {
%5 = alloca [20 x i8]
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%7 = tail call i32 @tyan_lcdm_set_rampos(i32 %0, i8 zeroext %2)
%8 = call i32 @memset(i8* %6, i8 signext 32, i32 20)
store i8 -15, i8* %6
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 1
store i8 112, i8* %9
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 2
store i8 2, i8* %10
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 19
store i8 -14, i8* %11
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 3
%13 = icmp slt i32 %3, 16
%14 = select i1 %13, i32 %3, i32 16
%15 = call i32 @memcpy(i8* %12, i8* %1, i32 %14)
%16 = call i32 @write(i32 %0, i8* %6, i32 20)
ret void
}