#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 recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int /*<<< orphan*/ sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
                          struct sockaddr *, 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(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];
    int sock2 = socket(PF_INET, SOCK_DGRAM, 0);
    while (1) {
      struct sockaddr caller;
      socklen_t size = sizeof(caller);
      int rec = recvfrom(sock, tampon, 99, 0, &caller, &size);
      tampon[rec] = '\0';
      sendto(sock2, tampon, strlen(tampon), 0, &caller,
             (socklen_t)sizeof(struct sockaddr_in));
    }
  }
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x1092,%edi
call   1040 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e12(%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   1090 <bind@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    129a <main+0x11a>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
mov    0x2dd2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x84(%rbp)
movl   $0x4,-0x8c(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x63,%edx
xor    %ecx,%ecx
lea    -0x88(%rbp),%r8
lea    -0x8c(%rbp),%r9
call   1080 <recvfrom@plt>
mov    %eax,-0x90(%rbp)
movslq -0x90(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
mov    -0x84(%rbp),%eax
mov    %eax,-0x9c(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    -0x80(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x9c(%rbp),%edi
mov    -0x98(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
lea    -0x88(%rbp),%r8
mov    $0xc,%r9d
call   1060 <sendto@plt>
jmp    1215 <main+0x95>
mov    -0x8(%rbp),%edi
call   1070 <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    $0x90,%rsp
mov    0x2e32(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e39(%rip),%rbp
mov    0x0(%rbp),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,%r14d
mov    0x2e35(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    $0x1092,%edi
call   1040 <htons@plt>
mov    %eax,0xc(%rsp)
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   1090 <bind@plt>
test   %eax,%eax
je     1209 <main+0x89>
mov    %r14d,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%edi
mov    0x0(%rbp),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,%r15d
lea    0x20(%rsp),%rbx
lea    0x18(%rsp),%rbp
lea    0x4(%rsp),%r12
nopw   0x0(%rax,%rax,1)
movl   $0x4,0x4(%rsp)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x63,%edx
xor    %ecx,%ecx
mov    %rbp,%r8
mov    %r12,%r9
call   1080 <recvfrom@plt>
cltq
movb   $0x0,0x20(%rsp,%rax,1)
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %rbp,%r8
mov    $0xc,%r9d
call   1060 <sendto@plt>
jmp    1230 <main+0xb0>

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