#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*/ buf;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int recv(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char const *argv[]) {
  int sock, listener, binding, bytes_read;
  struct sockaddr_in addr;
  char buf[1024];
  listener = socket(AF_INET, SOCK_STREAM, 0);
  if (listener < 0) {
    perror("Ошибка создания сокета");
    exit(1);
  }
  addr.sin_family = AF_INET;
  addr.sin_port = htons(3424);
  addr.sin_addr.s_addr = htonl(INADDR_ANY);
  binding = bind(listener, (struct sockaddr *)&addr, sizeof(addr));
  if (binding < 0) {
    perror("Ошибка Binding");
    exit(2);
  }
  listen(listener, 10);
  while (1) {
    sock = accept(listener, NULL, NULL);
    if (sock < 0) {
      perror("Ошибка слушающего сокета");
      exit(3);
    }
    while (1) {
      bytes_read = recv(sock, buf, sizeof(buf), 0);
      if (bytes_read <= 0)
        break;
      printf("%s ", buf);
    }
    close(sock);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
mov    0x2df7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1205 <main+0x55>
lea    0xe0a(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    $0xd60,%edi
call   1040 <htons@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1263 <main+0xb3>
lea    0xdd7(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x2,%edi
call   10c0 <exit@plt>
mov    -0x18(%rbp),%edi
mov    $0xa,%esi
call   1080 <listen@plt>
mov    -0x18(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   10b0 <accept@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12a2 <main+0xf2>
lea    0xdad(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x3,%edi
call   10c0 <exit@plt>
jmp    12a7 <main+0xf7>
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jg     12cf <main+0x11f>
jmp    12e7 <main+0x137>
lea    -0x430(%rbp),%rsi
lea    0xd92(%rip),%rdi
call   1050 <printf@plt>
jmp    12a7 <main+0xf7>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
jmp    1270 <main+0xc0>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x418,%rsp
mov    0x2e24(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e03(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
test   %eax,%eax
jns    11f0 <main+0x40>
lea    0xe1f(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    %eax,%r14d
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    $0xd60,%edi
call   1040 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   1090 <bind@plt>
test   %eax,%eax
jns    1242 <main+0x92>
lea    0xdf8(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x2,%edi
call   10c0 <exit@plt>
mov    %r14d,%edi
mov    $0xa,%esi
call   1080 <listen@plt>
mov    %r14d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10b0 <accept@plt>
test   %eax,%eax
js     12a9 <main+0xf9>
mov    %eax,%ebp
lea    0x10(%rsp),%rbx
lea    0xe02(%rip),%r15
jmp    127b <main+0xcb>
nop
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jg     1270 <main+0xc0>
mov    %ebp,%edi
call   1070 <close@plt>
mov    %r14d,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10b0 <accept@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    127b <main+0xcb>
lea    0xd90(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x3,%edi
call   10c0 <exit@plt>

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
@.str = [43 x i8] c"\D0\9E\D1\88\D0\B8\D0\B1\D0\BA\D0\B0 \D1\81\D0\BE\D0\B7\D0\B4\D0\B0\D0\BD\D0\B8\D1\8F \D1\81\D0\BE\D0\BA\D0\B5\D1\82\D0\B0\00"
@INADDR_ANY = global i32 0
@.str.1 = [21 x i8] c"\D0\9E\D1\88\D0\B8\D0\B1\D0\BA\D0\B0 Binding\00"
@.str.2 = [47 x i8] c"\D0\9E\D1\88\D0\B8\D0\B1\D0\BA\D0\B0 \D1\81\D0\BB\D1\83\D1\88\D0\B0\D1\8E\D1\89\D0\B5\D0\B3\D0\BE \D1\81\D0\BE\D0\BA\D0\B5\D1\82\D0\B0\00"
@.str.3 = [4 x i8] c"%s \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %21, i32* %22
%23 = call i32 @htons(i32 3424)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
store i32 %23, i32* %24
%25 = load i32, i32* @INADDR_ANY
%26 = call i32 @htonl(i32 %25)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%28 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %27, i32 0, i32 0
store i32 %26, i32* %28
%29 = load i32, i32* %7
%30 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%31 = call i32 @bind(i32 %29, %struct.sockaddr* %30, i32 12)
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %20
%35 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%36 = call i32 @exit(i32 2)
unreachable
37: ; preds = %20
%38 = load i32, i32* %7
%39 = call i32 @listen(i32 %38, i32 10)
br label %40
40: ; preds = %37, %59
%41 = load i32, i32* %7
%42 = call i32 @accept(i32 %41, i32* null, i32* null)
store i32 %42, i32* %6
%43 = load i32, i32* %6
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %40
%46 = call i32 @perror(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
%47 = call i32 @exit(i32 3)
unreachable
48: ; preds = %40
br label %49
49: ; preds = %48, %56
%50 = load i32, i32* %6
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%52 = call i32 @recv(i32 %50, i8* %51, i32 1024, i32 0)
store i32 %52, i32* %9
%53 = load i32, i32* %9
%54 = icmp sle i32 %53, 0
br i1 %54, label %55, label %56
55: ; preds = %49
br label %59
56: ; preds = %49
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%58 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %57)
br label %49
59: ; preds = %55
%60 = load i32, i32* %6
%61 = call i32 @close(i32 %60)
br label %40
}

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
@.str = [43 x i8] c"\D0\9E\D1\88\D0\B8\D0\B1\D0\BA\D0\B0 \D1\81\D0\BE\D0\B7\D0\B4\D0\B0\D0\BD\D0\B8\D1\8F \D1\81\D0\BE\D0\BA\D0\B5\D1\82\D0\B0\00"
@INADDR_ANY = global i32 0
@.str.1 = [21 x i8] c"\D0\9E\D1\88\D0\B8\D0\B1\D0\BA\D0\B0 Binding\00"
@.str.2 = [47 x i8] c"\D0\9E\D1\88\D0\B8\D0\B1\D0\BA\D0\B0 \D1\81\D0\BB\D1\83\D1\88\D0\B0\D1\8E\D1\89\D0\B5\D0\B3\D0\BE \D1\81\D0\BE\D0\BA\D0\B5\D1\82\D0\B0\00"
@.str.3 = [4 x i8] c"%s \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [1024 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, 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 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = tail call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %15, i32* %16
%17 = tail call i32 @htons(i32 3424)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %17, i32* %18
%19 = load i32, i32* @INADDR_ANY
%20 = tail call i32 @htonl(i32 %19)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %20, i32* %21
%22 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%23 = call i32 @bind(i32 %9, %struct.sockaddr* %22, i32 12)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %14
%26 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @exit(i32 2)
unreachable
28: ; preds = %14
%29 = call i32 @listen(i32 %9, i32 10)
%30 = call i32 @accept(i32 %9, i32* null, i32* null)
%31 = icmp slt i32 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %28, %43
%33 = phi i32 [ %45, %43 ], [ %30, %28 ]
%34 = call i32 @recv(i32 %33, i8* %6, i32 1024, i32 0)
%35 = icmp slt i32 %34, 1
br i1 %35, label %43, label %39
36: ; preds = %43, %28
%37 = call i32 @perror(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 @exit(i32 3)
unreachable
39: ; preds = %32, %39
%40 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%41 = call i32 @recv(i32 %33, i8* %6, i32 1024, i32 0)
%42 = icmp slt i32 %41, 1
br i1 %42, label %43, label %39
43: ; preds = %39, %32
%44 = call i32 @close(i32 %33)
%45 = call i32 @accept(i32 %9, i32* null, i32* null)
%46 = icmp slt i32 %45, 0
br i1 %46, label %36, label %32
}