#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_family;
  int /*<<< orphan*/ sin_port;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ server;
typedef int /*<<< orphan*/ msg;
typedef int /*<<< orphan*/ backMsg;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
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*/ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int strlen(char *);
int main() {
  int c;
  struct sockaddr_in server;
  char msg[256];
  char ccc;
  c = socket(AF_INET, SOCK_STREAM, 0);
  if (c < 0) {
    printf("Eroare la crearea socketului...\n");
    ;
    return 1;
  }
  memset(&server, 0, sizeof(server));
  server.sin_port = htons(5432);
  server.sin_family = AF_INET;
  server.sin_addr.s_addr = inet_addr("172.30.113.3");
  if (connect(c, (struct sockaddr *)&server, sizeof(server)) < 0) {
    printf("Eroare la conectare...\n");
    return 1;
  }
  while (1) {
    char backMsg[256];
    bzero(backMsg, 256);
    recv(c, &backMsg, sizeof(backMsg), 0);
    printf("Raspuns: %s\n", backMsg);
    printf("Mesaj: ");
    bzero(msg, 256);
    fgets(msg, sizeof(msg), stdin);
    send(c, msg, strlen(msg) * sizeof(char), 0);
  }
  close(c);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1202 <main+0x52>
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1334 <main+0x184>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    $0x1538,%edi
call   1050 <htons@plt>
mov    %eax,-0x10(%rbp)
mov    0x2dc2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
lea    0xdef(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <connect@plt>
cmp    $0x0,%rax
jge    126f <main+0xbf>
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1334 <main+0x184>
jmp    1274 <main+0xc4>
lea    -0x230(%rbp),%rdi
mov    $0x100,%esi
call   10b0 <bzero@plt>
mov    -0x8(%rbp),%edi
lea    -0x230(%rbp),%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    -0x230(%rbp),%rsi
lea    0xd9d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xd9c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x120(%rbp),%rdi
mov    $0x100,%esi
call   10b0 <bzero@plt>
lea    -0x120(%rbp),%rdi
mov    0x2d03(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1090 <fgets@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x244(%rbp)
lea    -0x120(%rbp),%rax
mov    %rax,-0x240(%rbp)
lea    -0x120(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x244(%rbp),%edi
mov    -0x240(%rbp),%rsi
cltq
shl    $0x0,%rax
mov    %rax,-0x238(%rbp)
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
jmp    1274 <main+0xc4>
mov    -0x4(%rbp),%eax
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    0x2e10(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
test   %eax,%eax
js     12dd <main+0x11d>
mov    %eax,%r12d
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1090 <memset@plt>
mov    $0x1538,%edi
call   1060 <htons@plt>
mov    %eax,0x8(%rsp)
mov    0x0(%rbp),%eax
mov    %eax,0x4(%rsp)
lea    0xddc(%rip),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,(%rsp)
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
test   %rax,%rax
js     12e6 <main+0x126>
lea    0x10(%rsp),%rbx
lea    0xdbc(%rip),%r14
lea    0xdc2(%rip),%r15
lea    0x110(%rsp),%rbp
mov    0x2d79(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x100,%esi
call   10c0 <bzero@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbp,%rdi
mov    $0x100,%esi
call   10c0 <bzero@plt>
mov    0x0(%r13),%edx
mov    %rbp,%rdi
mov    $0x100,%esi
call   10a0 <fgets@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
jmp    1270 <main+0xb0>
lea    0xd55(%rip),%rdi
jmp    12ed <main+0x12d>
lea    0xd35(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
add    $0x218,%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, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [33 x i8] c"Eroare la crearea socketului...\0A\00"
@.str.1 = [13 x i8] c"172.30.113.3\00"
@.str.2 = [24 x i8] c"Eroare la conectare...\0A\00"
@.str.3 = [13 x i8] c"Raspuns: %s\0A\00"
@.str.4 = [8 x i8] c"Mesaj: \00"
@stdin = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca [256 x i8]
%5 = alloca i8
%6 = alloca [256 x i8]
store i32 0, i32* %1
%7 = load i32, i32* @AF_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 %14
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %52
14: ; preds = %0
%15 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%16 = call i32 @htons(i32 5432)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %16, i32* %17
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %18, i32* %19
%20 = call i32 @inet_addr(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
store i32 %20, i32* %22
%23 = load i32, i32* %2
%24 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%25 = call i64 @connect(i32 %23, %struct.sockaddr* %24, i32 12)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %14
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %52
29: ; preds = %14
br label %30
30: ; preds = %29, %30
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%32 = call i32 @bzero(i8* %31, i32 256)
%33 = load i32, i32* %2
%34 = bitcast [256 x i8]* %6 to i8**
%35 = call i32 @recv(i32 %33, i8** %34, i32 256, i32 0)
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %36)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%40 = call i32 @bzero(i8* %39, i32 256)
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%42 = load i32, i32* @stdin
%43 = call i32 @fgets(i8* %41, i32 256, i32 %42)
%44 = load i32, i32* %2
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%47 = call i32 @strlen(i8* %46)
%48 = sext i32 %47 to i64
%49 = mul i64 %48, 1
%50 = trunc i64 %49 to i32
%51 = call i32 @send(i32 %44, i8* %45, i32 %50, i32 0)
br label %30
52: ; preds = %27, %12
%53 = load i32, i32* %1
ret i32 %53
}

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.1 = [13 x i8] c"172.30.113.3\00"
@.str.3 = [13 x i8] c"Raspuns: %s\0A\00"
@.str.4 = [8 x i8] c"Mesaj: \00"
@stdin = global i32 0
@str = [23 x i8] c"Eroare la conectare...\00"
@str.5 = [32 x i8] c"Eroare la crearea socketului...\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [256 x i8]
%3 = alloca [256 x i8]
%4 = bitcast %struct.sockaddr_in* %1 to i8*
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_STREAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.5, i64 0, i64 0))
br label %38
12: ; preds = %0
%13 = call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 12)
%14 = call i32 @htons(i32 5432)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %14, i32* %15
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %16, i32* %17
%18 = call i32 @inet_addr(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %18, i32* %19
%20 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%21 = call i64 @connect(i32 %8, %struct.sockaddr* %20, i32 12)
%22 = icmp slt i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %12
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%25 = bitcast [256 x i8]* %3 to i8**
br label %28
26: ; preds = %12
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %38
28: ; preds = %23, %28
%29 = call i32 @bzero(i8* %24, i32 256)
%30 = call i32 @recv(i32 %8, i8** %25, i32 256, i32 0)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %24)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%33 = call i32 @bzero(i8* %5, i32 256)
%34 = load i32, i32* @stdin
%35 = call i32 @fgets(i8* %5, i32 256, i32 %34)
%36 = call i32 @strlen(i8* %5)
%37 = call i32 @send(i32 %8, i8* %5, i32 %36, i32 0)
br label %28
38: ; preds = %26, %10
ret i32 1
}