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

/* Variables and functions */
int /*<<< orphan*/ WX_milliSleep(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 /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdout;
void runRemoteCommand(int recvFromServer, char command) {
  FILE *sendToServerfd;
  int i;
  char outChar = 0;
  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);
  }
  read(recvFromServer, &outChar, 1);
  while (outChar != 0) {
    outChar = 0;
    read(recvFromServer, &outChar, 1);
  }
  if ((command == 'q') || (command == 0x1b) || (command == 03))
    command = ' ';
  fputc(command, sendToServerfd);
  fflush(sendToServerfd);
  for (i = 0; i < 10; i++) {
    char outChar = 0;
    read(recvFromServer, &outChar, 1);
    while (outChar != 0) {
      fputc(outChar, stdout);
      fflush(stdout);
      outChar = 0;
      read(recvFromServer, &outChar, 1);
    }
    WX_milliSleep(100);
  }
  fclose(sendToServerfd);
}


x86 assembly (clang, -O0):
<runRemoteCommand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
movb   $0x0,-0x15(%rbp)
lea    0xe64(%rip),%rdi
lea    0xe73(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11dc <runRemoteCommand+0x5c>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xe52(%rip),%rsi
lea    0xe33(%rip),%rdx
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x4(%rbp),%edi
lea    -0x15(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
movsbl -0x15(%rbp),%eax
cmp    $0x0,%eax
je     1214 <runRemoteCommand+0x94>
movb   $0x0,-0x15(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x15(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
jmp    11ed <runRemoteCommand+0x6d>
movsbl -0x5(%rbp),%eax
cmp    $0x71,%eax
je     123b <runRemoteCommand+0xbb>
movsbl -0x5(%rbp),%eax
cmp    $0x1b,%eax
je     123b <runRemoteCommand+0xbb>
movsbl -0x5(%rbp),%eax
cmp    $0x3,%eax
jne    123f <runRemoteCommand+0xbf>
movb   $0x20,-0x5(%rbp)
mov    -0x5(%rbp),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1050 <fputc@plt>
mov    -0x10(%rbp),%rdi
call   1080 <fflush@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    12e0 <runRemoteCommand+0x160>
movb   $0x0,-0x16(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x16(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
movsbl -0x16(%rbp),%eax
cmp    $0x0,%eax
je     12c8 <runRemoteCommand+0x148>
mov    -0x16(%rbp),%al
mov    0x2d44(%rip),%rcx
mov    (%rcx),%rsi
movsbl %al,%edi
call   1050 <fputc@plt>
mov    0x2d32(%rip),%rax
mov    (%rax),%rdi
call   1080 <fflush@plt>
movb   $0x0,-0x16(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x16(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
jmp    127d <runRemoteCommand+0xfd>
mov    $0x64,%edi
call   1040 <WX_milliSleep@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    125e <runRemoteCommand+0xde>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<runRemoteCommand>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r15d
mov    %edi,%ebx
movb   $0x0,0xe(%rsp)
lea    0xe63(%rip),%rdi
lea    0xe72(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     129a <runRemoteCommand+0x11a>
mov    %rax,%r14
lea    0xe(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1060 <read@plt>
cmpb   $0x0,0xe(%rsp)
je     11fb <runRemoteCommand+0x7b>
lea    0xe(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0x0,0xe(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
cmpb   $0x0,0xe(%rsp)
jne    11e0 <runRemoteCommand+0x60>
cmp    $0x1b,%r15b
movzbl %r15b,%eax
mov    $0x20,%ecx
mov    %eax,%edx
cmove  %ecx,%edx
cmp    $0x71,%al
cmove  %ecx,%edx
cmp    $0x3,%al
cmove  %ecx,%edx
movsbl %dl,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
mov    %r14,%rdi
call   1080 <fflush@plt>
xor    %r12d,%r12d
lea    0xf(%rsp),%r15
mov    0x2d9f(%rip),%rbp
jmp    1255 <runRemoteCommand+0xd5>
nopl   0x0(%rax,%rax,1)
mov    0x0(%rbp),%rsi
movsbl %al,%edi
call   1050 <fputc@plt>
mov    0x0(%rbp),%rdi
call   1080 <fflush@plt>
movb   $0x0,0xf(%rsp)
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
movzbl 0xf(%rsp),%eax
test   %al,%al
jne    1240 <runRemoteCommand+0xc0>
mov    $0x64,%edi
call   1040 <WX_milliSleep@plt>
add    $0x1,%r12d
cmp    $0xa,%r12d
jne    1255 <runRemoteCommand+0xd5>
mov    %r14,%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
mov    0x2d3f(%rip),%rax
mov    (%rax),%edi
lea    0xd6e(%rip),%rsi
lea    0xd4f(%rip),%rdx
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"/tmp/WX_serverReceive\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [77 x i8] c"RTL-Wx: Unable to open pipe %s for sending commands to server. Exiting...\0A\0A\00"
@stdout = global i32* null
define void @runRemoteCommand(i32 %0, i8 signext %1) {
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8
store i32 %0, i32* %3
store i8 %1, i8* %4
store i8 0, i8* %7
%9 = call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %5
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i32, i32* %3
%17 = call i32 @read(i32 %16, i8* %7, i32 1)
br label %18
18: ; preds = %22, %15
%19 = load i8, i8* %7
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
store i8 0, i8* %7
%23 = load i32, i32* %3
%24 = call i32 @read(i32 %23, i8* %7, i32 1)
br label %18
25: ; preds = %18
%26 = load i8, i8* %4
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 113
br i1 %28, label %37, label %29
29: ; preds = %25
%30 = load i8, i8* %4
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 27
br i1 %32, label %37, label %33
33: ; preds = %29
%34 = load i8, i8* %4
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 3
br i1 %36, label %37, label %38
37: ; preds = %33, %29, %25
store i8 32, i8* %4
br label %38
38: ; preds = %37, %33
%39 = load i8, i8* %4
%40 = load i32*, i32** %5
%41 = call i32 @fputc(i8 signext %39, i32* %40)
%42 = load i32*, i32** %5
%43 = call i32 @fflush(i32* %42)
store i32 0, i32* %6
br label %44
44: ; preds = %64, %38
%45 = load i32, i32* %6
%46 = icmp slt i32 %45, 10
br i1 %46, label %47, label %67
47: ; preds = %44
store i8 0, i8* %8
%48 = load i32, i32* %3
%49 = call i32 @read(i32 %48, i8* %8, i32 1)
br label %50
50: ; preds = %54, %47
%51 = load i8, i8* %8
%52 = sext i8 %51 to i32
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %62
54: ; preds = %50
%55 = load i8, i8* %8
%56 = load i32*, i32** @stdout
%57 = call i32 @fputc(i8 signext %55, i32* %56)
%58 = load i32*, i32** @stdout
%59 = call i32 @fflush(i32* %58)
store i8 0, i8* %8
%60 = load i32, i32* %3
%61 = call i32 @read(i32 %60, i8* %8, i32 1)
br label %50
62: ; preds = %50
%63 = call i32 @WX_milliSleep(i32 100)
br label %64
64: ; preds = %62
%65 = load i32, i32* %6
%66 = add nsw i32 %65, 1
store i32 %66, i32* %6
br label %44
67: ; preds = %44
%68 = load i32*, i32** %5
%69 = call i32 @fclose(i32* %68)
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"/tmp/WX_serverReceive\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [77 x i8] c"RTL-Wx: Unable to open pipe %s for sending commands to server. Exiting...\0A\0A\00"
@stdout = global i32* null
define void @runRemoteCommand(i32 %0, i8 signext %1) {
%3 = alloca i8
%4 = alloca i8
store i8 0, i8* %3
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = call i32 @read(i32 %0, i8* %3, i32 1)
%13 = load i8, i8* %3
%14 = icmp eq i8 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %11, %15
store i8 0, i8* %3
%16 = call i32 @read(i32 %0, i8* %3, i32 1)
%17 = load i8, i8* %3
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %15
19: ; preds = %15, %11
%20 = icmp eq i8 %1, 113
%21 = icmp eq i8 %1, 27
%22 = or i1 %20, %21
%23 = icmp eq i8 %1, 3
%24 = or i1 %23, %22
%25 = select i1 %24, i8 32, i8 %1
%26 = tail call i32 @fputc(i8 signext %25, i32* %5)
%27 = tail call i32 @fflush(i32* %5)
br label %28
28: ; preds = %19, %42
%29 = phi i32 [ 0, %19 ], [ %44, %42 ]
store i8 0, i8* %4
%30 = call i32 @read(i32 %0, i8* %4, i32 1)
%31 = load i8, i8* %4
%32 = icmp eq i8 %31, 0
br i1 %32, label %42, label %33
33: ; preds = %28, %33
%34 = phi i8 [ %40, %33 ], [ %31, %28 ]
%35 = load i32*, i32** @stdout
%36 = tail call i32 @fputc(i8 signext %34, i32* %35)
%37 = load i32*, i32** @stdout
%38 = tail call i32 @fflush(i32* %37)
store i8 0, i8* %4
%39 = call i32 @read(i32 %0, i8* %4, i32 1)
%40 = load i8, i8* %4
%41 = icmp eq i8 %40, 0
br i1 %41, label %42, label %33
42: ; preds = %33, %28
%43 = tail call i32 @WX_milliSleep(i32 100)
%44 = add nuw nsw i32 %29, 1
%45 = icmp eq i32 %44, 10
br i1 %45, label %46, label %28
46: ; preds = %42
%47 = tail call i32 @fclose(i32* %5)
ret void
}