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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ MSG_NOSIGNAL;
int /*<<< orphan*/ SHUT_RDWR;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOMAXCONN;
int accept(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int *);
int /*<<< orphan*/ recv(int, int *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, int *, int, int /*<<< orphan*/);
int /*<<< orphan*/ shutdown(int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int masterSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  struct sockaddr_in sockAddr;
  sockAddr.sin_family = AF_INET;
  sockAddr.sin_port = htons(12345);
  sockAddr.sin_addr.s_addr = htonl(INADDR_ANY);
  bind(masterSocket, (struct sockaddr *)&sockAddr, sizeof(sockAddr));
  listen(masterSocket, SOMAXCONN);
  while (1) {
    int slaveSocket = accept(masterSocket, 0, 0);
    int buffer[5] = {0};
    recv(slaveSocket, buffer, sizeof(buffer) - 1, MSG_NOSIGNAL);
    send(slaveSocket, buffer, sizeof(buffer) - 1, MSG_NOSIGNAL);
    shutdown(slaveSocket, SHUT_RDWR);
    close(slaveSocket);
    printf("%s\n", buffer);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
mov    0x2dd2(%rip),%rax
mov    (%rax),%esi
mov    0x2de1(%rip),%rax
mov    (%rax),%edx
call   10e0 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    0x2de0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x3039,%edi
call   1050 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
mov    -0x14(%rbp),%edi
mov    0x2d82(%rip),%rax
mov    (%rax),%esi
call   10b0 <listen@plt>
mov    -0x14(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   10d0 <accept@plt>
mov    %eax,-0x24(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1090 <memset@plt>
mov    -0x24(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    0x2d3e(%rip),%rax
mov    (%rax),%ecx
mov    $0x13,%edx
call   1030 <recv@plt>
mov    -0x24(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    0x2d24(%rip),%rax
mov    (%rax),%ecx
mov    $0x13,%edx
call   1060 <send@plt>
mov    -0x24(%rbp),%edi
mov    0x2d4e(%rip),%rax
mov    (%rax),%esi
call   1040 <shutdown@plt>
mov    -0x24(%rbp),%edi
call   10a0 <close@plt>
lea    -0x40(%rbp),%rsi
lea    0xd44(%rip),%rdi
call   1070 <printf@plt>
jmp    1245 <main+0x85>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0x2e1b(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
mov    0x2df9(%rip),%rax
mov    (%rax),%edx
call   10d0 <socket@plt>
mov    %eax,%r15d
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    $0x3039,%edi
call   1050 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %r15d,%edi
mov    $0xc,%edx
call   10b0 <bind@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
call   10a0 <listen@plt>
mov    0x2d82(%rip),%r12
lea    0x10(%rsp),%rbx
mov    0x2db6(%rip),%r13
lea    0xdcf(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10c0 <accept@plt>
mov    %eax,%ebp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x20(%rsp)
mov    (%r12),%ecx
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x13,%edx
call   1030 <recv@plt>
mov    (%r12),%ecx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x13,%edx
call   1060 <send@plt>
mov    0x0(%r13),%esi
mov    %ebp,%edi
call   1040 <shutdown@plt>
mov    %ebp,%edi
call   1090 <close@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <printf@plt>
jmp    1250 <main+0xa0>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@INADDR_ANY = global i32 0
@SOMAXCONN = global i32 0
@MSG_NOSIGNAL = global i32 0
@SHUT_RDWR = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
%9 = alloca [5 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = load i32, i32* @IPPROTO_TCP
%13 = call i32 @socket(i32 %10, i32 %11, i32 %12)
store i32 %13, i32* %6
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %14, i32* %15
%16 = call i32 @htons(i32 12345)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %16, i32* %17
%18 = load i32, i32* @INADDR_ANY
%19 = call i32 @htonl(i32 %18)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%21 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %20, i32 0, i32 0
store i32 %19, i32* %21
%22 = load i32, i32* %6
%23 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%24 = call i32 @bind(i32 %22, %struct.sockaddr* %23, i32 12)
%25 = load i32, i32* %6
%26 = load i32, i32* @SOMAXCONN
%27 = call i32 @listen(i32 %25, i32 %26)
br label %28
28: ; preds = %2, %28
%29 = load i32, i32* %6
%30 = call i32 @accept(i32 %29, i32 0, i32 0)
store i32 %30, i32* %8
%31 = bitcast [5 x i32]* %9 to i8*
%32 = load i32, i32* %8
%33 = getelementptr inbounds [5 x i32], [5 x i32]* %9, i64 0, i64 0
%34 = load i32, i32* @MSG_NOSIGNAL
%35 = call i32 @recv(i32 %32, i32* %33, i32 19, i32 %34)
%36 = load i32, i32* %8
%37 = getelementptr inbounds [5 x i32], [5 x i32]* %9, i64 0, i64 0
%38 = load i32, i32* @MSG_NOSIGNAL
%39 = call i32 @send(i32 %36, i32* %37, i32 19, i32 %38)
%40 = load i32, i32* %8
%41 = load i32, i32* @SHUT_RDWR
%42 = call i32 @shutdown(i32 %40, i32 %41)
%43 = load i32, i32* %8
%44 = call i32 @close(i32 %43)
%45 = getelementptr inbounds [5 x i32], [5 x i32]* %9, i64 0, i64 0
%46 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %45)
br label %28
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@INADDR_ANY = global i32 0
@SOMAXCONN = global i32 0
@MSG_NOSIGNAL = global i32 0
@SHUT_RDWR = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [5 x i32]
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = load i32, i32* @IPPROTO_TCP
%8 = tail call i32 @socket(i32 %5, i32 %6, i32 %7)
%9 = bitcast %struct.sockaddr_in* %3 to i8*
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %10, i32* %11
%12 = tail call i32 @htons(i32 12345)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %12, i32* %13
%14 = load i32, i32* @INADDR_ANY
%15 = tail call i32 @htonl(i32 %14)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %15, i32* %16
%17 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%18 = call i32 @bind(i32 %8, %struct.sockaddr* %17, i32 12)
%19 = load i32, i32* @SOMAXCONN
%20 = call i32 @listen(i32 %8, i32 %19)
%21 = bitcast [5 x i32]* %4 to i8*
%22 = getelementptr inbounds [5 x i32], [5 x i32]* %4, i64 0, i64 0
br label %23
23: ; preds = %23, %2
%24 = call i32 @accept(i32 %8, i32 0, i32 0)
%25 = load i32, i32* @MSG_NOSIGNAL
%26 = call i32 @recv(i32 %24, i32* %22, i32 19, i32 %25)
%27 = load i32, i32* @MSG_NOSIGNAL
%28 = call i32 @send(i32 %24, i32* %22, i32 19, i32 %27)
%29 = load i32, i32* @SHUT_RDWR
%30 = call i32 @shutdown(i32 %24, i32 %29)
%31 = call i32 @close(i32 %24)
%32 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %22)
br label %23
}