#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 */
typedef int /*<<< orphan*/ yes;
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 /*<<< orphan*/ message;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int STDOUT_FILENO;
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  struct sockaddr_in addr;
  int rc, sd, yes = 1;
  char message[1024];
  addr.sin_family = AF_INET;
  addr.sin_addr.s_addr = htonl(INADDR_ANY);
  addr.sin_port = htons(7177);
  sd = socket(PF_INET, SOCK_DGRAM, 0);
  setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
  bind(sd, (struct sockaddr *)&addr, sizeof(addr));
  for (;;) {
    rc = read(sd, message, sizeof(message));
    write(STDOUT_FILENO, message, rc);
    write(sd, message, rc);
    printf("Received the end of input\n\n");
  }
  close(sd);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,-0xc(%rbp)
mov    $0x1c09,%edi
call   1050 <htons@plt>
mov    %eax,-0x10(%rbp)
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2df7(%rip),%rax
mov    (%rax),%esi
mov    0x2dbe(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    -0x18(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
mov    -0x18(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1080 <read@plt>
mov    %eax,-0x14(%rbp)
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <write@plt>
mov    -0x18(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <write@plt>
lea    0xda4(%rip),%rdi
call   1060 <printf@plt>
jmp    1214 <main+0x94>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x420,%rsp
movl   $0x1,0xc(%rsp)
mov    0x2e3a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    $0x1c09,%edi
call   1060 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,%r15d
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
mov    0x2dc0(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %r15d,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
lea    0x10(%rsp),%rsi
mov    %r15d,%edi
mov    $0xc,%edx
call   1090 <bind@plt>
lea    0x20(%rsp),%rbx
mov    0x2dcd(%rip),%r12
lea    0xdd6(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1080 <read@plt>
mov    %eax,%ebp
mov    (%r12),%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1050 <write@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
jmp    1230 <main+0xb0>

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
@INADDR_ANY = global i32 0
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@STDOUT_FILENO = global i32 0
@.str = [28 x i8] c"Received the end of input\0A\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [1024 x i8]
store i32 0, i32* %1
store i32 1, i32* %5
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 2
store i32 %7, i32* %8
%9 = load i32, i32* @INADDR_ANY
%10 = call i32 @htonl(i32 %9)
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 1
%12 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %11, i32 0, i32 0
store i32 %10, i32* %12
%13 = call i32 @htons(i32 7177)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
store i32 %13, i32* %14
%15 = load i32, i32* @PF_INET
%16 = load i32, i32* @SOCK_DGRAM
%17 = call i32 @socket(i32 %15, i32 %16, i32 0)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = load i32, i32* @SOL_SOCKET
%20 = load i32, i32* @SO_REUSEADDR
%21 = call i32 @setsockopt(i32 %18, i32 %19, i32 %20, i32* %5, i32 4)
%22 = load i32, i32* %4
%23 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%24 = call i32 @bind(i32 %22, %struct.sockaddr* %23, i32 12)
br label %25
25: ; preds = %25, %0
%26 = load i32, i32* %4
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%28 = call i32 @read(i32 %26, i8* %27, i32 1024)
store i32 %28, i32* %3
%29 = load i32, i32* @STDOUT_FILENO
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%31 = load i32, i32* %3
%32 = call i32 @write(i32 %29, i8* %30, i32 %31)
%33 = load i32, i32* %4
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%35 = load i32, i32* %3
%36 = call i32 @write(i32 %33, i8* %34, i32 %35)
%37 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %25
}

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
@INADDR_ANY = global i32 0
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@STDOUT_FILENO = global i32 0
@EXIT_SUCCESS = global i32 0
@str = [27 x i8] c"Received the end of input\0A\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = bitcast %struct.sockaddr_in* %1 to i8*
%5 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %7, i32* %8
%9 = load i32, i32* @INADDR_ANY
%10 = tail call i32 @htonl(i32 %9)
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %10, i32* %11
%12 = tail call i32 @htons(i32 7177)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %12, i32* %13
%14 = load i32, i32* @PF_INET
%15 = load i32, i32* @SOCK_DGRAM
%16 = tail call i32 @socket(i32 %14, i32 %15, i32 0)
%17 = load i32, i32* @SOL_SOCKET
%18 = load i32, i32* @SO_REUSEADDR
%19 = call i32 @setsockopt(i32 %16, i32 %17, i32 %18, i32* %2, i32 4)
%20 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%21 = call i32 @bind(i32 %16, %struct.sockaddr* %20, i32 12)
br label %22
22: ; preds = %22, %0
%23 = call i32 @read(i32 %16, i8* %6, i32 1024)
%24 = load i32, i32* @STDOUT_FILENO
%25 = call i32 @write(i32 %24, i8* %6, i32 %23)
%26 = call i32 @write(i32 %16, i8* %6, i32 %23)
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %22
}