#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 {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef size_t ssize_t;
typedef int /*<<< orphan*/ server_address;
typedef int in_port_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
size_t recv(int, char *, int, int /*<<< orphan*/);
size_t send(int, char *, size_t, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(int /*<<< orphan*/);
size_t strlen(char *);
int main(int argc, char *argv[]) {
  int sock;
  int ret_val;
  struct sockaddr_in server_address;
  ssize_t num_bytes;
  unsigned int total_byte_receveid = 0;
  if (argc < 3 || argc > 4) {
    fprintf(stderr, "Uso: %s <indirizzo server> <echo> [<porta server>]\n",
            argv[0]);
    exit(EXIT_FAILURE);
  }
  char *server_IP = argv[1];
  char *echo_string = argv[2];
  size_t echo_string_len = strlen(echo_string);
  in_port_t server_port = (argc == 4) ? atoi(argv[3]) : 7;
  if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
    fprintf(stderr, "Err. creazione socket - %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  memset(&server_address, 0, sizeof(server_address));
  server_address.sin_family = AF_INET;
  if ((ret_val = inet_pton(AF_INET, server_IP,
                           &server_address.sin_addr.s_addr)) == 0) {
    fprintf(stderr, "Err. inet_pton() str. invalida %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  } else if (ret_val < 0) {
    fprintf(stderr, "Err. inet_pton() fallita %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  server_address.sin_port = htons(server_port);
  if (connect(sock, (struct sockaddr *)&server_address,
              sizeof(server_address)) < 0) {
    fprintf(stderr, "Err. connect() %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  if ((num_bytes = send(sock, echo_string, echo_string_len, 0)) < 0) {
    fprintf(stderr, "Err. send() fallita %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  } else if (num_bytes != echo_string_len) {
    fprintf(stderr, "Err. send() %s numero byte errato\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  fputs("Ricevuti: ", stdout);
  while (total_byte_receveid < echo_string_len) {
    char buf[512];
    if ((num_bytes = recv(sock, buf, 512 - 1, 0)) < 0) {
      fprintf(stderr, "Err. recv() fallita %s\n", strerror(errno));
      exit(EXIT_FAILURE);
    } else if (num_bytes == 0) {
      fprintf(stderr, "Err. recv() conn. chiusa %s\n", strerror(errno));
      exit(EXIT_FAILURE);
    }
    total_byte_receveid += num_bytes;
    buf[num_bytes] = '\0';
    fputs(buf, stdout);
  }
  fputc('\n', stdout);
  close(sock);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x290,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x3,-0x8(%rbp)
jl     1224 <main+0x34>
cmpl   $0x4,-0x8(%rbp)
jle    124e <main+0x5e>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdc5(%rip),%rsi
call   10b0 <fprintf@plt>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x50(%rbp)
cmpl   $0x4,-0x8(%rbp)
jne    1295 <main+0xa5>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x264(%rbp)
jmp    12a5 <main+0xb5>
mov    $0x7,%eax
mov    %eax,-0x264(%rbp)
jmp    12a5 <main+0xb5>
mov    -0x264(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
mov    0x2d0a(%rip),%rax
mov    (%rax),%esi
mov    0x2d19(%rip),%rax
mov    (%rax),%edx
call   1110 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    131a <main+0x12a>
mov    0x2cef(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x268(%rbp)
mov    0x2cd0(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x268(%rbp),%edi
mov    %rax,%rdx
lea    0xd2d(%rip),%rsi
call   10b0 <fprintf@plt>
mov    0x2ca5(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2cb7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2cab(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%rsi
lea    -0x28(%rbp),%rdx
add    $0x4,%rdx
call   10c0 <inet_pton@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jne    139c <main+0x1ac>
mov    0x2c6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x26c(%rbp)
mov    0x2c4e(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x26c(%rbp),%edi
mov    %rax,%rdx
lea    0xcc7(%rip),%rsi
call   10b0 <fprintf@plt>
mov    0x2c23(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
cmpl   $0x0,-0x18(%rbp)
jge    13e6 <main+0x1f6>
mov    0x2c23(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x270(%rbp)
mov    0x2c04(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x270(%rbp),%edi
mov    %rax,%rdx
lea    0xca0(%rip),%rsi
call   10b0 <fprintf@plt>
mov    0x2bd9(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
jmp    13eb <main+0x1fb>
mov    -0x54(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   10f0 <connect@plt>
cmp    $0x0,%rax
jge    1451 <main+0x261>
mov    0x2bb8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x274(%rbp)
mov    0x2b99(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x274(%rbp),%edi
mov    %rax,%rdx
lea    0xc52(%rip),%rsi
call   10b0 <fprintf@plt>
mov    0x2b6e(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    -0x50(%rbp),%rdx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jae    14b1 <main+0x2c1>
mov    0x2b58(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x278(%rbp)
mov    0x2b39(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x278(%rbp),%edi
mov    %rax,%rdx
lea    0xc05(%rip),%rsi
call   10b0 <fprintf@plt>
mov    0x2b0e(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x30(%rbp),%rax
cmp    -0x50(%rbp),%rax
je     14ff <main+0x30f>
mov    0x2b0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x27c(%rbp)
mov    0x2aeb(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x27c(%rbp),%edi
mov    %rax,%rdx
lea    0xbcf(%rip),%rsi
call   10b0 <fprintf@plt>
mov    0x2ac0(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
jmp    1504 <main+0x314>
mov    0x2aa5(%rip),%rax
mov    (%rax),%esi
lea    0xbca(%rip),%rdi
call   1070 <fputs@plt>
mov    -0x34(%rbp),%eax
cmp    -0x50(%rbp),%rax
jae    160d <main+0x41d>
mov    -0x14(%rbp),%edi
lea    -0x260(%rbp),%rsi
mov    $0x1ff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jae    158a <main+0x39a>
mov    0x2a7f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x280(%rbp)
mov    0x2a60(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x280(%rbp),%edi
mov    %rax,%rdx
lea    0xb72(%rip),%rsi
call   10b0 <fprintf@plt>
mov    0x2a35(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
cmpq   $0x0,-0x30(%rbp)
jne    15d5 <main+0x3e5>
mov    0x2a34(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x284(%rbp)
mov    0x2a15(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x284(%rbp),%edi
mov    %rax,%rdx
lea    0xb3f(%rip),%rsi
call   10b0 <fprintf@plt>
mov    0x29ea(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
jmp    15da <main+0x3ea>
mov    -0x30(%rbp),%rcx
mov    -0x34(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rax
movb   $0x0,-0x260(%rbp,%rax,1)
lea    -0x260(%rbp),%rdi
mov    0x29af(%rip),%rax
mov    (%rax),%esi
call   1070 <fputs@plt>
jmp    1519 <main+0x329>
mov    0x299c(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   10a0 <fputc@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
mov    0x2979(%rip),%rax
mov    (%rax),%eax
add    $0x290,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x228,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    -0x5(%rbp),%eax
cmp    $0xfffffffd,%eax
jbe    13a4 <main+0x1b4>
mov    0x8(%rbx),%rax
mov    %rax,0x18(%rsp)
mov    0x10(%rbx),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%r13
mov    $0x7,%r15d
cmp    $0x4,%ebp
jne    1241 <main+0x51>
mov    0x18(%rbx),%rdi
call   10d0 <atoi@plt>
mov    %eax,%r15d
mov    0x2da0(%rip),%rbx
mov    (%rbx),%edi
mov    0x2d77(%rip),%rax
mov    (%rax),%esi
mov    0x2d86(%rip),%rax
mov    (%rax),%edx
call   1110 <socket@plt>
test   %eax,%eax
js     13b9 <main+0x1c9>
mov    %eax,%r12d
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    (%rbx),%edi
mov    %edi,0x10(%rsp)
lea    0xc(%rsp),%rdx
mov    0x18(%rsp),%rsi
call   10c0 <inet_pton@plt>
test   %eax,%eax
je     13d9 <main+0x1e9>
js     13f9 <main+0x209>
mov    %r15d,%edi
call   1050 <htons@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %r12d,%edi
mov    $0xc,%edx
call   10f0 <connect@plt>
test   %rax,%rax
js     141c <main+0x22c>
mov    %r12d,%edi
mov    %r14,%rsi
mov    %r13,%rdx
xor    %ecx,%ecx
call   1060 <send@plt>
cmp    %r13,%rax
jne    143f <main+0x24f>
mov    0x2cc9(%rip),%r14
mov    (%r14),%esi
lea    0xdd5(%rip),%rdi
call   1070 <fputs@plt>
test   %r13,%r13
je     133e <main+0x14e>
xor    %ebp,%ebp
lea    0x20(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x1ff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
je     136e <main+0x17e>
add    %eax,%ebp
movb   $0x0,0x20(%rsp,%rax,1)
mov    (%r14),%esi
mov    %rbx,%rdi
call   1070 <fputs@plt>
cmp    %r13,%rbp
jb     1310 <main+0x120>
mov    (%r14),%esi
mov    $0xa,%edi
call   10a0 <fputc@plt>
mov    %r12d,%edi
call   1090 <close@plt>
mov    0x2c4e(%rip),%rax
mov    (%rax),%eax
add    $0x228,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c5b(%rip),%rax
mov    (%rax),%ebx
mov    0x2c42(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xd45(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   10b0 <fprintf@plt>
mov    0x2c1b(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    0x2c25(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xc49(%rip),%rsi
jmp    1391 <main+0x1a1>
mov    0x2c10(%rip),%rax
mov    (%rax),%ebx
mov    0x2bf7(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xc5d(%rip),%rsi
jmp    138c <main+0x19c>
mov    0x2bf0(%rip),%rax
mov    (%rax),%ebx
mov    0x2bd7(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xc59(%rip),%rsi
jmp    138c <main+0x19c>
mov    0x2bd0(%rip),%rax
mov    (%rax),%ebx
mov    0x2bb7(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xc5c(%rip),%rsi
jmp    138c <main+0x19c>
mov    0x2bad(%rip),%rax
mov    (%rax),%ebx
mov    0x2b94(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xc56(%rip),%rsi
jmp    138c <main+0x19c>
mov    0x2b8a(%rip),%rax
mov    (%rax),%ebx
mov    0x2b71(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xc46(%rip),%rsi
jmp    138c <main+0x19c>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [52 x i8] c"Uso: %s <indirizzo server> <echo> [<porta server>]\0A\00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.1 = [28 x i8] c"Err. creazione socket - %s\0A\00"
@errno = global i32 0
@.str.2 = [35 x i8] c"Err. inet_pton() str. invalida %s\0A\00"
@.str.3 = [29 x i8] c"Err. inet_pton() fallita %s\0A\00"
@.str.4 = [19 x i8] c"Err. connect() %s\0A\00"
@.str.5 = [24 x i8] c"Err. send() fallita %s\0A\00"
@.str.6 = [35 x i8] c"Err. send() %s numero byte errato\0A\00"
@.str.7 = [11 x i8] c"Ricevuti: \00"
@stdout = global i32 0
@.str.8 = [24 x i8] c"Err. recv() fallita %s\0A\00"
@.str.9 = [29 x i8] c"Err. recv() conn. chiusa %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca i64
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i32
%15 = alloca [512 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 3
br i1 %17, label %21, label %18
18: ; preds = %2
%19 = load i32, i32* %4
%20 = icmp sgt i32 %19, 4
br i1 %20, label %21, label %29
21: ; preds = %18, %2
%22 = load i32, i32* @stderr
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* %25)
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %18
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
store i8* %32, i8** %11
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
store i8* %35, i8** %12
%36 = load i8*, i8** %12
%37 = call i64 @strlen(i8* %36)
store i64 %37, i64* %13
%38 = load i32, i32* %4
%39 = icmp eq i32 %38, 4
br i1 %39, label %40, label %45
40: ; preds = %29
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 3
%43 = load i8*, i8** %42
%44 = call i32 @atoi(i8* %43)
br label %46
45: ; preds = %29
br label %46
46: ; preds = %45, %40
%47 = phi i32 [ %44, %40 ], [ 7, %45 ]
store i32 %47, i32* %14
%48 = load i32, i32* @AF_INET
%49 = load i32, i32* @SOCK_STREAM
%50 = load i32, i32* @IPPROTO_TCP
%51 = call i32 @socket(i32 %48, i32 %49, i32 %50)
store i32 %51, i32* %6
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %60
53: ; preds = %46
%54 = load i32, i32* @stderr
%55 = load i32, i32* @errno
%56 = call i8* @strerror(i32 %55)
%57 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %56)
%58 = load i32, i32* @EXIT_FAILURE
%59 = call i32 @exit(i32 %58)
unreachable
60: ; preds = %46
%61 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 12)
%62 = load i32, i32* @AF_INET
%63 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %62, i32* %63
%64 = load i32, i32* @AF_INET
%65 = load i8*, i8** %11
%66 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%67 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %66, i32 0, i32 0
%68 = call i32 @inet_pton(i32 %64, i8* %65, i32* %67)
store i32 %68, i32* %7
%69 = icmp eq i32 %68, 0
br i1 %69, label %70, label %77
70: ; preds = %60
%71 = load i32, i32* @stderr
%72 = load i32, i32* @errno
%73 = call i8* @strerror(i32 %72)
%74 = call i32 @fprintf(i32 %71, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %73)
%75 = load i32, i32* @EXIT_FAILURE
%76 = call i32 @exit(i32 %75)
unreachable
77: ; preds = %60
%78 = load i32, i32* %7
%79 = icmp slt i32 %78, 0
br i1 %79, label %80, label %87
80: ; preds = %77
%81 = load i32, i32* @stderr
%82 = load i32, i32* @errno
%83 = call i8* @strerror(i32 %82)
%84 = call i32 @fprintf(i32 %81, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %83)
%85 = load i32, i32* @EXIT_FAILURE
%86 = call i32 @exit(i32 %85)
unreachable
87: ; preds = %77
br label %88
88: ; preds = %87
%89 = load i32, i32* %14
%90 = call i32 @htons(i32 %89)
%91 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %90, i32* %91
%92 = load i32, i32* %6
%93 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%94 = call i64 @connect(i32 %92, %struct.sockaddr* %93, i32 12)
%95 = icmp slt i64 %94, 0
br i1 %95, label %96, label %103
96: ; preds = %88
%97 = load i32, i32* @stderr
%98 = load i32, i32* @errno
%99 = call i8* @strerror(i32 %98)
%100 = call i32 @fprintf(i32 %97, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %99)
%101 = load i32, i32* @EXIT_FAILURE
%102 = call i32 @exit(i32 %101)
unreachable
103: ; preds = %88
%104 = load i32, i32* %6
%105 = load i8*, i8** %12
%106 = load i64, i64* %13
%107 = call i64 @send(i32 %104, i8* %105, i64 %106, i32 0)
store i64 %107, i64* %9
%108 = icmp ult i64 %107, 0
br i1 %108, label %109, label %116
109: ; preds = %103
%110 = load i32, i32* @stderr
%111 = load i32, i32* @errno
%112 = call i8* @strerror(i32 %111)
%113 = call i32 @fprintf(i32 %110, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %112)
%114 = load i32, i32* @EXIT_FAILURE
%115 = call i32 @exit(i32 %114)
unreachable
116: ; preds = %103
%117 = load i64, i64* %9
%118 = load i64, i64* %13
%119 = icmp ne i64 %117, %118
br i1 %119, label %120, label %127
120: ; preds = %116
%121 = load i32, i32* @stderr
%122 = load i32, i32* @errno
%123 = call i8* @strerror(i32 %122)
%124 = call i32 @fprintf(i32 %121, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i8* %123)
%125 = load i32, i32* @EXIT_FAILURE
%126 = call i32 @exit(i32 %125)
unreachable
127: ; preds = %116
br label %128
128: ; preds = %127
%129 = load i32, i32* @stdout
%130 = call i32 @fputs(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i32 %129)
br label %131
131: ; preds = %159, %128
%132 = load i32, i32* %10
%133 = zext i32 %132 to i64
%134 = load i64, i64* %13
%135 = icmp ult i64 %133, %134
br i1 %135, label %136, label %170
136: ; preds = %131
%137 = load i32, i32* %6
%138 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
%139 = call i64 @recv(i32 %137, i8* %138, i32 511, i32 0)
store i64 %139, i64* %9
%140 = icmp ult i64 %139, 0
br i1 %140, label %141, label %148
141: ; preds = %136
%142 = load i32, i32* @stderr
%143 = load i32, i32* @errno
%144 = call i8* @strerror(i32 %143)
%145 = call i32 @fprintf(i32 %142, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i8* %144)
%146 = load i32, i32* @EXIT_FAILURE
%147 = call i32 @exit(i32 %146)
unreachable
148: ; preds = %136
%149 = load i64, i64* %9
%150 = icmp eq i64 %149, 0
br i1 %150, label %151, label %158
151: ; preds = %148
%152 = load i32, i32* @stderr
%153 = load i32, i32* @errno
%154 = call i8* @strerror(i32 %153)
%155 = call i32 @fprintf(i32 %152, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0), i8* %154)
%156 = load i32, i32* @EXIT_FAILURE
%157 = call i32 @exit(i32 %156)
unreachable
158: ; preds = %148
br label %159
159: ; preds = %158
%160 = load i64, i64* %9
%161 = load i32, i32* %10
%162 = zext i32 %161 to i64
%163 = add i64 %162, %160
%164 = trunc i64 %163 to i32
store i32 %164, i32* %10
%165 = load i64, i64* %9
%166 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 %165
store i8 0, i8* %166
%167 = getelementptr inbounds [512 x i8], [512 x i8]* %15, i64 0, i64 0
%168 = load i32, i32* @stdout
%169 = call i32 @fputs(i8* %167, i32 %168)
br label %131
170: ; preds = %131
%171 = load i32, i32* @stdout
%172 = call i32 @fputc(i8 signext 10, i32 %171)
%173 = load i32, i32* %6
%174 = call i32 @close(i32 %173)
%175 = load i32, i32* @EXIT_SUCCESS
ret i32 %175
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [52 x i8] c"Uso: %s <indirizzo server> <echo> [<porta server>]\0A\00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.1 = [28 x i8] c"Err. creazione socket - %s\0A\00"
@errno = global i32 0
@.str.2 = [35 x i8] c"Err. inet_pton() str. invalida %s\0A\00"
@.str.3 = [29 x i8] c"Err. inet_pton() fallita %s\0A\00"
@.str.4 = [19 x i8] c"Err. connect() %s\0A\00"
@.str.6 = [35 x i8] c"Err. send() %s numero byte errato\0A\00"
@.str.7 = [11 x i8] c"Ricevuti: \00"
@stdout = global i32 0
@.str.9 = [29 x i8] c"Err. recv() conn. chiusa %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [512 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = add i32 %0, -5
%7 = icmp ult i32 %6, -2
br i1 %7, label %8, label %14
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i64 @strlen(i8* dereferenceable(1) %18)
%20 = icmp eq i32 %0, 4
br i1 %20, label %21, label %25
21: ; preds = %14
%22 = getelementptr inbounds i8*, i8** %1, i64 3
%23 = load i8*, i8** %22
%24 = tail call i32 @atoi(i8* %23)
br label %25
25: ; preds = %14, %21
%26 = phi i32 [ %24, %21 ], [ 7, %14 ]
%27 = load i32, i32* @AF_INET
%28 = load i32, i32* @SOCK_STREAM
%29 = load i32, i32* @IPPROTO_TCP
%30 = tail call i32 @socket(i32 %27, i32 %28, i32 %29)
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %39
32: ; preds = %25
%33 = load i32, i32* @stderr
%34 = load i32, i32* @errno
%35 = tail call i8* @strerror(i32 %34)
%36 = tail call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %35)
%37 = load i32, i32* @EXIT_FAILURE
%38 = tail call i32 @exit(i32 %37)
unreachable
39: ; preds = %25
%40 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%41 = load i32, i32* @AF_INET
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %41, i32* %42
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
%44 = call i32 @inet_pton(i32 %41, i8* %16, i32* %43)
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %53
46: ; preds = %39
%47 = load i32, i32* @stderr
%48 = load i32, i32* @errno
%49 = call i8* @strerror(i32 %48)
%50 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %49)
%51 = load i32, i32* @EXIT_FAILURE
%52 = call i32 @exit(i32 %51)
unreachable
53: ; preds = %39
%54 = icmp slt i32 %44, 0
br i1 %54, label %55, label %62
55: ; preds = %53
%56 = load i32, i32* @stderr
%57 = load i32, i32* @errno
%58 = call i8* @strerror(i32 %57)
%59 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %58)
%60 = load i32, i32* @EXIT_FAILURE
%61 = call i32 @exit(i32 %60)
unreachable
62: ; preds = %53
%63 = call i32 @htons(i32 %26)
%64 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %63, i32* %64
%65 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%66 = call i64 @connect(i32 %30, %struct.sockaddr* %65, i32 12)
%67 = icmp slt i64 %66, 0
br i1 %67, label %68, label %75
68: ; preds = %62
%69 = load i32, i32* @stderr
%70 = load i32, i32* @errno
%71 = call i8* @strerror(i32 %70)
%72 = call i32 @fprintf(i32 %69, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %71)
%73 = load i32, i32* @EXIT_FAILURE
%74 = call i32 @exit(i32 %73)
unreachable
75: ; preds = %62
%76 = call i64 @send(i32 %30, i8* %18, i64 %19, i32 0)
%77 = icmp eq i64 %76, %19
br i1 %77, label %85, label %78
78: ; preds = %75
%79 = load i32, i32* @stderr
%80 = load i32, i32* @errno
%81 = call i8* @strerror(i32 %80)
%82 = call i32 @fprintf(i32 %79, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i8* %81)
%83 = load i32, i32* @EXIT_FAILURE
%84 = call i32 @exit(i32 %83)
unreachable
85: ; preds = %75
%86 = load i32, i32* @stdout
%87 = call i32 @fputs(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i32 %86)
%88 = icmp eq i64 %19, 0
br i1 %88, label %109, label %89
89: ; preds = %85
%90 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
br label %91
91: ; preds = %89, %102
%92 = phi i64 [ 0, %89 ], [ %107, %102 ]
%93 = call i64 @recv(i32 %30, i8* %90, i32 511, i32 0)
%94 = icmp eq i64 %93, 0
br i1 %94, label %95, label %102
95: ; preds = %91
%96 = load i32, i32* @stderr
%97 = load i32, i32* @errno
%98 = call i8* @strerror(i32 %97)
%99 = call i32 @fprintf(i32 %96, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0), i8* %98)
%100 = load i32, i32* @EXIT_FAILURE
%101 = call i32 @exit(i32 %100)
unreachable
102: ; preds = %91
%103 = add i64 %93, %92
%104 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 %93
store i8 0, i8* %104
%105 = load i32, i32* @stdout
%106 = call i32 @fputs(i8* %90, i32 %105)
%107 = and i64 %103, 4294967295
%108 = icmp ult i64 %107, %19
br i1 %108, label %91, label %109
109: ; preds = %102, %85
%110 = load i32, i32* @stdout
%111 = call i32 @fputc(i8 signext 10, i32 %110)
%112 = call i32 @close(i32 %30)
%113 = load i32, i32* @EXIT_SUCCESS
ret i32 %113
}