#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*/ bzero(struct sockaddr_in *, 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(int argc, char **argv) {
  int sockfd, n;
  struct sockaddr_in servaddr, cliaddr;
  socklen_t len;
  char mesg[1000];
  sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  servaddr.sin_port = htons(1912);
  bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
  for (;;) {
    len = sizeof(cliaddr);
    n = recvfrom(sockfd, mesg, 1000, 0, (struct sockaddr *)&cliaddr, &len);
    sendto(sockfd, mesg, n, 0, (struct sockaddr *)&cliaddr, sizeof(cliaddr));
    printf("-------------------------------------------------------\n");
    mesg[n] = 0;
    printf("Received the following:\n");
    for (int i = 0; i < 8; ++i) {
      printf("%02X", mesg[i]);
    }
    printf("\n");
    printf("-------------------------------------------------------\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x14(%rbp)
lea    -0x28(%rbp),%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x24(%rbp)
mov    $0x778,%edi
call   1030 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   1080 <bind@plt>
movl   $0xc,-0x3c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
lea    -0x38(%rbp),%r8
mov    $0x3e8,%edx
xor    %ecx,%ecx
lea    -0x3c(%rbp),%r9
call   1070 <recvfrom@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    -0x18(%rbp),%edx
lea    -0x38(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1060 <sendto@plt>
lea    0xdb5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movslq -0x18(%rbp),%rax
movb   $0x0,-0x430(%rbp,%rax,1)
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x434(%rbp)
cmpl   $0x8,-0x434(%rbp)
jge    12b4 <main+0x134>
movslq -0x434(%rbp),%rax
movsbl -0x430(%rbp,%rax,1),%esi
ff
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x434(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x434(%rbp)
jmp    1276 <main+0xf6>
lea    0xd7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd37(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11fe <main+0x7e>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    0x2e30(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,%ebx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   10b0 <bzero@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    $0x778,%edi
call   1050 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
lea    0x30(%rsp),%r14
lea    0x20(%rsp),%r15
lea    0xdf7(%rip),%r13
lea    0xdd3(%rip),%r12
nopl   (%rax)
movl   $0xc,0xc(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x3e8,%edx
xor    %ecx,%ecx
mov    %r15,%r8
lea    0xc(%rsp),%r9
call   1090 <recvfrom@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    $0xc,%r9d
call   1080 <sendto@plt>
mov    %r13,%rdi
call   1040 <puts@plt>
movslq %ebp,%rax
movb   $0x0,0x30(%rsp,%rax,1)
lea    0xd84(%rip),%rdi
call   1040 <puts@plt>
movsbl 0x30(%rsp),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movsbl 0x31(%rsp),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movsbl 0x32(%rsp),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movsbl 0x33(%rsp),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movsbl 0x34(%rsp),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movsbl 0x35(%rsp),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movsbl 0x36(%rsp),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movsbl 0x37(%rsp),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r13,%rdi
call   1040 <puts@plt>
jmp    1230 <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 = [25 x i8] c"Received the following:\0A\00"
@.str.2 = [5 x i8] c"%02X\00"
@.str.3 = [2 x i8] c"\0A\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 [1000 x i8]
%12 = alloca i32
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 @bzero(%struct.sockaddr_in* %8, 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 1912)
%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 = %56, %2
store i32 12, i32* %10
%29 = load i32, i32* %6
%30 = getelementptr inbounds [1000 x i8], [1000 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 1000, i32 0, %struct.sockaddr* %31, i32* %10)
store i32 %32, i32* %7
%33 = load i32, i32* %6
%34 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%35 = load i32, i32* %7
%36 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%37 = call i32 @sendto(i32 %33, i8* %34, i32 %35, i32 0, %struct.sockaddr* %36, i32 12)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 %40
store i8 0, i8* %41
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %12
br label %43
43: ; preds = %53, %28
%44 = load i32, i32* %12
%45 = icmp slt i32 %44, 8
br i1 %45, label %46, label %56
46: ; preds = %43
%47 = load i32, i32* %12
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 %48
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %51)
br label %53
53: ; preds = %46
%54 = load i32, i32* %12
%55 = add nsw i32 %54, 1
store i32 %55, i32* %12
br label %43
56: ; preds = %43
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%58 = 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.2 = [5 x i8] c"%02X\00"
@str.4 = [24 x i8] c"Received the following:\00"
@str.5 = [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 [1000 x i8]
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_DGRAM
%13 = tail call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %15, i32* %16
%17 = load i32, i32* @INADDR_ANY
%18 = tail call i32 @htonl(i32 %17)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %18, i32* %19
%20 = tail call i32 @htons(i32 1912)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %20, i32* %21
%22 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%23 = call i32 @bind(i32 %13, %struct.sockaddr* %22, i32 12)
%24 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%25 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 1
%26 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 2
%27 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 3
%28 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 4
%29 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 5
%30 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 6
%31 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 7
br label %32
32: ; preds = %32, %2
store i32 12, i32* %5
%33 = call i32 @recvfrom(i32 %13, i8* %10, i32 1000, i32 0, %struct.sockaddr* %24, i32* %5)
%34 = call i32 @sendto(i32 %13, i8* %10, i32 %33, i32 0, %struct.sockaddr* %24, i32 12)
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str.5, i64 0, i64 0))
%36 = sext i32 %33 to i64
%37 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 %36
store i8 0, i8* %37
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.4, i64 0, i64 0))
%39 = load i8, i8* %10
%40 = sext i8 %39 to i32
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %40)
%42 = load i8, i8* %25
%43 = sext i8 %42 to i32
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %43)
%45 = load i8, i8* %26
%46 = sext i8 %45 to i32
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %46)
%48 = load i8, i8* %27
%49 = sext i8 %48 to i32
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %49)
%51 = load i8, i8* %28
%52 = sext i8 %51 to i32
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %52)
%54 = load i8, i8* %29
%55 = sext i8 %54 to i32
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %55)
%57 = load i8, i8* %30
%58 = sext i8 %57 to i32
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %58)
%60 = load i8, i8* %31
%61 = sext i8 %60 to i32
%62 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %61)
%63 = call i32 @putchar(i32 10)
%64 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str.5, i64 0, i64 0))
br label %32
}