#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;
};
struct in_addr {
  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 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 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, con_addr;
  int rc, sd, cd, yes = 1;
  socklen_t alen = sizeof(struct in_addr);
  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 = read(cd, message, sizeof(message));
    write(STDOUT_FILENO, message, rc);
    write(cd, message, rc);
    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   $0x4,-0x34(%rbp)
mov    0x2e01(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    0x2ded(%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    0x2db7(%rip),%rax
mov    (%rax),%edi
mov    0x2db6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
mov    0x2dc0(%rip),%rax
mov    (%rax),%esi
mov    0x2d87(%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   10b0 <bind@plt>
mov    -0x28(%rbp),%edi
mov    $0x5,%esi
call   10a0 <listen@plt>
lea    0xda1(%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   10c0 <accept@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x440(%rbp),%rsi
mov    $0x400,%edx
call   1090 <read@plt>
mov    %eax,-0x24(%rbp)
mov    0x2d54(%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
call   1040 <write@plt>
lea    0xd57(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x2c(%rbp),%edi
call   1080 <close@plt>
jmp    1258 <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   $0x4,0x8(%rsp)
mov    0x2df0(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2ddb(%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    0x2da3(%rip),%rax
mov    (%rax),%edi
mov    0x2da2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%ebp
mov    0x2db0(%rip),%rax
mov    (%rax),%esi
mov    0x2d77(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   10c0 <bind@plt>
mov    %ebp,%edi
mov    $0x5,%esi
call   10b0 <listen@plt>
lea    0x30(%rsp),%rbx
mov    0x2d7a(%rip),%r12
lea    0xda0(%rip),%r13
nopl   (%rax)
lea    0xd79(%rip),%rdi
mov    $0x1c09,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebp,%edi
lea    0x20(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   10d0 <accept@plt>
mov    %eax,%r14d
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   10a0 <read@plt>
mov    %eax,%r15d
mov    (%r12),%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1050 <write@plt>
mov    %r13,%rdi
call   1030 <puts@plt>
mov    %r14d,%edi
call   1090 <close@plt>
jmp    1280 <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 4, 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 = call i32 @read(i32 %35, i8* %36, i32 1024)
store i32 %37, i32* %4
%38 = load i32, i32* @STDOUT_FILENO
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%40 = load i32, i32* %4
%41 = call i32 @write(i32 %38, i8* %39, i32 %40)
%42 = load i32, i32* %6
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%44 = load i32, i32* %4
%45 = call i32 @write(i32 %42, i8* %43, i32 %44)
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%47 = load i32, i32* %6
%48 = call i32 @close(i32 %47)
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 4, 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 @read(i32 %30, i8* %10, i32 1024)
%32 = load i32, i32* @STDOUT_FILENO
%33 = call i32 @write(i32 %32, i8* %10, i32 %31)
%34 = call i32 @write(i32 %30, i8* %10, i32 %31)
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%36 = call i32 @close(i32 %30)
br label %28
}