#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 char 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;
typedef int /*<<< orphan*/ str;
typedef int /*<<< orphan*/ server;
typedef int /*<<< orphan*/ matchList;
typedef int /*<<< orphan*/ match;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ calloc(char, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
void *htons(char);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ recv(int, char **, int, int /*<<< orphan*/);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
char strlen(char *);
int main() {
  int c;
  struct sockaddr_in server;
  char str[100], match, *matchList;
  uint16_t str_size;
  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(1234);
  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);
  matchList = (char *)calloc(str_size, sizeof(char));
  printf("char:");
  scanf("%c", &match);
  str_size = htons(str_size);
  send(c, &str_size, sizeof(str_size), 0);
  send(c, str, sizeof(str), 0);
  send(c, &match, sizeof(match), 0);
  recv(c, &matchList, sizeof(matchList), 0);
  close(c);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
mov    0x2dde(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1220 <main+0x50>
lea    0xdf1(%rip),%rdi
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1364 <main+0x194>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
mov    $0xffffffd2,%edi
call   1050 <htons@plt>
mov    %rax,-0x10(%rbp)
mov    0x2da3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
lea    0xdd4(%rip),%rdi
call   10c0 <inet_addr@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   10e0 <connect@plt>
cmp    $0x0,%rax
jge    128c <main+0xbc>
lea    0xdb4(%rip),%rdi
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1364 <main+0x194>
lea    0xdbc(%rip),%rdi
call   1070 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2d3d(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   10a0 <fgets@plt>
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    %al,-0x91(%rbp)
mov    $0x1,%esi
movsbl -0x91(%rbp),%edi
call   10b0 <calloc@plt>
mov    %rax,-0x90(%rbp)
lea    0xd7a(%rip),%rdi
call   1070 <printf@plt>
lea    0xd74(%rip),%rdi
lea    -0x81(%rbp),%rsi
call   10d0 <scanf@plt>
movsbl -0x91(%rbp),%edi
call   1050 <htons@plt>
mov    %al,-0x91(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x91(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    -0x8(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    -0x8(%rbp),%edi
lea    -0x81(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    -0x8(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x8,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
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   %r12
push   %rbx
sub    $0x90,%rsp
mov    0x2df2(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
test   %eax,%eax
js     1325 <main+0x145>
mov    %eax,%ebp
lea    0x10(%rsp),%r14
xor    %r15d,%r15d
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1090 <memset@plt>
mov    $0xffffffd2,%edi
call   1060 <htons@plt>
mov    %rax,0x18(%rsp)
mov    (%rbx),%eax
mov    %eax,0x14(%rsp)
lea    0xdbb(%rip),%rdi
call   10d0 <inet_addr@plt>
mov    %eax,0x10(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x10,%edx
call   10f0 <connect@plt>
test   %rax,%rax
js     132e <main+0x14e>
lea    0xd9d(%rip),%rdi
call   1080 <printf@plt>
mov    0x2d67(%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>
movsbl %al,%ebx
mov    %ebx,%edi
mov    $0x1,%esi
call   10c0 <calloc@plt>
mov    %rax,0x8(%rsp)
lea    0xd62(%rip),%rdi
call   1080 <printf@plt>
lea    0xd5c(%rip),%rdi
lea    0x7(%rsp),%r12
mov    %r12,%rsi
call   10e0 <scanf@plt>
mov    %ebx,%edi
call   1060 <htons@plt>
mov    %al,0x6(%rsp)
lea    0x6(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x8,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %ebp,%edi
call   10a0 <close@plt>
jmp    1340 <main+0x160>
lea    0xd0e(%rip),%rdi
jmp    1335 <main+0x155>
lea    0xce6(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x90,%rsp
pop    %rbx
pop    %r12
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"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca [100 x i8]
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i8
store i32 0, i32* %1
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = call i32 @socket(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %56
15: ; preds = %0
%16 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 16)
%17 = call i8* @htons(i8 signext -46)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i8* %17, i8** %18
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, 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* %3, 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* %3 to %struct.sockaddr*
%26 = call i64 @connect(i32 %24, %struct.sockaddr* %25, i32 16)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %15
%29 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %56
30: ; preds = %15
%31 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%33 = load i32, i32* @stdin
%34 = call i32 @fgets(i8* %32, i32 100, i32 %33)
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%36 = call signext i8 @strlen(i8* %35)
store i8 %36, i8* %7
%37 = load i8, i8* %7
%38 = call i64 @calloc(i8 signext %37, i32 1)
%39 = inttoptr i64 %38 to i8*
store i8* %39, i8** %6
%40 = call i32 @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 i8, i8* %7
%43 = call i8* @htons(i8 signext %42)
%44 = ptrtoint i8* %43 to i8
store i8 %44, i8* %7
%45 = load i32, i32* %2
%46 = call i32 @send(i32 %45, i8* %7, i32 1, i32 0)
%47 = load i32, i32* %2
%48 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%49 = call i32 @send(i32 %47, i8* %48, i32 100, i32 0)
%50 = load i32, i32* %2
%51 = call i32 @send(i32 %50, i8* %5, i32 1, i32 0)
%52 = load i32, i32* %2
%53 = call i32 @recv(i32 %52, i8** %6, i32 8, i32 0)
%54 = load i32, i32* %2
%55 = call i32 @close(i32 %54)
br label %56
56: ; preds = %30, %28, %13
%57 = load i32, i32* %1
ret i32 %57
}

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 = [31 x i8] c"Eroare la conectarea la server\00"
@str.6 = [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 i8*
%5 = alloca i8
%6 = bitcast %struct.sockaddr_in* %1 to i8*
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%8 = bitcast i8** %4 to i8*
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.6, i64 0, i64 0))
br label %45
15: ; preds = %0
%16 = call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 16)
%17 = call i8* @htons(i8 signext -46)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i8* %17, i8** %18
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 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* %1, i64 0, i32 0, i32 0
store i32 %21, i32* %22
%23 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%24 = call i64 @connect(i32 %11, %struct.sockaddr* %23, i32 16)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %15
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
br label %45
28: ; preds = %15
%29 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%30 = load i32, i32* @stdin
%31 = call i32 @fgets(i8* %7, i32 100, i32 %30)
%32 = call signext i8 @strlen(i8* %7)
%33 = call i64 @calloc(i8 signext %32, i32 1)
%34 = inttoptr i64 %33 to i8*
store i8* %34, i8** %4
%35 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%36 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %3)
%37 = call i8* @htons(i8 signext %32)
%38 = ptrtoint i8* %37 to i64
%39 = trunc i64 %38 to i8
store i8 %39, i8* %5
%40 = call i32 @send(i32 %11, i8* %5, i32 1, i32 0)
%41 = call i32 @send(i32 %11, i8* %7, i32 100, i32 0)
%42 = call i32 @send(i32 %11, i8* %3, i32 1, i32 0)
%43 = call i32 @recv(i32 %11, i8** %4, i32 8, i32 0)
%44 = call i32 @close(i32 %11)
br label %45
45: ; preds = %28, %26, %13
%46 = phi i32 [ 1, %13 ], [ 1, %26 ], [ 0, %28 ]
ret i32 %46
}