#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 /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ command(int);
int /*<<< orphan*/ feof(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ lcdinit();
int /*<<< orphan*/ lcdwait();
int /*<<< orphan*/ stdin;
unsigned int strlen(char *);
int /*<<< orphan*/ writechars(char *);
int xxmain(int argc, char **argv) {
  int i = 0;
  lcdinit();
  if (argc == 2) {
    writechars(argv[1]);
  }
  if (argc > 2) {
    lcdwait();
    command(0xa8);
    writechars(argv[2]);
  }
  if (argc >= 2)
    return 0;
  while (!feof(stdin)) {
    char buf[512];
    lcdwait();
    if (i) {
      command(0xa8);
    } else {
      command(0x2);
    }
    i = i ^ 0x1;
    if (fgets(buf, sizeof(buf), stdin) != NULL) {
      unsigned int len;
      buf[0x27] = 0;
      len = strlen(buf);
      if (buf[len - 1] == '\n')
        buf[len - 1] = 0;
      writechars(buf);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<xxmain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1090 <lcdinit@plt>
cmpl   $0x2,-0x8(%rbp)
jne    11a7 <xxmain+0x37>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <writechars@plt>
cmpl   $0x2,-0x8(%rbp)
jle    11cf <xxmain+0x5f>
mov    $0x0,%al
call   1040 <lcdwait@plt>
mov    $0xa8,%edi
call   1060 <command@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1030 <writechars@plt>
cmpl   $0x2,-0x8(%rbp)
jl     11e5 <xxmain+0x75>
movl   $0x0,-0x4(%rbp)
jmp    12c4 <xxmain+0x154>
jmp    11ea <xxmain+0x7a>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    120d <xxmain+0x9d>
jmp    12bd <xxmain+0x14d>
mov    $0x0,%al
call   1040 <lcdwait@plt>
cmpl   $0x0,-0x14(%rbp)
je     122d <xxmain+0xbd>
mov    $0xa8,%edi
call   1060 <command@plt>
jmp    1237 <xxmain+0xc7>
mov    $0x2,%edi
call   1060 <command@plt>
mov    -0x14(%rbp),%eax
xor    $0x1,%eax
mov    %eax,-0x14(%rbp)
lea    -0x220(%rbp),%rdi
mov    0x2d9a(%rip),%rax
mov    (%rax),%edx
mov    $0x200,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12b8 <xxmain+0x148>
movb   $0x0,-0x1f9(%rbp)
lea    -0x220(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x224(%rbp)
mov    -0x224(%rbp),%eax
sub    $0x1,%eax
mov    %eax,%eax
movsbl -0x220(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    12ac <xxmain+0x13c>
mov    -0x224(%rbp),%eax
sub    $0x1,%eax
mov    %eax,%eax
movb   $0x0,-0x220(%rbp,%rax,1)
lea    -0x220(%rbp),%rdi
call   1030 <writechars@plt>
jmp    11ea <xxmain+0x7a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xxmain>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
call   1090 <lcdinit@plt>
mov    $0x1,%eax
cmp    $0x2,%ebp
je     11ab <xxmain+0x3b>
jle    11c4 <xxmain+0x54>
xor    %eax,%eax
call   1040 <lcdwait@plt>
mov    $0xa8,%edi
call   1060 <command@plt>
mov    $0x2,%eax
mov    (%rbx,%rax,8),%rdi
call   1030 <writechars@plt>
xor    %eax,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e1d(%rip),%r15
mov    (%r15),%edi
call   1080 <feof@plt>
test   %eax,%eax
jne    11b4 <xxmain+0x44>
mov    $0x2,%r14d
mov    %rsp,%rbx
xor    %ebp,%ebp
jmp    1207 <xxmain+0x97>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1030 <writechars@plt>
xor    $0x1,%ebp
mov    (%r15),%edi
call   1080 <feof@plt>
test   %eax,%eax
jne    11b4 <xxmain+0x44>
xor    %eax,%eax
call   1040 <lcdwait@plt>
test   %ebp,%ebp
mov    $0xa8,%edi
cmove  %r14d,%edi
call   1060 <command@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x200,%esi
call   1070 <fgets@plt>
test   %rax,%rax
je     11f8 <xxmain+0x88>
movb   $0x0,0x27(%rsp)
mov    %rbx,%rdi
call   1050 <strlen@plt>
add    $0xffffffff,%eax
cmpb   $0xa,(%rsp,%rax,1)
jne    11f0 <xxmain+0x80>
movb   $0x0,(%rsp,%rax,1)
jmp    11f0 <xxmain+0x80>

LLVM IR (-O0):
@stdin = global i32 0
define i32 @xxmain(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [512 x i8]
%8 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%9 = call i32 (...) @lcdinit()
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 2
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @writechars(i8* %15)
br label %17
17: ; preds = %12, %2
%18 = load i32, i32* %4
%19 = icmp sgt i32 %18, 2
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = call i32 (...) @lcdwait()
%22 = call i32 @command(i32 168)
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @writechars(i8* %25)
br label %27
27: ; preds = %20, %17
%28 = load i32, i32* %4
%29 = icmp sge i32 %28, 2
br i1 %29, label %30, label %31
30: ; preds = %27
store i32 0, i32* %3
br label %73
31: ; preds = %27
br label %32
32: ; preds = %71, %31
%33 = load i32, i32* @stdin
%34 = call i32 @feof(i32 %33)
%35 = icmp ne i32 %34, 0
%36 = xor i1 %35, true
br i1 %36, label %37, label %72
37: ; preds = %32
%38 = call i32 (...) @lcdwait()
%39 = load i32, i32* %6
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = call i32 @command(i32 168)
br label %45
43: ; preds = %37
%44 = call i32 @command(i32 2)
br label %45
45: ; preds = %43, %41
%46 = load i32, i32* %6
%47 = xor i32 %46, 1
store i32 %47, i32* %6
%48 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%49 = load i32, i32* @stdin
%50 = call i32* @fgets(i8* %48, i32 512, i32 %49)
%51 = icmp ne i32* %50, null
br i1 %51, label %52, label %71
52: ; preds = %45
%53 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 39
store i8 0, i8* %53
%54 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%55 = call i32 @strlen(i8* %54)
store i32 %55, i32* %8
%56 = load i32, i32* %8
%57 = sub i32 %56, 1
%58 = zext i32 %57 to i64
%59 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 %58
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = icmp eq i32 %61, 10
br i1 %62, label %63, label %68
63: ; preds = %52
%64 = load i32, i32* %8
%65 = sub i32 %64, 1
%66 = zext i32 %65 to i64
%67 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 %66
store i8 0, i8* %67
br label %68
68: ; preds = %63, %52
%69 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%70 = call i32 @writechars(i8* %69)
br label %71
71: ; preds = %68, %45
br label %32
72: ; preds = %32
store i32 0, i32* %3
br label %73
73: ; preds = %72, %30
%74 = load i32, i32* %3
ret i32 %74
}

LLVM IR (-O2):
@stdin = global i32 0
define i32 @xxmain(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8]
%4 = tail call i32 (...) @lcdinit()
%5 = icmp eq i32 %0, 2
br i1 %5, label %42, label %6
6: ; preds = %2
%7 = icmp sgt i32 %0, 2
br i1 %7, label %15, label %8
8: ; preds = %6
%9 = load i32, i32* @stdin
%10 = call i32 @feof(i32 %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %47
12: ; preds = %8
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 39
br label %18
15: ; preds = %6
%16 = tail call i32 (...) @lcdwait()
%17 = tail call i32 @command(i32 168)
br label %42
18: ; preds = %12, %38
%19 = phi i32 [ 0, %12 ], [ %24, %38 ]
%20 = call i32 (...) @lcdwait()
%21 = icmp eq i32 %19, 0
%22 = select i1 %21, i32 2, i32 168
%23 = call i32 @command(i32 %22)
%24 = xor i32 %19, 1
%25 = load i32, i32* @stdin
%26 = call i32* @fgets(i8* %13, i32 512, i32 %25)
%27 = icmp eq i32* %26, null
br i1 %27, label %38, label %28
28: ; preds = %18
store i8 0, i8* %14
%29 = call i32 @strlen(i8* %13)
%30 = add i32 %29, -1
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 10
br i1 %34, label %35, label %36
35: ; preds = %28
store i8 0, i8* %32
br label %36
36: ; preds = %35, %28
%37 = call i32 @writechars(i8* %13)
br label %38
38: ; preds = %36, %18
%39 = load i32, i32* @stdin
%40 = call i32 @feof(i32 %39)
%41 = icmp eq i32 %40, 0
br i1 %41, label %18, label %47
42: ; preds = %2, %15
%43 = phi i64 [ 2, %15 ], [ 1, %2 ]
%44 = getelementptr inbounds i8*, i8** %1, i64 %43
%45 = load i8*, i8** %44
%46 = tail call i32 @writechars(i8* %45)
br label %47
47: ; preds = %38, %42, %8
ret i32 0
}