#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 */
typedef int uint16_t;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
  void *sin_port;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ str_size_c;
typedef int /*<<< orphan*/ server;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
void *htons(int);
int /*<<< orphan*/ inet_addr(char *);
scalar_t__ malloc(unsigned int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
unsigned int ntohs(unsigned int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ recv(int, unsigned int *, int, int /*<<< orphan*/);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ send(int, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int strlen(char *);
int main() {
  int c;
  struct sockaddr_in server;
  char str[100], match;
  unsigned int *matchList, match_size;
  uint16_t str_size, str_size_c;
  c = socket(AF_INET, SOCK_STREAM, 0);
  if (c < 0) {
    printf("Eroare la crearea socketului client\n");
    return 1;
  }
  memset(&server, 0, sizeof(server));
  server.sin_port = htons(2018);
  server.sin_family = AF_INET;
  server.sin_addr.s_addr = inet_addr("127.0.0.1");
  if (connect(c, (struct sockaddr *)&server, sizeof(server)) < 0) {
    printf("Eroare la conectarea la server\n");
    return 1;
  }
  printf("string:");
  fgets(str, 100, stdin);
  str_size = strlen(str);
  printf("char:");
  scanf("%c", &match);
  str_size_c = str_size;
  str_size = htons(str_size);
  send(c, &str_size, sizeof(str_size_c), 0);
  send(c, str, sizeof(char) * str_size_c, 0);
  send(c, &match, sizeof(char), 0);
  recv(c, &match_size, sizeof(unsigned int), 0);
  match_size = ntohs(match_size);
  matchList = (unsigned int *)malloc(match_size * sizeof(unsigned int));
  recv(c, matchList, sizeof(unsigned int) * match_size, 0);
  for (int i = 0; i < match_size; i++) {
    printf("%u ", matchList[i]);
  }
  close(c);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2def(%rip),%rax
mov    (%rax),%edi
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1232 <main+0x52>
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1410 <main+0x230>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
mov    $0x7e2,%edi
call   1050 <htons@plt>
mov    %rax,-0x10(%rbp)
mov    0x2d91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
lea    0xdc2(%rip),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   10f0 <connect@plt>
cmp    $0x0,%rax
jge    12a0 <main+0xc0>
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1410 <main+0x230>
lea    0xda8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2d27(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   10a0 <fgets@plt>
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x98(%rbp)
lea    0xd7c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xd74(%rip),%rdi
lea    -0x81(%rbp),%rsi
call   10e0 <scanf@plt>
mov    -0x98(%rbp),%eax
mov    %eax,-0x9c(%rbp)
mov    -0x98(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x98(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x98(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
mov    $0x0,%al
call   1060 <send@plt>
mov    -0x8(%rbp),%edi
lea    -0x80(%rbp),%rsi
movslq -0x9c(%rbp),%rdx
shl    $0x0,%rdx
xor    %ecx,%ecx
mov    $0x0,%al
call   1060 <send@plt>
mov    -0x8(%rbp),%edi
lea    -0x81(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
mov    $0x0,%al
call   1060 <send@plt>
mov    -0x8(%rbp),%edi
lea    -0x94(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    -0x94(%rbp),%edi
call   10d0 <ntohs@plt>
mov    %eax,-0x94(%rbp)
mov    -0x94(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x90(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x90(%rbp),%rsi
mov    -0x94(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
movl   $0x0,-0xa0(%rbp)
mov    -0xa0(%rbp),%eax
cmp    -0x94(%rbp),%eax
jae    1408 <main+0x228>
mov    -0x90(%rbp),%rax
movslq -0xa0(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xc73(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0xa0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa0(%rbp)
jmp    13c3 <main+0x1e3>
mov    -0x8(%rbp),%edi
call   1090 <close@plt>
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    0x2de0(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2dbe(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
test   %eax,%eax
js     1395 <main+0x1a5>
mov    %eax,%r13d
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1090 <memset@plt>
mov    $0x7e2,%edi
call   1060 <htons@plt>
mov    %rax,0x18(%rsp)
mov    0x0(%rbp),%eax
mov    %eax,0x14(%rsp)
lea    0xda9(%rip),%rdi
call   10c0 <inet_addr@plt>
mov    %eax,0x10(%rsp)
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1100 <connect@plt>
test   %rax,%rax
js     139e <main+0x1ae>
lea    0xd8a(%rip),%rdi
xor    %r15d,%r15d
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edx
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    $0x64,%esi
call   10b0 <fgets@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
lea    0xd5c(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xd54(%rip),%rdi
lea    0xb(%rsp),%r12
mov    %r12,%rsi
call   10f0 <scanf@plt>
mov    %ebp,%edi
call   1060 <htons@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
mov    %r13d,%edi
xor    %ecx,%ecx
xor    %eax,%eax
call   1070 <send@plt>
movslq %ebp,%rdx
mov    %r13d,%edi
mov    %r14,%rsi
xor    %ecx,%ecx
xor    %eax,%eax
call   1070 <send@plt>
mov    $0x1,%edx
mov    %r13d,%edi
mov    %r12,%rsi
xor    %ecx,%ecx
xor    %eax,%eax
call   1070 <send@plt>
lea    0x4(%rsp),%rsi
mov    %r13d,%edi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    0x4(%rsp),%edi
call   10e0 <ntohs@plt>
mov    %eax,0x4(%rsp)
lea    0x0(,%rax,4),%edi
call   10d0 <malloc@plt>
mov    %rax,%rbp
mov    0x4(%rsp),%edx
shl    $0x2,%edx
mov    %r13d,%edi
mov    %rax,%rsi
xor    %ecx,%ecx
call   1030 <recv@plt>
cmpl   $0x0,0x4(%rsp)
je     138b <main+0x19b>
lea    0xcb1(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    0x0(%rbp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1080 <printf@plt>
add    $0x1,%rbx
mov    0x4(%rsp),%eax
cmp    %rax,%rbx
jb     1370 <main+0x180>
mov    %r13d,%edi
call   10a0 <close@plt>
jmp    13b0 <main+0x1c0>
lea    0xca2(%rip),%rdi
jmp    13a5 <main+0x1b5>
lea    0xc7a(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [37 x i8] c"Eroare la crearea socketului client\0A\00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [32 x i8] c"Eroare la conectarea la server\0A\00"
@.str.3 = [8 x i8] c"string:\00"
@stdin = global i32 0
@.str.4 = [6 x i8] c"char:\00"
@.str.5 = [3 x i8] c"%c\00"
@.str.6 = [4 x i8] c"%u \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca [100 x i8]
%5 = alloca i8
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %2
%14 = load i32, i32* %2
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %90
18: ; preds = %0
%19 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 16)
%20 = call i8* @htons(i32 2018)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i8* %20, i8** %21
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %22, i32* %23
%24 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %25, i32 0, i32 0
store i32 %24, i32* %26
%27 = load i32, i32* %2
%28 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%29 = call i64 @connect(i32 %27, %struct.sockaddr* %28, i32 16)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %18
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %90
33: ; preds = %18
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%36 = load i32, i32* @stdin
%37 = call i32 @fgets(i8* %35, i32 100, i32 %36)
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%39 = call i32 @strlen(i8* %38)
store i32 %39, i32* %8
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%41 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %5)
%42 = load i32, i32* %8
store i32 %42, i32* %9
%43 = load i32, i32* %8
%44 = call i8* @htons(i32 %43)
%45 = ptrtoint i8* %44 to i32
store i32 %45, i32* %8
%46 = load i32, i32* %2
%47 = call i32 (i32, ...) @send(i32 %46, i32* %8, i64 4, i32 0)
%48 = load i32, i32* %2
%49 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%50 = load i32, i32* %9
%51 = sext i32 %50 to i64
%52 = mul i64 1, %51
%53 = call i32 (i32, ...) @send(i32 %48, i8* %49, i64 %52, i32 0)
%54 = load i32, i32* %2
%55 = call i32 (i32, ...) @send(i32 %54, i8* %5, i64 1, i32 0)
%56 = load i32, i32* %2
%57 = call i32 @recv(i32 %56, i32* %7, i32 4, i32 0)
%58 = load i32, i32* %7
%59 = call i32 @ntohs(i32 %58)
store i32 %59, i32* %7
%60 = load i32, i32* %7
%61 = zext i32 %60 to i64
%62 = mul i64 %61, 4
%63 = trunc i64 %62 to i32
%64 = call i64 @malloc(i32 %63)
%65 = inttoptr i64 %64 to i32*
store i32* %65, i32** %6
%66 = load i32, i32* %2
%67 = load i32*, i32** %6
%68 = load i32, i32* %7
%69 = zext i32 %68 to i64
%70 = mul i64 4, %69
%71 = trunc i64 %70 to i32
%72 = call i32 @recv(i32 %66, i32* %67, i32 %71, i32 0)
store i32 0, i32* %10
br label %73
73: ; preds = %84, %33
%74 = load i32, i32* %10
%75 = load i32, i32* %7
%76 = icmp ult i32 %74, %75
br i1 %76, label %77, label %87
77: ; preds = %73
%78 = load i32*, i32** %6
%79 = load i32, i32* %10
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i32, i32* %78, i64 %80
%82 = load i32, i32* %81
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %82)
br label %84
84: ; preds = %77
%85 = load i32, i32* %10
%86 = add nsw i32 %85, 1
store i32 %86, i32* %10
br label %73
87: ; preds = %73
%88 = load i32, i32* %2
%89 = call i32 @close(i32 %88)
br label %90
90: ; preds = %87, %31, %16
%91 = load i32, i32* %1
ret i32 %91
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.3 = [8 x i8] c"string:\00"
@stdin = global i32 0
@.str.4 = [6 x i8] c"char:\00"
@.str.5 = [3 x i8] c"%c\00"
@.str.6 = [4 x i8] c"%u \00"
@str = [31 x i8] c"Eroare la conectarea la server\00"
@str.7 = [36 x i8] c"Eroare la crearea socketului client\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [100 x i8]
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
%6 = bitcast %struct.sockaddr_in* %1 to i8*
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = tail call i32 @socket(i32 %10, i32 %11, i32 0)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.7, i64 0, i64 0))
br label %65
16: ; preds = %0
%17 = call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 16)
%18 = call i8* @htons(i32 2018)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i8* %18, i8** %19
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %20, i32* %21
%22 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %22, i32* %23
%24 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%25 = call i64 @connect(i32 %12, %struct.sockaddr* %24, i32 16)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %16
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
br label %65
29: ; preds = %16
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%31 = load i32, i32* @stdin
%32 = call i32 @fgets(i8* %7, i32 100, i32 %31)
%33 = call i32 @strlen(i8* %7)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%35 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %3)
%36 = call i8* @htons(i32 %33)
%37 = ptrtoint i8* %36 to i64
%38 = trunc i64 %37 to i32
store i32 %38, i32* %5
%39 = call i32 (i32, ...) @send(i32 %12, i32* %5, i64 4, i32 0)
%40 = sext i32 %33 to i64
%41 = call i32 (i32, ...) @send(i32 %12, i8* %7, i64 %40, i32 0)
%42 = call i32 (i32, ...) @send(i32 %12, i8* %3, i64 1, i32 0)
%43 = call i32 @recv(i32 %12, i32* %4, i32 4, i32 0)
%44 = load i32, i32* %4
%45 = call i32 @ntohs(i32 %44)
store i32 %45, i32* %4
%46 = shl i32 %45, 2
%47 = call i64 @malloc(i32 %46)
%48 = inttoptr i64 %47 to i32*
%49 = load i32, i32* %4
%50 = shl i32 %49, 2
%51 = call i32 @recv(i32 %12, i32* %48, i32 %50, i32 0)
%52 = load i32, i32* %4
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %56, %29
%55 = call i32 @close(i32 %12)
br label %65
56: ; preds = %29, %56
%57 = phi i64 [ %61, %56 ], [ 0, %29 ]
%58 = getelementptr inbounds i32, i32* %48, i64 %57
%59 = load i32, i32* %58
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %59)
%61 = add nuw nsw i64 %57, 1
%62 = load i32, i32* %4
%63 = zext i32 %62 to i64
%64 = icmp ult i64 %61, %63
br i1 %64, label %56, label %54
65: ; preds = %54, %27, %14
%66 = phi i32 [ 1, %14 ], [ 1, %27 ], [ 0, %54 ]
ret i32 %66
}