#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;
  void *sin_family;
};
struct sockaddr {
  int dummy;
};
struct addrinfo {
  struct sockaddr *ai_addr;
  int /*<<< orphan*/ ai_socktype;
  void *ai_family;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ ok;
typedef int /*<<< orphan*/ caller;

/* Variables and functions */
void *AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_BROADCAST;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int getaddrinfo(char *, char *, int /*<<< orphan*/ *, struct addrinfo **);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int /*<<< orphan*/ sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
                          struct sockaddr *, int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int main() {
  int sock = socket(PF_INET, SOCK_DGRAM, 0);
  struct sockaddr_in address_sock;
  address_sock.sin_family = AF_INET;
  address_sock.sin_port = htons(12321);
  address_sock.sin_addr.s_addr = htonl(INADDR_ANY);
  int sock_b = socket(PF_INET, SOCK_DGRAM, 0);
  int ok = 1;
  int r = setsockopt(sock_b, SOL_SOCKET, SO_BROADCAST, &ok, sizeof(ok));
  if (r != 0) {
    exit(1);
  }
  struct addrinfo *first_info;
  struct addrinfo hints;
  memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = AF_INET;
  hints.ai_socktype = SOCK_DGRAM;
  r = getaddrinfo("255.255.255.255", "10101", NULL, &first_info);
  r = bind(sock, (struct sockaddr *)&address_sock, sizeof(struct sockaddr_in));
  if (r != 0 || first_info == NULL)
    exit(1);
  struct sockaddr *saddr = first_info->ai_addr;
  char tampon[100];
  while (1) {
    struct sockaddr_in caller;
    socklen_t size = sizeof(caller);
    int rec = recvfrom(sock, tampon, 99, 0, (struct sockaddr *)&caller, &size);
    tampon[rec] = '\0';
    printf("Message recu : %s\n", tampon);
    sendto(sock_b, tampon, strlen(tampon), 0, saddr,
           (socklen_t)sizeof(struct sockaddr_in));
  }
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    0x2deb(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
mov    $0x3021,%edi
call   1050 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
mov    0x2da6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2da1(%rip),%rax
mov    (%rax),%esi
mov    0x2d78(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1278 <main+0xb8>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1080 <memset@plt>
mov    0x2d51(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2d33(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
lea    0xd57(%rip),%rdi
lea    0xd60(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x30(%rbp),%rcx
call   10d0 <getaddrinfo@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   10b0 <bind@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    12e9 <main+0x129>
cmpq   $0x0,-0x30(%rbp)
jne    12f3 <main+0x133>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
movl   $0x10,-0xd4(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xc0(%rbp),%rsi
lea    -0xd0(%rbp),%r8
mov    $0x63,%edx
xor    %ecx,%ecx
lea    -0xd4(%rbp),%r9
call   10a0 <recvfrom@plt>
mov    %eax,-0xd8(%rbp)
movslq -0xd8(%rbp),%rax
movb   $0x0,-0xc0(%rbp,%rax,1)
lea    -0xc0(%rbp),%rsi
lea    0xcc7(%rip),%rdi
call   1060 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0xe4(%rbp)
lea    -0xc0(%rbp),%rax
mov    %rax,-0xe0(%rbp)
lea    -0xc0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xe4(%rbp),%edi
mov    -0xe0(%rbp),%rsi
mov    %eax,%edx
mov    -0x50(%rbp),%r8
xor    %ecx,%ecx
mov    $0x10,%r9d
call   1090 <sendto@plt>
jmp    12fe <main+0x13e>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
mov    0x2de0(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2dee(%rip),%r15
mov    (%r15),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%ebx
mov    0x2deb(%rip),%r14
mov    (%r14),%rax
mov    %rax,0x20(%rsp)
mov    $0x3021,%edi
call   1050 <htons@plt>
mov    %eax,0x1c(%rsp)
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,0x18(%rsp)
mov    0x0(%rbp),%edi
mov    (%r15),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%r12d
movl   $0x1,0xc(%rsp)
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
mov    0x2d83(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %r12d,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %eax,%eax
jne    1336 <main+0x176>
lea    0x28(%rsp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1080 <memset@plt>
mov    (%r14),%rax
mov    %rax,0x38(%rsp)
mov    (%r15),%eax
mov    %eax,0x30(%rsp)
lea    0xd77(%rip),%rdi
lea    0xd80(%rip),%rsi
lea    0x10(%rsp),%rcx
xor    %edx,%edx
call   10d0 <getaddrinfo@plt>
lea    0x18(%rsp),%rsi
mov    %ebx,%r15d
mov    %ebx,%edi
mov    $0x10,%edx
call   10b0 <bind@plt>
test   %eax,%eax
jne    1336 <main+0x176>
mov    0x10(%rsp),%rax
test   %rax,%rax
je     1336 <main+0x176>
mov    (%rax),%rbx
lea    0x50(%rsp),%rbp
lea    0x8(%rsp),%r13
lea    0xd40(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
movl   $0x10,0x8(%rsp)
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x63,%edx
xor    %ecx,%ecx
lea    0x40(%rsp),%r8
mov    %r13,%r9
call   10a0 <recvfrom@plt>
cltq
movb   $0x0,0x50(%rsp,%rax,1)
mov    %r14,%rdi
mov    %rbp,%rsi
call   1060 <printf@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
mov    $0x10,%r9d
call   1090 <sendto@plt>
jmp    12e0 <main+0x120>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.addrinfo = type { %struct.sockaddr*, i32, i8* }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@AF_INET = global i8* null
@INADDR_ANY = global i32 0
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str = [16 x i8] c"255.255.255.255\00"
@.str.1 = [6 x i8] c"10101\00"
@.str.2 = [19 x i8] c"Message recu : %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.addrinfo*
%8 = alloca %struct.addrinfo
%9 = alloca %struct.sockaddr*
%10 = alloca [100 x i8]
%11 = alloca %struct.sockaddr_in
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %1
%14 = load i32, i32* @PF_INET
%15 = load i32, i32* @SOCK_DGRAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
store i32 %16, i32* %2
%17 = load i8*, i8** @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i8* %17, i8** %18
%19 = call i32 @htons(i32 12321)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %19, i32* %20
%21 = load i32, i32* @INADDR_ANY
%22 = call i32 @htonl(i32 %21)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%24 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %23, i32 0, i32 0
store i32 %22, i32* %24
%25 = load i32, i32* @PF_INET
%26 = load i32, i32* @SOCK_DGRAM
%27 = call i32 @socket(i32 %25, i32 %26, i32 0)
store i32 %27, i32* %4
store i32 1, i32* %5
%28 = load i32, i32* %4
%29 = load i32, i32* @SOL_SOCKET
%30 = load i32, i32* @SO_BROADCAST
%31 = call i32 @setsockopt(i32 %28, i32 %29, i32 %30, i32* %5, i32 4)
store i32 %31, i32* %6
%32 = load i32, i32* %6
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %0
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %0
%37 = call i32 @memset(%struct.addrinfo* %8, i32 0, i32 24)
%38 = load i8*, i8** @AF_INET
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 2
store i8* %38, i8** %39
%40 = load i32, i32* @SOCK_DGRAM
%41 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 1
store i32 %40, i32* %41
%42 = call i32 @getaddrinfo(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* null, %struct.addrinfo** %7)
store i32 %42, i32* %6
%43 = load i32, i32* %2
%44 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%45 = call i32 @bind(i32 %43, %struct.sockaddr* %44, i32 16)
store i32 %45, i32* %6
%46 = load i32, i32* %6
%47 = icmp ne i32 %46, 0
br i1 %47, label %51, label %48
48: ; preds = %36
%49 = load %struct.addrinfo*, %struct.addrinfo** %7
%50 = icmp eq %struct.addrinfo* %49, null
br i1 %50, label %51, label %53
51: ; preds = %48, %36
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %48
%54 = load %struct.addrinfo*, %struct.addrinfo** %7
%55 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %54, i32 0, i32 0
%56 = load %struct.sockaddr*, %struct.sockaddr** %55
store %struct.sockaddr* %56, %struct.sockaddr** %9
br label %57
57: ; preds = %53, %57
store i32 16, i32* %12
%58 = load i32, i32* %2
%59 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%60 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%61 = call i32 @recvfrom(i32 %58, i8* %59, i32 99, i32 0, %struct.sockaddr* %60, i32* %12)
store i32 %61, i32* %13
%62 = load i32, i32* %13
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 %63
store i8 0, i8* %64
%65 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%66 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %65)
%67 = load i32, i32* %4
%68 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%69 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%70 = call i32 @strlen(i8* %69)
%71 = load %struct.sockaddr*, %struct.sockaddr** %9
%72 = call i32 @sendto(i32 %67, i8* %68, i32 %70, i32 0, %struct.sockaddr* %71, i32 16)
br label %57
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.addrinfo = type { %struct.sockaddr*, i32, i8* }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@AF_INET = global i8* null
@INADDR_ANY = global i32 0
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str = [16 x i8] c"255.255.255.255\00"
@.str.1 = [6 x i8] c"10101\00"
@.str.2 = [19 x i8] c"Message recu : %s\0A\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i32
%3 = alloca %struct.addrinfo*
%4 = alloca %struct.addrinfo
%5 = alloca [100 x i8]
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = load i32, i32* @PF_INET
%9 = load i32, i32* @SOCK_DGRAM
%10 = tail call i32 @socket(i32 %8, i32 %9, i32 0)
%11 = bitcast %struct.sockaddr_in* %1 to i8*
%12 = load i8*, i8** @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i8* %12, i8** %13
%14 = tail call i32 @htons(i32 12321)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %14, i32* %15
%16 = load i32, i32* @INADDR_ANY
%17 = tail call i32 @htonl(i32 %16)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %17, i32* %18
%19 = load i32, i32* @PF_INET
%20 = load i32, i32* @SOCK_DGRAM
%21 = tail call i32 @socket(i32 %19, i32 %20, i32 0)
%22 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%23 = load i32, i32* @SOL_SOCKET
%24 = load i32, i32* @SO_BROADCAST
%25 = call i32 @setsockopt(i32 %21, i32 %23, i32 %24, i32* %2, i32 4)
%26 = icmp eq i32 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %0
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %0
%30 = bitcast %struct.addrinfo** %3 to i8*
%31 = bitcast %struct.addrinfo* %4 to i8*
%32 = call i32 @memset(%struct.addrinfo* %4, i32 0, i32 24)
%33 = load i8*, i8** @AF_INET
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 2
store i8* %33, i8** %34
%35 = load i32, i32* @SOCK_DGRAM
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 1
store i32 %35, i32* %36
%37 = call i32 @getaddrinfo(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* null, %struct.addrinfo** %3)
%38 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%39 = call i32 @bind(i32 %10, %struct.sockaddr* %38, i32 16)
%40 = icmp ne i32 %39, 0
%41 = load %struct.addrinfo*, %struct.addrinfo** %3
%42 = icmp eq %struct.addrinfo* %41, null
%43 = select i1 %40, i1 true, i1 %42
br i1 %43, label %44, label %46
44: ; preds = %29
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %29
%47 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %41, i64 0, i32 0
%48 = load %struct.sockaddr*, %struct.sockaddr** %47
%49 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%50 = bitcast %struct.sockaddr_in* %6 to i8*
%51 = bitcast i32* %7 to i8*
%52 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
br label %53
53: ; preds = %53, %46
store i32 16, i32* %7
%54 = call i32 @recvfrom(i32 %10, i8* %49, i32 99, i32 0, %struct.sockaddr* %52, i32* %7)
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %55
store i8 0, i8* %56
%57 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %49)
%58 = call i32 @strlen(i8* %49)
%59 = call i32 @sendto(i32 %21, i8* %49, i32 %58, i32 0, %struct.sockaddr* %48, i32 16)
br label %53
}