#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 /*<<< orphan*/ client_adr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htons(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *,
                    unsigned int *);
int /*<<< orphan*/ sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
                          struct sockaddr *, unsigned int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int main() {
  unsigned int clientlen;
  int nbClients = 0;
  int sock;
  struct sockaddr_in *clientaddr[100];
  struct sockaddr_in client_adr;
  char buf[100];
  sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  client_adr.sin_family = AF_INET;
  client_adr.sin_port = htons(2222);
  client_adr.sin_addr.s_addr = INADDR_ANY;
  bind(sock, (struct sockaddr *)&client_adr, sizeof(client_adr));
  while (1) {
    clientlen = sizeof(struct sockaddr_in);
    printf("En attente d'un message...\n");
    clientaddr[nbClients] =
        (struct sockaddr_in *)malloc(sizeof(struct sockaddr_in));
    if (recvfrom(sock, buf, 100, 0, (struct sockaddr *)clientaddr[nbClients],
                 &clientlen) < 0)
      perror("Error recvfrom : L41 - server.c");
    if (buf[0] == '@')
      nbClients++;
    else
      for (int k = 0; k < nbClients; k++)
        sendto(sock, buf, strlen(buf), 0, (struct sockaddr *)clientaddr[k],
               clientlen);
    printf("Message(s) envoyé(s)...\n");
  }
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3d0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
mov    0x2dfe(%rip),%rax
mov    (%rax),%edx
call   10b0 <socket@plt>
mov    %eax,-0x10(%rbp)
mov    0x2e15(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x338(%rbp)
mov    $0x8ae,%edi
call   1040 <htons@plt>
mov    %eax,-0x33c(%rbp)
mov    0x2dee(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x340(%rbp)
mov    -0x10(%rbp),%edi
lea    -0x340(%rbp),%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
movl   $0xc,-0x8(%rbp)
lea    0xde4(%rip),%rdi
call   1050 <printf@plt>
mov    $0xc,%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
mov    %rcx,-0x330(%rbp,%rax,8)
ff
mov    -0x10(%rbp),%edi
lea    -0x3b0(%rbp),%rsi
movslq -0xc(%rbp),%rax
mov    -0x330(%rbp,%rax,8),%r8
ff
mov    $0x64,%edx
xor    %ecx,%ecx
lea    -0x8(%rbp),%r9
call   1080 <recvfrom@plt>
cmp    $0x0,%rax
jge    1276 <main+0xe6>
lea    0xdab(%rip),%rdi
call   10a0 <perror@plt>
movsbl -0x3b0(%rbp),%eax
cmp    $0x40,%eax
jne    1294 <main+0x104>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1312 <main+0x182>
movl   $0x0,-0x3b4(%rbp)
mov    -0x3b4(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    130d <main+0x17d>
mov    -0x10(%rbp),%eax
mov    %eax,-0x3c4(%rbp)
lea    -0x3b0(%rbp),%rax
mov    %rax,-0x3c0(%rbp)
lea    -0x3b0(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x3c4(%rbp),%edi
mov    -0x3c0(%rbp),%rsi
mov    %eax,%edx
movslq -0x3b4(%rbp),%rax
mov    -0x330(%rbp,%rax,8),%r8
ff
mov    -0x8(%rbp),%r9d
xor    %ecx,%ecx
call   1060 <sendto@plt>
mov    -0x3b4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3b4(%rbp)
jmp    129e <main+0x10e>
jmp    1312 <main+0x182>
lea    0xd23(%rip),%rdi
call   1050 <printf@plt>
jmp    120e <main+0x7e>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3b8,%rsp
mov    0x2e40(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
mov    0x2e06(%rip),%rax
mov    (%rax),%edx
call   10b0 <socket@plt>
mov    %eax,%ebp
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    $0x8ae,%edi
call   1050 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2e02(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   1090 <bind@plt>
xor    %r12d,%r12d
lea    0xe21(%rip),%r14
lea    0x20(%rsp),%rbx
lea    0xc(%rsp),%r15
lea    0xdf0(%rip),%r13
jmp    1230 <main+0xa0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%r12d
lea    0xe10(%rip),%rdi
call   1030 <puts@plt>
movl   $0xc,0xc(%rsp)
mov    %r14,%rdi
call   1030 <puts@plt>
mov    $0xc,%edi
call   1070 <malloc@plt>
movslq %r12d,%rcx
mov    %rax,0x90(%rsp,%rcx,8)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
mov    %rax,%r8
mov    %r15,%r9
call   1080 <recvfrom@plt>
test   %rax,%rax
jns    1279 <main+0xe9>
mov    %r13,%rdi
call   10a0 <perror@plt>
cmpb   $0x40,0x20(%rsp)
je     1220 <main+0x90>
test   %r12d,%r12d
jle    1224 <main+0x94>
mov    %r14,%r13
mov    %r12d,%r14d
xor    %r15d,%r15d
xchg   %ax,%ax
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    0x90(%rsp,%r15,8),%r8
mov    0xc(%rsp),%r9d
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <sendto@plt>
add    $0x1,%r15
cmp    %r15,%r14
jne    1290 <main+0x100>
mov    %r13,%r14
lea    0xc(%rsp),%r15
lea    0xd35(%rip),%r13
jmp    1224 <main+0x94>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@INADDR_ANY = global i32 0
@.str = [28 x i8] c"En attente d'un message...\0A\00"
@.str.1 = [32 x i8] c"Error recvfrom : L41 - server.c\00"
@.str.2 = [26 x i8] c"Message(s) envoy\C3\A9(s)...\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [100 x %struct.sockaddr_in*]
%6 = alloca %struct.sockaddr_in
%7 = alloca [100 x i8]
%8 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_DGRAM
%11 = load i32, i32* @IPPROTO_UDP
%12 = call i32 @socket(i32 %9, i32 %10, i32 %11)
store i32 %12, i32* %4
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %13, i32* %14
%15 = call i32 @htons(i32 2222)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %15, i32* %16
%17 = load i32, i32* @INADDR_ANY
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%19 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %18, i32 0, i32 0
store i32 %17, i32* %19
%20 = load i32, i32* %4
%21 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%22 = call i32 @bind(i32 %20, %struct.sockaddr* %21, i32 12)
br label %23
23: ; preds = %0, %70
store i32 12, i32* %2
%24 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%25 = call i64 @malloc(i32 12)
%26 = inttoptr i64 %25 to %struct.sockaddr_in*
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [100 x %struct.sockaddr_in*], [100 x %struct.sockaddr_in*]* %5, i64 0, i64 %28
store %struct.sockaddr_in* %26, %struct.sockaddr_in** %29
%30 = load i32, i32* %4
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [100 x %struct.sockaddr_in*], [100 x %struct.sockaddr_in*]* %5, i64 0, i64 %33
%35 = load %struct.sockaddr_in*, %struct.sockaddr_in** %34
%36 = bitcast %struct.sockaddr_in* %35 to %struct.sockaddr*
%37 = call i64 @recvfrom(i32 %30, i8* %31, i32 100, i32 0, %struct.sockaddr* %36, i32* %2)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %23
%40 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %41
41: ; preds = %39, %23
%42 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 64
br i1 %45, label %46, label %49
46: ; preds = %41
%47 = load i32, i32* %3
%48 = add nsw i32 %47, 1
store i32 %48, i32* %3
br label %70
49: ; preds = %41
store i32 0, i32* %8
br label %50
50: ; preds = %66, %49
%51 = load i32, i32* %8
%52 = load i32, i32* %3
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %69
54: ; preds = %50
%55 = load i32, i32* %4
%56 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%57 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%58 = call i32 @strlen(i8* %57)
%59 = load i32, i32* %8
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [100 x %struct.sockaddr_in*], [100 x %struct.sockaddr_in*]* %5, i64 0, i64 %60
%62 = load %struct.sockaddr_in*, %struct.sockaddr_in** %61
%63 = bitcast %struct.sockaddr_in* %62 to %struct.sockaddr*
%64 = load i32, i32* %2
%65 = call i32 @sendto(i32 %55, i8* %56, i32 %58, i32 0, %struct.sockaddr* %63, i32 %64)
br label %66
66: ; preds = %54
%67 = load i32, i32* %8
%68 = add nsw i32 %67, 1
store i32 %68, i32* %8
br label %50
69: ; preds = %50
br label %70
70: ; preds = %69, %46
%71 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %23
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [32 x i8] c"Error recvfrom : L41 - server.c\00"
@str = [27 x i8] c"En attente d'un message...\00"
@str.3 = [25 x i8] c"Message(s) envoy\C3\A9(s)...\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x %struct.sockaddr_in*]
%3 = alloca %struct.sockaddr_in
%4 = alloca [100 x i8]
%5 = bitcast i32* %1 to i8*
%6 = bitcast [100 x %struct.sockaddr_in*]* %2 to i8*
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_DGRAM
%11 = load i32, i32* @IPPROTO_UDP
%12 = tail call i32 @socket(i32 %9, i32 %10, i32 %11)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %13, i32* %14
%15 = tail call i32 @htons(i32 2222)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %15, i32* %16
%17 = load i32, i32* @INADDR_ANY
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %17, i32* %18
%19 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%20 = call i32 @bind(i32 %12, %struct.sockaddr* %19, i32 12)
br label %21
21: ; preds = %52, %0
%22 = phi i32 [ 0, %0 ], [ %53, %52 ]
store i32 12, i32* %1
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%24 = call i64 @malloc(i32 12)
%25 = inttoptr i64 %24 to %struct.sockaddr_in*
%26 = sext i32 %22 to i64
%27 = getelementptr inbounds [100 x %struct.sockaddr_in*], [100 x %struct.sockaddr_in*]* %2, i64 0, i64 %26
store %struct.sockaddr_in* %25, %struct.sockaddr_in** %27
%28 = inttoptr i64 %24 to %struct.sockaddr*
%29 = call i64 @recvfrom(i32 %12, i8* %8, i32 100, i32 0, %struct.sockaddr* %28, i32* %1)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %21
%32 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %31, %21
%34 = load i8, i8* %8
%35 = icmp eq i8 %34, 64
br i1 %35, label %40, label %36
36: ; preds = %33
%37 = icmp sgt i32 %22, 0
br i1 %37, label %38, label %52
38: ; preds = %36
%39 = zext i32 %22 to i64
br label %42
40: ; preds = %33
%41 = add nsw i32 %22, 1
br label %52
42: ; preds = %38, %42
%43 = phi i64 [ 0, %38 ], [ %50, %42 ]
%44 = call i32 @strlen(i8* %8)
%45 = getelementptr inbounds [100 x %struct.sockaddr_in*], [100 x %struct.sockaddr_in*]* %2, i64 0, i64 %43
%46 = bitcast %struct.sockaddr_in** %45 to %struct.sockaddr**
%47 = load %struct.sockaddr*, %struct.sockaddr** %46
%48 = load i32, i32* %1
%49 = call i32 @sendto(i32 %12, i8* %8, i32 %44, i32 0, %struct.sockaddr* %47, i32 %48)
%50 = add nuw nsw i64 %43, 1
%51 = icmp eq i64 %50, %39
br i1 %51, label %52, label %42
52: ; preds = %42, %36, %40
%53 = phi i32 [ %41, %40 ], [ %22, %36 ], [ %22, %42 ]
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.3, i64 0, i64 0))
br label %21
}