#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_DGRAM;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ printf(char *, char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
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(4242);
  address_sock.sin_addr.s_addr = htonl(INADDR_ANY);
  int r =
      bind(sock, (struct sockaddr *)&address_sock, sizeof(struct sockaddr_in));
  if (r == 0) {
    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);
    }
  }
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e43(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x1092,%edi
call   1030 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    123d <main+0xcd>
jmp    11eb <main+0x7b>
movl   $0xc,-0x94(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x80(%rbp),%rsi
lea    -0x90(%rbp),%r8
mov    $0x63,%edx
xor    %ecx,%ecx
lea    -0x94(%rbp),%r9
call   1070 <recvfrom@plt>
mov    %eax,-0x98(%rbp)
movslq -0x98(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
lea    -0x80(%rbp),%rsi
lea    0xdcd(%rip),%rdi
call   1040 <printf@plt>
jmp    11eb <main+0x7b>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xa0,%rsp
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,%ebp
mov    0x2e47(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    $0x1092,%edi
call   1030 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   1080 <bind@plt>
test   %eax,%eax
je     11f5 <main+0x85>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x30(%rsp),%rbx
lea    0x20(%rsp),%r14
lea    0xc(%rsp),%r15
lea    0xdf5(%rip),%r12
nopl   0x0(%rax,%rax,1)
movl   $0xc,0xc(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x63,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    %r15,%r9
call   1070 <recvfrom@plt>
cltq
movb   $0x0,0x30(%rsp,%rax,1)
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
jmp    1210 <main+0xa0>

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_DGRAM = global i32 0
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str = [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 [100 x i8]
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = load i32, i32* @PF_INET
%10 = load i32, i32* @SOCK_DGRAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %2
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %12, i32* %13
%14 = call i32 @htons(i32 4242)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %14, i32* %15
%16 = load i32, i32* @INADDR_ANY
%17 = call i32 @htonl(i32 %16)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, 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* %2
%21 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%22 = call i32 @bind(i32 %20, %struct.sockaddr* %21, i32 12)
store i32 %22, i32* %4
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %36
25: ; preds = %0
br label %26
26: ; preds = %25, %26
store i32 12, i32* %7
%27 = load i32, i32* %2
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%29 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%30 = call i32 @recvfrom(i32 %27, i8* %28, i32 99, i32 0, %struct.sockaddr* %29, i32* %7)
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %32
store i8 0, i8* %33
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%35 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %34)
br label %26
36: ; preds = %0
%37 = load i32, i32* %2
%38 = call i32 @close(i32 %37)
ret i32 0
}

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_DGRAM = global i32 0
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str = [19 x i8] c"Message recu : %s\0A\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [100 x i8]
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = load i32, i32* @PF_INET
%6 = load i32, i32* @SOCK_DGRAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = bitcast %struct.sockaddr_in* %1 to i8*
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %9, i32* %10
%11 = tail call i32 @htons(i32 4242)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %11, i32* %12
%13 = load i32, i32* @INADDR_ANY
%14 = tail call i32 @htonl(i32 %13)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %14, i32* %15
%16 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%17 = call i32 @bind(i32 %7, %struct.sockaddr* %16, i32 12)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %29
19: ; preds = %0
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%21 = bitcast %struct.sockaddr_in* %3 to i8*
%22 = bitcast i32* %4 to i8*
%23 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %24
24: ; preds = %24, %19
store i32 12, i32* %4
%25 = call i32 @recvfrom(i32 %7, i8* %20, i32 99, i32 0, %struct.sockaddr* %23, i32* %4)
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %26
store i8 0, i8* %27
%28 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %20)
br label %24
29: ; preds = %0
%30 = call i32 @close(i32 %7)
ret i32 0
}