#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_cc;
  scalar_t__ c_lflag;
  scalar_t__ c_oflag;
  scalar_t__ c_iflag;
  scalar_t__ c_cflag;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int O_NOCTTY;
int O_NONBLOCK;
int O_RDWR;
int /*<<< orphan*/ TCIFLUSH;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ WX_milliSleep(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int open(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdout;
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
void runClientLoop(int recvFromServer) {
  struct termios oldkey, newkey;
  FILE *sendToServerfd;
  char Key;
  int tty;
  printf("\nAttempting to connect to Server...\n\n");
  if ((sendToServerfd = fopen("/tmp/WX_serverReceive", "w")) == NULL) {
    fprintf(stderr,
            "RTL-Wx: Unable to open pipe %s for sending commands to server.  "
            "Exiting...\n\n",
            "/tmp/WX_serverReceive");
    exit(1);
  }
  printf("Suceeded! \n\n");
  fputc('x', sendToServerfd);
  fflush(sendToServerfd);
  tty = open("/dev/tty", O_RDWR | O_NOCTTY | O_NONBLOCK);
  tcgetattr(tty, &oldkey);
  newkey.c_cflag = 0;
  newkey.c_iflag = 0;
  newkey.c_oflag = 0;
  newkey.c_lflag = 0;
  newkey.c_cc[VMIN] = 1;
  newkey.c_cc[VTIME] = 0;
  tcflush(tty, TCIFLUSH);
  tcsetattr(tty, TCSANOW, &newkey);
  Key = 0;
  while (Key != 'q') {
    char outChar;
    Key = 0;
    read(tty, &Key, 1);
    if ((Key != 0) && (Key != 'q')) {
      fputc(Key, sendToServerfd);
      fflush(sendToServerfd);
    }
    outChar = 0;
    read(recvFromServer, &outChar, 1);
    while (outChar != 0) {
      fputc(outChar, stdout);
      outChar = 0;
      read(recvFromServer, &outChar, 1);
    }
    WX_milliSleep(100);
  }
  tcsetattr(tty, TCSANOW, &oldkey);
  close(tty);
  fclose(sendToServerfd);
  printf("RTL-Wx Client exiting...\n");
}


x86 assembly (clang, -O0):
<runClientLoop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
lea    0xe0e(%rip),%rdi
call   1050 <printf@plt>
lea    0xe28(%rip),%rdi
lea    0xe37(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x60(%rbp)
cmp    $0x0,%rax
jne    123e <runClientLoop+0x5e>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
lea    0xe16(%rip),%rsi
lea    0xdf7(%rip),%rdx
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    0xe46(%rip),%rdi
call   1050 <printf@plt>
mov    -0x60(%rbp),%rsi
mov    $0x78,%edi
call   1080 <fputc@plt>
mov    -0x60(%rbp),%rdi
call   10b0 <fflush@plt>
mov    0x2d80(%rip),%rax
mov    (%rax),%esi
mov    0x2d47(%rip),%rax
or     (%rax),%esi
mov    0x2d66(%rip),%rax
or     (%rax),%esi
lea    0xe15(%rip),%rdi
call   10e0 <open@plt>
mov    %eax,-0x68(%rbp)
mov    -0x68(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   10c0 <tcgetattr@plt>
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x58(%rbp),%rax
mov    0x2d0e(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x58(%rbp),%rax
mov    0x2cc9(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x68(%rbp),%edi
mov    0x2cd5(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
mov    -0x68(%rbp),%edi
mov    0x2cdc(%rip),%rax
mov    (%rax),%esi
lea    -0x58(%rbp),%rdx
call   10d0 <tcsetattr@plt>
movb   $0x0,-0x61(%rbp)
movsbl -0x61(%rbp),%eax
cmp    $0x71,%eax
je     13bf <runClientLoop+0x1df>
movb   $0x0,-0x61(%rbp)
mov    -0x68(%rbp),%edi
lea    -0x61(%rbp),%rsi
mov    $0x1,%edx
call   1090 <read@plt>
movsbl -0x61(%rbp),%eax
cmp    $0x0,%eax
je     135f <runClientLoop+0x17f>
movsbl -0x61(%rbp),%eax
cmp    $0x71,%eax
je     135f <runClientLoop+0x17f>
mov    -0x61(%rbp),%al
mov    -0x60(%rbp),%rsi
movsbl %al,%edi
call   1080 <fputc@plt>
mov    -0x60(%rbp),%rdi
call   10b0 <fflush@plt>
movb   $0x0,-0x69(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x69(%rbp),%rsi
mov    $0x1,%edx
call   1090 <read@plt>
movsbl -0x69(%rbp),%eax
cmp    $0x0,%eax
je     13b0 <runClientLoop+0x1d0>
mov    -0x69(%rbp),%al
mov    0x2c1d(%rip),%rcx
mov    (%rcx),%rsi
movsbl %al,%edi
call   1080 <fputc@plt>
movb   $0x0,-0x69(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x69(%rbp),%rsi
mov    $0x1,%edx
call   1090 <read@plt>
jmp    1374 <runClientLoop+0x194>
mov    $0x64,%edi
call   1060 <WX_milliSleep@plt>
jmp    130b <runClientLoop+0x12b>
mov    -0x68(%rbp),%edi
mov    0x2c0f(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   10d0 <tcsetattr@plt>
mov    -0x68(%rbp),%edi
call   1070 <close@plt>
mov    -0x60(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xcb5(%rip),%rdi
call   1050 <printf@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<runClientLoop>:
push   %rbx
sub    $0x30,%rsp
lea    0xee2(%rip),%rdi
call   1030 <puts@plt>
lea    0xe68(%rip),%rdi
lea    0xe77(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
jne    11cf <runClientLoop+0x4f>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
lea    0xe5f(%rip),%rsi
lea    0xe40(%rip),%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    %rax,%rbx
lea    0xeba(%rip),%rdi
call   1030 <puts@plt>
mov    $0x78,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
mov    %rbx,%rdi
call   1060 <fflush@plt>
mov    0x2dee(%rip),%rax
mov    0x2dcf(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2dd4(%rip),%rax
or     (%rax),%esi
lea    0xe50(%rip),%rdi
call   1080 <open@plt>
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   1070 <tcgetattr@plt>

LLVM IR (-O0):
%struct.termios = type { i32*, i64, i64, i64, i64 }
@.str = [38 x i8] c"\0AAttempting to connect to Server...\0A\0A\00"
@.str.1 = [22 x i8] c"/tmp/WX_serverReceive\00"
@.str.2 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.3 = [77 x i8] c"RTL-Wx: Unable to open pipe %s for sending commands to server. Exiting...\0A\0A\00"
@.str.4 = [13 x i8] c"Suceeded! \0A\0A\00"
@.str.5 = [9 x i8] c"/dev/tty\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NONBLOCK = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
@stdout = global i32* null
@.str.6 = [26 x i8] c"RTL-Wx Client exiting...\0A\00"
define void @runClientLoop(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.termios
%4 = alloca %struct.termios
%5 = alloca i32*
%6 = alloca i8
%7 = alloca i32
%8 = alloca i8
store i32 %0, i32* %2
%9 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%10 = call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %10, i32** %5
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %1
%17 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%18 = load i32*, i32** %5
%19 = call i32 @fputc(i8 signext 120, i32* %18)
%20 = load i32*, i32** %5
%21 = call i32 @fflush(i32* %20)
%22 = load i32, i32* @O_RDWR
%23 = load i32, i32* @O_NOCTTY
%24 = or i32 %22, %23
%25 = load i32, i32* @O_NONBLOCK
%26 = or i32 %24, %25
%27 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %26)
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = call i32 @tcgetattr(i32 %28, %struct.termios* %3)
%30 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 4
store i64 0, i64* %30
%31 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 3
store i64 0, i64* %31
%32 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 2
store i64 0, i64* %32
%33 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
store i64 0, i64* %33
%34 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%35 = load i32*, i32** %34
%36 = load i64, i64* @VMIN
%37 = getelementptr inbounds i32, i32* %35, i64 %36
store i32 1, i32* %37
%38 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%39 = load i32*, i32** %38
%40 = load i64, i64* @VTIME
%41 = getelementptr inbounds i32, i32* %39, i64 %40
store i32 0, i32* %41
%42 = load i32, i32* %7
%43 = load i32, i32* @TCIFLUSH
%44 = call i32 @tcflush(i32 %42, i32 %43)
%45 = load i32, i32* %7
%46 = load i32, i32* @TCSANOW
%47 = call i32 @tcsetattr(i32 %45, i32 %46, %struct.termios* %4)
store i8 0, i8* %6
br label %48
48: ; preds = %81, %16
%49 = load i8, i8* %6
%50 = sext i8 %49 to i32
%51 = icmp ne i32 %50, 113
br i1 %51, label %52, label %83
52: ; preds = %48
store i8 0, i8* %6
%53 = load i32, i32* %7
%54 = call i32 @read(i32 %53, i8* %6, i32 1)
%55 = load i8, i8* %6
%56 = sext i8 %55 to i32
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %68
58: ; preds = %52
%59 = load i8, i8* %6
%60 = sext i8 %59 to i32
%61 = icmp ne i32 %60, 113
br i1 %61, label %62, label %68
62: ; preds = %58
%63 = load i8, i8* %6
%64 = load i32*, i32** %5
%65 = call i32 @fputc(i8 signext %63, i32* %64)
%66 = load i32*, i32** %5
%67 = call i32 @fflush(i32* %66)
br label %68
68: ; preds = %62, %58, %52
store i8 0, i8* %8
%69 = load i32, i32* %2
%70 = call i32 @read(i32 %69, i8* %8, i32 1)
br label %71
71: ; preds = %75, %68
%72 = load i8, i8* %8
%73 = sext i8 %72 to i32
%74 = icmp ne i32 %73, 0
br i1 %74, label %75, label %81
75: ; preds = %71
%76 = load i8, i8* %8
%77 = load i32*, i32** @stdout
%78 = call i32 @fputc(i8 signext %76, i32* %77)
store i8 0, i8* %8
%79 = load i32, i32* %2
%80 = call i32 @read(i32 %79, i8* %8, i32 1)
br label %71
81: ; preds = %71
%82 = call i32 @WX_milliSleep(i32 100)
br label %48
83: ; preds = %48
%84 = load i32, i32* %7
%85 = load i32, i32* @TCSANOW
%86 = call i32 @tcsetattr(i32 %84, i32 %85, %struct.termios* %3)
%87 = load i32, i32* %7
%88 = call i32 @close(i32 %87)
%89 = load i32*, i32** %5
%90 = call i32 @fclose(i32* %89)
%91 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32*, i64, i64, i64, i64 }
@.str.1 = [22 x i8] c"/tmp/WX_serverReceive\00"
@.str.2 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.3 = [77 x i8] c"RTL-Wx: Unable to open pipe %s for sending commands to server. Exiting...\0A\0A\00"
@.str.5 = [9 x i8] c"/dev/tty\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NONBLOCK = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
@stdout = global i32* null
@str = [37 x i8] c"\0AAttempting to connect to Server...\0A\00"
@str.7 = [12 x i8] c"Suceeded! \0A\00"
define void @runClientLoop(i32 %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %1
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.7, i64 0, i64 0))
%13 = tail call i32 @fputc(i8 signext 120, i32* %5)
%14 = tail call i32 @fflush(i32* %5)
%15 = load i32, i32* @O_RDWR
%16 = load i32, i32* @O_NOCTTY
%17 = or i32 %16, %15
%18 = load i32, i32* @O_NONBLOCK
%19 = or i32 %17, %18
%20 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %19)
%21 = call i32 @tcgetattr(i32 %20, %struct.termios* %2)
unreachable
}