#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*/ sa;

/* 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 /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ shutdown(int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int socket_master = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  struct sockaddr_in sa;
  sa.sin_family = AF_INET;
  sa.sin_port = htons(12345);
  sa.sin_addr.s_addr = htonl(INADDR_ANY);
  bind(socket_master, (struct sockaddr *)(&sa), sizeof(sa));
  listen(socket_master, SOMAXCONN);
  while (1) {
    int socket_slave = accept(socket_master, 0, 0);
    char buf[5] = {0, 0, 0, 0, 0};
    recv(socket_slave, buf, 4, MSG_NOSIGNAL);
    printf("Server got: %s\n", buf);
    buf[1] = '@';
    send(socket_slave, buf, 4, MSG_NOSIGNAL);
    shutdown(socket_slave, SHUT_RDWR);
    close(socket_slave);
  }
  printf("Server closed.");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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    -0x29(%rbp),%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1090 <memset@plt>
mov    -0x24(%rbp),%edi
lea    -0x29(%rbp),%rsi
mov    0x2d3e(%rip),%rax
mov    (%rax),%ecx
mov    $0x4,%edx
call   1030 <recv@plt>
lea    -0x29(%rbp),%rsi
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movb   $0x40,-0x28(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x29(%rbp),%rsi
mov    0x2d0e(%rip),%rax
mov    (%rax),%ecx
mov    $0x4,%edx
call   1060 <send@plt>
mov    -0x24(%rbp),%edi
mov    0x2d38(%rip),%rax
mov    (%rax),%esi
call   1040 <shutdown@plt>
mov    -0x24(%rbp),%edi
call   10a0 <close@plt>
jmp    1245 <main+0x85>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%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,0x10(%rsp)
mov    $0x3039,%edi
call   1050 <htons@plt>
mov    %eax,0xc(%rsp)
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %r15d,%edi
mov    $0xc,%edx
call   10b0 <bind@plt>
mov    0x2da0(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
call   10a0 <listen@plt>
mov    0x2d7f(%rip),%r12
mov    %rsp,%rbx
lea    0xdc5(%rip),%r14
mov    0x2dae(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10c0 <accept@plt>
mov    %eax,%ebp
movb   $0x0,0x4(%rsp)
movl   $0x0,(%rsp)
mov    (%r12),%ecx
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <recv@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
movb   $0x40,0x1(%rsp)
mov    (%r12),%ecx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1060 <send@plt>
mov    0x0(%r13),%esi
mov    %ebp,%edi
call   1040 <shutdown@plt>
mov    %ebp,%edi
call   1090 <close@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
@.str = [16 x i8] c"Server got: %s\0A\00"
@SHUT_RDWR = global i32 0
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 i8]
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 i8]* %9 to i8*
%32 = load i32, i32* %8
%33 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 0
%34 = load i32, i32* @MSG_NOSIGNAL
%35 = call i32 @recv(i32 %32, i8* %33, i32 4, i32 %34)
%36 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 0
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %36)
%38 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 1
store i8 64, i8* %38
%39 = load i32, i32* %8
%40 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 0
%41 = load i32, i32* @MSG_NOSIGNAL
%42 = call i32 @send(i32 %39, i8* %40, i32 4, i32 %41)
%43 = load i32, i32* %8
%44 = load i32, i32* @SHUT_RDWR
%45 = call i32 @shutdown(i32 %43, i32 %44)
%46 = load i32, i32* %8
%47 = call i32 @close(i32 %46)
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
@.str = [16 x i8] c"Server got: %s\0A\00"
@SHUT_RDWR = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [5 x i8]
%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 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%22 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 1
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, i8* %21, i32 4, i32 %25)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %21)
store i8 64, i8* %22
%28 = load i32, i32* @MSG_NOSIGNAL
%29 = call i32 @send(i32 %24, i8* %21, i32 4, i32 %28)
%30 = load i32, i32* @SHUT_RDWR
%31 = call i32 @shutdown(i32 %24, i32 %30)
%32 = call i32 @close(i32 %24)
br label %23
}