#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 timeval {
  int tv_usec;
  scalar_t__ tv_sec;
};
struct sockaddr_un {
  int /*<<< orphan*/ sun_path;
  int /*<<< orphan*/ sun_family;
};
struct sockaddr {
  int dummy;
};
struct dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
scalar_t__ fexist(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ getcwd(char *, int);
int /*<<< orphan*/ negotiateTelnetOptions(int);
int /*<<< orphan*/ *opendir(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, unsigned char *, int);
struct dirent *readdir(int /*<<< orphan*/ *);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct timeval *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int strlen(int /*<<< orphan*/);
scalar_t__ strstr(char *, char *);
int telnetInterpret(unsigned char *, int);
int /*<<< orphan*/ write(int, unsigned char *, int);
int /*<<< orphan*/ writeWIAC(int, unsigned char *, int);
int main(void) {
  int s, t, nt, len, retval;
  struct sockaddr_un remote;
  struct timeval tv;
  fd_set rfds, wfds;
  char tmptext[128];
  char lockpath[128];
  unsigned char str[512];
  struct dirent *dirp = NULL;
  DIR *dir = NULL;
  if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
    perror("socket");
    exit(1);
  }
  dir = opendir(getcwd(tmptext, 128));
  while ((dirp = readdir(dir))) {
    if (strstr(dirp->d_name, "maxipc") && !strstr(dirp->d_name, ".lck")) {
      sprintf(lockpath, "%s.lck", dirp->d_name);
      if (fexist(lockpath))
        continue;
      strcpy(remote.sun_path, dirp->d_name);
      remote.sun_family = AF_UNIX;
      break;
    }
  }
  negotiateTelnetOptions(1);
  len = strlen(remote.sun_path) + sizeof(remote.sun_family);
  if (connect(s, (struct sockaddr *)&remote, len) == -1) {
    perror("Sorry no more free nodes!");
    exit(1);
  }
  for (;;) {
    tv.tv_usec = 5;
    tv.tv_sec = 0;
    FD_ZERO(&wfds);
    FD_SET(s, &wfds);
    if (select(s + 1, &wfds, 0, 0, &tv) > 0) {
      if ((t = read(s, str, 512)) > 0) {
        writeWIAC(1, str, t);
      } else {
        if (t < 0)
          perror("recv");
        else
          fprintf(stdout, "Server closed connection\n");
        exit(1);
      }
    }
    FD_ZERO(&rfds);
    FD_SET(0, &rfds);
    tv.tv_usec = 5;
    tv.tv_sec = 0;
    if ((retval = select(0 + 1, &rfds, 0, 0, &tv)) > 0) {
      if ((t = read(0, str, 512))) {
        t = telnetInterpret(str, t);
        write(s, str, t);
      } else {
        exit(1);
      }
    }
  }
  close(s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x350,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x348(%rbp)
movq   $0x0,-0x350(%rbp)
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
mov    0x2d50(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1170 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    12b3 <main+0x63>
lea    0xd5c(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
lea    -0xc0(%rbp),%rdi
mov    $0x80,%esi
call   10a0 <getcwd@plt>
mov    %eax,%edi
call   1060 <opendir@plt>
mov    %rax,-0x350(%rbp)
mov    -0x350(%rbp),%rdi
call   10f0 <readdir@plt>
mov    %rax,-0x348(%rbp)
cmp    $0x0,%rax
je     138f <main+0x13f>
mov    -0x348(%rbp),%rax
mov    (%rax),%rdi
lea    0xd07(%rip),%rsi
call   1160 <strstr@plt>
cmp    $0x0,%rax
je     138a <main+0x13a>
mov    -0x348(%rbp),%rax
mov    (%rax),%rdi
lea    0xcf0(%rip),%rsi
call   1160 <strstr@plt>
cmp    $0x0,%rax
jne    138a <main+0x13a>
lea    -0x140(%rbp),%rdi
mov    -0x348(%rbp),%rax
mov    (%rax),%rdx
lea    0xcc7(%rip),%rsi
call   1110 <sprintf@plt>
lea    -0x140(%rbp),%rdi
call   1040 <fexist@plt>
cmp    $0x0,%rax
je     1367 <main+0x117>
jmp    12d2 <main+0x82>
mov    -0x20(%rbp),%edi
mov    -0x348(%rbp),%rax
mov    (%rax),%rsi
call   1030 <strcpy@plt>
mov    0x2c68(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    138f <main+0x13f>
jmp    12d2 <main+0x82>
mov    $0x1,%edi
call   1090 <negotiateTelnetOptions@plt>
mov    -0x20(%rbp),%edi
call   1080 <strlen@plt>
cltq
add    $0x4,%rax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1130 <connect@plt>
cmp    $0xffffffff,%eax
jne    13d8 <main+0x188>
lea    0xc4c(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
jmp    13dd <main+0x18d>
movl   $0x5,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
lea    -0x38(%rbp),%rdi
call   10d0 <FD_ZERO@plt>
mov    -0x8(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   1150 <FD_SET@plt>
mov    -0x8(%rbp),%edi
add    $0x1,%edi
lea    -0x38(%rbp),%rsi
xor    %ecx,%ecx
lea    -0x30(%rbp),%r8
mov    %ecx,%edx
call   10e0 <select@plt>
cmp    $0x0,%eax
jle    1499 <main+0x249>
mov    -0x8(%rbp),%edi
lea    -0x340(%rbp),%rsi
mov    $0x200,%edx
call   10b0 <read@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jle    145a <main+0x20a>
lea    -0x340(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    $0x1,%edi
call   1140 <writeWIAC@plt>
jmp    1494 <main+0x244>
cmpl   $0x0,-0xc(%rbp)
jge    1475 <main+0x225>
lea    0xbc4(%rip),%rdi
call   1100 <perror@plt>
jmp    148a <main+0x23a>
mov    0x2b54(%rip),%rax
mov    (%rax),%edi
lea    0xbaf(%rip),%rsi
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
jmp    1499 <main+0x249>
lea    -0x34(%rbp),%rdi
call   10d0 <FD_ZERO@plt>
xor    %edi,%edi
lea    -0x34(%rbp),%rsi
call   1150 <FD_SET@plt>
movl   $0x5,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
mov    $0x1,%edi
lea    -0x34(%rbp),%rsi
xor    %ecx,%ecx
lea    -0x30(%rbp),%r8
mov    %ecx,%edx
call   10e0 <select@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jle    1535 <main+0x2e5>
lea    -0x340(%rbp),%rsi
xor    %edi,%edi
mov    $0x200,%edx
call   10b0 <read@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
je     1526 <main+0x2d6>
lea    -0x340(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1070 <telnetInterpret@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x340(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1050 <write@plt>
jmp    1530 <main+0x2e0>
mov    $0x1,%edi
call   1120 <exit@plt>
jmp    1535 <main+0x2e5>
jmp    13dd <main+0x18d>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x328,%rsp
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
mov    0x2d67(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1170 <socket@plt>
cmp    $0xffffffff,%eax
jne    128b <main+0x3b>
lea    0xd7a(%rip),%rdi
jmp    1472 <main+0x222>
mov    %eax,%r12d
lea    0xa0(%rsp),%rdi
mov    $0x80,%esi
call   10a0 <getcwd@plt>
mov    %eax,%edi
call   1060 <opendir@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   10f0 <readdir@plt>
test   %rax,%rax
jne    12eb <main+0x9b>
mov    $0x1,%edi
call   1090 <negotiateTelnetOptions@plt>
call   1080 <strlen@plt>
lea    0x4(%rax),%edx
lea    0x10(%rsp),%rsi
mov    %r12d,%edi
call   1130 <connect@plt>
cmp    $0xffffffff,%eax
jne    137d <main+0x12d>
lea    0xd2f(%rip),%rdi
jmp    1472 <main+0x222>
mov    %rax,%rbp
lea    0xd12(%rip),%r14
lea    0xd14(%rip),%r15
lea    0x20(%rsp),%r13
jmp    1320 <main+0xd0>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   10f0 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     12b7 <main+0x67>
mov    0x0(%rbp),%rdi
mov    %r14,%rsi
call   1160 <strstr@plt>
test   %rax,%rax
je     1310 <main+0xc0>
mov    0x0(%rbp),%rdi
mov    %r15,%rsi
call   1160 <strstr@plt>
test   %rax,%rax
jne    1310 <main+0xc0>
mov    0x0(%rbp),%rdx
mov    %r13,%rdi
lea    0xcbe(%rip),%rsi
call   1110 <sprintf@plt>
mov    %r13,%rdi
call   1040 <fexist@plt>
test   %rax,%rax
jne    1310 <main+0xc0>
mov    0x0(%rbp),%rsi
call   1030 <strcpy@plt>
mov    0x2c76(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
jmp    12b7 <main+0x67>
mov    %r12d,%r14d
add    $0x1,%r14d
lea    0x18(%rsp),%r13
mov    %rsp,%r15
lea    0x120(%rsp),%rbx
lea    0x1c(%rsp),%rbp
nopl   0x0(%rax)
movl   $0x5,(%rsp)
movq   $0x0,0x8(%rsp)
mov    %r13,%rdi
call   10d0 <FD_ZERO@plt>
mov    %r12d,%edi
mov    %r13,%rsi
call   1150 <FD_SET@plt>
mov    %r14d,%edi
mov    %r13,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r15,%r8
call   10e0 <select@plt>
test   %eax,%eax
jle    13fc <main+0x1ac>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   10b0 <read@plt>
test   %eax,%eax
jle    1469 <main+0x219>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1140 <writeWIAC@plt>
mov    %rbp,%rdi
call   10d0 <FD_ZERO@plt>
xor    %edi,%edi
mov    %rbp,%rsi
call   1150 <FD_SET@plt>
movl   $0x5,(%rsp)
movq   $0x0,0x8(%rsp)
mov    $0x1,%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r15,%r8
call   10e0 <select@plt>
test   %eax,%eax
jle    13a0 <main+0x150>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   10b0 <read@plt>
test   %eax,%eax
je     1496 <main+0x246>
mov    %rbx,%rdi
mov    %eax,%esi
call   1070 <telnetInterpret@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
jmp    13a0 <main+0x150>
jns    1481 <main+0x231>
lea    0xbbd(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    0x2b48(%rip),%rax
mov    (%rax),%edi
lea    0xba3(%rip),%rsi
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.timeval = type { i32, i64 }
%struct.dirent = type { i8* }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [7 x i8] c"maxipc\00"
@.str.2 = [5 x i8] c".lck\00"
@.str.3 = [7 x i8] c"%s.lck\00"
@.str.4 = [26 x i8] c"Sorry no more free nodes!\00"
@.str.5 = [5 x i8] c"recv\00"
@stdout = global i32 0
@.str.6 = [26 x i8] c"Server closed connection\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.sockaddr_un
%8 = alloca %struct.timeval
%9 = alloca i32
%10 = alloca i32
%11 = alloca [128 x i8]
%12 = alloca [128 x i8]
%13 = alloca [512 x i8]
%14 = alloca %struct.dirent*
%15 = alloca i32*
store i32 0, i32* %1
store %struct.dirent* null, %struct.dirent** %14
store i32* null, i32** %15
%16 = load i32, i32* @AF_UNIX
%17 = load i32, i32* @SOCK_STREAM
%18 = call i32 @socket(i32 %16, i32 %17, i32 0)
store i32 %18, i32* %2
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %0
%21 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %0
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%25 = call i32 @getcwd(i8* %24, i32 128)
%26 = call i32* @opendir(i32 %25)
store i32* %26, i32** %15
br label %27
27: ; preds = %62, %52, %23
%28 = load i32*, i32** %15
%29 = call %struct.dirent* @readdir(i32* %28)
store %struct.dirent* %29, %struct.dirent** %14
%30 = icmp ne %struct.dirent* %29, null
br i1 %30, label %31, label %63
31: ; preds = %27
%32 = load %struct.dirent*, %struct.dirent** %14
%33 = getelementptr inbounds %struct.dirent, %struct.dirent* %32, i32 0, i32 0
%34 = load i8*, i8** %33
%35 = call i64 @strstr(i8* %34, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %62
37: ; preds = %31
%38 = load %struct.dirent*, %struct.dirent** %14
%39 = getelementptr inbounds %struct.dirent, %struct.dirent* %38, i32 0, i32 0
%40 = load i8*, i8** %39
%41 = call i64 @strstr(i8* %40, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%42 = icmp ne i64 %41, 0
br i1 %42, label %62, label %43
43: ; preds = %37
%44 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%45 = load %struct.dirent*, %struct.dirent** %14
%46 = getelementptr inbounds %struct.dirent, %struct.dirent* %45, i32 0, i32 0
%47 = load i8*, i8** %46
%48 = call i32 @sprintf(i8* %44, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %47)
%49 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%50 = call i64 @fexist(i8* %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %43
br label %27
53: ; preds = %43
%54 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 0
%55 = load i32, i32* %54
%56 = load %struct.dirent*, %struct.dirent** %14
%57 = getelementptr inbounds %struct.dirent, %struct.dirent* %56, i32 0, i32 0
%58 = load i8*, i8** %57
%59 = call i32 @strcpy(i32 %55, i8* %58)
%60 = load i32, i32* @AF_UNIX
%61 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 1
store i32 %60, i32* %61
br label %63
62: ; preds = %37, %31
br label %27
63: ; preds = %53, %27
%64 = call i32 @negotiateTelnetOptions(i32 1)
%65 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 0
%66 = load i32, i32* %65
%67 = call i32 @strlen(i32 %66)
%68 = sext i32 %67 to i64
%69 = add i64 %68, 4
%70 = trunc i64 %69 to i32
store i32 %70, i32* %5
%71 = load i32, i32* %2
%72 = bitcast %struct.sockaddr_un* %7 to %struct.sockaddr*
%73 = load i32, i32* %5
%74 = call i32 @connect(i32 %71, %struct.sockaddr* %72, i32 %73)
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %79
76: ; preds = %63
%77 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%78 = call i32 @exit(i32 1)
unreachable
79: ; preds = %63
br label %80
80: ; preds = %132, %79
%81 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
store i32 5, i32* %81
%82 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
store i64 0, i64* %82
%83 = call i32 @FD_ZERO(i32* %10)
%84 = load i32, i32* %2
%85 = call i32 @FD_SET(i32 %84, i32* %10)
%86 = load i32, i32* %2
%87 = add nsw i32 %86, 1
%88 = call i32 @select(i32 %87, i32* %10, i32 0, i32 0, %struct.timeval* %8)
%89 = icmp sgt i32 %88, 0
br i1 %89, label %90, label %110
90: ; preds = %80
%91 = load i32, i32* %2
%92 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%93 = call i32 @read(i32 %91, i8* %92, i32 512)
store i32 %93, i32* %3
%94 = icmp sgt i32 %93, 0
br i1 %94, label %95, label %99
95: ; preds = %90
%96 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%97 = load i32, i32* %3
%98 = call i32 @writeWIAC(i32 1, i8* %96, i32 %97)
br label %109
99: ; preds = %90
%100 = load i32, i32* %3
%101 = icmp slt i32 %100, 0
br i1 %101, label %102, label %104
102: ; preds = %99
%103 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %107
104: ; preds = %99
%105 = load i32, i32* @stdout
%106 = call i32 @fprintf(i32 %105, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
br label %107
107: ; preds = %104, %102
%108 = call i32 @exit(i32 1)
unreachable
109: ; preds = %95
br label %110
110: ; preds = %109, %80
%111 = call i32 @FD_ZERO(i32* %9)
%112 = call i32 @FD_SET(i32 0, i32* %9)
%113 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
store i32 5, i32* %113
%114 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
store i64 0, i64* %114
%115 = call i32 @select(i32 1, i32* %9, i32 0, i32 0, %struct.timeval* %8)
store i32 %115, i32* %6
%116 = icmp sgt i32 %115, 0
br i1 %116, label %117, label %132
117: ; preds = %110
%118 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%119 = call i32 @read(i32 0, i8* %118, i32 512)
store i32 %119, i32* %3
%120 = icmp ne i32 %119, 0
br i1 %120, label %121, label %129
121: ; preds = %117
%122 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%123 = load i32, i32* %3
%124 = call i32 @telnetInterpret(i8* %122, i32 %123)
store i32 %124, i32* %3
%125 = load i32, i32* %2
%126 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%127 = load i32, i32* %3
%128 = call i32 @write(i32 %125, i8* %126, i32 %127)
br label %131
129: ; preds = %117
%130 = call i32 @exit(i32 1)
unreachable
131: ; preds = %121
br label %132
132: ; preds = %131, %110
br label %80
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.timeval = type { i32, i64 }
%struct.dirent = type { i8* }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [7 x i8] c"maxipc\00"
@.str.2 = [5 x i8] c".lck\00"
@.str.3 = [7 x i8] c"%s.lck\00"
@.str.4 = [26 x i8] c"Sorry no more free nodes!\00"
@.str.5 = [5 x i8] c"recv\00"
@stdout = global i32 0
@.str.6 = [26 x i8] c"Server closed connection\0A\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_un
%2 = alloca %struct.timeval
%3 = alloca i32
%4 = alloca i32
%5 = alloca [128 x i8]
%6 = alloca [128 x i8]
%7 = alloca [512 x i8]
%8 = bitcast %struct.sockaddr_un* %1 to i8*
%9 = bitcast %struct.timeval* %2 to i8*
%10 = bitcast i32* %3 to i8*
%11 = bitcast i32* %4 to i8*
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%15 = load i32, i32* @AF_UNIX
%16 = load i32, i32* @SOCK_STREAM
%17 = tail call i32 @socket(i32 %15, i32 %16, i32 0)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %0
%20 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %0
%23 = call i32 @getcwd(i8* %12, i32 128)
%24 = call i32* @opendir(i32 %23)
%25 = call %struct.dirent* @readdir(i32* %24)
%26 = icmp eq %struct.dirent* %25, null
br i1 %26, label %50, label %27
27: ; preds = %22, %47
%28 = phi %struct.dirent* [ %48, %47 ], [ %25, %22 ]
%29 = getelementptr inbounds %struct.dirent, %struct.dirent* %28, i64 0, i32 0
%30 = load i8*, i8** %29
%31 = call i64 @strstr(i8* %30, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %47, label %33
33: ; preds = %27
%34 = load i8*, i8** %29
%35 = call i64 @strstr(i8* %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %47
37: ; preds = %33
%38 = load i8*, i8** %29
%39 = call i32 @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %38)
%40 = call i64 @fexist(i8* %13)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %37
%43 = load i8*, i8** %29
%44 = call i32 @strcpy(i32 undef, i8* %43)
%45 = load i32, i32* @AF_UNIX
%46 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 1
store i32 %45, i32* %46
br label %50
47: ; preds = %27, %33, %37
%48 = call %struct.dirent* @readdir(i32* %24)
%49 = icmp eq %struct.dirent* %48, null
br i1 %49, label %50, label %27
50: ; preds = %47, %22, %42
%51 = call i32 @negotiateTelnetOptions(i32 1)
%52 = call i32 @strlen(i32 undef)
%53 = add i32 %52, 4
%54 = bitcast %struct.sockaddr_un* %1 to %struct.sockaddr*
%55 = call i32 @connect(i32 %17, %struct.sockaddr* %54, i32 %53)
%56 = icmp eq i32 %55, -1
br i1 %56, label %61, label %57
57: ; preds = %50
%58 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%59 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%60 = add nsw i32 %17, 1
br label %64
61: ; preds = %50
%62 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %94, %57
store i32 5, i32* %58
store i64 0, i64* %59
%65 = call i32 @FD_ZERO(i32* %4)
%66 = call i32 @FD_SET(i32 %17, i32* %4)
%67 = call i32 @select(i32 %60, i32* %4, i32 0, i32 0, %struct.timeval* %2)
%68 = icmp sgt i32 %67, 0
br i1 %68, label %69, label %83
69: ; preds = %64
%70 = call i32 @read(i32 %17, i8* %14, i32 512)
%71 = icmp sgt i32 %70, 0
br i1 %71, label %72, label %74
72: ; preds = %69
%73 = call i32 @writeWIAC(i32 1, i8* %14, i32 %70)
br label %83
74: ; preds = %69
%75 = icmp slt i32 %70, 0
br i1 %75, label %76, label %78
76: ; preds = %74
%77 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %81
78: ; preds = %74
%79 = load i32, i32* @stdout
%80 = call i32 @fprintf(i32 %79, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
br label %81
81: ; preds = %78, %76
%82 = call i32 @exit(i32 1)
unreachable
83: ; preds = %72, %64
%84 = call i32 @FD_ZERO(i32* %3)
%85 = call i32 @FD_SET(i32 0, i32* %3)
store i32 5, i32* %58
store i64 0, i64* %59
%86 = call i32 @select(i32 1, i32* %3, i32 0, i32 0, %struct.timeval* %2)
%87 = icmp sgt i32 %86, 0
br i1 %87, label %88, label %94
88: ; preds = %83
%89 = call i32 @read(i32 0, i8* %14, i32 512)
%90 = icmp eq i32 %89, 0
br i1 %90, label %95, label %91
91: ; preds = %88
%92 = call i32 @telnetInterpret(i8* %14, i32 %89)
%93 = call i32 @write(i32 %17, i8* %14, i32 %92)
br label %94
94: ; preds = %91, %83
br label %64
95: ; preds = %88
%96 = call i32 @exit(i32 1)
unreachable
}