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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ atoi(char *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ error_handling(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int serverSocket;
  int clientSocket;
  struct sockaddr_in serv_addr;
  struct sockaddr_in clnt_addr;
  socklen_t clnt_addr_size;
  char message[1024];
  int str_len, i;
  if (argc != 2) {
    printf("Usage : %s <port>\n", argv[0]);
    exit(1);
  }
  serverSocket = socket(PF_INET, SOCK_STREAM, 0);
  if (serverSocket == -1) {
    error_handling("socket() error");
  }
  memset(&serv_addr, 0, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  serv_addr.sin_port = htons(atoi(argv[1]));
  if (bind(serverSocket, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) ==
      -1) {
    error_handling("bind() error");
  }
  if (listen(serverSocket, 5) == -1) {
    error_handling("listen() error");
  }
  clnt_addr_size = sizeof(clnt_addr);
  for (i = 0; i < 5; i++) {
    clientSocket =
        accept(serverSocket, (struct sockaddr *)&clnt_addr, &clnt_addr_size);
    if (clientSocket == -1) {
      error_handling("accept() error");
    } else {
      printf("Conneted Client %d \n", i + 1);
    }
    while ((str_len = read(clientSocket, message, 1024)) != 0) {
      write(clientSocket, message, str_len);
    }
    close(clientSocket);
  }
  close(serverSocket);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1222 <main+0x42>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
mov    0x2d9e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1254 <main+0x74>
lea    0xdc4(%rip),%rdi
call   10a0 <error_handling@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2d7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
jne    12be <main+0xde>
lea    0xd69(%rip),%rdi
call   10a0 <error_handling@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   10b0 <listen@plt>
cmp    $0xffffffff,%eax
jne    12e0 <main+0x100>
lea    0xd54(%rip),%rdi
call   10a0 <error_handling@plt>
movl   $0xc,-0x3c(%rbp)
movl   $0x0,-0x448(%rbp)
cmpl   $0x5,-0x448(%rbp)
jge    13a1 <main+0x1c1>
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
call   10d0 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    132c <main+0x14c>
lea    0xd1c(%rip),%rdi
call   10a0 <error_handling@plt>
jmp    1343 <main+0x163>
mov    -0x448(%rbp),%esi
add    $0x1,%esi
lea    0xd11(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1348 <main+0x168>
mov    -0x18(%rbp),%edi
lea    -0x440(%rbp),%rsi
mov    $0x400,%edx
call   1090 <read@plt>
mov    %eax,-0x444(%rbp)
cmp    $0x0,%eax
je     1385 <main+0x1a5>
mov    -0x18(%rbp),%edi
lea    -0x440(%rbp),%rsi
mov    -0x444(%rbp),%edx
call   1030 <write@plt>
jmp    1348 <main+0x168>
mov    -0x18(%rbp),%edi
call   1080 <close@plt>
mov    -0x448(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x448(%rbp)
jmp    12f1 <main+0x111>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    135e <main+0x17e>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
mov    0x2dc3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1229 <main+0x49>
lea    0xdef(%rip),%rdi
call   10a0 <error_handling@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    0x8(%rbx),%rdi
call   10e0 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1290 <main+0xb0>
lea    0xd97(%rip),%rdi
call   10a0 <error_handling@plt>
mov    %ebp,%edi
mov    $0x5,%esi
call   10b0 <listen@plt>
cmp    $0xffffffff,%eax
jne    12ad <main+0xcd>
lea    0xd87(%rip),%rdi
call   10a0 <error_handling@plt>
movl   $0xc,0xc(%rsp)
lea    0x20(%rsp),%r14
lea    0xc(%rsp),%r15
lea    0x30(%rsp),%rbx
xor    %r13d,%r13d
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   10d0 <accept@plt>
mov    %eax,%r12d
cmp    $0xffffffff,%eax
je     1300 <main+0x120>
lea    0x1(%r13),%esi
lea    0xd5d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    131d <main+0x13d>
nopl   0x0(%rax)
lea    0xd37(%rip),%rdi
call   10a0 <error_handling@plt>
jmp    131d <main+0x13d>
xchg   %ax,%ax
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1090 <read@plt>
test   %eax,%eax
jne    1310 <main+0x130>
mov    %r12d,%edi
call   1080 <close@plt>
add    $0x1,%r13d
cmp    $0x5,%r13d
jne    12d0 <main+0xf0>
mov    %ebp,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x438,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0xc98(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [19 x i8] c"Usage : %s <port>\0A\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [15 x i8] c"socket() error\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [13 x i8] c"bind() error\00"
@.str.3 = [15 x i8] c"listen() error\00"
@.str.4 = [15 x i8] c"accept() error\00"
@.str.5 = [21 x i8] c"Conneted Client %d \0A\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 %struct.sockaddr_in
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = alloca [1024 x i8]
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 2
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %2
%23 = load i32, i32* @PF_INET
%24 = load i32, i32* @SOCK_STREAM
%25 = call i32 @socket(i32 %23, i32 %24, i32 0)
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = call i32 @error_handling(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %28, %22
%31 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 12)
%32 = load i32, i32* @AF_INET
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %32, i32* %33
%34 = load i32, i32* @INADDR_ANY
%35 = call i32 @htonl(i32 %34)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%37 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %36, i32 0, i32 0
store i32 %35, i32* %37
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 @atoi(i8* %40)
%42 = call i32 @htons(i32 %41)
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %42, i32* %43
%44 = load i32, i32* %6
%45 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%46 = call i32 @bind(i32 %44, %struct.sockaddr* %45, i32 12)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %50
48: ; preds = %30
%49 = call i32 @error_handling(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %50
50: ; preds = %48, %30
%51 = load i32, i32* %6
%52 = call i32 @listen(i32 %51, i32 5)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = call i32 @error_handling(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %56
56: ; preds = %54, %50
store i32 12, i32* %10
store i32 0, i32* %13
br label %57
57: ; preds = %86, %56
%58 = load i32, i32* %13
%59 = icmp slt i32 %58, 5
br i1 %59, label %60, label %89
60: ; preds = %57
%61 = load i32, i32* %6
%62 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%63 = call i32 @accept(i32 %61, %struct.sockaddr* %62, i32* %10)
store i32 %63, i32* %7
%64 = load i32, i32* %7
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %68
66: ; preds = %60
%67 = call i32 @error_handling(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %72
68: ; preds = %60
%69 = load i32, i32* %13
%70 = add nsw i32 %69, 1
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %70)
br label %72
72: ; preds = %68, %66
br label %73
73: ; preds = %78, %72
%74 = load i32, i32* %7
%75 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%76 = call i32 @read(i32 %74, i8* %75, i32 1024)
store i32 %76, i32* %12
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %83
78: ; preds = %73
%79 = load i32, i32* %7
%80 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%81 = load i32, i32* %12
%82 = call i32 @write(i32 %79, i8* %80, i32 %81)
br label %73
83: ; preds = %73
%84 = load i32, i32* %7
%85 = call i32 @close(i32 %84)
br label %86
86: ; preds = %83
%87 = load i32, i32* %13
%88 = add nsw i32 %87, 1
store i32 %88, i32* %13
br label %57
89: ; preds = %57
%90 = load i32, i32* %6
%91 = call i32 @close(i32 %90)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [19 x i8] c"Usage : %s <port>\0A\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [15 x i8] c"socket() error\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [13 x i8] c"bind() error\00"
@.str.3 = [15 x i8] c"listen() error\00"
@.str.4 = [15 x i8] c"accept() error\00"
@.str.5 = [21 x i8] c"Conneted Client %d \0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%11 = icmp eq i32 %0, 2
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = load i8*, i8** %1
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i32, i32* @PF_INET
%18 = load i32, i32* @SOCK_STREAM
%19 = tail call i32 @socket(i32 %17, i32 %18, i32 0)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = tail call i32 @error_handling(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %16
%24 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %25, i32* %26
%27 = load i32, i32* @INADDR_ANY
%28 = call i32 @htonl(i32 %27)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %28, i32* %29
%30 = getelementptr inbounds i8*, i8** %1, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @atoi(i8* %31)
%33 = call i32 @htons(i32 %32)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %33, i32* %34
%35 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%36 = call i32 @bind(i32 %19, %struct.sockaddr* %35, i32 12)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %40
38: ; preds = %23
%39 = call i32 @error_handling(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %40
40: ; preds = %38, %23
%41 = call i32 @listen(i32 %19, i32 5)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = call i32 @error_handling(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %45
45: ; preds = %43, %40
store i32 12, i32* %5
%46 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
br label %47
47: ; preds = %45, %64
%48 = phi i32 [ 0, %45 ], [ %66, %64 ]
%49 = call i32 @accept(i32 %19, %struct.sockaddr* %46, i32* %5)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %53
51: ; preds = %47
%52 = call i32 @error_handling(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %56
53: ; preds = %47
%54 = add nuw nsw i32 %48, 1
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %54)
br label %56
56: ; preds = %53, %51
%57 = call i32 @read(i32 %49, i8* %10, i32 1024)
%58 = icmp eq i32 %57, 0
br i1 %58, label %64, label %59
59: ; preds = %56, %59
%60 = phi i32 [ %62, %59 ], [ %57, %56 ]
%61 = call i32 @write(i32 %49, i8* %10, i32 %60)
%62 = call i32 @read(i32 %49, i8* %10, i32 1024)
%63 = icmp eq i32 %62, 0
br i1 %63, label %64, label %59
64: ; preds = %59, %56
%65 = call i32 @close(i32 %49)
%66 = add nuw nsw i32 %48, 1
%67 = icmp eq i32 %66, 5
br i1 %67, label %68, label %47
68: ; preds = %64
%69 = call i32 @close(i32 %19)
ret i32 0
}