#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 */
struct termios {
  int c_cflag;
  int *c_cc;
  int /*<<< orphan*/ c_lflag;
};
struct pollfd {
  int fd;
  int events;
  int revents;
};

/* Variables and functions */
int B9600;
int CBAUD;
int CLOCAL;
int CREAD;
int CS8;
int CSIZE;
int /*<<< orphan*/ ICANON;
int /*<<< orphan*/ ISIG;
int /*<<< orphan*/ O_RDWR;
int POLLIN;
int POLLPRI;
int /*<<< orphan*/ TCSANOW;
size_t VEOL;
size_t VEOL2;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ killAll(char *, int);
int open(char *, int /*<<< orphan*/);
int poll(struct pollfd *, int, int);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int fd;
  struct termios tios;
  struct pollfd pfd;
  char cbuf[13];
  char buf[13];
  int pos = 0;
  int state = 0;
  char c;
  killAll("r2100", 9);
  close(0);
  fd = open("/dev/ttyS0", O_RDWR);
  if (fd == -1) {
    fprintf(stderr, "cannot open %s\n", "/dev/ttyS0");
    return 1;
  }
  close(2);
  tcgetattr(fd, &tios);
  tios.c_lflag &= ~ICANON;
  tios.c_lflag &= ~ISIG;
  tios.c_cflag &= ~CSIZE;
  tios.c_cflag &= ~CBAUD;
  tios.c_cflag |= CS8 | B9600 | CLOCAL | CREAD;
  tios.c_cc[VEOL] = 0x02;
  tios.c_cc[VEOL2] = 0x03;
  tcsetattr(fd, TCSANOW, &tios);
  pfd.fd = fd;
  pfd.events = POLLIN | POLLPRI;
  buf[0] = '\0';
  for (;;) {
    if (poll(&pfd, 1, -1) == 1) {
      if (pfd.revents & pfd.events) {
        if (1 == read(fd, &c, 1)) {
          if (state == 0 && c == 0x02) {
            state = 1;
            pos = 0;
          } else if (state && c == 0x03) {
            cbuf[pos++] = '\n';
            cbuf[pos] = '\0';
            if (strcmp(buf, cbuf)) {
              strcpy(buf, cbuf);
              write(1, buf, strlen(buf));
            }
            state = 0;
          } else if (state) {
            cbuf[pos++] = c;
            if (pos == 11)
              pos--;
          }
        }
      } else
        break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x60(%rbp)
movl   $0x0,-0x64(%rbp)
lea    0xe15(%rip),%rdi
mov    $0x9,%esi
call   10e0 <killAll@plt>
xor    %edi,%edi
call   1060 <close@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
lea    0xdfa(%rip),%rdi
call   10d0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1246 <main+0x86>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
lea    0xde3(%rip),%rsi
lea    0xdd1(%rip),%rdx
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1484 <main+0x2c4>
mov    $0x2,%edi
call   1060 <close@plt>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   10b0 <tcgetattr@plt>
mov    0x2d25(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d53(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d19(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2cdf(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2cfd(%rip),%rax
mov    (%rax),%eax
mov    0x2d0c(%rip),%rcx
or     (%rcx),%eax
mov    0x2cab(%rip),%rcx
or     (%rcx),%eax
mov    0x2cea(%rip),%rcx
or     (%rcx),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2c97(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x2,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2cea(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x3,(%rax,%rcx,4)
mov    -0x14(%rbp),%edi
mov    0x2cce(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   10c0 <tcsetattr@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    0x2c9e(%rip),%rax
mov    (%rax),%eax
mov    0x2ccd(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x3c(%rbp)
movb   $0x0,-0x5a(%rbp)
lea    -0x40(%rbp),%rdi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   10a0 <poll@plt>
cmp    $0x1,%eax
jne    1478 <main+0x2b8>
mov    -0x38(%rbp),%eax
and    -0x3c(%rbp),%eax
cmp    $0x0,%eax
je     146e <main+0x2ae>
mov    -0x14(%rbp),%edi
lea    -0x65(%rbp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
jne    1469 <main+0x2a9>
cmpl   $0x0,-0x64(%rbp)
jne    13a1 <main+0x1e1>
movsbl -0x65(%rbp),%eax
cmp    $0x2,%eax
jne    13a1 <main+0x1e1>
movl   $0x1,-0x64(%rbp)
movl   $0x0,-0x60(%rbp)
jmp    1464 <main+0x2a4>
cmpl   $0x0,-0x64(%rbp)
je     1424 <main+0x264>
movsbl -0x65(%rbp),%eax
cmp    $0x3,%eax
jne    1424 <main+0x264>
mov    -0x60(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x60(%rbp)
cltq
movb   $0xa,-0x4d(%rbp,%rax,1)
movslq -0x60(%rbp),%rax
movb   $0x0,-0x4d(%rbp,%rax,1)
lea    -0x5a(%rbp),%rdi
lea    -0x4d(%rbp),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     1418 <main+0x258>
lea    -0x5a(%rbp),%rdi
lea    -0x4d(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x5a(%rbp),%rax
mov    %rax,-0x70(%rbp)
lea    -0x5a(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x70(%rbp),%rsi
mov    %eax,%edx
mov    $0x1,%edi
call   1040 <write@plt>
movl   $0x0,-0x64(%rbp)
jmp    145f <main+0x29f>
cmpl   $0x0,-0x64(%rbp)
je     145a <main+0x29a>
mov    -0x65(%rbp),%cl
mov    -0x60(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x60(%rbp)
cltq
mov    %cl,-0x4d(%rbp,%rax,1)
cmpl   $0xb,-0x60(%rbp)
jne    1455 <main+0x295>
mov    -0x60(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x60(%rbp)
jmp    145a <main+0x29a>
jmp    145f <main+0x29f>
jmp    1464 <main+0x2a4>
jmp    1469 <main+0x2a9>
jmp    1473 <main+0x2b3>
jmp    147d <main+0x2bd>
jmp    1478 <main+0x2b8>
jmp    132c <main+0x16c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
lea    0xe2b(%rip),%rdi
mov    $0x9,%esi
call   10e0 <killAll@plt>
xor    %r13d,%r13d
xor    %edi,%edi
call   1060 <close@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%esi
lea    0xe0d(%rip),%rdi
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     13ce <main+0x20e>
mov    %eax,%ebp
mov    $0x2,%edi
call   1060 <close@plt>
lea    0x30(%rsp),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
call   10b0 <tcgetattr@plt>
mov    0x2d5f(%rip),%rax
mov    (%rax),%eax
mov    0x2d96(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    %eax,0x40(%rsp)
mov    0x2d5f(%rip),%rax
mov    (%rax),%eax
mov    0x2d2e(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    0x30(%rsp),%eax
mov    0x2d4f(%rip),%rcx
mov    0x2d60(%rip),%rdx
mov    0x2d01(%rip),%rsi
mov    0x2d42(%rip),%rdi
or     (%rcx),%eax
or     (%rdx),%eax
or     (%rsi),%eax
or     (%rdi),%eax
mov    %eax,0x30(%rsp)
mov    0x38(%rsp),%rax
mov    0x2cea(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x2,(%rax,%rcx,4)
mov    0x2d41(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x3,(%rax,%rcx,4)
mov    0x2d28(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %rbx,%rdx
call   10c0 <tcsetattr@plt>
mov    0x2cfd(%rip),%rax
mov    0x2d2e(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ebp,0x8(%rsp)
mov    %ecx,0xc(%rsp)
movb   $0x0,0x23(%rsp)
lea    0x8(%rsp),%rbx
lea    0x7(%rsp),%r14
xor    %r15d,%r15d
mov    %r15d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   10a0 <poll@plt>
cmp    $0x1,%eax
jne    12f0 <main+0x130>
mov    0xc(%rsp),%eax
test   %eax,0x10(%rsp)
je     13ca <main+0x20a>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
cmp    $0x1,%eax
jne    12f0 <main+0x130>
movzbl 0x7(%rsp),%eax
mov    $0x1,%r15d
test   %r12d,%r12d
jne    133d <main+0x17d>
cmp    $0x2,%al
je     136b <main+0x1ab>
test   %r12d,%r12d
je     1346 <main+0x186>
cmp    $0x3,%al
je     1373 <main+0x1b3>
test   %r12d,%r12d
mov    $0x0,%r12d
je     12f0 <main+0x130>
lea    0x1(%r13),%ecx
movslq %r13d,%rdx
mov    %al,0x16(%rsp,%rdx,1)
cmp    $0xb,%ecx
cmove  %r13d,%ecx
mov    %ecx,%r13d
jmp    12e0 <main+0x120>
xor    %r13d,%r13d
jmp    12e0 <main+0x120>
movslq %r13d,%rax
add    $0x1,%r13d
movw   $0xa,0x16(%rsp,%rax,1)
lea    0x23(%rsp),%rdi
lea    0x16(%rsp),%rsi
call   1080 <strcmp@plt>
xor    %r15d,%r15d
test   %rax,%rax
je     12e0 <main+0x120>
lea    0x23(%rsp),%r12
mov    %r12,%rdi
lea    0x16(%rsp),%rsi
call   1030 <strcpy@plt>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    $0x1,%edi
mov    %r12,%rsi
mov    %eax,%edx
call   1040 <write@plt>
jmp    12e0 <main+0x120>
xor    %eax,%eax
jmp    13ef <main+0x22f>
mov    0x2bbb(%rip),%rax
mov    (%rax),%edi
lea    0xc33(%rip),%rsi
lea    0xc21(%rip),%rdx
call   1090 <fprintf@plt>
mov    $0x1,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32*, i32 }
%struct.pollfd = type { i32, i32, i32 }
@.str = [6 x i8] c"r2100\00"
@.str.1 = [11 x i8] c"/dev/ttyS0\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.2 = [16 x i8] c"cannot open %s\0A\00"
@ICANON = global i32 0
@ISIG = global i32 0
@CSIZE = global i32 0
@CBAUD = global i32 0
@CS8 = global i32 0
@B9600 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@VEOL = global i64 0
@VEOL2 = global i64 0
@TCSANOW = global i32 0
@POLLIN = global i32 0
@POLLPRI = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.termios
%8 = alloca %struct.pollfd
%9 = alloca [13 x i8]
%10 = alloca [13 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %11
store i32 0, i32* %12
%14 = call i32 @killAll(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 9)
%15 = call i32 @close(i32 0)
%16 = load i32, i32* @O_RDWR
%17 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %148
23: ; preds = %2
%24 = call i32 @close(i32 2)
%25 = load i32, i32* %6
%26 = call i32 @tcgetattr(i32 %25, %struct.termios* %7)
%27 = load i32, i32* @ICANON
%28 = xor i32 %27, -1
%29 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 2
%30 = load i32, i32* %29
%31 = and i32 %30, %28
store i32 %31, i32* %29
%32 = load i32, i32* @ISIG
%33 = xor i32 %32, -1
%34 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 2
%35 = load i32, i32* %34
%36 = and i32 %35, %33
store i32 %36, i32* %34
%37 = load i32, i32* @CSIZE
%38 = xor i32 %37, -1
%39 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%40 = load i32, i32* %39
%41 = and i32 %40, %38
store i32 %41, i32* %39
%42 = load i32, i32* @CBAUD
%43 = xor i32 %42, -1
%44 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%45 = load i32, i32* %44
%46 = and i32 %45, %43
store i32 %46, i32* %44
%47 = load i32, i32* @CS8
%48 = load i32, i32* @B9600
%49 = or i32 %47, %48
%50 = load i32, i32* @CLOCAL
%51 = or i32 %49, %50
%52 = load i32, i32* @CREAD
%53 = or i32 %51, %52
%54 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%55 = load i32, i32* %54
%56 = or i32 %55, %53
store i32 %56, i32* %54
%57 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 1
%58 = load i32*, i32** %57
%59 = load i64, i64* @VEOL
%60 = getelementptr inbounds i32, i32* %58, i64 %59
store i32 2, i32* %60
%61 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 1
%62 = load i32*, i32** %61
%63 = load i64, i64* @VEOL2
%64 = getelementptr inbounds i32, i32* %62, i64 %63
store i32 3, i32* %64
%65 = load i32, i32* %6
%66 = load i32, i32* @TCSANOW
%67 = call i32 @tcsetattr(i32 %65, i32 %66, %struct.termios* %7)
%68 = load i32, i32* %6
%69 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %8, i32 0, i32 0
store i32 %68, i32* %69
%70 = load i32, i32* @POLLIN
%71 = load i32, i32* @POLLPRI
%72 = or i32 %70, %71
%73 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %8, i32 0, i32 1
store i32 %72, i32* %73
%74 = getelementptr inbounds [13 x i8], [13 x i8]* %10, i64 0, i64 0
store i8 0, i8* %74
br label %75
75: ; preds = %146, %23
%76 = call i32 @poll(%struct.pollfd* %8, i32 1, i32 -1)
%77 = icmp eq i32 %76, 1
br i1 %77, label %78, label %146
78: ; preds = %75
%79 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %8, i32 0, i32 2
%80 = load i32, i32* %79
%81 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %8, i32 0, i32 1
%82 = load i32, i32* %81
%83 = and i32 %80, %82
%84 = icmp ne i32 %83, 0
br i1 %84, label %85, label %144
85: ; preds = %78
%86 = load i32, i32* %6
%87 = call i32 @read(i32 %86, i8* %13, i32 1)
%88 = icmp eq i32 1, %87
br i1 %88, label %89, label %143
89: ; preds = %85
%90 = load i32, i32* %12
%91 = icmp eq i32 %90, 0
br i1 %91, label %92, label %97
92: ; preds = %89
%93 = load i8, i8* %13
%94 = sext i8 %93 to i32
%95 = icmp eq i32 %94, 2
br i1 %95, label %96, label %97
96: ; preds = %92
store i32 1, i32* %12
store i32 0, i32* %11
br label %142
97: ; preds = %92, %89
%98 = load i32, i32* %12
%99 = icmp ne i32 %98, 0
br i1 %99, label %100, label %125
100: ; preds = %97
%101 = load i8, i8* %13
%102 = sext i8 %101 to i32
%103 = icmp eq i32 %102, 3
br i1 %103, label %104, label %125
104: ; preds = %100
%105 = load i32, i32* %11
%106 = add nsw i32 %105, 1
store i32 %106, i32* %11
%107 = sext i32 %105 to i64
%108 = getelementptr inbounds [13 x i8], [13 x i8]* %9, i64 0, i64 %107
store i8 10, i8* %108
%109 = load i32, i32* %11
%110 = sext i32 %109 to i64
%111 = getelementptr inbounds [13 x i8], [13 x i8]* %9, i64 0, i64 %110
store i8 0, i8* %111
%112 = getelementptr inbounds [13 x i8], [13 x i8]* %10, i64 0, i64 0
%113 = getelementptr inbounds [13 x i8], [13 x i8]* %9, i64 0, i64 0
%114 = call i64 @strcmp(i8* %112, i8* %113)
%115 = icmp ne i64 %114, 0
br i1 %115, label %116, label %124
116: ; preds = %104
%117 = getelementptr inbounds [13 x i8], [13 x i8]* %10, i64 0, i64 0
%118 = getelementptr inbounds [13 x i8], [13 x i8]* %9, i64 0, i64 0
%119 = call i32 @strcpy(i8* %117, i8* %118)
%120 = getelementptr inbounds [13 x i8], [13 x i8]* %10, i64 0, i64 0
%121 = getelementptr inbounds [13 x i8], [13 x i8]* %10, i64 0, i64 0
%122 = call i32 @strlen(i8* %121)
%123 = call i32 @write(i32 1, i8* %120, i32 %122)
br label %124
124: ; preds = %116, %104
store i32 0, i32* %12
br label %141
125: ; preds = %100, %97
%126 = load i32, i32* %12
%127 = icmp ne i32 %126, 0
br i1 %127, label %128, label %140
128: ; preds = %125
%129 = load i8, i8* %13
%130 = load i32, i32* %11
%131 = add nsw i32 %130, 1
store i32 %131, i32* %11
%132 = sext i32 %130 to i64
%133 = getelementptr inbounds [13 x i8], [13 x i8]* %9, i64 0, i64 %132
store i8 %129, i8* %133
%134 = load i32, i32* %11
%135 = icmp eq i32 %134, 11
br i1 %135, label %136, label %139
136: ; preds = %128
%137 = load i32, i32* %11
%138 = add nsw i32 %137, -1
store i32 %138, i32* %11
br label %139
139: ; preds = %136, %128
br label %140
140: ; preds = %139, %125
br label %141
141: ; preds = %140, %124
br label %142
142: ; preds = %141, %96
br label %143
143: ; preds = %142, %85
br label %145
144: ; preds = %78
br label %147
145: ; preds = %143
br label %146
146: ; preds = %145, %75
br label %75
147: ; preds = %144
store i32 0, i32* %3
br label %148
148: ; preds = %147, %20
%149 = load i32, i32* %3
ret i32 %149
}

LLVM IR (-O2):
%struct.termios = type { i32, i32*, i32 }
%struct.pollfd = type { i32, i32, i32 }
@.str = [6 x i8] c"r2100\00"
@.str.1 = [11 x i8] c"/dev/ttyS0\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.2 = [16 x i8] c"cannot open %s\0A\00"
@ICANON = global i32 0
@ISIG = global i32 0
@CSIZE = global i32 0
@CBAUD = global i32 0
@CS8 = global i32 0
@B9600 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@VEOL = global i64 0
@VEOL2 = global i64 0
@TCSANOW = global i32 0
@POLLIN = global i32 0
@POLLPRI = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.termios
%4 = alloca %struct.pollfd
%5 = alloca [13 x i8]
%6 = alloca [13 x i8]
%7 = alloca i8
%8 = bitcast %struct.termios* %3 to i8*
%9 = bitcast %struct.pollfd* %4 to i8*
%10 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [13 x i8], [13 x i8]* %6, i64 0, i64 0
%12 = tail call i32 @killAll(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 9)
%13 = tail call i32 @close(i32 0)
%14 = load i32, i32* @O_RDWR
%15 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %107
20: ; preds = %2
%21 = tail call i32 @close(i32 2)
%22 = call i32 @tcgetattr(i32 %15, %struct.termios* %3)
%23 = load i32, i32* @ICANON
%24 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 2
%25 = load i32, i32* %24
%26 = load i32, i32* @ISIG
%27 = or i32 %23, %26
%28 = xor i32 %27, -1
%29 = and i32 %25, %28
store i32 %29, i32* %24
%30 = load i32, i32* @CSIZE
%31 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%32 = load i32, i32* %31
%33 = load i32, i32* @CBAUD
%34 = or i32 %30, %33
%35 = xor i32 %34, -1
%36 = and i32 %32, %35
%37 = load i32, i32* @CS8
%38 = load i32, i32* @B9600
%39 = load i32, i32* @CLOCAL
%40 = load i32, i32* @CREAD
%41 = or i32 %37, %36
%42 = or i32 %41, %38
%43 = or i32 %42, %39
%44 = or i32 %43, %40
store i32 %44, i32* %31
%45 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%46 = load i32*, i32** %45
%47 = load i64, i64* @VEOL
%48 = getelementptr inbounds i32, i32* %46, i64 %47
store i32 2, i32* %48
%49 = load i64, i64* @VEOL2
%50 = getelementptr inbounds i32, i32* %46, i64 %49
store i32 3, i32* %50
%51 = load i32, i32* @TCSANOW
%52 = call i32 @tcsetattr(i32 %15, i32 %51, %struct.termios* %3)
%53 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %4, i64 0, i32 0
store i32 %15, i32* %53
%54 = load i32, i32* @POLLIN
%55 = load i32, i32* @POLLPRI
%56 = or i32 %55, %54
%57 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %4, i64 0, i32 1
store i32 %56, i32* %57
store i8 0, i8* %11
%58 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %4, i64 0, i32 2
br label %59
59: ; preds = %97, %20
%60 = phi i32 [ 0, %20 ], [ %98, %97 ]
%61 = phi i32 [ 0, %20 ], [ %99, %97 ]
br label %62
62: ; preds = %59, %100
%63 = phi i32 [ %61, %59 ], [ 0, %100 ]
br label %64
64: ; preds = %75, %62
%65 = call i32 @poll(%struct.pollfd* %4, i32 1, i32 -1)
%66 = icmp eq i32 %65, 1
br i1 %66, label %67, label %75
67: ; preds = %64
%68 = load i32, i32* %58
%69 = load i32, i32* %57
%70 = and i32 %69, %68
%71 = icmp eq i32 %70, 0
br i1 %71, label %107, label %72
72: ; preds = %67
%73 = call i32 @read(i32 %15, i8* %7, i32 1)
%74 = icmp eq i32 %73, 1
br i1 %74, label %76, label %75
75: ; preds = %72, %64
br label %64
76: ; preds = %72
%77 = icmp eq i32 %63, 0
%78 = load i8, i8* %7
%79 = icmp eq i8 %78, 2
%80 = select i1 %77, i1 %79, i1 false
br i1 %80, label %97, label %81
81: ; preds = %76
%82 = icmp ne i32 %63, 0
%83 = icmp eq i8 %78, 3
%84 = select i1 %82, i1 %83, i1 false
br i1 %84, label %85, label %100
85: ; preds = %81
%86 = add nsw i32 %60, 1
%87 = sext i32 %60 to i64
%88 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 %87
store i8 10, i8* %88
%89 = sext i32 %86 to i64
%90 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 %89
store i8 0, i8* %90
%91 = call i64 @strcmp(i8* %11, i8* %10)
%92 = icmp eq i64 %91, 0
br i1 %92, label %97, label %93
93: ; preds = %85
%94 = call i32 @strcpy(i8* %11, i8* %10)
%95 = call i32 @strlen(i8* %11)
%96 = call i32 @write(i32 1, i8* %11, i32 %95)
br label %97
97: ; preds = %76, %93, %85, %101
%98 = phi i32 [ %106, %101 ], [ %86, %85 ], [ %86, %93 ], [ 0, %76 ]
%99 = phi i32 [ 1, %101 ], [ 0, %85 ], [ 0, %93 ], [ 1, %76 ]
br label %59
100: ; preds = %81
br i1 %82, label %101, label %62
101: ; preds = %100
%102 = add nsw i32 %60, 1
%103 = sext i32 %60 to i64
%104 = getelementptr inbounds [13 x i8], [13 x i8]* %5, i64 0, i64 %103
store i8 %78, i8* %104
%105 = icmp eq i32 %102, 11
%106 = select i1 %105, i32 %60, i32 %102
br label %97
107: ; preds = %67, %17
%108 = phi i32 [ 1, %17 ], [ 0, %67 ]
ret i32 %108
}