#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 int32_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ MSG_WAITALL;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int ntohl(int);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, int *, int, int /*<<< orphan*/);
int send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int strlen(char *);
int main() {
  int c, cod;
  int32_t r;
  struct sockaddr_in server;
  char s[100];
  c = socket(PF_INET, SOCK_STREAM, 0);
  if (c < 0) {
    fprintf(stderr, "Eroare la creare socket client.\n");
    return 1;
  }
  memset(&server, 0, sizeof(struct sockaddr_in));
  server.sin_family = AF_INET;
  server.sin_port = htons(4321);
  server.sin_addr.s_addr = inet_addr("127.0.0.1");
  cod = connect(c, (struct sockaddr *)&server, sizeof(struct sockaddr_in));
  if (cod < 0) {
    fprintf(stderr, "Eroare la conectarea la server.\n");
    return 1;
  }
  printf("Dati o fraza pentru trimis la server: ");
  fgets(s, 100, stdin);
  cod = send(c, s, strlen(s) + 1, 0);
  if (cod != strlen(s) + 1) {
    fprintf(stderr, "Eroare la trimiterea datelor la server.\n");
    return 1;
  }
  cod = recv(c, &r, sizeof(int32_t), MSG_WAITALL);
  r = ntohl(r);
  if (cod != sizeof(int)) {
    fprintf(stderr, "Eroare la primirea datelor de la client.\n");
    return 1;
  }
  printf("Serverul a returnat %d caractere spatiu in sirul trimis.\n", r);
  close(c);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
mov    0x2dd6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1229 <main+0x59>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
lea    0xde8(%rip),%rsi
call   10c0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c0 <main+0x1f0>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x10e1,%edi
call   1050 <htons@plt>
mov    %eax,-0x1c(%rbp)
lea    0xdc8(%rip),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    12a0 <main+0xd0>
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
lea    0xd9c(%rip),%rsi
call   10c0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c0 <main+0x1f0>
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x90(%rbp),%rdi
mov    0x2d24(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   10a0 <fgets@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0xa4(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0xa0(%rbp)
lea    -0x90(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xa4(%rbp),%edi
mov    -0xa0(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x94(%rbp)
lea    -0x90(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x94(%rbp),%eax
add    $0x1,%ecx
cmp    %ecx,%eax
je     1350 <main+0x180>
mov    0x2c9a(%rip),%rax
mov    (%rax),%edi
lea    0xd34(%rip),%rsi
call   10c0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c0 <main+0x1f0>
mov    -0x8(%rbp),%edi
mov    0x2c56(%rip),%rax
mov    (%rax),%ecx
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1030 <recv@plt>
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
call   10e0 <ntohl@plt>
mov    %eax,-0x10(%rbp)
movslq -0xc(%rbp),%rax
cmp    $0x4,%rax
je     13a7 <main+0x1d7>
mov    0x2c43(%rip),%rax
mov    (%rax),%edi
lea    0xd06(%rip),%rsi
call   10c0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c0 <main+0x1f0>
mov    -0x10(%rbp),%esi
lea    0xd15(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%edi
call   1090 <close@plt>
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x90,%rsp
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
test   %eax,%eax
js     12ee <main+0x11e>
mov    %eax,%ebx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2dcf(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    $0x10e1,%edi
call   1050 <htons@plt>
mov    %eax,0x14(%rsp)
lea    0xded(%rip),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,0x10(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
test   %eax,%eax
js     1300 <main+0x130>
lea    0xdf1(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2d77(%rip),%rax
mov    (%rax),%edx
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    $0x64,%esi
call   10a0 <fgets@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edx
mov    %ebx,%edi
mov    %r14,%rsi
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cmp    %eax,%ebp
jne    1312 <main+0x142>
mov    0x2d04(%rip),%rax
mov    (%rax),%ecx
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <recv@plt>
mov    %eax,%ebp
mov    0xc(%rsp),%edi
call   10e0 <ntohl@plt>
mov    %eax,0xc(%rsp)
cmp    $0x4,%ebp
jne    1324 <main+0x154>
lea    0xdec(%rip),%rdi
xor    %ebp,%ebp
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebx,%edi
call   1090 <close@plt>
jmp    133e <main+0x16e>
mov    0x2cdb(%rip),%rax
mov    (%rax),%edi
lea    0xd02(%rip),%rsi
jmp    1334 <main+0x164>
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
lea    0xd1b(%rip),%rsi
jmp    1334 <main+0x164>
mov    0x2cb7(%rip),%rax
mov    (%rax),%edi
lea    0xd51(%rip),%rsi
jmp    1334 <main+0x164>
mov    0x2ca5(%rip),%rax
mov    (%rax),%edi
lea    0xd68(%rip),%rsi
call   10c0 <fprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [33 x i8] c"Eroare la creare socket client.\0A\00"
@AF_INET = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [33 x i8] c"Eroare la conectarea la server.\0A\00"
@.str.3 = [39 x i8] c"Dati o fraza pentru trimis la server: \00"
@stdin = global i32 0
@.str.4 = [41 x i8] c"Eroare la trimiterea datelor la server.\0A\00"
@MSG_WAITALL = global i32 0
@.str.5 = [42 x i8] c"Eroare la primirea datelor de la client.\0A\00"
@.str.6 = [58 x i8] c"Serverul a returnat %d caractere spatiu in sirul trimis.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca [100 x i8]
store i32 0, i32* %1
%7 = load i32, i32* @PF_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 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %68
15: ; preds = %0
%16 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 12)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %17, i32* %18
%19 = call i32 @htons(i32 4321)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
store i32 %19, i32* %20
%21 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%23 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %22, i32 0, i32 0
store i32 %21, i32* %23
%24 = load i32, i32* %2
%25 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%26 = call i32 @connect(i32 %24, %struct.sockaddr* %25, i32 12)
store i32 %26, i32* %3
%27 = load i32, i32* %3
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %15
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %68
32: ; preds = %15
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%35 = load i32, i32* @stdin
%36 = call i32 @fgets(i8* %34, i32 100, i32 %35)
%37 = load i32, i32* %2
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%39 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%40 = call i32 @strlen(i8* %39)
%41 = add nsw i32 %40, 1
%42 = call i32 @send(i32 %37, i8* %38, i32 %41, i32 0)
store i32 %42, i32* %3
%43 = load i32, i32* %3
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%45 = call i32 @strlen(i8* %44)
%46 = add nsw i32 %45, 1
%47 = icmp ne i32 %43, %46
br i1 %47, label %48, label %51
48: ; preds = %32
%49 = load i32, i32* @stderr
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %1
br label %68
51: ; preds = %32
%52 = load i32, i32* %2
%53 = load i32, i32* @MSG_WAITALL
%54 = call i32 @recv(i32 %52, i32* %4, i32 4, i32 %53)
store i32 %54, i32* %3
%55 = load i32, i32* %4
%56 = call i32 @ntohl(i32 %55)
store i32 %56, i32* %4
%57 = load i32, i32* %3
%58 = sext i32 %57 to i64
%59 = icmp ne i64 %58, 4
br i1 %59, label %60, label %63
60: ; preds = %51
%61 = load i32, i32* @stderr
%62 = call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %1
br label %68
63: ; preds = %51
%64 = load i32, i32* %4
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.6, i64 0, i64 0), i32 %64)
%66 = load i32, i32* %2
%67 = call i32 @close(i32 %66)
br label %68
68: ; preds = %63, %60, %48, %29, %12
%69 = load i32, i32* %1
ret i32 %69
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [33 x i8] c"Eroare la creare socket client.\0A\00"
@AF_INET = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [33 x i8] c"Eroare la conectarea la server.\0A\00"
@.str.3 = [39 x i8] c"Dati o fraza pentru trimis la server: \00"
@stdin = global i32 0
@.str.4 = [41 x i8] c"Eroare la trimiterea datelor la server.\0A\00"
@MSG_WAITALL = global i32 0
@.str.5 = [42 x i8] c"Eroare la primirea datelor de la client.\0A\00"
@.str.6 = [58 x i8] c"Serverul a returnat %d caractere spatiu in sirul trimis.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca [100 x i8]
%4 = bitcast i32* %1 to i8*
%5 = bitcast %struct.sockaddr_in* %2 to i8*
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @PF_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 = %0
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %53
14: ; preds = %0
%15 = call i32 @memset(%struct.sockaddr_in* %2, i32 0, i32 12)
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %16, i32* %17
%18 = call i32 @htons(i32 4321)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %18, i32* %19
%20 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0, i32 0
store i32 %20, i32* %21
%22 = bitcast %struct.sockaddr_in* %2 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 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %53
28: ; preds = %14
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
%30 = load i32, i32* @stdin
%31 = call i32 @fgets(i8* %6, i32 100, i32 %30)
%32 = call i32 @strlen(i8* %6)
%33 = add nsw i32 %32, 1
%34 = call i32 @send(i32 %9, i8* %6, i32 %33, i32 0)
%35 = call i32 @strlen(i8* %6)
%36 = add nsw i32 %35, 1
%37 = icmp eq i32 %34, %36
br i1 %37, label %41, label %38
38: ; preds = %28
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0))
br label %53
41: ; preds = %28
%42 = load i32, i32* @MSG_WAITALL
%43 = call i32 @recv(i32 %9, i32* %1, i32 4, i32 %42)
%44 = load i32, i32* %1
%45 = call i32 @ntohl(i32 %44)
store i32 %45, i32* %1
%46 = icmp eq i32 %43, 4
br i1 %46, label %50, label %47
47: ; preds = %41
%48 = load i32, i32* @stderr
%49 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0))
br label %53
50: ; preds = %41
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.6, i64 0, i64 0), i32 %45)
%52 = call i32 @close(i32 %9)
br label %53
53: ; preds = %50, %47, %38, %25, %11
%54 = phi i32 [ 1, %11 ], [ 1, %25 ], [ 1, %38 ], [ 1, %47 ], [ 0, %50 ]
ret i32 %54
}