#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*/ sin;
typedef int pid_t;
typedef int /*<<< orphan*/ from;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SIGCHLD;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int atoi(char *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ communication(struct sockaddr_in, int);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ htons(int);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int s, ns, r, port;
  pid_t pid;
  socklen_t fromlen;
  struct sockaddr_in sin, from;
  signal(SIGCHLD, SIG_IGN);
  if (argc != 2) {
    printf("Usage : %s  port_serveur\n", argv[0]);
    exit(1);
  }
  port = atoi(argv[1]);
  if (port < 5000) {
    printf("donnez un numero de port superieur a 5000\n");
    exit(1);
  }
  memset(&sin, 0, sizeof(sin));
  sin.sin_family = AF_INET;
  sin.sin_addr.s_addr = INADDR_ANY;
  sin.sin_port = htons(port);
  s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  if (s == -1) {
    perror("socket");
    exit(2);
  }
  r = bind(s, (struct sockaddr *)&sin, sizeof(sin));
  if (r == -1) {
    perror("bind");
    exit(3);
  }
  if (listen(s, 5) < 0) {
    perror("listen");
    exit(4);
  }
  fromlen = sizeof(from);
  for (;;) {
    ns = accept(s, (struct sockaddr *)&from, &fromlen);
    if (ns == -1) {
      perror("accept");
      exit(1);
    }
    pid = fork();
    if (pid == -1) {
      perror("Error forking!");
      exit(5);
    }
    if (pid == 0) {
      communication(from, ns);
      exit(0);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
mov    0x2dd2(%rip),%rax
mov    (%rax),%esi
call   1070 <signal@plt>
cmpl   $0x2,-0x8(%rbp)
je     1226 <main+0x56>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1388,-0x20(%rbp)
jge    125b <main+0x8b>
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d62(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x38(%rbp)
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
mov    0x2d1a(%rip),%rax
mov    (%rax),%esi
mov    0x2d31(%rip),%rax
mov    (%rax),%edx
call   10f0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    12d1 <main+0x101>
lea    0xd83(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x2,%edi
call   10d0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1305 <main+0x135>
lea    0xd56(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x3,%edi
call   10d0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   1080 <listen@plt>
cmp    $0x0,%rax
jge    1332 <main+0x162>
lea    0xd2e(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x4,%edi
call   10d0 <exit@plt>
movl   $0xc,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x48(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   10b0 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    136c <main+0x19c>
lea    0xcfb(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1396 <main+0x1c6>
lea    0xcd8(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x5,%edi
call   10d0 <exit@plt>
cmpl   $0x0,-0x24(%rbp)
jne    13c4 <main+0x1f4>
mov    -0x18(%rbp),%edx
mov    -0x48(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x40(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%esi
call   1060 <communication@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
jmp    1339 <main+0x169>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
mov    0x2dc9(%rip),%rax
mov    (%rax),%esi
call   1080 <signal@plt>
cmp    $0x2,%ebp
jne    1231 <main+0x51>
mov    0x8(%rbx),%rdi
call   10d0 <atoi@plt>
cmp    $0x1387,%eax
jg     124c <main+0x6c>
lea    0xe21(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    (%rbx),%rsi
lea    0xdc5(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    %eax,%ebx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2d82(%rip),%rbp
mov    0x0(%rbp),%eax
mov    %eax,0x10(%rsp)
mov    0x2d6c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    %ebx,%edi
call   1040 <htons@plt>
mov    %eax,0x8(%rsp)
mov    0x0(%rbp),%edi
mov    0x2d29(%rip),%rax
mov    (%rax),%esi
mov    0x2d40(%rip),%rax
mov    (%rax),%edx
call   1100 <socket@plt>
cmp    $0xffffffff,%eax
jne    12ba <main+0xda>
lea    0xd6f(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x2,%edi
call   10e0 <exit@plt>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
mov    $0xc,%edx
call   10a0 <bind@plt>
cmp    $0xffffffff,%eax
jne    12e8 <main+0x108>
lea    0xd48(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x3,%edi
call   10e0 <exit@plt>
mov    %ebx,%edi
mov    $0x5,%esi
call   1090 <listen@plt>
test   %rax,%rax
jns    130f <main+0x12f>
lea    0xd26(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x4,%edi
call   10e0 <exit@plt>
movl   $0xc,0x4(%rsp)
lea    0x18(%rsp),%r14
lea    0x4(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   10c0 <accept@plt>
cmp    $0xffffffff,%eax
je     136a <main+0x18a>
mov    %eax,%ebp
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     1380 <main+0x1a0>
cmp    $0xffffffff,%eax
jne    1330 <main+0x150>
lea    0xcd9(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x5,%edi
call   10e0 <exit@plt>
lea    0xcbc(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x18(%rsp),%rdi
mov    0x20(%rsp),%esi
mov    %ebp,%edx
call   1070 <communication@plt>
xor    %edi,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@SIGCHLD = global i32 0
@SIG_IGN = global i32 0
@.str = [26 x i8] c"Usage : %s port_serveur\0A\00"
@.str.1 = [43 x i8] c"donnez un numero de port superieur a 5000\0A\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@.str.3 = [5 x i8] c"bind\00"
@.str.4 = [7 x i8] c"listen\00"
@.str.5 = [7 x i8] c"accept\00"
@.str.6 = [15 x i8] c"Error forking!\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 i32
%11 = alloca i32
%12 = alloca %struct.sockaddr_in
%13 = alloca %struct.sockaddr_in
%14 = alloca { i64, i32 }
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* @SIGCHLD
%16 = load i32, i32* @SIG_IGN
%17 = call i32 @signal(i32 %15, i32 %16)
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 2
br i1 %19, label %20, label %26
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %2
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %9
%31 = load i32, i32* %9
%32 = icmp slt i32 %31, 5000
br i1 %32, label %33, label %36
33: ; preds = %26
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %26
%37 = call i32 @memset(%struct.sockaddr_in* %12, i32 0, i32 12)
%38 = load i32, i32* @AF_INET
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 2
store i32 %38, i32* %39
%40 = load i32, i32* @INADDR_ANY
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, 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 i32, i32* %9
%44 = call i32 @htons(i32 %43)
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
store i32 %44, i32* %45
%46 = load i32, i32* @AF_INET
%47 = load i32, i32* @SOCK_STREAM
%48 = load i32, i32* @IPPROTO_TCP
%49 = call i32 @socket(i32 %46, i32 %47, i32 %48)
store i32 %49, i32* %6
%50 = load i32, i32* %6
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %55
52: ; preds = %36
%53 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%54 = call i32 @exit(i32 2)
unreachable
55: ; preds = %36
%56 = load i32, i32* %6
%57 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%58 = call i32 @bind(i32 %56, %struct.sockaddr* %57, i32 12)
store i32 %58, i32* %8
%59 = load i32, i32* %8
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %64
61: ; preds = %55
%62 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%63 = call i32 @exit(i32 3)
unreachable
64: ; preds = %55
%65 = load i32, i32* %6
%66 = call i64 @listen(i32 %65, i32 5)
%67 = icmp slt i64 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %64
%69 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%70 = call i32 @exit(i32 4)
unreachable
71: ; preds = %64
store i32 12, i32* %11
br label %72
72: ; preds = %101, %71
%73 = load i32, i32* %6
%74 = bitcast %struct.sockaddr_in* %13 to %struct.sockaddr*
%75 = call i32 @accept(i32 %73, %struct.sockaddr* %74, i32* %11)
store i32 %75, i32* %7
%76 = load i32, i32* %7
%77 = icmp eq i32 %76, -1
br i1 %77, label %78, label %81
78: ; preds = %72
%79 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%80 = call i32 @exit(i32 1)
unreachable
81: ; preds = %72
%82 = call i32 (...) @fork()
store i32 %82, i32* %10
%83 = load i32, i32* %10
%84 = icmp eq i32 %83, -1
br i1 %84, label %85, label %88
85: ; preds = %81
%86 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
%87 = call i32 @exit(i32 5)
unreachable
88: ; preds = %81
%89 = load i32, i32* %10
%90 = icmp eq i32 %89, 0
br i1 %90, label %91, label %101
91: ; preds = %88
%92 = load i32, i32* %7
%93 = bitcast { i64, i32 }* %14 to i8*
%94 = bitcast %struct.sockaddr_in* %13 to i8*
%95 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %14, i32 0, i32 0
%96 = load i64, i64* %95
%97 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %14, i32 0, i32 1
%98 = load i32, i32* %97
%99 = call i32 @communication(i64 %96, i32 %98, i32 %92)
%100 = call i32 @exit(i32 0)
unreachable
101: ; preds = %88
br label %72
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@SIGCHLD = global i32 0
@SIG_IGN = global i32 0
@.str = [26 x i8] c"Usage : %s port_serveur\0A\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@.str.3 = [5 x i8] c"bind\00"
@.str.4 = [7 x i8] c"listen\00"
@.str.5 = [7 x i8] c"accept\00"
@.str.6 = [15 x i8] c"Error forking!\00"
@str = [42 x i8] c"donnez un numero de port superieur a 5000\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = bitcast i32* %3 to i8*
%7 = bitcast %struct.sockaddr_in* %4 to i8*
%8 = bitcast %struct.sockaddr_in* %5 to i8*
%9 = load i32, i32* @SIGCHLD
%10 = load i32, i32* @SIG_IGN
%11 = tail call i32 @signal(i32 %9, i32 %10)
%12 = icmp eq i32 %0, 2
br i1 %12, label %17, label %13
13: ; preds = %2
%14 = load i8*, i8** %1
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = tail call i32 @atoi(i8* %19)
%21 = icmp slt i32 %20, 5000
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %17
%26 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 12)
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %27, i32* %28
%29 = load i32, i32* @INADDR_ANY
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %29, i32* %30
%31 = call i32 @htons(i32 %20)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %31, i32* %32
%33 = load i32, i32* @AF_INET
%34 = load i32, i32* @SOCK_STREAM
%35 = load i32, i32* @IPPROTO_TCP
%36 = call i32 @socket(i32 %33, i32 %34, i32 %35)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %41
38: ; preds = %25
%39 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 @exit(i32 2)
unreachable
41: ; preds = %25
%42 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%43 = call i32 @bind(i32 %36, %struct.sockaddr* %42, i32 12)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%47 = call i32 @exit(i32 3)
unreachable
48: ; preds = %41
%49 = call i64 @listen(i32 %36, i32 5)
%50 = icmp slt i64 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%53 = call i32 @exit(i32 4)
unreachable
54: ; preds = %48
store i32 12, i32* %3
%55 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
br label %56
56: ; preds = %62, %54
%57 = call i32 @accept(i32 %36, %struct.sockaddr* %55, i32* %3)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %62
59: ; preds = %56
%60 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%61 = call i32 @exit(i32 1)
unreachable
62: ; preds = %56
%63 = call i32 (...) @fork()
switch i32 %63, label %56 [
i32 -1, label %64
i32 0, label %67
]
64: ; preds = %62
%65 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
%66 = call i32 @exit(i32 5)
unreachable
67: ; preds = %62
%68 = bitcast %struct.sockaddr_in* %5 to i64*
%69 = load i64, i64* %68
%70 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
%71 = load i32, i32* %70
%72 = call i32 @communication(i64 %69, i32 %71, i32 %57)
%73 = call i32 @exit(i32 0)
unreachable
}