#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 sockaddr_in {
  int /*<<< orphan*/ sin_family;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ h_addr;
};
typedef int /*<<< orphan*/ saddr;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int BUFSIZ;
int EOF;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ bcopy(int /*<<< orphan*/, int /*<<< orphan*/ *,
                         int /*<<< orphan*/);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int getc(int /*<<< orphan*/ *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ gethostname(char *, int);
int /*<<< orphan*/ htons(int);
scalar_t__ listen(int, int);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ sanitize(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int main(int ac, char *av[]) {
  struct sockaddr_in saddr;
  struct hostent *hp;
  char hostname[256];
  int sock_id, sock_fd;
  FILE *sock_fpi, *sock_fpo;
  FILE *pipe_fp;
  char dirname[BUFSIZ];
  char command[BUFSIZ];
  int dirlen, c;
  sock_id = socket(PF_INET, SOCK_STREAM, 0);
  if (sock_id == -1) {
    perror("socket");
    exit(1);
  };
  bzero(&saddr, sizeof(saddr));
  gethostname(hostname, 256);
  hp = gethostbyname(hostname);
  bcopy(hp->h_addr, &saddr.sin_addr, hp->h_length);
  saddr.sin_port = htons(15000);
  saddr.sin_family = AF_INET;
  if (bind(sock_id, (struct sockaddr *)&saddr, sizeof(saddr)) != 0) {
    perror("bind");
    exit(1);
  };
  if (listen(sock_id, 1) != 0) {
    perror("listen");
    exit(1);
  };
  while (1) {
    sock_fd = accept(sock_id, NULL, NULL);
    if (sock_fd == -1) {
      perror("accept");
      exit(1);
    };
    if ((sock_fpi = fdopen(sock_fd, "r")) == NULL) {
      perror("fdopen reading");
      exit(1);
    };
    if (fgets(dirname, BUFSIZ - 5, sock_fpi) == NULL) {
      perror("reading dirname");
      exit(1);
    };
    sanitize(dirname);
    if ((sock_fpo = fdopen(sock_fd, "w")) == NULL) {
      perror("fdopen writing");
      exit(1);
    };
    sprintf(command, "ls %s", dirname);
    if ((pipe_fp = popen(command, "r")) == NULL) {
      perror("popen");
      exit(1);
    };
    while ((c = getc(pipe_fp)) != EOF)
      putc(c, sock_fpo);
    pclose(pipe_fp);
    fclose(sock_fpo);
    fclose(sock_fpi);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2d68(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x158(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x180(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x160(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x178(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x168(%rbp)
mov    0x2d07(%rip),%rax
mov    (%rax),%edi
mov    0x2d0e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
mov    %eax,-0x134(%rbp)
cmpl   $0xffffffff,-0x134(%rbp)
jne    12f4 <main+0xb4>
lea    0xd1b(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   10f0 <bzero@plt>
lea    -0x130(%rbp),%rdi
mov    $0x100,%esi
call   1110 <gethostname@plt>
lea    -0x130(%rbp),%rdi
call   1080 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x20(%rbp),%rsi
add    $0x8,%rsi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
call   10b0 <bcopy@plt>
mov    $0x3a98,%edi
call   1040 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2c97(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x134(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
cmp    $0x0,%rax
je     138a <main+0x14a>
lea    0xc8c(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x134(%rbp),%edi
mov    $0x1,%esi
call   1090 <listen@plt>
cmp    $0x0,%rax
je     13ba <main+0x17a>
lea    0xc61(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
jmp    13bf <main+0x17f>
jmp    13c4 <main+0x184>
mov    -0x134(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1100 <accept@plt>
mov    %eax,-0x138(%rbp)
cmpl   $0xffffffff,-0x138(%rbp)
jne    13ff <main+0x1bf>
lea    0xc23(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x138(%rbp),%edi
lea    0xc0e(%rip),%rsi
call   10a0 <fdopen@plt>
mov    %rax,-0x140(%rbp)
cmp    $0x0,%rax
jne    1438 <main+0x1f8>
lea    0xbf3(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x180(%rbp),%rdi
mov    0x2b82(%rip),%rax
mov    (%rax),%esi
sub    $0x5,%esi
mov    -0x140(%rbp),%rdx
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    1477 <main+0x237>
lea    0xbc3(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x180(%rbp),%rdi
call   1140 <sanitize@plt>
mov    -0x138(%rbp),%edi
lea    0xbab(%rip),%rsi
call   10a0 <fdopen@plt>
mov    %rax,-0x148(%rbp)
cmp    $0x0,%rax
jne    14bc <main+0x27c>
lea    0xb90(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x178(%rbp),%rdi
mov    -0x180(%rbp),%rdx
lea    0xb7b(%rip),%rsi
call   1120 <sprintf@plt>
mov    -0x178(%rbp),%rdi
lea    0xb36(%rip),%rsi
call   10d0 <popen@plt>
mov    %rax,-0x150(%rbp)
cmp    $0x0,%rax
jne    1510 <main+0x2d0>
lea    0xb51(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
jmp    1515 <main+0x2d5>
mov    -0x150(%rbp),%rdi
call   1150 <getc@plt>
mov    %eax,-0x170(%rbp)
mov    0x2ab2(%rip),%rcx
cmp    (%rcx),%eax
je     154d <main+0x30d>
mov    -0x170(%rbp),%edi
mov    -0x148(%rbp),%rsi
call   1070 <putc@plt>
jmp    1515 <main+0x2d5>
mov    -0x150(%rbp),%rdi
call   1050 <pclose@plt>
mov    -0x148(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x140(%rbp),%rdi
call   1030 <fclose@plt>
jmp    13bf <main+0x17f>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    0x2d6d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsp,%rcx
sub    %rax,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    0x2d3e(%rip),%rax
mov    (%rax),%edi
mov    0x2d45(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
cmp    $0xffffffff,%eax
jne    12a5 <main+0x65>
lea    0xd60(%rip),%rdi
jmp    1351 <main+0x111>
mov    %eax,%r12d
mov    %rbx,-0x40(%rbp)
lea    -0x38(%rbp),%r15
mov    %r15,%rdi
mov    $0xc,%esi
call   10f0 <bzero@plt>
lea    -0x150(%rbp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1110 <gethostname@plt>
mov    %rbx,%rdi
call   1080 <gethostbyname@plt>
mov    (%rax),%edx
mov    0x4(%rax),%edi
lea    -0x30(%rbp),%rsi
call   10b0 <bcopy@plt>
mov    $0x3a98,%edi
call   1040 <htons@plt>
mov    %eax,-0x34(%rbp)
mov    0x2ced(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    %r12d,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
test   %rax,%rax
jne    1341 <main+0x101>
mov    %r12d,%edi
mov    $0x1,%esi
call   1090 <listen@plt>
test   %rax,%rax
jne    134a <main+0x10a>
mov    %r12d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1100 <accept@plt>
cmp    $0xffffffff,%eax
jne    1360 <main+0x120>
lea    0xcd4(%rip),%rdi
jmp    1351 <main+0x111>
lea    0xcbf(%rip),%rdi
jmp    1351 <main+0x111>
lea    0xcbb(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    %eax,%r15d
mov    0x2c76(%rip),%r14
jmp    139c <main+0x15c>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <pclose@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %r13,%rdi
call   1030 <fclose@plt>
mov    %r12d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1100 <accept@plt>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
je     1338 <main+0xf8>
mov    %r15d,%edi
lea    0xc74(%rip),%rsi
call   10a0 <fdopen@plt>
test   %rax,%rax
je     144d <main+0x20d>
mov    %rax,%r13
mov    0x2c0a(%rip),%rax
mov    (%rax),%esi
add    $0xfffffffb,%esi
mov    -0x40(%rbp),%rbx
mov    %rbx,%rdi
mov    %r13,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1459 <main+0x219>
mov    %rbx,%rdi
call   1140 <sanitize@plt>
mov    %r15d,%edi
lea    0xc4e(%rip),%rsi
call   10a0 <fdopen@plt>
test   %rax,%rax
je     1465 <main+0x225>
mov    %rbx,%rdx
mov    %rax,%r15
mov    -0x48(%rbp),%rbx
mov    %rbx,%rdi
lea    0xc41(%rip),%rsi
call   1120 <sprintf@plt>
mov    %rbx,%rdi
lea    0xc00(%rip),%rsi
call   10d0 <popen@plt>
test   %rax,%rax
je     1471 <main+0x231>
mov    %rax,%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1150 <getc@plt>
cmp    (%r14),%eax
je     1370 <main+0x130>
mov    %eax,%edi
mov    %r15,%rsi
call   1070 <putc@plt>
jmp    1430 <main+0x1f0>
lea    0xbc8(%rip),%rdi
jmp    1351 <main+0x111>
lea    0xbcb(%rip),%rdi
jmp    1351 <main+0x111>
lea    0xbd1(%rip),%rdi
jmp    1351 <main+0x111>
lea    0xbda(%rip),%rdi
jmp    1351 <main+0x111>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i32 }
%struct.sockaddr = type { i32 }
@BUFSIZ = global i32 0
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@AF_INET = global i32 0
@.str.1 = [5 x i8] c"bind\00"
@.str.2 = [7 x i8] c"listen\00"
@.str.3 = [7 x i8] c"accept\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [15 x i8] c"fdopen reading\00"
@.str.6 = [16 x i8] c"reading dirname\00"
@.str.7 = [2 x i8] c"w\00"
@.str.8 = [15 x i8] c"fdopen writing\00"
@.str.9 = [6 x i8] c"ls %s\00"
@.str.10 = [6 x i8] c"popen\00"
@EOF = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.hostent*
%8 = alloca [256 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i8*
%15 = alloca i64
%16 = alloca i64
%17 = alloca i32
%18 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = load i32, i32* @BUFSIZ
%20 = zext i32 %19 to i64
%21 = call i8* @llvm.stacksave()
store i8* %21, i8** %14
%22 = alloca i8, i64 %20
store i64 %20, i64* %15
%23 = load i32, i32* @BUFSIZ
%24 = zext i32 %23 to i64
%25 = alloca i8, i64 %24
store i64 %24, i64* %16
%26 = load i32, i32* @PF_INET
%27 = load i32, i32* @SOCK_STREAM
%28 = call i32 @socket(i32 %26, i32 %27, i32 0)
store i32 %28, i32* %9
%29 = load i32, i32* %9
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %34
31: ; preds = %2
%32 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %2
%35 = call i32 @bzero(%struct.sockaddr_in* %6, i32 12)
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%37 = call i32 @gethostname(i8* %36, i32 256)
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%39 = call %struct.hostent* @gethostbyname(i8* %38)
store %struct.hostent* %39, %struct.hostent** %7
%40 = load %struct.hostent*, %struct.hostent** %7
%41 = getelementptr inbounds %struct.hostent, %struct.hostent* %40, i32 0, i32 1
%42 = load i32, i32* %41
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
%44 = load %struct.hostent*, %struct.hostent** %7
%45 = getelementptr inbounds %struct.hostent, %struct.hostent* %44, i32 0, i32 0
%46 = load i32, i32* %45
%47 = call i32 @bcopy(i32 %42, i32* %43, i32 %46)
%48 = call i32 @htons(i32 15000)
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %48, i32* %49
%50 = load i32, i32* @AF_INET
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %50, i32* %51
%52 = load i32, i32* %9
%53 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%54 = call i64 @bind(i32 %52, %struct.sockaddr* %53, i32 12)
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %34
%57 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %34
%60 = load i32, i32* %9
%61 = call i64 @listen(i32 %60, i32 1)
%62 = icmp ne i64 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %59
%64 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%65 = call i32 @exit(i32 1)
unreachable
66: ; preds = %59
br label %67
67: ; preds = %117, %66
br label %68
68: ; preds = %67
%69 = load i32, i32* %9
%70 = call i32 @accept(i32 %69, i32* null, i32* null)
store i32 %70, i32* %10
%71 = load i32, i32* %10
%72 = icmp eq i32 %71, -1
br i1 %72, label %73, label %76
73: ; preds = %68
%74 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%75 = call i32 @exit(i32 1)
unreachable
76: ; preds = %68
%77 = load i32, i32* %10
%78 = call i32* @fdopen(i32 %77, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %78, i32** %11
%79 = icmp eq i32* %78, null
br i1 %79, label %80, label %83
80: ; preds = %76
%81 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%82 = call i32 @exit(i32 1)
unreachable
83: ; preds = %76
%84 = load i32, i32* @BUFSIZ
%85 = sub nsw i32 %84, 5
%86 = load i32*, i32** %11
%87 = call i32* @fgets(i8* %22, i32 %85, i32* %86)
%88 = icmp eq i32* %87, null
br i1 %88, label %89, label %92
89: ; preds = %83
%90 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%91 = call i32 @exit(i32 1)
unreachable
92: ; preds = %83
%93 = call i32 @sanitize(i8* %22)
%94 = load i32, i32* %10
%95 = call i32* @fdopen(i32 %94, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %95, i32** %12
%96 = icmp eq i32* %95, null
br i1 %96, label %97, label %100
97: ; preds = %92
%98 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
%99 = call i32 @exit(i32 1)
unreachable
100: ; preds = %92
%101 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i8* %22)
%102 = call i32* @popen(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %102, i32** %13
%103 = icmp eq i32* %102, null
br i1 %103, label %104, label %107
104: ; preds = %100
%105 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
%106 = call i32 @exit(i32 1)
unreachable
107: ; preds = %100
br label %108
108: ; preds = %113, %107
%109 = load i32*, i32** %13
%110 = call i32 @getc(i32* %109)
store i32 %110, i32* %18
%111 = load i32, i32* @EOF
%112 = icmp ne i32 %110, %111
br i1 %112, label %113, label %117
113: ; preds = %108
%114 = load i32, i32* %18
%115 = load i32*, i32** %12
%116 = call i32 @putc(i32 %114, i32* %115)
br label %108
117: ; preds = %108
%118 = load i32*, i32** %13
%119 = call i32 @pclose(i32* %118)
%120 = load i32*, i32** %12
%121 = call i32 @fclose(i32* %120)
%122 = load i32*, i32** %11
%123 = call i32 @fclose(i32* %122)
br label %67
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i32 }
%struct.sockaddr = type { i32 }
@BUFSIZ = global i32 0
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@AF_INET = global i32 0
@.str.1 = [5 x i8] c"bind\00"
@.str.2 = [7 x i8] c"listen\00"
@.str.3 = [7 x i8] c"accept\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [15 x i8] c"fdopen reading\00"
@.str.6 = [16 x i8] c"reading dirname\00"
@.str.7 = [2 x i8] c"w\00"
@.str.8 = [15 x i8] c"fdopen writing\00"
@.str.9 = [6 x i8] c"ls %s\00"
@.str.10 = [6 x i8] c"popen\00"
@EOF = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [256 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* @BUFSIZ
%8 = zext i32 %7 to i64
%9 = alloca i8, i64 %8
%10 = alloca i8, i64 %8
%11 = load i32, i32* @PF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = tail call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%20 = call i32 @gethostname(i8* %6, i32 256)
%21 = call %struct.hostent* @gethostbyname(i8* %6)
%22 = getelementptr inbounds %struct.hostent, %struct.hostent* %21, i64 0, i32 1
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
%25 = getelementptr inbounds %struct.hostent, %struct.hostent* %21, i64 0, i32 0
%26 = load i32, i32* %25
%27 = call i32 @bcopy(i32 %23, i32* %24, i32 %26)
%28 = call i32 @htons(i32 15000)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %28, i32* %29
%30 = load i32, i32* @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %30, i32* %31
%32 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%33 = call i64 @bind(i32 %13, %struct.sockaddr* %32, i32 12)
%34 = icmp eq i64 %33, 0
br i1 %34, label %38, label %35
35: ; preds = %18
%36 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %18
%39 = call i64 @listen(i32 %13, i32 1)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = call i32 @accept(i32 %13, i32* null, i32* null)
%43 = icmp eq i32 %42, -1
br i1 %43, label %47, label %50
44: ; preds = %38
%45 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %89, %41
%48 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %41, %89
%51 = phi i32 [ %93, %89 ], [ %42, %41 ]
%52 = call i32* @fdopen(i32 %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%53 = icmp eq i32* %52, null
br i1 %53, label %54, label %57
54: ; preds = %50
%55 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %50
%58 = load i32, i32* @BUFSIZ
%59 = add nsw i32 %58, -5
%60 = call i32* @fgets(i8* %9, i32 %59, i32* %52)
%61 = icmp eq i32* %60, null
br i1 %61, label %62, label %65
62: ; preds = %57
%63 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%64 = call i32 @exit(i32 1)
unreachable
65: ; preds = %57
%66 = call i32 @sanitize(i8* %9)
%67 = call i32* @fdopen(i32 %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%68 = icmp eq i32* %67, null
br i1 %68, label %69, label %72
69: ; preds = %65
%70 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
%71 = call i32 @exit(i32 1)
unreachable
72: ; preds = %65
%73 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i8* %9)
%74 = call i32* @popen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%75 = icmp eq i32* %74, null
br i1 %75, label %80, label %76
76: ; preds = %72
%77 = call i32 @getc(i32* %74)
%78 = load i32, i32* @EOF
%79 = icmp eq i32 %77, %78
br i1 %79, label %89, label %83
80: ; preds = %72
%81 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
%82 = call i32 @exit(i32 1)
unreachable
83: ; preds = %76, %83
%84 = phi i32 [ %86, %83 ], [ %77, %76 ]
%85 = call i32 @putc(i32 %84, i32* %67)
%86 = call i32 @getc(i32* %74)
%87 = load i32, i32* @EOF
%88 = icmp eq i32 %86, %87
br i1 %88, label %89, label %83
89: ; preds = %83, %76
%90 = call i32 @pclose(i32* %74)
%91 = call i32 @fclose(i32* %67)
%92 = call i32 @fclose(i32* %52)
%93 = call i32 @accept(i32 %13, i32* null, i32* null)
%94 = icmp eq i32 %93, -1
br i1 %94, label %47, label %50
}