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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_LOOPBACK;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int sendall(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char const *argv[]) {
  int sock, conneting, sending;
  struct sockaddr_in addr;
  char msg[] = "Test\n";
  sock = socket(AF_INET, SOCK_STREAM, 0);
  if (sock < 0) {
    perror("Ошибка создания сокета!");
    exit(1);
  }
  addr.sin_family = AF_INET;
  addr.sin_port = htons(3424);
  addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  conneting = connect(sock, (struct sockaddr *)&addr, sizeof(addr));
  if (conneting < 0) {
    perror("Ошибка подключения");
    exit(2);
  }
  while (1) {
    sending = sendall(sock, msg, sizeof(msg), 0);
    if (sending > 0) {
      printf("Успешная передача!\n");
    }
    sleep(1);
  }
  close(sock);
  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    0xe54(%rip),%eax
mov    %eax,-0x2e(%rbp)
mov    0xe4e(%rip),%ax
mov    %ax,-0x2a(%rbp)
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
mov    0x2e06(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11f6 <main+0x66>
lea    0xe1f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2deb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    $0xd60,%edi
call   1030 <htons@plt>
mov    %eax,-0x24(%rbp)
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1254 <main+0xc4>
lea    0xded(%rip),%rdi
call   1070 <perror@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
jmp    1259 <main+0xc9>
mov    -0x14(%rbp),%edi
lea    -0x2e(%rbp),%rsi
mov    $0x6,%edx
xor    %ecx,%ecx
call   1060 <sendall@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    1285 <main+0xf5>
lea    0xdd6(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
jmp    1259 <main+0xc9>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
movw   $0xa,0xc(%rsp)
movl   $0x74736554,0x8(%rsp)
74
mov    0x2e39(%rip),%r14
mov    (%r14),%edi
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
test   %eax,%eax
js     1249 <main+0xb9>
mov    %eax,%ebx
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
mov    $0xd60,%edi
call   1040 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1090 <connect@plt>
test   %eax,%eax
js     125f <main+0xcf>
lea    0x8(%rsp),%r14
lea    0xe42(%rip),%r15
jmp    122a <main+0x9a>
cs nopw 0x0(%rax,%rax,1)
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x6,%edx
xor    %ecx,%ecx
call   1060 <sendall@plt>
test   %eax,%eax
jle    1220 <main+0x90>
mov    %r15,%rdi
call   1030 <puts@plt>
jmp    1220 <main+0x90>
lea    0xdb6(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xdcc(%rip),%rdi
call   1070 <perror@plt>
mov    $0x2,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.msg = [6 x i8] c"Test\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [44 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_LOOPBACK = global i32 0
@.str.1 = [36 x i8] c"\D0\9E\D1\88\D0\B8\D0\B1\D0\BA\D0\B0 \D0\BF\D0\BE\D0\B4\D0\BA\D0\BB\D1\8E\D1\87\D0\B5\D0\BD\D0\B8\D1\8F\00"
@.str.2 = [36 x i8] c"\D0\A3\D1\81\D0\BF\D0\B5\D1\88\D0\BD\D0\B0\D1\8F \D0\BF\D0\B5\D1\80\D0\B5\D0\B4\D0\B0\D1\87\D0\B0!\0A\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 %struct.sockaddr_in
%10 = alloca [6 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [6 x i8]* %10 to i8*
%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* %6
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 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* %9, i32 0, i32 2
store i32 %21, i32* %22
%23 = call i32 @htons(i32 3424)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i32 %23, i32* %24
%25 = load i32, i32* @INADDR_LOOPBACK
%26 = call i32 @htonl(i32 %25)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, 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* %6
%30 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%31 = call i32 @connect(i32 %29, %struct.sockaddr* %30, i32 12)
store i32 %31, i32* %7
%32 = load i32, i32* %7
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %20
%35 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%36 = call i32 @exit(i32 2)
unreachable
37: ; preds = %20
br label %38
38: ; preds = %37, %46
%39 = load i32, i32* %6
%40 = getelementptr inbounds [6 x i8], [6 x i8]* %10, i64 0, i64 0
%41 = call i32 @sendall(i32 %39, i8* %40, i32 6, i32 0)
store i32 %41, i32* %8
%42 = load i32, i32* %8
%43 = icmp sgt i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %38
%45 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
br label %46
46: ; preds = %44, %38
%47 = call i32 @sleep(i32 1)
br label %38
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.msg = [6 x i8] c"Test\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [44 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_LOOPBACK = global i32 0
@.str.1 = [36 x i8] c"\D0\9E\D1\88\D0\B8\D0\B1\D0\BA\D0\B0 \D0\BF\D0\BE\D0\B4\D0\BA\D0\BB\D1\8E\D1\87\D0\B5\D0\BD\D0\B8\D1\8F\00"
@str = [35 x i8] c"\D0\A3\D1\81\D0\BF\D0\B5\D1\88\D0\BD\D0\B0\D1\8F \D0\BF\D0\B5\D1\80\D0\B5\D0\B4\D0\B0\D1\87\D0\B0!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [6 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [6 x i8], [6 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 ([44 x i8], [44 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_LOOPBACK
%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 @connect(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 ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @exit(i32 2)
unreachable
28: ; preds = %14, %33
%29 = call i32 @sendall(i32 %9, i8* %6, i32 6, i32 0)
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
br label %33
33: ; preds = %31, %28
%34 = call i32 @sleep(i32 1)
br label %28
}