#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;
typedef int /*<<< orphan*/ suma;
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*/ server;
typedef int /*<<< orphan*/ b;
typedef int /*<<< orphan*/ a;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
void *htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int ntohs(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ recv(int, int *, int, int /*<<< orphan*/);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ send(int, int *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main() {
  int c;
  struct sockaddr_in server;
  uint16_t a, b, suma;
  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("a = ");
  scanf("%hu", &a);
  printf("b = ");
  scanf("%hu", &b);
  a = htons(a);
  b = htons(b);
  send(c, &a, sizeof(a), 0);
  send(c, &b, sizeof(b), 0);
  recv(c, &suma, sizeof(suma), 0);
  suma = ntohs(suma);
  printf("Suma este %hu\n", suma);
  close(c);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
mov    0x2e09(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11ff <main+0x4f>
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    131c <main+0x16c>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <memset@plt>
mov    $0x4d2,%edi
call   1040 <htons@plt>
mov    %rax,-0x10(%rbp)
mov    0x2dc4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
lea    0xdf5(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   10c0 <connect@plt>
cmp    $0x0,%rax
jge    126d <main+0xbd>
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    131c <main+0x16c>
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xdd2(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   10b0 <scanf@plt>
lea    0xdc6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xdb4(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   10b0 <scanf@plt>
mov    -0x1c(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    -0x8(%rbp),%edi
lea    -0x24(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    -0x24(%rbp),%edi
call   10a0 <ntohs@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xd50(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%edi
call   1080 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    0x2e15(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dfc(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
test   %eax,%eax
js     12fb <main+0x13b>
mov    %eax,%ebp
lea    0x10(%rsp),%r14
xor    %r12d,%r12d
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
mov    $0x4d2,%edi
call   1050 <htons@plt>
mov    %rax,0x18(%rsp)
mov    (%rbx),%eax
mov    %eax,0x14(%rsp)
lea    0xdde(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0x10(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x10,%edx
call   10d0 <connect@plt>
test   %rax,%rax
js     1304 <main+0x144>
lea    0xdc0(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xdb7(%rip),%rbx
lea    0xc(%rsp),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   10c0 <scanf@plt>
lea    0xda4(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x8(%rsp),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   10c0 <scanf@plt>
mov    0xc(%rsp),%edi
call   1050 <htons@plt>
mov    %eax,0xc(%rsp)
mov    0x8(%rsp),%edi
call   1050 <htons@plt>
mov    %eax,0x8(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
lea    0x4(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    0x4(%rsp),%edi
call   10b0 <ntohs@plt>
mov    %eax,0x4(%rsp)
lea    0xd2f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebp,%edi
call   1090 <close@plt>
jmp    1316 <main+0x156>
lea    0xd44(%rip),%rdi
jmp    130b <main+0x14b>
lea    0xd1c(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r12d
mov    %r12d,%eax
add    $0x20,%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 = [5 x i8] c"a = \00"
@.str.4 = [4 x i8] c"%hu\00"
@.str.5 = [5 x i8] c"b = \00"
@.str.6 = [15 x i8] c"Suma este %hu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
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 ([37 x i8], [37 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 16)
%16 = call i8* @htons(i32 1234)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i8* %16, i8** %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 ([10 x i8], [10 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 16)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %14
%28 = 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 %52
29: ; preds = %14
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %4)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%33 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %5)
%34 = load i32, i32* %4
%35 = call i8* @htons(i32 %34)
%36 = ptrtoint i8* %35 to i32
store i32 %36, i32* %4
%37 = load i32, i32* %5
%38 = call i8* @htons(i32 %37)
%39 = ptrtoint i8* %38 to i32
store i32 %39, i32* %5
%40 = load i32, i32* %2
%41 = call i32 @send(i32 %40, i32* %4, i32 4, i32 0)
%42 = load i32, i32* %2
%43 = call i32 @send(i32 %42, i32* %5, i32 4, i32 0)
%44 = load i32, i32* %2
%45 = call i32 @recv(i32 %44, i32* %6, i32 4, i32 0)
%46 = load i32, i32* %6
%47 = call i32 @ntohs(i32 %46)
store i32 %47, i32* %6
%48 = load i32, i32* %6
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %48)
%50 = load i32, i32* %2
%51 = call i32 @close(i32 %50)
br label %52
52: ; preds = %29, %27, %12
%53 = load i32, i32* %1
ret i32 %53
}

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 = [5 x i8] c"a = \00"
@.str.4 = [4 x i8] c"%hu\00"
@.str.5 = [5 x i8] c"b = \00"
@.str.6 = [15 x i8] c"Suma este %hu\0A\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 i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast %struct.sockaddr_in* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %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.7, i64 0, i64 0))
br label %48
15: ; preds = %0
%16 = call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 16)
%17 = call i8* @htons(i32 1234)
%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 %48
28: ; preds = %15
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%30 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %2)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%32 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32* %3)
%33 = load i32, i32* %2
%34 = call i8* @htons(i32 %33)
%35 = ptrtoint i8* %34 to i64
%36 = trunc i64 %35 to i32
store i32 %36, i32* %2
%37 = load i32, i32* %3
%38 = call i8* @htons(i32 %37)
%39 = ptrtoint i8* %38 to i64
%40 = trunc i64 %39 to i32
store i32 %40, i32* %3
%41 = call i32 @send(i32 %11, i32* %2, i32 4, i32 0)
%42 = call i32 @send(i32 %11, i32* %3, i32 4, i32 0)
%43 = call i32 @recv(i32 %11, i32* %4, i32 4, i32 0)
%44 = load i32, i32* %4
%45 = call i32 @ntohs(i32 %44)
store i32 %45, i32* %4
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %45)
%47 = call i32 @close(i32 %11)
br label %48
48: ; preds = %28, %26, %13
%49 = phi i32 [ 1, %13 ], [ 1, %26 ], [ 0, %28 ]
ret i32 %49
}