#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 {
  short sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ server;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
int bind(int, struct sockaddr *, int);
scalar_t__ correctArgs(char *);
scalar_t__ correctNumberOfArguments(int *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int listen(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
char *strstr(char *, char *);
int /*<<< orphan*/ tests(int *, char **);
int main(int argc, char *argv[]) {
  tests(&argc, argv);
  if (correctNumberOfArguments(&argc) && correctArgs(argv[1]) && false) {
    short portno = 10600;
    int sockfd;
    int clientsocket;
    int c;
    int read_size;
    struct sockaddr_in server;
    struct sockaddr_in client;
    char clientMSG[512];
    int bindstate = 0;
    int listenstate = 0;
    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if (sockfd < 0) {
      perror("could not create socket");
    }
    puts("socket created");
    server.sin_family = AF_INET;
    server.sin_addr.s_addr = INADDR_ANY;
    server.sin_port = portno;
    bindstate = bind(sockfd, (struct sockaddr *)&server, sizeof(server));
    if (bindstate < 0) {
      perror("Error: bind failed");
    }
    puts("bind done");
    listenstate = listen(sockfd, 5);
    if (listenstate < 0) {
      perror("Error listen() call returned status -1");
    }
    puts("waiting for incoming connections");
    c = sizeof(struct sockaddr_in);
    clientsocket = accept(sockfd, (struct sockaddr *)&client, (socklen_t *)&c);
    if (clientsocket < 0) {
      perror("accept failed");
    }
    puts("connection accepted");
    read_size = recv(clientsocket, clientMSG, 512, 0);
    char *msgcheck = 0;
    while (read_size > 0) {
      printf("message: %s", clientMSG);
      msgcheck = strstr(clientMSG, "close");
      send(clientsocket, clientMSG, strlen(clientMSG), 0);
      if (msgcheck == 0) {
        read_size = recv(clientsocket, clientMSG, 512, 0);
      } else {
        read_size = 0;
      }
    }
    if (read_size == 0) {
      puts("client disconnected");
      fflush(stdout);
    } else if (read_size == -1) {
      perror("recv ended with code -1");
    }
  } else {
    printf("malformed command, specify run mode\nusage:\n");
    printf("for server mode\n%s -s\n", argv[0]);
    printf("for client mode\n%s -c\n", argv[0]);
    exit(0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x260,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x8(%rbp),%rdi
call   1080 <tests@plt>
lea    -0x8(%rbp),%rdi
call   10c0 <correctNumberOfArguments@plt>
cmp    $0x0,%rax
je     149e <main+0x29e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <correctArgs@plt>
cmp    $0x0,%rax
je     149e <main+0x29e>
xor    %eax,%eax
test   $0x1,%al
jne    125f <main+0x5f>
jmp    149e <main+0x29e>
movw   $0x2968,-0x12(%rbp)
movl   $0x0,-0x244(%rbp)
movl   $0x0,-0x248(%rbp)
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
mov    0x2d47(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    12ab <main+0xab>
lea    0xd5a(%rip),%rdi
call   10e0 <perror@plt>
lea    0xd66(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d16(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x12(%rbp),%ax
mov    %ax,-0x30(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
mov    %eax,-0x244(%rbp)
cmpl   $0x0,-0x244(%rbp)
jge    1307 <main+0x107>
lea    0xd25(%rip),%rdi
call   10e0 <perror@plt>
lea    0xd2c(%rip),%rdi
call   1040 <puts@plt>
mov    -0x18(%rbp),%edi
mov    $0x5,%esi
call   10b0 <listen@plt>
mov    %eax,-0x248(%rbp)
cmpl   $0x0,-0x248(%rbp)
jge    133f <main+0x13f>
lea    0xd0a(%rip),%rdi
call   10e0 <perror@plt>
lea    0xd25(%rip),%rdi
call   1040 <puts@plt>
movl   $0xc,-0x20(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x40(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   10f0 <accept@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    137b <main+0x17b>
lea    0xd16(%rip),%rdi
call   10e0 <perror@plt>
lea    0xd18(%rip),%rdi
call   1040 <puts@plt>
mov    -0x1c(%rbp),%edi
lea    -0x240(%rbp),%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x24(%rbp)
movq   $0x0,-0x250(%rbp)
cmpl   $0x0,-0x24(%rbp)
jle    1455 <main+0x255>
lea    -0x240(%rbp),%rsi
lea    0xceb(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x240(%rbp),%rdi
lea    0xce2(%rip),%rsi
call   1110 <strstr@plt>
mov    %rax,-0x250(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x25c(%rbp)
lea    -0x240(%rbp),%rax
mov    %rax,-0x258(%rbp)
lea    -0x240(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x25c(%rbp),%edi
mov    -0x258(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
cmpq   $0x0,-0x250(%rbp)
jne    1449 <main+0x249>
mov    -0x1c(%rbp),%edi
lea    -0x240(%rbp),%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x24(%rbp)
jmp    1450 <main+0x250>
movl   $0x0,-0x24(%rbp)
jmp    13ab <main+0x1ab>
cmpl   $0x0,-0x24(%rbp)
jne    147e <main+0x27e>
lea    0xc5a(%rip),%rdi
call   1040 <puts@plt>
mov    0x2b56(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
jmp    1499 <main+0x299>
cmpl   $0xffffffff,-0x24(%rbp)
jne    1494 <main+0x294>
lea    0xc45(%rip),%rdi
call   10e0 <perror@plt>
jmp    1499 <main+0x299>
jmp    14dd <main+0x2dd>
lea    0xc47(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xc5e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xc60(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   1100 <exit@plt>
xor    %eax,%eax
add    $0x260,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,0x4(%rsp)
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1050 <tests@plt>
mov    %r14,%rdi
call   1070 <correctNumberOfArguments@plt>
test   %rax,%rax
je     118e <main+0x2e>
mov    0x8(%rbx),%rdi
call   1060 <correctArgs@plt>
lea    0xe99(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%rsi
lea    0xe5c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%rsi
lea    0xe62(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i16, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [24 x i8] c"could not create socket\00"
@.str.1 = [15 x i8] c"socket created\00"
@INADDR_ANY = global i32 0
@.str.2 = [19 x i8] c"Error: bind failed\00"
@.str.3 = [10 x i8] c"bind done\00"
@.str.4 = [39 x i8] c"Error listen() call returned status -1\00"
@.str.5 = [33 x i8] c"waiting for incoming connections\00"
@.str.6 = [14 x i8] c"accept failed\00"
@.str.7 = [20 x i8] c"connection accepted\00"
@.str.8 = [12 x i8] c"message: %s\00"
@.str.9 = [6 x i8] c"close\00"
@.str.10 = [20 x i8] c"client disconnected\00"
@stdout = global i32 0
@.str.11 = [24 x i8] c"recv ended with code -1\00"
@.str.12 = [44 x i8] c"malformed command, specify run mode\0Ausage:\0A\00"
@.str.13 = [23 x i8] c"for server mode\0A%s -s\0A\00"
@.str.14 = [23 x i8] c"for client mode\0A%s -c\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i16
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.sockaddr_in
%12 = alloca %struct.sockaddr_in
%13 = alloca [512 x i8]
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i8**, i8*** %5
%18 = call i32 @tests(i32* %4, i8** %17)
%19 = call i64 @correctNumberOfArguments(i32* %4)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %109
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i64 @correctArgs(i8* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %109
27: ; preds = %21
br i1 false, label %28, label %109
28: ; preds = %27
store i16 10600, i16* %6
store i32 0, i32* %14
store i32 0, i32* %15
%29 = load i32, i32* @AF_INET
%30 = load i32, i32* @SOCK_STREAM
%31 = call i32 @socket(i32 %29, i32 %30, i32 0)
store i32 %31, i32* %7
%32 = load i32, i32* %7
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %28
%35 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %36
36: ; preds = %34, %28
%37 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%38 = load i32, i32* @AF_INET
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i32 %38, i32* %39
%40 = load i32, i32* @INADDR_ANY
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
%42 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %41, i32 0, i32 0
store i32 %40, i32* %42
%43 = load i16, i16* %6
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
store i16 %43, i16* %44
%45 = load i32, i32* %7
%46 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%47 = call i32 @bind(i32 %45, %struct.sockaddr* %46, i32 12)
store i32 %47, i32* %14
%48 = load i32, i32* %14
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %36
%51 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %52
52: ; preds = %50, %36
%53 = call i32 @puts(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%54 = load i32, i32* %7
%55 = call i32 @listen(i32 %54, i32 5)
store i32 %55, i32* %15
%56 = load i32, i32* %15
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %52
%59 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
br label %60
60: ; preds = %58, %52
%61 = call i32 @puts(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0))
store i32 12, i32* %9
%62 = load i32, i32* %7
%63 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%64 = call i32 @accept(i32 %62, %struct.sockaddr* %63, i32* %9)
store i32 %64, i32* %8
%65 = load i32, i32* %8
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %60
%68 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
br label %69
69: ; preds = %67, %60
%70 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
%71 = load i32, i32* %8
%72 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%73 = call i32 @recv(i32 %71, i8* %72, i32 512, i32 0)
store i32 %73, i32* %10
store i8* null, i8** %16
br label %74
74: ; preds = %94, %69
%75 = load i32, i32* %10
%76 = icmp sgt i32 %75, 0
br i1 %76, label %77, label %95
77: ; preds = %74
%78 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i8* %78)
%80 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%81 = call i8* @strstr(i8* %80, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
store i8* %81, i8** %16
%82 = load i32, i32* %8
%83 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%84 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%85 = call i32 @strlen(i8* %84)
%86 = call i32 @send(i32 %82, i8* %83, i32 %85, i32 0)
%87 = load i8*, i8** %16
%88 = icmp eq i8* %87, null
br i1 %88, label %89, label %93
89: ; preds = %77
%90 = load i32, i32* %8
%91 = getelementptr inbounds [512 x i8], [512 x i8]* %13, i64 0, i64 0
%92 = call i32 @recv(i32 %90, i8* %91, i32 512, i32 0)
store i32 %92, i32* %10
br label %94
93: ; preds = %77
store i32 0, i32* %10
br label %94
94: ; preds = %93, %89
br label %74
95: ; preds = %74
%96 = load i32, i32* %10
%97 = icmp eq i32 %96, 0
br i1 %97, label %98, label %102
98: ; preds = %95
%99 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0))
%100 = load i32, i32* @stdout
%101 = call i32 @fflush(i32 %100)
br label %108
102: ; preds = %95
%103 = load i32, i32* %10
%104 = icmp eq i32 %103, -1
br i1 %104, label %105, label %107
105: ; preds = %102
%106 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.11, i64 0, i64 0))
br label %107
107: ; preds = %105, %102
br label %108
108: ; preds = %107, %98
br label %120
109: ; preds = %27, %21, %2
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.12, i64 0, i64 0))
%111 = load i8**, i8*** %5
%112 = getelementptr inbounds i8*, i8** %111, i64 0
%113 = load i8*, i8** %112
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.13, i64 0, i64 0), i8* %113)
%115 = load i8**, i8*** %5
%116 = getelementptr inbounds i8*, i8** %115, i64 0
%117 = load i8*, i8** %116
%118 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.14, i64 0, i64 0), i8* %117)
%119 = call i32 @exit(i32 0)
unreachable
120: ; preds = %108
ret i32 0
}

LLVM IR (-O2):
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
@stdout = global i32 0
@.str.13 = [23 x i8] c"for server mode\0A%s -s\0A\00"
@.str.14 = [23 x i8] c"for client mode\0A%s -c\0A\00"
@str = [43 x i8] c"malformed command, specify run mode\0Ausage:\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
store i32 %0, i32* %3
%4 = call i32 @tests(i32* %3, i8** %1)
%5 = call i64 @correctNumberOfArguments(i32* %3)
%6 = icmp eq i64 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = call i64 @correctArgs(i8* %9)
br label %11
11: ; preds = %7, %2
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
%13 = load i8*, i8** %1
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.13, i64 0, i64 0), i8* %13)
%15 = load i8*, i8** %1
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.14, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 0)
unreachable
}