#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 */

/* Type definitions */
typedef int /*<<< orphan*/ zerb_helb;
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int strlen(char *);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int m, mezluz;
  int sock;
  int n;
  char buf[1024];
  struct sockaddr_in zerb_helb;
  if (argc != 2) {
    fprintf(stderr, "EZ DA ARGUMENTURIK PASA, MESEDEZ IP HELBIDEA IDATZI!!!",
            argv[0]);
    exit(1);
  }
  if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    printf("ERROREA SOCKETA SORTZERAKOAN");
    exit(1);
  }
  zerb_helb.sin_family = AF_INET;
  zerb_helb.sin_port = htons(50002);
  inet_aton(argv[1], &zerb_helb.sin_addr);
  if (connect(sock, (struct sockaddr *)&zerb_helb, sizeof(zerb_helb)) == -1) {
    printf("ERROREA ZERBITZARIAREKIN KONEKTATZERAKOAN");
    exit(1);
  }
  while (fgets(buf, 1024, stdin) != NULL) {
    m = 0;
    if (write(sock, buf, strlen(buf)) == -1) {
      printf("ERROREA MEZUA BIDALTZEAN");
      exit(1);
    }
    mezluz = strlen(buf);
    while (m < mezluz) {
      if ((n = read(sock, buf, 1024)) == -1) {
        printf("ERROREA MEZUA JASOTZEAN");
        exit(1);
      }
      buf[n] = 0;
      printf("Zerbitzaritik jasotako textua : %s", buf);
      m = m + n;
    }
  }
  if (close(sock) == -1) {
    printf("ERROREA KONEXIOA IXTEAN");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1209 <main+0x49>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe06(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
mov    0x2daf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    1246 <main+0x86>
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2d9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x428(%rbp)
mov    $0xc352,%edi
call   1050 <htons@plt>
mov    %eax,-0x42c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x430(%rbp),%rsi
call   10b0 <inet_aton@plt>
mov    -0x1c(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
cmp    $0xffffffff,%eax
jne    12ae <main+0xee>
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    12b3 <main+0xf3>
lea    -0x420(%rbp),%rdi
mov    0x2d1f(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     13bd <main+0x1fd>
movl   $0x0,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x43c(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x438(%rbp)
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x43c(%rbp),%edi
mov    -0x438(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    1336 <main+0x176>
lea    0xd59(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    13b8 <main+0x1f8>
mov    -0x1c(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1080 <read@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
jne    1389 <main+0x1c9>
lea    0xd1f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
movslq -0x20(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
lea    -0x420(%rbp),%rsi
lea    0xd0c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1345 <main+0x185>
jmp    12b3 <main+0xf3>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    13e6 <main+0x226>
lea    0xcfd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    133a <main+0x17a>
mov    0x2e04(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
cmp    $0xffffffff,%eax
je     135c <main+0x19c>
mov    %eax,%r15d
mov    0x0(%rbp),%eax
mov    %eax,0x8(%rsp)
mov    $0xc352,%edi
call   1050 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x8(%rbx),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   10b0 <inet_aton@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
cmp    $0xffffffff,%eax
je     1365 <main+0x1a5>
mov    0x2d99(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
call   1090 <fgets@plt>
test   %rax,%rax
je     12f8 <main+0x138>
lea    0x10(%rsp),%r12
lea    0xe42(%rip),%r14
jmp    128b <main+0xcb>
nop
mov    0x2d69(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
mov    $0x400,%esi
call   1090 <fgets@plt>
test   %rax,%rax
je     12f8 <main+0x138>
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %r15d,%edi
mov    %r12,%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     1331 <main+0x171>
mov    %r12,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    1270 <main+0xb0>
mov    %eax,%ebp
xor    %r13d,%r13d
nopw   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %r12,%rsi
mov    $0x400,%edx
call   1080 <read@plt>
cmp    $0xffffffff,%eax
je     1319 <main+0x159>
mov    %eax,%ebx
cltq
movb   $0x0,0x10(%rsp,%rax,1)
mov    %r14,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
add    %ebx,%r13d
cmp    %ebp,%r13d
jl     12c0 <main+0x100>
jmp    1270 <main+0xb0>
mov    %r15d,%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
je     136e <main+0x1ae>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd77(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    0xd46(%rip),%rdi
jmp    1320 <main+0x160>
mov    0x2c8f(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xcb3(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    0xcd4(%rip),%rdi
jmp    1320 <main+0x160>
lea    0xce8(%rip),%rdi
jmp    1320 <main+0x160>
lea    0xd5d(%rip),%rdi
jmp    1320 <main+0x160>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [55 x i8] c"EZ DA ARGUMENTURIK PASA, MESEDEZ IP HELBIDEA IDATZI!!!\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [29 x i8] c"ERROREA SOCKETA SORTZERAKOAN\00"
@.str.2 = [42 x i8] c"ERROREA ZERBITZARIAREKIN KONEKTATZERAKOAN\00"
@stdin = global i32 0
@.str.3 = [25 x i8] c"ERROREA MEZUA BIDALTZEAN\00"
@.str.4 = [24 x i8] c"ERROREA MEZUA JASOTZEAN\00"
@.str.5 = [35 x i8] c"Zerbitzaritik jasotako textua : %s\00"
@.str.6 = [24 x i8] c"ERROREA KONEXIOA IXTEAN\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [1024 x i8]
%11 = alloca %struct.sockaddr_in
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i32, i32* @AF_INET
%23 = load i32, i32* @SOCK_STREAM
%24 = call i32 @socket(i32 %22, i32 %23, i32 0)
store i32 %24, i32* %8
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %21
%30 = load i32, i32* @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i32 %30, i32* %31
%32 = call i32 @htons(i32 50002)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
store i32 %32, i32* %33
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
%38 = call i32 @inet_aton(i8* %36, i32* %37)
%39 = load i32, i32* %8
%40 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%41 = call i32 @connect(i32 %39, %struct.sockaddr* %40, i32 12)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %46
43: ; preds = %29
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %29
br label %47
47: ; preds = %86, %46
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%49 = load i32, i32* @stdin
%50 = call i32* @fgets(i8* %48, i32 1024, i32 %49)
%51 = icmp ne i32* %50, null
br i1 %51, label %52, label %87
52: ; preds = %47
store i32 0, i32* %6
%53 = load i32, i32* %8
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%56 = call i32 @strlen(i8* %55)
%57 = call i32 @write(i32 %53, i8* %54, i32 %56)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %62
59: ; preds = %52
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%61 = call i32 @exit(i32 1)
unreachable
62: ; preds = %52
%63 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%64 = call i32 @strlen(i8* %63)
store i32 %64, i32* %7
br label %65
65: ; preds = %77, %62
%66 = load i32, i32* %6
%67 = load i32, i32* %7
%68 = icmp slt i32 %66, %67
br i1 %68, label %69, label %86
69: ; preds = %65
%70 = load i32, i32* %8
%71 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%72 = call i32 @read(i32 %70, i8* %71, i32 1024)
store i32 %72, i32* %9
%73 = icmp eq i32 %72, -1
br i1 %73, label %74, label %77
74: ; preds = %69
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%76 = call i32 @exit(i32 1)
unreachable
77: ; preds = %69
%78 = load i32, i32* %9
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 %79
store i8 0, i8* %80
%81 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* %81)
%83 = load i32, i32* %6
%84 = load i32, i32* %9
%85 = add nsw i32 %83, %84
store i32 %85, i32* %6
br label %65
86: ; preds = %65
br label %47
87: ; preds = %47
%88 = load i32, i32* %8
%89 = call i32 @close(i32 %88)
%90 = icmp eq i32 %89, -1
br i1 %90, label %91, label %94
91: ; preds = %87
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%93 = call i32 @exit(i32 1)
unreachable
94: ; preds = %87
%95 = load i32, i32* %3
ret i32 %95
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [55 x i8] c"EZ DA ARGUMENTURIK PASA, MESEDEZ IP HELBIDEA IDATZI!!!\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [29 x i8] c"ERROREA SOCKETA SORTZERAKOAN\00"
@.str.2 = [42 x i8] c"ERROREA ZERBITZARIAREKIN KONEKTATZERAKOAN\00"
@stdin = global i32 0
@.str.3 = [25 x i8] c"ERROREA MEZUA BIDALTZEAN\00"
@.str.4 = [24 x i8] c"ERROREA MEZUA JASOTZEAN\00"
@.str.5 = [35 x i8] c"Zerbitzaritik jasotako textua : %s\00"
@.str.6 = [24 x i8] c"ERROREA KONEXIOA IXTEAN\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca %struct.sockaddr_in
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = icmp eq i32 %0, 2
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = tail call i32 @socket(i32 %14, i32 %15, i32 0)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %13
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %22, i32* %23
%24 = tail call i32 @htons(i32 50002)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %24, i32* %25
%26 = getelementptr inbounds i8*, i8** %1, i64 1
%27 = load i8*, i8** %26
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%29 = call i32 @inet_aton(i8* %27, i32* %28)
%30 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%31 = call i32 @connect(i32 %16, %struct.sockaddr* %30, i32 12)
%32 = icmp eq i32 %31, -1
br i1 %32, label %37, label %33
33: ; preds = %21
%34 = load i32, i32* @stdin
%35 = call i32* @fgets(i8* %5, i32 1024, i32 %34)
%36 = icmp eq i32* %35, null
br i1 %36, label %67, label %44
37: ; preds = %21
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %61, %51
%41 = load i32, i32* @stdin
%42 = call i32* @fgets(i8* %5, i32 1024, i32 %41)
%43 = icmp eq i32* %42, null
br i1 %43, label %67, label %44
44: ; preds = %33, %40
%45 = call i32 @strlen(i8* %5)
%46 = call i32 @write(i32 %16, i8* %5, i32 %45)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %51
48: ; preds = %44
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %44
%52 = call i32 @strlen(i8* %5)
%53 = icmp sgt i32 %52, 0
br i1 %53, label %54, label %40
54: ; preds = %51, %61
%55 = phi i32 [ %65, %61 ], [ 0, %51 ]
%56 = call i32 @read(i32 %16, i8* %5, i32 1024)
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %61
58: ; preds = %54
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %54
%62 = sext i32 %56 to i64
%63 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %62
store i8 0, i8* %63
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* %5)
%65 = add nsw i32 %56, %55
%66 = icmp slt i32 %65, %52
br i1 %66, label %54, label %40
67: ; preds = %40, %33
%68 = call i32 @close(i32 %16)
%69 = icmp eq i32 %68, -1
br i1 %69, label %70, label %73
70: ; preds = %67
%71 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%72 = call i32 @exit(i32 1)
unreachable
73: ; preds = %67
ret i32 0
}