#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*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int listen(int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int strlen(char *);
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 = accept(sockServer, (struct sockaddr *)&caller, &size);
    if (retour == -1) {
      perror(strerror(errno));
      continue;
    }
    char *mess = "Yeah!\n";
    send(descSock, mess, strlen(mess) * sizeof(char), 0);
    char buff[1024];
    int recu = recv(descSock, buff, 1023 * sizeof(char), 0);
    buff[recu] = '\0';
    printf("Message recu : %s\n", buff);
    close(descSock);
  }
  close(sockServer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
mov    0x2dc0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x18(%rbp)
mov    0x2dc5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    $0x106a,%edi
call   1050 <htons@plt>
mov    %eax,-0x24(%rbp)
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <bind@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1283 <main+0xa3>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    %eax,%edi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x18(%rbp),%edi
xor    %esi,%esi
call   10a0 <listen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    12b9 <main+0xd9>
mov    0x2d27(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    %eax,%edi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
jmp    12be <main+0xde>
movl   $0xc,-0x3c(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
call   10d0 <accept@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    12fc <main+0x11c>
mov    0x2cdf(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    %eax,%edi
call   10c0 <perror@plt>
jmp    12be <main+0xde>
lea    0xcfd(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%eax
mov    %eax,-0x464(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x460(%rbp)
mov    -0x48(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x464(%rbp),%edi
mov    -0x460(%rbp),%rsi
cltq
shl    $0x0,%rax
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    -0x40(%rbp),%edi
lea    -0x450(%rbp),%rsi
mov    $0x3ff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x454(%rbp)
movslq -0x454(%rbp),%rax
movb   $0x0,-0x450(%rbp,%rax,1)
lea    -0x450(%rbp),%rsi
lea    0xc8e(%rip),%rdi
call   1070 <printf@plt>
mov    -0x40(%rbp),%edi
call   1090 <close@plt>
jmp    12be <main+0xde>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
mov    0x2dcf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,%r12d
mov    0x2dd4(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    $0x106a,%edi
call   1050 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %r12d,%edi
mov    $0xc,%edx
call   10b0 <bind@plt>
cmp    $0xffffffff,%eax
je     12e0 <main+0x100>
mov    %r12d,%edi
xor    %esi,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
je     12e0 <main+0x100>
lea    0xc(%rsp),%r15
lea    0xd8c(%rip),%rbx
lea    0x30(%rsp),%rbp
lea    0xd87(%rip),%r13
movl   $0xc,0xc(%rsp)
mov    %r12d,%edi
lea    0x20(%rsp),%rsi
mov    %r15,%rdx
call   10d0 <accept@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x3ff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cltq
movb   $0x0,0x30(%rsp,%rax,1)
mov    %r13,%rdi
mov    %rbp,%rsi
call   1070 <printf@plt>
mov    %r14d,%edi
call   1090 <close@plt>
jmp    1280 <main+0xa0>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    %eax,%edi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

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
@.str = [7 x i8] c"Yeah!\0A\00"
@.str.1 = [19 x i8] c"Message recu : %s\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 i32
%12 = alloca i8*
%13 = alloca [1024 x i8]
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%15 = load i32, i32* @PF_INET
%16 = load i32, i32* @SOCK_STREAM
%17 = call i32 @socket(i32 %15, i32 %16, i32 0)
store i32 %17, i32* %7
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %18, i32* %19
%20 = call i32 @htons(i32 4202)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %20, i32* %21
%22 = load i32, i32* @INADDR_ANY
%23 = call i32 @htonl(i32 %22)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %24, i32 0, i32 0
store i32 %23, i32* %25
%26 = load i32, i32* %7
%27 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%28 = call i32 @bind(i32 %26, %struct.sockaddr* %27, i32 12)
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %36
31: ; preds = %2
%32 = load i32, i32* @errno
%33 = call i32 @strerror(i32 %32)
%34 = call i32 @perror(i32 %33)
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %2
%37 = load i32, i32* %7
%38 = call i32 @listen(i32 %37, i32 0)
store i32 %38, i32* %6
%39 = load i32, i32* %6
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %46
41: ; preds = %36
%42 = load i32, i32* @errno
%43 = call i32 @strerror(i32 %42)
%44 = call i32 @perror(i32 %43)
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %36
br label %47
47: ; preds = %46, %53, %57
store i32 12, i32* %10
%48 = load i32, i32* %7
%49 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%50 = call i32 @accept(i32 %48, %struct.sockaddr* %49, i32* %10)
store i32 %50, i32* %11
%51 = load i32, i32* %6
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %57
53: ; preds = %47
%54 = load i32, i32* @errno
%55 = call i32 @strerror(i32 %54)
%56 = call i32 @perror(i32 %55)
br label %47
57: ; preds = %47
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %12
%58 = load i32, i32* %11
%59 = load i8*, i8** %12
%60 = load i8*, i8** %12
%61 = call i32 @strlen(i8* %60)
%62 = sext i32 %61 to i64
%63 = mul i64 %62, 1
%64 = trunc i64 %63 to i32
%65 = call i32 @send(i32 %58, i8* %59, i32 %64, i32 0)
%66 = load i32, i32* %11
%67 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%68 = call i32 @recv(i32 %66, i8* %67, i32 1023, i32 0)
store i32 %68, i32* %14
%69 = load i32, i32* %14
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 %70
store i8 0, i8* %71
%72 = getelementptr inbounds [1024 x i8], [1024 x i8]* %13, i64 0, i64 0
%73 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %72)
%74 = load i32, i32* %11
%75 = call i32 @close(i32 %74)
br label %47
}

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
@.str = [7 x i8] c"Yeah!\0A\00"
@.str.1 = [19 x i8] c"Message recu : %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = load i32, i32* @PF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = bitcast %struct.sockaddr_in* %3 to i8*
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %11, i32* %12
%13 = tail call i32 @htons(i32 4202)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %13, i32* %14
%15 = load i32, i32* @INADDR_ANY
%16 = tail call i32 @htonl(i32 %15)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %16, i32* %17
%18 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%19 = call i32 @bind(i32 %9, %struct.sockaddr* %18, i32 12)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %26
21: ; preds = %2
%22 = load i32, i32* @errno
%23 = call i32 @strerror(i32 %22)
%24 = call i32 @perror(i32 %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %2
%27 = call i32 @listen(i32 %9, i32 0)
%28 = icmp eq i32 %27, -1
br i1 %28, label %34, label %29
29: ; preds = %26
%30 = bitcast %struct.sockaddr_in* %4 to i8*
%31 = bitcast i32* %5 to i8*
%32 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
br label %39
34: ; preds = %26
%35 = load i32, i32* @errno
%36 = call i32 @strerror(i32 %35)
%37 = call i32 @perror(i32 %36)
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %29, %39
store i32 12, i32* %5
%40 = call i32 @accept(i32 %9, %struct.sockaddr* %32, i32* %5)
%41 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%42 = call i32 @send(i32 %40, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %41, i32 0)
%43 = call i32 @recv(i32 %40, i8* %33, i32 1023, i32 0)
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %44
store i8 0, i8* %45
%46 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %33)
%47 = call i32 @close(i32 %40)
br label %39
}