#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_zero;
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ server;
typedef int /*<<< orphan*/ runresponse;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
scalar_t__ bind(int, struct sockaddr *, int);
scalar_t__ cleanser(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ memset(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int socket_desc, client_sock, socketlength, read_size;
  struct sockaddr_in server, client;
  char client_message[2000];
  FILE *clientistream;
  char runresponse[4000];
  char NOOUT[] = "command did not return any output. could be an error or not.";
  socket_desc = socket(AF_INET, SOCK_STREAM, 0);
  if (socket_desc < 0) {
    printf("could not create socket.");
    exit(EXIT_FAILURE);
  }
  puts("socket created.");
  server.sin_family = AF_INET;
  server.sin_addr.s_addr = INADDR_ANY;
  server.sin_port = htons(8888);
  memset(server.sin_zero, 0, 8);
  if (bind(socket_desc, (struct sockaddr *)&server, sizeof(server)) < 0) {
    perror("bind failed.error.");
    return 1;
  }
  puts("bind done.");
  listen(socket_desc, 3);
  puts("Waiting for incoming connections...");
  socketlength = sizeof(struct sockaddr_in);
  client_sock = accept(socket_desc, (struct sockaddr *)&client,
                       (socklen_t *)&socketlength);
  if (client_sock < 0) {
    perror("could not accept incoming client.");
    return 1;
  }
  puts("connection accpeted.");
  while ((read_size = recv(client_sock, client_message, 2000, 0)) > 0) {
    fflush(stdin);
    puts("got command from client.");
    if (cleanser(client_message)) {
      clientistream = popen(client_message, "r");
    } else {
      puts("what are you trying to do exactly?");
      continue;
    }
    if (clientistream == NULL) {
      perror("client command did not run successfully.");
    }
    puts("task completed.");
    for (int i = 0; i < 2000; ++i) {
      client_message[i] = 0;
    }
    if (fgets(runresponse, sizeof(runresponse), clientistream) == NULL) {
      write(client_sock, NOOUT, strlen(NOOUT));
    }
    rewind(clientistream);
    while (fgets(runresponse, sizeof(runresponse), clientistream) != NULL) {
      puts("command stdout:");
      puts(runresponse);
      write(client_sock, runresponse, strlen(runresponse));
    }
    puts("response sent to client.");
    fflush(stdout);
    pclose(clientistream);
    puts("checkpoint 1");
  }
  puts("checkpoint 10");
  if (read_size == 0) {
    puts("client disconnected");
    fflush(stdout);
  } else if (read_size == -1) {
    perror("recv failed.");
  } else {
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1830,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x1800(%rbp),%rdi
lea    0xd99(%rip),%rsi
mov    $0x3d,%edx
call   10e0 <memcpy@plt>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
mov    0x2d47(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12b1 <main+0x71>
lea    0xd9f(%rip),%rdi
call   1090 <printf@plt>
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
call   1150 <exit@plt>
lea    0xd9e(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d24(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d08(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    $0x22b8,%edi
call   1080 <htons@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x30(%rbp),%edi
xor    %esi,%esi
mov    $0x8,%edx
call   10c0 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x10,%edx
call   1110 <bind@plt>
cmp    $0x0,%rax
jge    1324 <main+0xe4>
lea    0xd53(%rip),%rdi
call   1130 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    15e9 <main+0x3a9>
lea    0xd4e(%rip),%rdi
call   1040 <puts@plt>
mov    -0x14(%rbp),%edi
mov    $0x3,%esi
call   1100 <listen@plt>
lea    0xd40(%rip),%rdi
call   1040 <puts@plt>
movl   $0x10,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1140 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1385 <main+0x145>
lea    0xd34(%rip),%rdi
call   1130 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    15e9 <main+0x3a9>
lea    0xd3e(%rip),%rdi
call   1040 <puts@plt>
mov    -0x18(%rbp),%edi
lea    -0x810(%rbp),%rsi
mov    $0x7d0,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jle    1588 <main+0x348>
mov    0x2c26(%rip),%rax
mov    (%rax),%edi
call   10f0 <fflush@plt>
lea    0xd17(%rip),%rdi
call   1040 <puts@plt>
lea    -0x810(%rbp),%rdi
call   1060 <cleanser@plt>
cmp    $0x0,%rax
je     1402 <main+0x1c2>
lea    -0x810(%rbp),%rdi
lea    0xd07(%rip),%rsi
call   1120 <popen@plt>
mov    %rax,-0x818(%rbp)
jmp    1413 <main+0x1d3>
lea    0xcf1(%rip),%rdi
call   1040 <puts@plt>
jmp    1391 <main+0x151>
cmpq   $0x0,-0x818(%rbp)
jne    142d <main+0x1ed>
lea    0xcf5(%rip),%rdi
call   1130 <perror@plt>
lea    0xd12(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x1804(%rbp)
cmpl   $0x7d0,-0x1804(%rbp)
jge    1476 <main+0x236>
movslq -0x1804(%rbp),%rax
movb   $0x0,-0x810(%rbp,%rax,1)
mov    -0x1804(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1804(%rbp)
jmp    1443 <main+0x203>
lea    -0x17c0(%rbp),%rdi
mov    -0x818(%rbp),%rdx
mov    $0xfa0,%esi
call   10d0 <fgets@plt>
cmp    $0x0,%rax
jne    14cf <main+0x28f>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1814(%rbp)
lea    -0x1800(%rbp),%rax
mov    %rax,-0x1810(%rbp)
lea    -0x1800(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x1814(%rbp),%edi
mov    -0x1810(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    -0x818(%rbp),%rdi
call   10a0 <rewind@plt>
lea    -0x17c0(%rbp),%rdi
mov    -0x818(%rbp),%rdx
mov    $0xfa0,%esi
call   10d0 <fgets@plt>
cmp    $0x0,%rax
je     1551 <main+0x311>
lea    0xc52(%rip),%rdi
call   1040 <puts@plt>
lea    -0x17c0(%rbp),%rdi
call   1040 <puts@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1824(%rbp)
lea    -0x17c0(%rbp),%rax
mov    %rax,-0x1820(%rbp)
lea    -0x17c0(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x1824(%rbp),%edi
mov    -0x1820(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
jmp    14db <main+0x29b>
lea    0xc0e(%rip),%rdi
call   1040 <puts@plt>
mov    0x2a54(%rip),%rax
mov    (%rax),%edi
call   10f0 <fflush@plt>
mov    -0x818(%rbp),%rdi
call   10b0 <pclose@plt>
lea    0xc01(%rip),%rdi
call   1040 <puts@plt>
jmp    1391 <main+0x151>
lea    0xbfd(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,-0x20(%rbp)
jne    15bd <main+0x37d>
lea    0xbf5(%rip),%rdi
call   1040 <puts@plt>
mov    0x2a07(%rip),%rax
mov    (%rax),%edi
call   10f0 <fflush@plt>
jmp    15e2 <main+0x3a2>
cmpl   $0xffffffff,-0x20(%rbp)
jne    15d8 <main+0x398>
lea    0xbe0(%rip),%rdi
call   1130 <perror@plt>
jmp    15dd <main+0x39d>
jmp    15dd <main+0x39d>
jmp    15e2 <main+0x3a2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x17e8,%rsp
movups 0xde5(%rip),%xmm0
movups %xmm0,0x4d(%rsp)
movaps 0xdcc(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xdb0(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xd94(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
mov    0x2d70(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2d46(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
test   %eax,%eax
js     1528 <main+0x2f8>
mov    %eax,%ebx
lea    0xdba(%rip),%rdi
call   1040 <puts@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x1c(%rsp)
mov    0x2d29(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    $0x22b8,%edi
call   1080 <htons@plt>
mov    %eax,0x14(%rsp)
xor    %esi,%esi
mov    $0x8,%edx
call   10c0 <memset@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x10,%edx
call   1100 <bind@plt>
test   %rax,%rax
js     14f8 <main+0x2c8>
lea    0xd89(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
mov    $0x3,%esi
call   10f0 <listen@plt>
lea    0xd7c(%rip),%rdi
call   1040 <puts@plt>
movl   $0x10,0xc(%rsp)
lea    0x60(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   1130 <accept@plt>
test   %eax,%eax
js     1501 <main+0x2d1>
mov    %eax,%ebp
lea    0xd93(%rip),%rdi
call   1040 <puts@plt>
lea    0x70(%rsp),%rsi
xor    %r14d,%r14d
mov    %ebp,%edi
mov    $0x7d0,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    14b7 <main+0x287>
lea    0x70(%rsp),%r15
lea    0x840(%rsp),%r14
lea    0xde8(%rip),%r13
jmp    13b7 <main+0x187>
lea    0xdef(%rip),%rdi
call   1040 <puts@plt>
mov    0x2c35(%rip),%rax
mov    (%rax),%edi
call   10e0 <fflush@plt>
mov    %r12,%rdi
call   10b0 <pclose@plt>
lea    0xde6(%rip),%rdi
call   1040 <puts@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x7d0,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    14b0 <main+0x280>
mov    0x2c22(%rip),%rax
mov    (%rax),%edi
call   10e0 <fflush@plt>
lea    0xd13(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   1060 <cleanser@plt>
lea    0xd1a(%rip),%rdi
test   %rax,%rax
je     1399 <main+0x169>
mov    %r15,%rdi
lea    0xd09(%rip),%rsi
call   1110 <popen@plt>
mov    %rax,%r12
test   %rax,%rax
je     149f <main+0x26f>
lea    0xd3f(%rip),%rdi
call   1040 <puts@plt>
mov    $0x7d0,%edx
mov    %r15,%rdi
xor    %esi,%esi
call   10c0 <memset@plt>
mov    %r14,%rdi
mov    $0xfa0,%esi
mov    %r12,%rdx
call   10d0 <fgets@plt>
test   %rax,%rax
jne    1449 <main+0x219>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    %r12,%rdi
call   10a0 <rewind@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0xfa0,%esi
mov    %r12,%rdx
call   10d0 <fgets@plt>
test   %rax,%rax
je     1370 <main+0x140>
mov    %r13,%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1070 <strlen@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1050 <write@plt>
jmp    1460 <main+0x230>
lea    0xc77(%rip),%rdi
call   1120 <perror@plt>
jmp    1400 <main+0x1d0>
mov    %eax,%ebx
xor    %r14d,%r14d
jmp    14b9 <main+0x289>
mov    %eax,%ebx
lea    0xccc(%rip),%rdi
call   1040 <puts@plt>
test   %ebx,%ebx
je     14dc <main+0x2ac>
cmp    $0xffffffff,%ebx
jne    1513 <main+0x2e3>
lea    0xcd9(%rip),%rdi
call   1120 <perror@plt>
jmp    1513 <main+0x2e3>
lea    0xcb7(%rip),%rdi
call   1040 <puts@plt>
mov    0x2ac9(%rip),%rax
mov    (%rax),%edi
call   10e0 <fflush@plt>
jmp    1513 <main+0x2e3>
lea    0xb67(%rip),%rdi
jmp    1508 <main+0x2d8>
lea    0xba0(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x17e8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb0e(%rip),%rdi
call   1090 <printf@plt>
mov    0x2a85(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.NOOUT = [61 x i8] c"command did not return any output. could be an error or not.\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [25 x i8] c"could not create socket.\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [16 x i8] c"socket created.\00"
@INADDR_ANY = global i32 0
@.str.2 = [19 x i8] c"bind failed.error.\00"
@.str.3 = [11 x i8] c"bind done.\00"
@.str.4 = [36 x i8] c"Waiting for incoming connections...\00"
@.str.5 = [34 x i8] c"could not accept incoming client.\00"
@.str.6 = [21 x i8] c"connection accpeted.\00"
@stdin = global i32 0
@.str.7 = [25 x i8] c"got command from client.\00"
@.str.8 = [2 x i8] c"r\00"
@.str.9 = [35 x i8] c"what are you trying to do exactly?\00"
@.str.10 = [41 x i8] c"client command did not run successfully.\00"
@.str.11 = [16 x i8] c"task completed.\00"
@.str.12 = [16 x i8] c"command stdout:\00"
@.str.13 = [25 x i8] c"response sent to client.\00"
@stdout = global i32 0
@.str.14 = [13 x i8] c"checkpoint 1\00"
@.str.15 = [14 x i8] c"checkpoint 10\00"
@.str.16 = [20 x i8] c"client disconnected\00"
@.str.17 = [13 x i8] c"recv failed.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca %struct.sockaddr_in
%12 = alloca [2000 x i8]
%13 = alloca i32*
%14 = alloca [4000 x i8]
%15 = alloca [61 x i8]
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = bitcast [61 x i8]* %15 to i8*
%18 = load i32, i32* @AF_INET
%19 = load i32, i32* @SOCK_STREAM
%20 = call i32 @socket(i32 %18, i32 %19, i32 0)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %2
%24 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %2
%28 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%29 = load i32, i32* @AF_INET
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 3
store i32 %29, i32* %30
%31 = load i32, i32* @INADDR_ANY
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
%33 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %32, i32 0, i32 0
store i32 %31, i32* %33
%34 = call i32 @htons(i32 8888)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
store i32 %34, i32* %35
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%37 = load i32, i32* %36
%38 = call i32 @memset(i32 %37, i32 0, i32 8)
%39 = load i32, i32* %6
%40 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%41 = call i64 @bind(i32 %39, %struct.sockaddr* %40, i32 16)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %27
%44 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %144
45: ; preds = %27
%46 = call i32 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%47 = load i32, i32* %6
%48 = call i32 @listen(i32 %47, i32 3)
%49 = call i32 @puts(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
store i32 16, i32* %8
%50 = load i32, i32* %6
%51 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%52 = call i32 @accept(i32 %50, %struct.sockaddr* %51, i32* %8)
store i32 %52, i32* %7
%53 = load i32, i32* %7
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %45
%56 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %144
57: ; preds = %45
%58 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %59
59: ; preds = %121, %74, %57
%60 = load i32, i32* %7
%61 = getelementptr inbounds [2000 x i8], [2000 x i8]* %12, i64 0, i64 0
%62 = call i32 @recv(i32 %60, i8* %61, i32 2000, i32 0)
store i32 %62, i32* %9
%63 = icmp sgt i32 %62, 0
br i1 %63, label %64, label %128
64: ; preds = %59
%65 = load i32, i32* @stdin
%66 = call i32 @fflush(i32 %65)
%67 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
%68 = getelementptr inbounds [2000 x i8], [2000 x i8]* %12, i64 0, i64 0
%69 = call i64 @cleanser(i8* %68)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %64
%72 = getelementptr inbounds [2000 x i8], [2000 x i8]* %12, i64 0, i64 0
%73 = call i32* @popen(i8* %72, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
store i32* %73, i32** %13
br label %76
74: ; preds = %64
%75 = call i32 @puts(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.9, i64 0, i64 0))
br label %59
76: ; preds = %71
%77 = load i32*, i32** %13
%78 = icmp eq i32* %77, null
br i1 %78, label %79, label %81
79: ; preds = %76
%80 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.10, i64 0, i64 0))
br label %81
81: ; preds = %79, %76
%82 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0))
store i32 0, i32* %16
br label %83
83: ; preds = %90, %81
%84 = load i32, i32* %16
%85 = icmp slt i32 %84, 2000
br i1 %85, label %86, label %93
86: ; preds = %83
%87 = load i32, i32* %16
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds [2000 x i8], [2000 x i8]* %12, i64 0, i64 %88
store i8 0, i8* %89
br label %90
90: ; preds = %86
%91 = load i32, i32* %16
%92 = add nsw i32 %91, 1
store i32 %92, i32* %16
br label %83
93: ; preds = %83
%94 = getelementptr inbounds [4000 x i8], [4000 x i8]* %14, i64 0, i64 0
%95 = load i32*, i32** %13
%96 = call i32* @fgets(i8* %94, i32 4000, i32* %95)
%97 = icmp eq i32* %96, null
br i1 %97, label %98, label %104
98: ; preds = %93
%99 = load i32, i32* %7
%100 = getelementptr inbounds [61 x i8], [61 x i8]* %15, i64 0, i64 0
%101 = getelementptr inbounds [61 x i8], [61 x i8]* %15, i64 0, i64 0
%102 = call i32 @strlen(i8* %101)
%103 = call i32 @write(i32 %99, i8* %100, i32 %102)
br label %104
104: ; preds = %98, %93
%105 = load i32*, i32** %13
%106 = call i32 @rewind(i32* %105)
br label %107
107: ; preds = %112, %104
%108 = getelementptr inbounds [4000 x i8], [4000 x i8]* %14, i64 0, i64 0
%109 = load i32*, i32** %13
%110 = call i32* @fgets(i8* %108, i32 4000, i32* %109)
%111 = icmp ne i32* %110, null
br i1 %111, label %112, label %121
112: ; preds = %107
%113 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.12, i64 0, i64 0))
%114 = getelementptr inbounds [4000 x i8], [4000 x i8]* %14, i64 0, i64 0
%115 = call i32 @puts(i8* %114)
%116 = load i32, i32* %7
%117 = getelementptr inbounds [4000 x i8], [4000 x i8]* %14, i64 0, i64 0
%118 = getelementptr inbounds [4000 x i8], [4000 x i8]* %14, i64 0, i64 0
%119 = call i32 @strlen(i8* %118)
%120 = call i32 @write(i32 %116, i8* %117, i32 %119)
br label %107
121: ; preds = %107
%122 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.13, i64 0, i64 0))
%123 = load i32, i32* @stdout
%124 = call i32 @fflush(i32 %123)
%125 = load i32*, i32** %13
%126 = call i32 @pclose(i32* %125)
%127 = call i32 @puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.14, i64 0, i64 0))
br label %59
128: ; preds = %59
%129 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.15, i64 0, i64 0))
%130 = load i32, i32* %9
%131 = icmp eq i32 %130, 0
br i1 %131, label %132, label %136
132: ; preds = %128
%133 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.16, i64 0, i64 0))
%134 = load i32, i32* @stdout
%135 = call i32 @fflush(i32 %134)
br label %143
136: ; preds = %128
%137 = load i32, i32* %9
%138 = icmp eq i32 %137, -1
br i1 %138, label %139, label %141
139: ; preds = %136
%140 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.17, i64 0, i64 0))
br label %142
141: ; preds = %136
br label %142
142: ; preds = %141, %139
br label %143
143: ; preds = %142, %132
store i32 0, i32* %3
br label %144
144: ; preds = %143, %55, %43
%145 = load i32, i32* %3
ret i32 %145
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.NOOUT = [61 x i8] c"command did not return any output. could be an error or not.\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [25 x i8] c"could not create socket.\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [16 x i8] c"socket created.\00"
@INADDR_ANY = global i32 0
@.str.2 = [19 x i8] c"bind failed.error.\00"
@.str.3 = [11 x i8] c"bind done.\00"
@.str.4 = [36 x i8] c"Waiting for incoming connections...\00"
@.str.5 = [34 x i8] c"could not accept incoming client.\00"
@.str.6 = [21 x i8] c"connection accpeted.\00"
@stdin = global i32 0
@.str.7 = [25 x i8] c"got command from client.\00"
@.str.8 = [2 x i8] c"r\00"
@.str.9 = [35 x i8] c"what are you trying to do exactly?\00"
@.str.10 = [41 x i8] c"client command did not run successfully.\00"
@.str.11 = [16 x i8] c"task completed.\00"
@.str.12 = [16 x i8] c"command stdout:\00"
@.str.13 = [25 x i8] c"response sent to client.\00"
@stdout = global i32 0
@.str.14 = [13 x i8] c"checkpoint 1\00"
@.str.15 = [14 x i8] c"checkpoint 10\00"
@.str.16 = [20 x i8] c"client disconnected\00"
@.str.17 = [13 x i8] c"recv failed.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca [2000 x i8]
%7 = getelementptr inbounds [2000 x i8], [2000 x i8]* %6, i64 0, i64 0
%8 = alloca [4000 x i8]
%9 = alloca [61 x i8]
%10 = bitcast i32* %3 to i8*
%11 = bitcast %struct.sockaddr_in* %4 to i8*
%12 = bitcast %struct.sockaddr_in* %5 to i8*
%13 = getelementptr inbounds [2000 x i8], [2000 x i8]* %6, i64 0, i64 0
%14 = getelementptr inbounds [4000 x i8], [4000 x i8]* %8, i64 0, i64 0
%15 = getelementptr inbounds [61 x i8], [61 x i8]* %9, i64 0, i64 0
%16 = load i32, i32* @AF_INET
%17 = load i32, i32* @SOCK_STREAM
%18 = tail call i32 @socket(i32 %16, i32 %17, i32 0)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %2
%21 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %2
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* @AF_INET
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 3
store i32 %26, i32* %27
%28 = load i32, i32* @INADDR_ANY
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2, i32 0
store i32 %28, i32* %29
%30 = tail call i32 @htons(i32 8888)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %30, i32* %31
%32 = tail call i32 @memset(i32 undef, i32 0, i32 8)
%33 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%34 = call i64 @bind(i32 %18, %struct.sockaddr* %33, i32 16)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %24
%37 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %99
38: ; preds = %24
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%40 = call i32 @listen(i32 %18, i32 3)
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
store i32 16, i32* %3
%42 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%43 = call i32 @accept(i32 %18, %struct.sockaddr* %42, i32* %3)
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %38
%46 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
br label %99
47: ; preds = %38
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%49 = call i32 @recv(i32 %43, i8* %13, i32 2000, i32 0)
%50 = icmp sgt i32 %49, 0
br i1 %50, label %51, label %90
51: ; preds = %47, %60
%52 = load i32, i32* @stdin
%53 = call i32 @fflush(i32 %52)
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0))
%55 = call i64 @cleanser(i8* %13)
%56 = icmp eq i64 %55, 0
br i1 %56, label %60, label %57
57: ; preds = %51
%58 = call i32* @popen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%59 = icmp eq i32* %58, null
br i1 %59, label %65, label %67
60: ; preds = %51, %85
%61 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.14, i64 0, i64 0), %85 ], [ getelementptr inbounds ([35 x i8], [35 x i8]* @.str.9, i64 0, i64 0), %51 ]
%62 = call i32 @puts(i8* dereferenceable(1) %61)
%63 = call i32 @recv(i32 %43, i8* %13, i32 2000, i32 0)
%64 = icmp sgt i32 %63, 0
br i1 %64, label %51, label %90
65: ; preds = %57
%66 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.10, i64 0, i64 0))
br label %67
67: ; preds = %65, %57
%68 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0))
%69 = call i32* @fgets(i8* %14, i32 4000, i32* %58)
%70 = icmp eq i32* %69, null
br i1 %70, label %71, label %74
71: ; preds = %67
%72 = call i32 @strlen(i8* %15)
%73 = call i32 @write(i32 %43, i8* %15, i32 %72)
br label %74
74: ; preds = %71, %67
%75 = call i32 @rewind(i32* %58)
%76 = call i32* @fgets(i8* %14, i32 4000, i32* %58)
%77 = icmp eq i32* %76, null
br i1 %77, label %85, label %78
78: ; preds = %74, %78
%79 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.12, i64 0, i64 0))
%80 = call i32 @puts(i8* %14)
%81 = call i32 @strlen(i8* %14)
%82 = call i32 @write(i32 %43, i8* %14, i32 %81)
%83 = call i32* @fgets(i8* %14, i32 4000, i32* %58)
%84 = icmp eq i32* %83, null
br i1 %84, label %85, label %78
85: ; preds = %78, %74
%86 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.13, i64 0, i64 0))
%87 = load i32, i32* @stdout
%88 = call i32 @fflush(i32 %87)
%89 = call i32 @pclose(i32* %58)
br label %60
90: ; preds = %60, %47
%91 = phi i32 [ %49, %47 ], [ %63, %60 ]
%92 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.15, i64 0, i64 0))
switch i32 %91, label %99 [
i32 0, label %93
i32 -1, label %97
]
93: ; preds = %90
%94 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.16, i64 0, i64 0))
%95 = load i32, i32* @stdout
%96 = call i32 @fflush(i32 %95)
br label %99
97: ; preds = %90
%98 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.17, i64 0, i64 0))
br label %99
99: ; preds = %93, %97, %90, %45, %36
%100 = phi i32 [ 1, %36 ], [ 1, %45 ], [ 0, %90 ], [ 0, %97 ], [ 0, %93 ]
ret i32 %100
}