#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 pollfd {
  int fd;
  int events;
  int revents;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int POLLIN;
int POLLOUT;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int poll(struct pollfd *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int strlen(char const *);
int write(int, char const *, int);
int main(void) {
  struct pollfd fds[2];
  int ret, rfd, wfd;
  int len;
  char rbuf[40];
  const char *wbuf =
      "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  int total_bytes = strlen(wbuf);
  int count;
  rfd = open("/dev/poll_dev", O_RDONLY);
  fds[0].fd = rfd;
  fds[0].events = POLLIN;
  wfd = open("/dev/poll_dev", O_WRONLY);
  fds[1].fd = wfd;
  fds[1].events = POLLOUT;
  while (1) {
    ret = poll(fds, 2, 100 * 1000);
    if (ret == -1) {
      perror("poll");
      return -1;
    }
    if (!ret) {
      printf("%d seconds elapsed, \n", 100);
      return 0;
    }
    if (fds[0].revents & POLLIN) {
      printf("fd is readable\n");
      memset(rbuf, 0, 40);
      ret = read(rfd, rbuf, total_bytes);
      if (ret == -1) {
        perror("read");
        exit(EXIT_FAILURE);
      }
      printf("\nREAD %d byte: %s\n", ret, rbuf);
      if (ret < total_bytes) {
        printf("\nNeeds to read addtional %d bytes\n", (total_bytes - ret));
        total_bytes -= ret;
      } else {
        printf("\nALL DATA IS READ. Exiting ...\n");
        break;
      }
    }
    if (fds[1].revents & POLLOUT) {
      printf("fd is writable\n");
      ret = write(wfd, wbuf, strlen(wbuf));
      if (ret == -1) {
        perror("write");
        break;
      }
      printf("\n WROTE %d byte|size of buffer %d\n", ret, strlen(wbuf));
      if (ret < strlen(wbuf)) {
        printf("\nNeeds to write addtional %d bytes\n", (strlen(wbuf) - ret));
        wbuf += ret;
      } else
        printf("\n All data is written\n");
    }
  }
  close(rfd);
  close(wfd);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe47(%rip),%rax
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x6c(%rbp)
mov    0x2e10(%rip),%rax
mov    (%rax),%esi
lea    0xe66(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2dea(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2db6(%rip),%rax
mov    (%rax),%esi
lea    0xe3c(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2de0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x2,%esi
mov    $0x186a0,%edx
call   1090 <poll@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1255 <main+0xb5>
lea    0xe09(%rip),%rdi
call   10b0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1456 <main+0x2b6>
cmpl   $0x0,-0x24(%rbp)
jne    127e <main+0xde>
lea    0xdec(%rip),%rdi
mov    $0x64,%esi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1456 <main+0x2b6>
mov    -0x18(%rbp),%eax
mov    0x2d50(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1344 <main+0x1a4>
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1060 <memset@plt>
mov    -0x28(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    -0x6c(%rbp),%edx
call   1080 <read@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    12e7 <main+0x147>
lea    0xda4(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2ce8(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x24(%rbp),%esi
lea    -0x60(%rbp),%rdx
lea    0xd88(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
cmp    -0x6c(%rbp),%eax
jge    132c <main+0x18c>
mov    -0x6c(%rbp),%esi
sub    -0x24(%rbp),%esi
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%ecx
mov    -0x6c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x6c(%rbp)
jmp    133f <main+0x19f>
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1438 <main+0x298>
jmp    1344 <main+0x1a4>
mov    -0xc(%rbp),%eax
mov    0x2caa(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1433 <main+0x293>
lea    0xd73(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x68(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x68(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x7c(%rbp),%edi
mov    -0x78(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    13aa <main+0x20a>
lea    0xd43(%rip),%rdi
call   10b0 <perror@plt>
jmp    1438 <main+0x298>
mov    -0x24(%rbp),%eax
mov    %eax,-0x84(%rbp)
mov    -0x68(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x84(%rbp),%esi
mov    %eax,%edx
lea    0xd1e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x80(%rbp)
mov    -0x68(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x80(%rbp),%eax
cmp    %ecx,%eax
jge    1420 <main+0x280>
mov    -0x68(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%esi
sub    -0x24(%rbp),%esi
lea    0xd09(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%ecx
mov    -0x68(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x68(%rbp)
jmp    142e <main+0x28e>
lea    0xd09(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1433 <main+0x293>
jmp    121d <main+0x7d>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
mov    -0x2c(%rbp),%edi
call   1070 <close@plt>
mov    0x2b71(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
lea    0xe3b(%rip),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
lea    0xe60(%rip),%rbx
mov    %rbx,%rdi
call   10b0 <open@plt>
mov    %eax,0xc(%rsp)
mov    %eax,0x10(%rsp)
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x2dad(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10b0 <open@plt>
mov    %eax,%r15d
mov    %eax,0x1c(%rsp)
mov    0x2ddd(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
lea    0x30(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
lea    0x10(%rsp),%rdi
mov    $0x2,%esi
mov    $0x186a0,%edx
call   10a0 <poll@plt>
test   %eax,%eax
je     1362 <main+0x1b2>
cmp    $0xffffffff,%eax
je     1388 <main+0x1d8>
mov    0x2d7c(%rip),%rax
mov    (%rax),%eax
test   %eax,0x18(%rsp)
je     12c3 <main+0x113>
lea    0xeaa(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1070 <memset@plt>
mov    0xc(%rsp),%edi
mov    %r13,%rsi
mov    %ebp,%edx
call   1090 <read@plt>
cmp    $0xffffffff,%eax
je     13c6 <main+0x216>
mov    %eax,%ebx
lea    0xdce(%rip),%rdi
mov    %eax,%esi
mov    %r13,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
sub    %ebx,%ebp
jle    13e0 <main+0x230>
lea    0xdc6(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d2e(%rip),%rax
mov    (%rax),%eax
test   %eax,0x24(%rsp)
je     1230 <main+0x80>
lea    0xe13(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     139b <main+0x1eb>
mov    %eax,%r12d
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0xd97(%rip),%rdi
mov    %r12d,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
cmp    %eax,%r12d
jl     133c <main+0x18c>
lea    0xdcd(%rip),%rdi
call   1030 <puts@plt>
jmp    1230 <main+0x80>
mov    %r14,%rdi
call   1050 <strlen@plt>
sub    %r12d,%eax
lea    0xd7e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
movslq %r12d,%rax
add    %rax,%r14
jmp    1230 <main+0x80>
lea    0xce9(%rip),%rdi
xor    %ebx,%ebx
mov    $0x64,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcbe(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%ebx
jmp    1377 <main+0x1c7>
lea    0xd01(%rip),%rdi
call   10c0 <perror@plt>
mov    0xc(%rsp),%edi
call   1080 <close@plt>
mov    %r15d,%edi
call   1080 <close@plt>
mov    0x2c01(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
lea    0xc9b(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2bef(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
lea    0xd3d(%rip),%rdi
call   1030 <puts@plt>
jmp    13a7 <main+0x1f7>

LLVM IR (-O0):
%struct.pollfd = type { i32, i32, i32 }
@.str = [63 x i8] c"abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
@.str.1 = [14 x i8] c"/dev/poll_dev\00"
@O_RDONLY = global i32 0
@POLLIN = global i32 0
@O_WRONLY = global i32 0
@POLLOUT = global i32 0
@.str.2 = [5 x i8] c"poll\00"
@.str.3 = [22 x i8] c"%d seconds elapsed, \0A\00"
@.str.4 = [16 x i8] c"fd is readable\0A\00"
@.str.5 = [5 x i8] c"read\00"
@EXIT_FAILURE = global i32 0
@.str.6 = [19 x i8] c"\0AREAD %d byte: %s\0A\00"
@.str.7 = [35 x i8] c"\0ANeeds to read addtional %d bytes\0A\00"
@.str.8 = [32 x i8] c"\0AALL DATA IS READ. Exiting ...\0A\00"
@.str.9 = [16 x i8] c"fd is writable\0A\00"
@.str.10 = [6 x i8] c"write\00"
@.str.11 = [35 x i8] c"\0A WROTE %d byte|size of buffer %d\0A\00"
@.str.12 = [36 x i8] c"\0ANeeds to write addtional %d bytes\0A\00"
@.str.13 = [23 x i8] c"\0A All data is written\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x %struct.pollfd]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [40 x i8]
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0), i8** %8
%11 = load i8*, i8** %8
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %9
%13 = load i32, i32* @O_RDONLY
%14 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %13)
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %2, i64 0, i64 0
%17 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %16, i32 0, i32 0
store i32 %15, i32* %17
%18 = load i32, i32* @POLLIN
%19 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %2, i64 0, i64 0
%20 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %19, i32 0, i32 1
store i32 %18, i32* %20
%21 = load i32, i32* @O_WRONLY
%22 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %21)
store i32 %22, i32* %5
%23 = load i32, i32* %5
%24 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %2, i64 0, i64 1
%25 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %24, i32 0, i32 0
store i32 %23, i32* %25
%26 = load i32, i32* @POLLOUT
%27 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %2, i64 0, i64 1
%28 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %27, i32 0, i32 1
store i32 %26, i32* %28
br label %29
29: ; preds = %0, %120
%30 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %2, i64 0, i64 0
%31 = call i32 @poll(%struct.pollfd* %30, i32 2, i32 100000)
store i32 %31, i32* %3
%32 = load i32, i32* %3
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %128
36: ; preds = %29
%37 = load i32, i32* %3
%38 = icmp ne i32 %37, 0
br i1 %38, label %41, label %39
39: ; preds = %36
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 100)
store i32 0, i32* %1
br label %128
41: ; preds = %36
%42 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %2, i64 0, i64 0
%43 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %42, i32 0, i32 2
%44 = load i32, i32* %43
%45 = load i32, i32* @POLLIN
%46 = and i32 %44, %45
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %80
48: ; preds = %41
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%50 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%51 = call i32 @memset(i8* %50, i32 0, i32 40)
%52 = load i32, i32* %4
%53 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%54 = load i32, i32* %9
%55 = call i32 @read(i32 %52, i8* %53, i32 %54)
store i32 %55, i32* %3
%56 = load i32, i32* %3
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %62
58: ; preds = %48
%59 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%60 = load i32, i32* @EXIT_FAILURE
%61 = call i32 @exit(i32 %60)
unreachable
62: ; preds = %48
%63 = load i32, i32* %3
%64 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %63, i8* %64)
%66 = load i32, i32* %3
%67 = load i32, i32* %9
%68 = icmp slt i32 %66, %67
br i1 %68, label %69, label %77
69: ; preds = %62
%70 = load i32, i32* %9
%71 = load i32, i32* %3
%72 = sub nsw i32 %70, %71
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0), i32 %72)
%74 = load i32, i32* %3
%75 = load i32, i32* %9
%76 = sub nsw i32 %75, %74
store i32 %76, i32* %9
br label %79
77: ; preds = %62
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0))
br label %121
79: ; preds = %69
br label %80
80: ; preds = %79, %41
%81 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %2, i64 0, i64 1
%82 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %81, i32 0, i32 2
%83 = load i32, i32* %82
%84 = load i32, i32* @POLLOUT
%85 = and i32 %83, %84
%86 = icmp ne i32 %85, 0
br i1 %86, label %87, label %120
87: ; preds = %80
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
%89 = load i32, i32* %5
%90 = load i8*, i8** %8
%91 = load i8*, i8** %8
%92 = call i32 @strlen(i8* %91)
%93 = call i32 @write(i32 %89, i8* %90, i32 %92)
store i32 %93, i32* %3
%94 = load i32, i32* %3
%95 = icmp eq i32 %94, -1
br i1 %95, label %96, label %98
96: ; preds = %87
%97 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
br label %121
98: ; preds = %87
%99 = load i32, i32* %3
%100 = load i8*, i8** %8
%101 = call i32 @strlen(i8* %100)
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.11, i64 0, i64 0), i32 %99, i32 %101)
%103 = load i32, i32* %3
%104 = load i8*, i8** %8
%105 = call i32 @strlen(i8* %104)
%106 = icmp slt i32 %103, %105
br i1 %106, label %107, label %117
107: ; preds = %98
%108 = load i8*, i8** %8
%109 = call i32 @strlen(i8* %108)
%110 = load i32, i32* %3
%111 = sub nsw i32 %109, %110
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.12, i64 0, i64 0), i32 %111)
%113 = load i32, i32* %3
%114 = load i8*, i8** %8
%115 = sext i32 %113 to i64
%116 = getelementptr inbounds i8, i8* %114, i64 %115
store i8* %116, i8** %8
br label %119
117: ; preds = %98
%118 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.13, i64 0, i64 0))
br label %119
119: ; preds = %117, %107
br label %120
120: ; preds = %119, %80
br label %29
121: ; preds = %96, %77
%122 = load i32, i32* %4
%123 = call i32 @close(i32 %122)
%124 = load i32, i32* %5
%125 = call i32 @close(i32 %124)
%126 = load i32, i32* @EXIT_SUCCESS
%127 = call i32 @exit(i32 %126)
unreachable
128: ; preds = %39, %34
%129 = load i32, i32* %1
ret i32 %129
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32, i32 }
@.str = [63 x i8] c"abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
@.str.1 = [14 x i8] c"/dev/poll_dev\00"
@O_RDONLY = global i32 0
@POLLIN = global i32 0
@O_WRONLY = global i32 0
@POLLOUT = global i32 0
@.str.2 = [5 x i8] c"poll\00"
@.str.3 = [22 x i8] c"%d seconds elapsed, \0A\00"
@.str.5 = [5 x i8] c"read\00"
@EXIT_FAILURE = global i32 0
@.str.6 = [19 x i8] c"\0AREAD %d byte: %s\0A\00"
@.str.7 = [35 x i8] c"\0ANeeds to read addtional %d bytes\0A\00"
@.str.10 = [6 x i8] c"write\00"
@.str.11 = [35 x i8] c"\0A WROTE %d byte|size of buffer %d\0A\00"
@.str.12 = [36 x i8] c"\0ANeeds to write addtional %d bytes\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [15 x i8] c"fd is writable\00"
@str.14 = [22 x i8] c"\0A All data is written\00"
@str.15 = [15 x i8] c"fd is readable\00"
@str.16 = [31 x i8] c"\0AALL DATA IS READ. Exiting ...\00"
define i32 @main() {
%1 = alloca [2 x %struct.pollfd]
%2 = alloca [40 x i8]
%3 = bitcast [2 x %struct.pollfd]* %1 to i8*
%4 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @O_RDONLY
%7 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %1, i64 0, i64 0
%9 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %1, i64 0, i64 0, i32 0
store i32 %7, i32* %9
%10 = load i32, i32* @POLLIN
%11 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %1, i64 0, i64 0, i32 1
store i32 %10, i32* %11
%12 = load i32, i32* @O_WRONLY
%13 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %1, i64 0, i64 1, i32 0
store i32 %13, i32* %14
%15 = load i32, i32* @POLLOUT
%16 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %1, i64 0, i64 1, i32 1
store i32 %15, i32* %16
%17 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %1, i64 0, i64 0, i32 2
%18 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %1, i64 0, i64 1, i32 2
br label %19
19: ; preds = %69, %0
%20 = phi i8* [ %74, %69 ], [ getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0), %0 ]
%21 = phi i32 [ %52, %69 ], [ %5, %0 ]
br label %22
22: ; preds = %77, %19
%23 = phi i32 [ %21, %19 ], [ %52, %77 ]
%24 = call i32 @poll(%struct.pollfd* %8, i32 2, i32 100000)
switch i32 %24, label %29 [
i32 -1, label %25
i32 0, label %27
]
25: ; preds = %22
%26 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %83
27: ; preds = %22
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 100)
br label %83
29: ; preds = %22
%30 = load i32, i32* %17
%31 = load i32, i32* @POLLIN
%32 = and i32 %31, %30
%33 = icmp eq i32 %32, 0
br i1 %33, label %51, label %34
34: ; preds = %29
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.15, i64 0, i64 0))
%36 = call i32 @memset(i8* %4, i32 0, i32 40)
%37 = call i32 @read(i32 %7, i8* %4, i32 %23)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %43
39: ; preds = %34
%40 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %34
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %37, i8* %4)
%45 = icmp sgt i32 %23, %37
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = sub nsw i32 %23, %37
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0), i32 %47)
br label %51
49: ; preds = %43
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.16, i64 0, i64 0))
br label %78
51: ; preds = %46, %29
%52 = phi i32 [ %47, %46 ], [ %23, %29 ]
%53 = load i32, i32* %18
%54 = load i32, i32* @POLLOUT
%55 = and i32 %54, %53
%56 = icmp eq i32 %55, 0
br i1 %56, label %77, label %57
57: ; preds = %51
%58 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%59 = call i32 @strlen(i8* %20)
%60 = call i32 @write(i32 %13, i8* %20, i32 %59)
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %64
62: ; preds = %57
%63 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
br label %78
64: ; preds = %57
%65 = call i32 @strlen(i8* %20)
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.11, i64 0, i64 0), i32 %60, i32 %65)
%67 = call i32 @strlen(i8* %20)
%68 = icmp slt i32 %60, %67
br i1 %68, label %69, label %75
69: ; preds = %64
%70 = call i32 @strlen(i8* %20)
%71 = sub nsw i32 %70, %60
%72 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.12, i64 0, i64 0), i32 %71)
%73 = sext i32 %60 to i64
%74 = getelementptr inbounds i8, i8* %20, i64 %73
br label %19
75: ; preds = %64
%76 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.14, i64 0, i64 0))
br label %77
77: ; preds = %75, %51
br label %22
78: ; preds = %62, %49
%79 = call i32 @close(i32 %7)
%80 = call i32 @close(i32 %13)
%81 = load i32, i32* @EXIT_SUCCESS
%82 = call i32 @exit(i32 %81)
unreachable
83: ; preds = %27, %25
%84 = phi i32 [ -1, %25 ], [ 0, %27 ]
ret i32 %84
}