#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 socklen_t;
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_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int /*<<< orphan*/ STDOUT_FILENO;
int accept(int, struct sockaddr *, int *);
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*/ listen(int, 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 /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
int main(void) {
  struct sockaddr_in addr, con_addr;
  int rc, sd, cd, yes = 1;
  socklen_t alen = sizeof(struct sockaddr_in);
  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_STREAM, 0);
  setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
  bind(sd, (struct sockaddr *)&addr, sizeof(addr));
  listen(sd, 5);
  for (;;) {
    printf("\nAccepting input on port %d\n", 7177);
    cd = accept(sd, (struct sockaddr *)&con_addr, &alen);
    rc = recvfrom(cd, message, sizeof(message), 0, (struct sockaddr *)&con_addr,
                  &alen);
    write(STDOUT_FILENO, message, rc);
    sendto(cd, message, rc, 0, (struct sockaddr *)&con_addr, alen);
    printf("Received the end of input\n\n");
    close(cd);
  }
  close(sd);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x30(%rbp)
movl   $0xc,-0x34(%rbp)
mov    0x2df1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    0x2ddd(%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    0x2da7(%rip),%rax
mov    (%rax),%edi
mov    0x2da6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
mov    0x2db0(%rip),%rax
mov    (%rax),%esi
mov    0x2d77(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    -0x28(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
mov    -0x28(%rbp),%edi
mov    $0x5,%esi
call   10a0 <listen@plt>
lea    0xd91(%rip),%rdi
mov    $0x1c09,%esi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   10d0 <accept@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x440(%rbp),%rsi
lea    -0x20(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0x34(%rbp),%r9
call   10b0 <recvfrom@plt>
mov    %eax,-0x24(%rbp)
mov    0x2d3a(%rip),%rax
mov    (%rax),%edi
lea    -0x440(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <write@plt>
mov    -0x2c(%rbp),%edi
lea    -0x440(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    -0x20(%rbp),%r8
mov    -0x34(%rbp),%r9d
xor    %ecx,%ecx
call   1080 <sendto@plt>
lea    0xd33(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x2c(%rbp),%edi
call   1090 <close@plt>
jmp    1268 <main+0xa8>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
movl   $0x1,0xc(%rsp)
movl   $0xc,0x8(%rsp)
mov    0x2de0(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    $0x1c09,%edi
call   1060 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
mov    0x2d92(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,%r15d
mov    0x2d9f(%rip),%rax
mov    (%rax),%esi
mov    0x2d66(%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   10d0 <bind@plt>
mov    %r15d,%edi
mov    $0x5,%esi
call   10b0 <listen@plt>
lea    0x20(%rsp),%rbx
lea    0x8(%rsp),%r12
lea    0x30(%rsp),%rbp
nopl   (%rax)
lea    0xd69(%rip),%rdi
mov    $0x1c09,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   10e0 <accept@plt>
mov    %eax,%r14d
mov    %eax,%edi
mov    %rbp,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
mov    %r12,%r9
call   10c0 <recvfrom@plt>
mov    %eax,%r13d
mov    0x2d1b(%rip),%rax
mov    (%rax),%edi
mov    %rbp,%rsi
mov    %r13d,%edx
call   1050 <write@plt>
mov    0x8(%rsp),%r9d
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %r13d,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
call   1090 <sendto@plt>
lea    0xd1c(%rip),%rdi
call   1030 <puts@plt>
mov    %r14d,%edi
call   10a0 <close@plt>
jmp    1290 <main+0xc0>

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_STREAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str = [29 x i8] c"\0AAccepting input on port %d\0A\00"
@STDOUT_FILENO = global i32 0
@.str.1 = [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 %struct.sockaddr_in
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [1024 x i8]
store i32 0, i32* %1
store i32 1, i32* %7
store i32 12, i32* %8
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 2
store i32 %10, i32* %11
%12 = load i32, i32* @INADDR_ANY
%13 = call i32 @htonl(i32 %12)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 1
%15 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %14, i32 0, i32 0
store i32 %13, i32* %15
%16 = call i32 @htons(i32 7177)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
store i32 %16, i32* %17
%18 = load i32, i32* @PF_INET
%19 = load i32, i32* @SOCK_STREAM
%20 = call i32 @socket(i32 %18, i32 %19, i32 0)
store i32 %20, i32* %5
%21 = load i32, i32* %5
%22 = load i32, i32* @SOL_SOCKET
%23 = load i32, i32* @SO_REUSEADDR
%24 = call i32 @setsockopt(i32 %21, i32 %22, i32 %23, i32* %7, i32 4)
%25 = load i32, i32* %5
%26 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%27 = call i32 @bind(i32 %25, %struct.sockaddr* %26, i32 12)
%28 = load i32, i32* %5
%29 = call i32 @listen(i32 %28, i32 5)
br label %30
30: ; preds = %30, %0
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 7177)
%32 = load i32, i32* %5
%33 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%34 = call i32 @accept(i32 %32, %struct.sockaddr* %33, i32* %8)
store i32 %34, i32* %6
%35 = load i32, i32* %6
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%37 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%38 = call i32 @recvfrom(i32 %35, i8* %36, i32 1024, i32 0, %struct.sockaddr* %37, i32* %8)
store i32 %38, i32* %4
%39 = load i32, i32* @STDOUT_FILENO
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%41 = load i32, i32* %4
%42 = call i32 @write(i32 %39, i8* %40, i32 %41)
%43 = load i32, i32* %6
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%45 = load i32, i32* %4
%46 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%47 = load i32, i32* %8
%48 = call i32 @sendto(i32 %43, i8* %44, i32 %45, i32 0, %struct.sockaddr* %46, i32 %47)
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%50 = load i32, i32* %6
%51 = call i32 @close(i32 %50)
br label %30
}

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_STREAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str = [29 x i8] c"\0AAccepting input on port %d\0A\00"
@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 %struct.sockaddr_in
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = bitcast %struct.sockaddr_in* %1 to i8*
%7 = bitcast %struct.sockaddr_in* %2 to i8*
%8 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%9 = bitcast i32* %4 to i8*
store i32 12, i32* %4
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
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 1, i32 0
store i32 %14, i32* %15
%16 = tail call i32 @htons(i32 7177)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %16, i32* %17
%18 = load i32, i32* @PF_INET
%19 = load i32, i32* @SOCK_STREAM
%20 = tail call i32 @socket(i32 %18, i32 %19, i32 0)
%21 = load i32, i32* @SOL_SOCKET
%22 = load i32, i32* @SO_REUSEADDR
%23 = call i32 @setsockopt(i32 %20, i32 %21, i32 %22, i32* %3, i32 4)
%24 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%25 = call i32 @bind(i32 %20, %struct.sockaddr* %24, i32 12)
%26 = call i32 @listen(i32 %20, i32 5)
%27 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
br label %28
28: ; preds = %28, %0
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 7177)
%30 = call i32 @accept(i32 %20, %struct.sockaddr* %27, i32* %4)
%31 = call i32 @recvfrom(i32 %30, i8* %10, i32 1024, i32 0, %struct.sockaddr* %27, i32* %4)
%32 = load i32, i32* @STDOUT_FILENO
%33 = call i32 @write(i32 %32, i8* %10, i32 %31)
%34 = load i32, i32* %4
%35 = call i32 @sendto(i32 %30, i8* %10, i32 %31, i32 0, %struct.sockaddr* %27, i32 %34)
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%37 = call i32 @close(i32 %30)
br label %28
}