#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 {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ servaddr;
typedef int /*<<< orphan*/ cliaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_ntoa(TYPE_1__);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int ntohs(int /*<<< orphan*/);
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 /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int sockfd, n;
  struct sockaddr_in servaddr, cliaddr;
  socklen_t len;
  char mesg[1000000];
  char buf[100];
  sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  memset(&servaddr, 0, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  servaddr.sin_port = htons(32000);
  bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
  for (;;) {
    len = sizeof(cliaddr);
    n = recvfrom(sockfd, mesg, 1000000, 0, (struct sockaddr *)&cliaddr, &len);
    strcpy(buf, inet_ntoa(cliaddr.sin_addr));
    sendto(sockfd, mesg, n, 0, (struct sockaddr *)&cliaddr, sizeof(cliaddr));
    printf("-------------------------------------------------------\n");
    mesg[n] = 0;
    printf("Received the following %d bytes from %s:%d:\n", n, buf,
           ntohs(cliaddr.sin_port));
    printf("%s", mesg);
    printf("-------------------------------------------------------\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf4310,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,-0x24(%rbp)
mov    $0x7d00,%edi
call   1050 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
movl   $0xc,-0x3c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0xf4280(%rbp),%rsi
lea    -0x38(%rbp),%r8
mov    $0xf4240,%edx
xor    %ecx,%ecx
lea    -0x3c(%rbp),%r9
call   10a0 <recvfrom@plt>
mov    %eax,-0x18(%rbp)
lea    -0xf42f0(%rbp),%rax
mov    %rax,-0xf4308(%rbp)
mov    -0x34(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    -0xf4308(%rbp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    -0x14(%rbp),%edi
lea    -0xf4280(%rbp),%rsi
mov    -0x18(%rbp),%edx
lea    -0x38(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1090 <sendto@plt>
lea    0xd5f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movslq -0x18(%rbp),%rax
movb   $0x0,-0xf4280(%rbp,%rax,1)
mov    -0x18(%rbp),%eax
mov    %eax,-0xf42fc(%rbp)
lea    -0xf42f0(%rbp),%rax
mov    %rax,-0xf42f8(%rbp)
mov    -0x38(%rbp),%edi
call   10b0 <ntohs@plt>
mov    -0xf42fc(%rbp),%esi
mov    -0xf42f8(%rbp),%rdx
mov    %eax,%ecx
lea    0xd50(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0xf4280(%rbp),%rsi
lea    0xd68(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xcf4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1230 <main+0x80>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xf42e8,%rsp
mov    0x2e10(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%r14d
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1090 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    $0x7d00,%edi
call   1060 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
lea    0xa0(%rsp),%rbx
lea    0x30(%rsp),%r12
lea    0xde3(%rip),%r13
nopl   (%rax)
movl   $0xc,0xc(%rsp)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0xf4240,%edx
xor    %ecx,%ecx
lea    0x20(%rsp),%rbp
mov    %rbp,%r8
lea    0xc(%rsp),%r9
call   10b0 <recvfrom@plt>
mov    %eax,%r15d
mov    0x24(%rsp),%edi
call   1050 <inet_ntoa@plt>
mov    %r12,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %r15d,%edx
xor    %ecx,%ecx
mov    %rbp,%r8
mov    $0xc,%r9d
call   10a0 <sendto@plt>
mov    %r13,%rdi
call   1040 <puts@plt>
movslq %r15d,%rbp
movb   $0x0,0xa0(%rsp,%rbp,1)
mov    0x20(%rsp),%edi
call   10c0 <ntohs@plt>
lea    0xd37(%rip),%rdi
mov    %ebp,%esi
mov    %r12,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd4f(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r13,%rdi
call   1040 <puts@plt>
jmp    1250 <main+0x90>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@INADDR_ANY = global i32 0
@.str = [57 x i8] c"-------------------------------------------------------\0A\00"
@.str.1 = [45 x i8] c"Received the following %d bytes from %s:%d:\0A\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = alloca [1000000 x i8]
%12 = alloca [100 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_DGRAM
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %6
%16 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 12)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %17, i32* %18
%19 = load i32, i32* @INADDR_ANY
%20 = call i32 @htonl(i32 %19)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
store i32 %20, i32* %22
%23 = call i32 @htons(i32 32000)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %23, i32* %24
%25 = load i32, i32* %6
%26 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%27 = call i32 @bind(i32 %25, %struct.sockaddr* %26, i32 12)
br label %28
28: ; preds = %28, %2
store i32 12, i32* %10
%29 = load i32, i32* %6
%30 = getelementptr inbounds [1000000 x i8], [1000000 x i8]* %11, i64 0, i64 0
%31 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%32 = call i32 @recvfrom(i32 %29, i8* %30, i32 1000000, i32 0, %struct.sockaddr* %31, i32* %10)
store i32 %32, i32* %7
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%35 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = call i32 @inet_ntoa(i32 %36)
%38 = call i32 @strcpy(i8* %33, i32 %37)
%39 = load i32, i32* %6
%40 = getelementptr inbounds [1000000 x i8], [1000000 x i8]* %11, i64 0, i64 0
%41 = load i32, i32* %7
%42 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%43 = call i32 @sendto(i32 %39, i8* %40, i32 %41, i32 0, %struct.sockaddr* %42, i32 12)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
%45 = load i32, i32* %7
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [1000000 x i8], [1000000 x i8]* %11, i64 0, i64 %46
store i8 0, i8* %47
%48 = load i32, i32* %7
%49 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%51 = load i32, i32* %50
%52 = call i32 @ntohs(i32 %51)
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 %48, i8* %49, i32 %52)
%54 = getelementptr inbounds [1000000 x i8], [1000000 x i8]* %11, i64 0, i64 0
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %54)
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
br label %28
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [45 x i8] c"Received the following %d bytes from %s:%d:\0A\00"
@.str.2 = [3 x i8] c"%s\00"
@str.3 = [56 x i8] c"-------------------------------------------------------\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [1000000 x i8]
%7 = alloca [100 x i8]
%8 = bitcast %struct.sockaddr_in* %3 to i8*
%9 = bitcast %struct.sockaddr_in* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = getelementptr inbounds [1000000 x i8], [1000000 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_DGRAM
%15 = tail call i32 @socket(i32 %13, i32 %14, i32 0)
%16 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %17, i32* %18
%19 = load i32, i32* @INADDR_ANY
%20 = call i32 @htonl(i32 %19)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %20, i32* %21
%22 = call i32 @htons(i32 32000)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %22, i32* %23
%24 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%25 = call i32 @bind(i32 %15, %struct.sockaddr* %24, i32 12)
%26 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
br label %29
29: ; preds = %29, %2
store i32 12, i32* %5
%30 = call i32 @recvfrom(i32 %15, i8* %11, i32 1000000, i32 0, %struct.sockaddr* %26, i32* %5)
%31 = load i32, i32* %27
%32 = call i32 @inet_ntoa(i32 %31)
%33 = call i32 @strcpy(i8* %12, i32 %32)
%34 = call i32 @sendto(i32 %15, i8* %11, i32 %30, i32 0, %struct.sockaddr* %26, i32 12)
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str.3, i64 0, i64 0))
%36 = sext i32 %30 to i64
%37 = getelementptr inbounds [1000000 x i8], [1000000 x i8]* %6, i64 0, i64 %36
store i8 0, i8* %37
%38 = load i32, i32* %28
%39 = call i32 @ntohs(i32 %38)
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 %30, i8* %12, i32 %39)
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str.3, i64 0, i64 0))
br label %29
}