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

/* Variables and functions */
void *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 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 *);
size_t read(int /*<<< orphan*/, char *, int);
size_t recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
                          struct sockaddr *, int /*<<< orphan*/);
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(4243);
  address_sock.sin_addr.s_addr = htonl(INADDR_ANY);
  int r =
      bind(sock, (struct sockaddr *)&address_sock, sizeof(struct sockaddr_in));
  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("0.0.0.0", "4242", NULL, &first_info);
  if (r == 0) {
    if (first_info != NULL) {
      struct sockaddr *saddr = first_info->ai_addr;
      char tampon[100];
      tampon[read(0, tampon, 99)] = 0;
      sendto(sock, tampon, strlen(tampon), 0, saddr,
             (socklen_t)sizeof(struct sockaddr_in));
      tampon[recv(sock, tampon, 99, 0)] = 0;
      printf("%s\n", tampon);
    }
  }
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2def(%rip),%rax
mov    (%rax),%edi
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    0x2df3(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
mov    $0x1093,%edi
call   1050 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   10c0 <bind@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1080 <memset@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2d85(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
lea    0xda1(%rip),%rdi
lea    0xda2(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x28(%rbp),%rcx
call   10d0 <getaddrinfo@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    132a <main+0x16a>
cmpq   $0x0,-0x28(%rbp)
je     1325 <main+0x165>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
lea    -0xb0(%rbp),%rsi
xor    %edi,%edi
mov    $0x63,%edx
call   10b0 <read@plt>
movb   $0x0,-0xb0(%rbp,%rax,1)
mov    -0x8(%rbp),%eax
mov    %eax,-0xbc(%rbp)
lea    -0xb0(%rbp),%rax
mov    %rax,-0xb8(%rbp)
lea    -0xb0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xbc(%rbp),%edi
mov    -0xb8(%rbp),%rsi
mov    %eax,%edx
mov    -0x48(%rbp),%r8
xor    %ecx,%ecx
mov    $0x10,%r9d
call   1090 <sendto@plt>
mov    -0x8(%rbp),%edi
lea    -0xb0(%rbp),%rsi
mov    $0x63,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
movb   $0x0,-0xb0(%rbp,%rax,1)
lea    -0xb0(%rbp),%rsi
lea    0xced(%rip),%rdi
call   1060 <printf@plt>
jmp    132a <main+0x16a>
mov    -0x8(%rbp),%edi
call   10a0 <close@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xa0,%rsp
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
mov    0x2dfc(%rip),%r14
mov    (%r14),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%ebx
mov    0x2df9(%rip),%r15
mov    (%r15),%rax
mov    %rax,0x10(%rsp)
mov    $0x1093,%edi
call   1050 <htons@plt>
mov    %eax,0xc(%rsp)
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x10,%edx
call   10c0 <bind@plt>
lea    0x18(%rsp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1080 <memset@plt>
mov    (%r15),%rax
mov    %rax,0x28(%rsp)
mov    (%r14),%eax
mov    %eax,0x20(%rsp)
lea    0xdb1(%rip),%rdi
lea    0xdb2(%rip),%rsi
mov    %rsp,%rcx
xor    %edx,%edx
call   10d0 <getaddrinfo@plt>
test   %eax,%eax
jne    12cd <main+0x10d>
mov    (%rsp),%rax
test   %rax,%rax
je     12cd <main+0x10d>
mov    (%rax),%r15
lea    0x30(%rsp),%r14
xor    %edi,%edi
mov    %r14,%rsi
mov    $0x63,%edx
call   10b0 <read@plt>
movb   $0x0,0x30(%rsp,%rax,1)
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    $0x10,%r9d
call   1090 <sendto@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x63,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
movb   $0x0,0x30(%rsp,%rax,1)
lea    0xd48(%rip),%rdi
mov    %r14,%rsi
call   1060 <printf@plt>
mov    %ebx,%edi
call   10a0 <close@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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
@.str = [8 x i8] c"0.0.0.0\00"
@.str.1 = [5 x i8] c"4242\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca %struct.addrinfo*
%6 = alloca %struct.addrinfo
%7 = alloca %struct.sockaddr*
%8 = alloca [100 x i8]
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 i8*, i8** @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i8* %12, i8** %13
%14 = call i32 @htons(i32 4243)
%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 16)
store i32 %22, i32* %4
%23 = call i32 @memset(%struct.addrinfo* %6, i32 0, i32 24)
%24 = load i8*, i8** @AF_INET
%25 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 2
store i8* %24, i8** %25
%26 = load i32, i32* @SOCK_DGRAM
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 1
store i32 %26, i32* %27
%28 = call i32 @getaddrinfo(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* null, %struct.addrinfo** %5)
store i32 %28, i32* %4
%29 = load i32, i32* %4
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %54
31: ; preds = %0
%32 = load %struct.addrinfo*, %struct.addrinfo** %5
%33 = icmp ne %struct.addrinfo* %32, null
br i1 %33, label %34, label %53
34: ; preds = %31
%35 = load %struct.addrinfo*, %struct.addrinfo** %5
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i32 0, i32 0
%37 = load %struct.sockaddr*, %struct.sockaddr** %36
store %struct.sockaddr* %37, %struct.sockaddr** %7
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%39 = call i64 @read(i32 0, i8* %38, i32 99)
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %39
store i8 0, i8* %40
%41 = load i32, i32* %2
%42 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%43 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%44 = call i32 @strlen(i8* %43)
%45 = load %struct.sockaddr*, %struct.sockaddr** %7
%46 = call i32 @sendto(i32 %41, i8* %42, i32 %44, i32 0, %struct.sockaddr* %45, i32 16)
%47 = load i32, i32* %2
%48 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%49 = call i64 @recv(i32 %47, i8* %48, i32 99, i32 0)
%50 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %49
store i8 0, i8* %50
%51 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%52 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %51)
br label %53
53: ; preds = %34, %31
br label %54
54: ; preds = %53, %0
%55 = load i32, i32* %2
%56 = call i32 @close(i32 %55)
ret i32 0
}

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
@.str = [8 x i8] c"0.0.0.0\00"
@.str.1 = [5 x i8] c"4242\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.addrinfo*
%3 = alloca %struct.addrinfo
%4 = alloca [100 x i8]
%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 i8*, i8** @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i8* %9, i8** %10
%11 = tail call i32 @htons(i32 4243)
%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 16)
%18 = bitcast %struct.addrinfo** %2 to i8*
%19 = bitcast %struct.addrinfo* %3 to i8*
%20 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 24)
%21 = load i8*, i8** @AF_INET
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 2
store i8* %21, i8** %22
%23 = load i32, i32* @SOCK_DGRAM
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 1
store i32 %23, i32* %24
%25 = call i32 @getaddrinfo(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* null, %struct.addrinfo** %2)
%26 = icmp eq i32 %25, 0
%27 = load %struct.addrinfo*, %struct.addrinfo** %2
%28 = icmp ne %struct.addrinfo* %27, null
%29 = select i1 %26, i1 %28, i1 false
br i1 %29, label %30, label %41
30: ; preds = %0
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %27, i64 0, i32 0
%32 = load %struct.sockaddr*, %struct.sockaddr** %31
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%34 = call i64 @read(i32 0, i8* %33, i32 99)
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %34
store i8 0, i8* %35
%36 = call i32 @strlen(i8* %33)
%37 = call i32 @sendto(i32 %7, i8* %33, i32 %36, i32 0, %struct.sockaddr* %32, i32 16)
%38 = call i64 @recv(i32 %7, i8* %33, i32 99, i32 0)
%39 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %38
store i8 0, i8* %39
%40 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %33)
br label %41
41: ; preds = %30, %0
%42 = call i32 @close(i32 %7)
ret i32 0
}