#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;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ opt;
typedef int /*<<< orphan*/ conn;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
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);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, char **, int);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int /*<<< orphan*/ snprintf(char *, int, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main() {
  int sock, client, opt = 1;
  struct sockaddr_in conn;
  char buf[512 + 1];
  sock = socket(AF_INET, SOCK_STREAM, 0);
  setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
  memset(&conn, 0, sizeof(conn));
  conn.sin_port = htons(1100);
  conn.sin_addr.s_addr = htonl(INADDR_ANY);
  bind(sock, (struct sockaddr *)&conn, sizeof(conn));
  listen(sock, 1);
  client = accept(sock, NULL, NULL);
  read(client, &buf, 512);
  printf("got from client: %s", buf);
  snprintf(buf, 512, "data from server\n");
  printf("sending to client: %s", buf);
  write(client, buf, strlen(buf));
  close(client);
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x10(%rbp)
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
mov    0x2dbf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2dc9(%rip),%rax
mov    (%rax),%esi
mov    0x2d98(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   10a0 <memset@plt>
mov    $0x44c,%edi
call   1060 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   10e0 <bind@plt>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   10d0 <listen@plt>
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   10f0 <accept@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
call   10c0 <read@plt>
lea    -0x220(%rbp),%rsi
lea    0xd47(%rip),%rdi
call   1070 <printf@plt>
lea    -0x220(%rbp),%rdi
mov    $0x200,%esi
lea    0xd43(%rip),%rdx
call   1080 <snprintf@plt>
lea    -0x220(%rbp),%rsi
lea    0xd42(%rip),%rdi
call   1070 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x22c(%rbp)
lea    -0x220(%rbp),%rax
mov    %rax,-0x228(%rbp)
lea    -0x220(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x22c(%rbp),%edi
mov    -0x228(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0xc(%rbp),%edi
call   10b0 <close@plt>
mov    -0x8(%rbp),%edi
call   10b0 <close@plt>
xor    %eax,%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x220,%rsp
movl   $0x1,0x4(%rsp)
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,%r14d
mov    0x2dd2(%rip),%rax
mov    (%rax),%esi
mov    0x2da1(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %r14d,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   10a0 <memset@plt>
mov    $0x44c,%edi
call   1060 <htons@plt>
mov    %eax,0xc(%rsp)
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,0x8(%rsp)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x8,%edx
call   10e0 <bind@plt>
mov    %r14d,%edi
mov    $0x1,%esi
call   10d0 <listen@plt>
mov    %r14d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10f0 <accept@plt>
mov    %eax,%ebp
lea    0x10(%rsp),%rbx
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   10c0 <read@plt>
lea    0xd52(%rip),%rdi
mov    %rbx,%rsi
call   1070 <printf@plt>
lea    0xd57(%rip),%rdx
mov    %rbx,%rdi
mov    $0x200,%esi
call   1080 <snprintf@plt>
lea    0xd55(%rip),%rdi
mov    %rbx,%rsi
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebp,%edi
call   10b0 <close@plt>
mov    %r14d,%edi
call   10b0 <close@plt>
xor    %eax,%eax
add    $0x220,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@INADDR_ANY = global i32 0
@.str = [20 x i8] c"got from client: %s\00"
@.str.1 = [18 x i8] c"data from server\0A\00"
@.str.2 = [22 x i8] c"sending to client: %s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca [513 x i8]
store i32 0, i32* %1
store i32 1, i32* %4
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = load i32, i32* @SOL_SOCKET
%12 = load i32, i32* @SO_REUSEADDR
%13 = call i32 @setsockopt(i32 %10, i32 %11, i32 %12, i32* %4, i32 4)
%14 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 8)
%15 = call i32 @htons(i32 1100)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
store i32 %15, i32* %16
%17 = load i32, i32* @INADDR_ANY
%18 = call i32 @htonl(i32 %17)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%20 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %19, i32 0, i32 0
store i32 %18, i32* %20
%21 = load i32, i32* %2
%22 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%23 = call i32 @bind(i32 %21, %struct.sockaddr* %22, i32 8)
%24 = load i32, i32* %2
%25 = call i32 @listen(i32 %24, i32 1)
%26 = load i32, i32* %2
%27 = call i32 @accept(i32 %26, i32* null, i32* null)
store i32 %27, i32* %3
%28 = load i32, i32* %3
%29 = bitcast [513 x i8]* %6 to i8**
%30 = call i32 @read(i32 %28, i8** %29, i32 512)
%31 = getelementptr inbounds [513 x i8], [513 x i8]* %6, i64 0, i64 0
%32 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %31)
%33 = getelementptr inbounds [513 x i8], [513 x i8]* %6, i64 0, i64 0
%34 = call i32 @snprintf(i8* %33, i32 512, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%35 = getelementptr inbounds [513 x i8], [513 x i8]* %6, i64 0, i64 0
%36 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %35)
%37 = load i32, i32* %3
%38 = getelementptr inbounds [513 x i8], [513 x i8]* %6, i64 0, i64 0
%39 = getelementptr inbounds [513 x i8], [513 x i8]* %6, i64 0, i64 0
%40 = call i32 @strlen(i8* %39)
%41 = call i32 @write(i32 %37, i8* %38, i32 %40)
%42 = load i32, i32* %3
%43 = call i32 @close(i32 %42)
%44 = load i32, i32* %2
%45 = call i32 @close(i32 %44)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@INADDR_ANY = global i32 0
@.str = [20 x i8] c"got from client: %s\00"
@.str.1 = [18 x i8] c"data from server\0A\00"
@.str.2 = [22 x i8] c"sending to client: %s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca [513 x i8]
%4 = bitcast i32* %1 to i8*
store i32 1, i32* %1
%5 = bitcast %struct.sockaddr_in* %2 to i8*
%6 = getelementptr inbounds [513 x i8], [513 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = load i32, i32* @SOL_SOCKET
%11 = load i32, i32* @SO_REUSEADDR
%12 = call i32 @setsockopt(i32 %9, i32 %10, i32 %11, i32* %1, i32 4)
%13 = call i32 @memset(%struct.sockaddr_in* %2, i32 0, i32 8)
%14 = call i32 @htons(i32 1100)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %14, i32* %15
%16 = load i32, i32* @INADDR_ANY
%17 = call i32 @htonl(i32 %16)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0, i32 0
store i32 %17, i32* %18
%19 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%20 = call i32 @bind(i32 %9, %struct.sockaddr* %19, i32 8)
%21 = call i32 @listen(i32 %9, i32 1)
%22 = call i32 @accept(i32 %9, i32* null, i32* null)
%23 = bitcast [513 x i8]* %3 to i8**
%24 = call i32 @read(i32 %22, i8** %23, i32 512)
%25 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %6)
%26 = call i32 @snprintf(i8* %6, i32 512, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%28 = call i32 @strlen(i8* %6)
%29 = call i32 @write(i32 %22, i8* %6, i32 %28)
%30 = call i32 @close(i32 %22)
%31 = call i32 @close(i32 %9)
ret i32 0
}