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

/* 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*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ printf(char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int /*<<< orphan*/ sendto(int, char *, int, int /*<<< orphan*/,
                          struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(void) {
  int sock;
  struct sockaddr_in stSockAddr, source;
  int size = 100;
  int addr_len = sizeof(struct sockaddr_in);
  char data[2000];
  bzero(&stSockAddr, sizeof(stSockAddr));
  stSockAddr.sin_family = AF_INET;
  stSockAddr.sin_port = htons(6001);
  stSockAddr.sin_addr.s_addr = htonl(INADDR_ANY);
  sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  bind(sock, (struct sockaddr *)&stSockAddr, addr_len);
  printf("Wating for message\n\r");
  while (1) {
    size = recvfrom(sock, data, 2000, 0, (struct sockaddr *)&source, &addr_len);
    sendto(sock, data, size, 0, (struct sockaddr *)&source, addr_len);
  }
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x800,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x64,-0x2c(%rbp)
movl   $0xc,-0x30(%rbp)
lea    -0x18(%rbp),%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x1771,%edi
call   1030 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    0x2df0(%rip),%rax
mov    (%rax),%esi
mov    0x2dcf(%rip),%rax
mov    (%rax),%edx
call   10a0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%edx
call   1080 <bind@plt>
lea    0xdef(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x800(%rbp),%rsi
lea    -0x28(%rbp),%r8
mov    $0x7d0,%edx
xor    %ecx,%ecx
lea    -0x30(%rbp),%r9
call   1070 <recvfrom@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x800(%rbp),%rsi
mov    -0x2c(%rbp),%edx
lea    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9d
xor    %ecx,%ecx
call   1060 <sendto@plt>
jmp    1216 <main+0x96>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x808,%rsp
movl   $0xc,0xc(%rsp)
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    0x2e39(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    $0x1771,%edi
call   1030 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x10(%rsp)
mov    (%rbx),%edi
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
mov    0x2dd9(%rip),%rax
mov    (%rax),%edx
call   10a0 <socket@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
lea    0xdfa(%rip),%rdi
call   1040 <printf@plt>
lea    0x30(%rsp),%r14
lea    0x20(%rsp),%r15
lea    0xc(%rsp),%r12
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x7d0,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r12,%r9
call   1070 <recvfrom@plt>
mov    0xc(%rsp),%r9d
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r15,%r8
call   1060 <sendto@plt>
jmp    1220 <main+0xa0>

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
@INADDR_ANY = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str = [21 x i8] c"Wating for message\0A\0D\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca i32
%7 = alloca [2000 x i8]
store i32 0, i32* %1
store i32 100, i32* %5
store i32 12, i32* %6
%8 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %9, i32* %10
%11 = call i32 @htons(i32 6001)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %11, i32* %12
%13 = load i32, i32* @INADDR_ANY
%14 = call i32 @htonl(i32 %13)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%16 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %15, i32 0, i32 0
store i32 %14, i32* %16
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @SOCK_DGRAM
%19 = load i32, i32* @IPPROTO_UDP
%20 = call i32 @socket(i32 %17, i32 %18, i32 %19)
store i32 %20, i32* %2
%21 = load i32, i32* %2
%22 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%23 = load i32, i32* %6
%24 = call i32 @bind(i32 %21, %struct.sockaddr* %22, i32 %23)
%25 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %0, %26
%27 = load i32, i32* %2
%28 = getelementptr inbounds [2000 x i8], [2000 x i8]* %7, i64 0, i64 0
%29 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%30 = call i32 @recvfrom(i32 %27, i8* %28, i32 2000, i32 0, %struct.sockaddr* %29, i32* %6)
store i32 %30, i32* %5
%31 = load i32, i32* %2
%32 = getelementptr inbounds [2000 x i8], [2000 x i8]* %7, i64 0, i64 0
%33 = load i32, i32* %5
%34 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%35 = load i32, i32* %6
%36 = call i32 @sendto(i32 %31, i8* %32, i32 %33, i32 0, %struct.sockaddr* %34, i32 %35)
br label %26
}

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
@INADDR_ANY = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str = [21 x i8] c"Wating for message\0A\0D\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca [2000 x i8]
%5 = bitcast %struct.sockaddr_in* %1 to i8*
%6 = bitcast %struct.sockaddr_in* %2 to i8*
%7 = bitcast i32* %3 to i8*
store i32 12, i32* %3
%8 = getelementptr inbounds [2000 x i8], [2000 x i8]* %4, i64 0, i64 0
%9 = call i32 @bzero(%struct.sockaddr_in* %1, i32 12)
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %10, i32* %11
%12 = tail call i32 @htons(i32 6001)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %12, i32* %13
%14 = load i32, i32* @INADDR_ANY
%15 = tail call i32 @htonl(i32 %14)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %15, i32* %16
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @SOCK_DGRAM
%19 = load i32, i32* @IPPROTO_UDP
%20 = tail call i32 @socket(i32 %17, i32 %18, i32 %19)
%21 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%22 = call i32 @bind(i32 %20, %struct.sockaddr* %21, i32 12)
%23 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%24 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
br label %25
25: ; preds = %25, %0
%26 = call i32 @recvfrom(i32 %20, i8* %8, i32 2000, i32 0, %struct.sockaddr* %24, i32* %3)
%27 = load i32, i32* %3
%28 = call i32 @sendto(i32 %20, i8* %8, i32 %26, i32 0, %struct.sockaddr* %24, i32 %27)
br label %25
}