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

/* 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 bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fonctionThread(int *);
scalar_t__ fork();
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int listen(int, int /*<<< orphan*/);
int *malloc(int);
int /*<<< orphan*/ perror(int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int main(int argc, char const *argv[]) {
  int retour = 0;
  int sockServer = socket(PF_INET, SOCK_STREAM, 0);
  struct sockaddr_in address_sock;
  address_sock.sin_family = AF_INET;
  address_sock.sin_port = htons(4202);
  address_sock.sin_addr.s_addr = htonl(INADDR_ANY);
  retour = bind(sockServer, (struct sockaddr *)&address_sock,
                sizeof(struct sockaddr_in));
  if (retour == -1) {
    perror(strerror(errno));
    exit(1);
  }
  retour = listen(sockServer, 0);
  if (retour == -1) {
    perror(strerror(errno));
    exit(1);
  }
  while (42) {
    struct sockaddr_in caller;
    socklen_t size = sizeof(caller);
    int *descSock = malloc(sizeof(int));
    if (descSock == NULL) {
      exit(1);
    }
    *descSock = accept(sockServer, (struct sockaddr *)&caller, &size);
    if (retour == -1) {
      perror(strerror(errno));
      continue;
    }
    if (fork() == 0) {
      fonctionThread(descSock);
    } else {
      close(*descSock);
    }
  }
  close(sockServer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
mov    0x2dd3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x18(%rbp)
mov    0x2dd8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    $0x106a,%edi
call   1030 <htons@plt>
mov    %eax,-0x24(%rbp)
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1270 <main+0xa0>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    %eax,%edi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x18(%rbp),%edi
xor    %esi,%esi
call   1080 <listen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    12a6 <main+0xd6>
mov    0x2d3a(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    %eax,%edi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    12ab <main+0xdb>
movl   $0xc,-0x3c(%rbp)
mov    $0x4,%edi
call   1070 <malloc@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    12d5 <main+0x105>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x18(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
call   10b0 <accept@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1311 <main+0x141>
mov    0x2cca(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    %eax,%edi
call   10a0 <perror@plt>
jmp    12ab <main+0xdb>
mov    $0x0,%al
call   10e0 <fork@plt>
cmp    $0x0,%rax
jne    1330 <main+0x160>
mov    -0x48(%rbp),%rdi
call   1060 <fonctionThread@plt>
jmp    133b <main+0x16b>
mov    -0x48(%rbp),%rax
mov    (%rax),%edi
call   1050 <close@plt>
jmp    12ab <main+0xdb>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,%ebp
mov    0x2dec(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    $0x106a,%edi
call   1030 <htons@plt>
mov    %eax,0xc(%rsp)
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   1090 <bind@plt>
cmp    $0xffffffff,%eax
je     1246 <main+0x76>
mov    %ebp,%edi
xor    %esi,%esi
call   1080 <listen@plt>
cmp    $0xffffffff,%eax
jne    1265 <main+0x95>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    %eax,%edi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
movl   $0xc,0x4(%rsp)
mov    $0x4,%edi
call   1070 <malloc@plt>
test   %rax,%rax
jne    1286 <main+0xb6>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    %rax,%rbx
lea    0x18(%rsp),%r14
lea    0x4(%rsp),%r15
jmp    12c1 <main+0xf1>
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rbx),%edi
call   1050 <close@plt>
movl   $0xc,0x4(%rsp)
mov    $0x4,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     127c <main+0xac>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   10b0 <accept@plt>
mov    %eax,(%rbx)
xor    %eax,%eax
call   10e0 <fork@plt>
test   %rax,%rax
jne    12a0 <main+0xd0>
mov    %rbx,%rdi
call   1060 <fonctionThread@plt>
jmp    12a7 <main+0xd7>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@errno = global i32 0
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 i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%12 = load i32, i32* @PF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
store i32 %14, i32* %7
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %15, i32* %16
%17 = call i32 @htons(i32 4202)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %17, i32* %18
%19 = load i32, i32* @INADDR_ANY
%20 = call i32 @htonl(i32 %19)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
store i32 %20, i32* %22
%23 = load i32, i32* %7
%24 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%25 = call i32 @bind(i32 %23, %struct.sockaddr* %24, i32 12)
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %33
28: ; preds = %2
%29 = load i32, i32* @errno
%30 = call i32 @strerror(i32 %29)
%31 = call i32 @perror(i32 %30)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %2
%34 = load i32, i32* %7
%35 = call i32 @listen(i32 %34, i32 0)
store i32 %35, i32* %6
%36 = load i32, i32* %6
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %43
38: ; preds = %33
%39 = load i32, i32* @errno
%40 = call i32 @strerror(i32 %39)
%41 = call i32 @perror(i32 %40)
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %33
br label %44
44: ; preds = %43, %57, %71
store i32 12, i32* %10
%45 = call i32* @malloc(i32 4)
store i32* %45, i32** %11
%46 = load i32*, i32** %11
%47 = icmp eq i32* %46, null
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %44
%51 = load i32, i32* %7
%52 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%53 = call i32 @accept(i32 %51, %struct.sockaddr* %52, i32* %10)
%54 = load i32*, i32** %11
store i32 %53, i32* %54
%55 = load i32, i32* %6
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %61
57: ; preds = %50
%58 = load i32, i32* @errno
%59 = call i32 @strerror(i32 %58)
%60 = call i32 @perror(i32 %59)
br label %44
61: ; preds = %50
%62 = call i64 (...) @fork()
%63 = icmp eq i64 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %61
%65 = load i32*, i32** %11
%66 = call i32 @fonctionThread(i32* %65)
br label %71
67: ; preds = %61
%68 = load i32*, i32** %11
%69 = load i32, i32* %68
%70 = call i32 @close(i32 %69)
br label %71
71: ; preds = %67, %64
br label %44
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = load i32, i32* @PF_INET
%7 = load i32, i32* @SOCK_STREAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = bitcast %struct.sockaddr_in* %3 to i8*
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %10, i32* %11
%12 = tail call i32 @htons(i32 4202)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %12, i32* %13
%14 = load i32, i32* @INADDR_ANY
%15 = tail call i32 @htonl(i32 %14)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %15, i32* %16
%17 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%18 = call i32 @bind(i32 %8, %struct.sockaddr* %17, i32 12)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %25
20: ; preds = %2
%21 = load i32, i32* @errno
%22 = call i32 @strerror(i32 %21)
%23 = call i32 @perror(i32 %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %2
%26 = call i32 @listen(i32 %8, i32 0)
%27 = icmp eq i32 %26, -1
br i1 %27, label %35, label %28
28: ; preds = %25
%29 = bitcast %struct.sockaddr_in* %4 to i8*
%30 = bitcast i32* %5 to i8*
store i32 12, i32* %5
%31 = call i32* @malloc(i32 4)
%32 = icmp eq i32* %31, null
br i1 %32, label %40, label %33
33: ; preds = %28
%34 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
br label %42
35: ; preds = %25
%36 = load i32, i32* @errno
%37 = call i32 @strerror(i32 %36)
%38 = call i32 @perror(i32 %37)
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %52, %28
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %52, %33
%43 = phi i32* [ %31, %33 ], [ %53, %52 ]
%44 = call i32 @accept(i32 %8, %struct.sockaddr* %34, i32* %5)
store i32 %44, i32* %43
%45 = call i64 (...) @fork()
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %42
%48 = call i32 @fonctionThread(i32* %43)
br label %52
49: ; preds = %42
%50 = load i32, i32* %43
%51 = call i32 @close(i32 %50)
br label %52
52: ; preds = %47, %49
store i32 12, i32* %5
%53 = call i32* @malloc(i32 4)
%54 = icmp eq i32* %53, null
br i1 %54, label %40, label %42
}