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

/* Variables and functions */
char EOF;
int EXIT_SUCCESS;
scalar_t__ isprint(char);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int prepare_client_socket(char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ process_data(char);
int /*<<< orphan*/ putchar(char);
int read(int, char *, int);
int main(int argc, char *argv[]) {
  char buffer[1024];
  if (argc < 3) {
    printf("Please type: <ip> <port>\n");
    return -1;
  }
  memset(buffer, '0', sizeof(buffer));
  int socket_id = prepare_client_socket(argv[1], argv[2]);
  if (socket_id == -1) {
    perror("Preparation of client socket has filed...");
    return -1;
  }
  int n = 0;
  while ((n = read(socket_id, buffer, sizeof(buffer) - 1)) > 0) {
    buffer[n] = '\0';
    for (int i = 0; i < n; i++) {
      if (isprint(buffer[i])) {
        process_data(buffer[i]);
      } else if (buffer[i] == '\n') {
        break;
      } else if (buffer[i] == EOF) {
        perror("Socket error! EOF");
        break;
      }
    }
    break;
  }
  putchar('\n');
  if (n < 0) {
    perror("No data has been read... ");
    return -1;
  }
  printf("\nThank you!\n");
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11bb <main+0x3b>
lea    0xe56(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1361 <main+0x1e1>
lea    -0x410(%rbp),%rdi
mov    $0x30,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1080 <prepare_client_socket@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0xffffffff,-0x414(%rbp)
jne    1211 <main+0x91>
lea    0xe1a(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1361 <main+0x1e1>
movl   $0x0,-0x418(%rbp)
mov    -0x414(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x3ff,%edx
call   1070 <read@plt>
mov    %eax,-0x418(%rbp)
cmp    $0x0,%eax
jle    131a <main+0x19a>
movslq -0x418(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
movl   $0x0,-0x41c(%rbp)
mov    -0x41c(%rbp),%eax
cmp    -0x418(%rbp),%eax
jge    1315 <main+0x195>
movslq -0x41c(%rbp),%rax
movsbl -0x410(%rbp,%rax,1),%edi
ff
call   1090 <isprint@plt>
cmp    $0x0,%rax
je     12a3 <main+0x123>
movslq -0x41c(%rbp),%rax
movsbl -0x410(%rbp,%rax,1),%edi
ff
call   1040 <process_data@plt>
jmp    12fc <main+0x17c>
movslq -0x41c(%rbp),%rax
movsbl -0x410(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    12c0 <main+0x140>
jmp    1315 <main+0x195>
movslq -0x41c(%rbp),%rax
movsbl -0x410(%rbp,%rax,1),%eax
ff
mov    0x2d12(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    12f2 <main+0x172>
lea    0xd5c(%rip),%rdi
call   10a0 <perror@plt>
jmp    1315 <main+0x195>
jmp    12f7 <main+0x177>
jmp    12fc <main+0x17c>
jmp    1301 <main+0x181>
mov    -0x41c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x41c(%rbp)
jmp    125a <main+0xda>
jmp    131a <main+0x19a>
mov    $0xa,%edi
call   1030 <putchar@plt>
cmpl   $0x0,-0x418(%rbp)
jge    1349 <main+0x1c9>
lea    0xd1e(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1361 <main+0x1e1>
lea    0xd20(%rip),%rdi
call   1050 <printf@plt>
mov    0x2c7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
cmp    $0x2,%edi
jg     11a8 <main+0x28>
lea    0xec9(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%eax
jmp    125d <main+0xdd>
mov    %rsi,%rbx
mov    %rsp,%rdi
mov    $0x30,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
call   1080 <prepare_client_socket@plt>
cmp    $0xffffffff,%eax
je     126b <main+0xeb>
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x3ff,%edx
call   1070 <read@plt>
mov    %eax,%r14d
test   %eax,%eax
jle    1239 <main+0xb9>
mov    %r14d,%ebx
movb   $0x0,(%rsp,%rbx,1)
xor    %ebp,%ebp
mov    0x2def(%rip),%r15
jmp    1211 <main+0x91>
nopl   0x0(%rax,%rax,1)
movsbl %cl,%edi
call   1040 <process_data@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
je     1239 <main+0xb9>
movsbl (%rsp,%rbp,1),%edi
call   1090 <isprint@plt>
movzbl (%rsp,%rbp,1),%ecx
test   %rax,%rax
jne    1200 <main+0x80>
cmp    $0xa,%cl
je     1239 <main+0xb9>
cmp    (%r15),%cl
jne    1208 <main+0x88>
lea    0xdf6(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
test   %r14d,%r14d
js     1274 <main+0xf4>
lea    0xe07(%rip),%rdi
call   1050 <puts@plt>
mov    0x2d7d(%rip),%rax
mov    (%rax),%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd8e(%rip),%rdi
jmp    127b <main+0xfb>
lea    0xdc1(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%eax
jmp    125d <main+0xdd>

LLVM IR (-O0):
@.str = [26 x i8] c"Please type: <ip> <port>\0A\00"
@.str.1 = [42 x i8] c"Preparation of client socket has filed...\00"
@EOF = global i8 0
@.str.2 = [18 x i8] c"Socket error! EOF\00"
@.str.3 = [26 x i8] c"No data has been read... \00"
@.str.4 = [13 x i8] c"\0AThank you!\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 [1024 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %90
14: ; preds = %2
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%16 = call i32 @memset(i8* %15, i32 48, i32 1024)
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @prepare_client_socket(i8* %19, i8* %22)
store i32 %23, i32* %7
%24 = load i32, i32* %7
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %14
%27 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %90
28: ; preds = %14
store i32 0, i32* %8
br label %29
29: ; preds = %28
%30 = load i32, i32* %7
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%32 = call i32 @read(i32 %30, i8* %31, i32 1023)
store i32 %32, i32* %8
%33 = icmp sgt i32 %32, 0
br i1 %33, label %34, label %81
34: ; preds = %29
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %36
store i8 0, i8* %37
store i32 0, i32* %9
br label %38
38: ; preds = %77, %34
%39 = load i32, i32* %9
%40 = load i32, i32* %8
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %80
42: ; preds = %38
%43 = load i32, i32* %9
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = call i64 @isprint(i8 signext %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %55
49: ; preds = %42
%50 = load i32, i32* %9
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %51
%53 = load i8, i8* %52
%54 = call i32 @process_data(i8 signext %53)
br label %76
55: ; preds = %42
%56 = load i32, i32* %9
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %57
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %60, 10
br i1 %61, label %62, label %63
62: ; preds = %55
br label %80
63: ; preds = %55
%64 = load i32, i32* %9
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %65
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = load i8, i8* @EOF
%70 = sext i8 %69 to i32
%71 = icmp eq i32 %68, %70
br i1 %71, label %72, label %74
72: ; preds = %63
%73 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %80
74: ; preds = %63
br label %75
75: ; preds = %74
br label %76
76: ; preds = %75, %49
br label %77
77: ; preds = %76
%78 = load i32, i32* %9
%79 = add nsw i32 %78, 1
store i32 %79, i32* %9
br label %38
80: ; preds = %72, %62, %38
br label %81
81: ; preds = %80, %29
%82 = call i32 @putchar(i8 signext 10)
%83 = load i32, i32* %8
%84 = icmp slt i32 %83, 0
br i1 %84, label %85, label %87
85: ; preds = %81
%86 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %90
87: ; preds = %81
%88 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%89 = load i32, i32* @EXIT_SUCCESS
store i32 %89, i32* %3
br label %90
90: ; preds = %87, %85, %26, %12
%91 = load i32, i32* %3
ret i32 %91
}

LLVM IR (-O2):
@.str.1 = [42 x i8] c"Preparation of client socket has filed...\00"
@EOF = global i8 0
@.str.2 = [18 x i8] c"Socket error! EOF\00"
@.str.3 = [26 x i8] c"No data has been read... \00"
@EXIT_SUCCESS = global i32 0
@str = [12 x i8] c"\0AThank you!\00"
@str.5 = [25 x i8] c"Please type: <ip> <port>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.5, i64 0, i64 0))
br label %51
8: ; preds = %2
%9 = call i32 @memset(i8* %4, i32 48, i32 1024)
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = call i32 @prepare_client_socket(i8* %11, i8* %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %8
%17 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
br label %51
18: ; preds = %8
%19 = call i32 @read(i32 %14, i8* %4, i32 1023)
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %43
21: ; preds = %18
%22 = zext i32 %19 to i64
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %22
store i8 0, i8* %23
br label %24
24: ; preds = %21, %40
%25 = phi i64 [ 0, %21 ], [ %41, %40 ]
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = call i64 @isprint(i8 signext %27)
%29 = icmp eq i64 %28, 0
%30 = load i8, i8* %26
br i1 %29, label %33, label %31
31: ; preds = %24
%32 = call i32 @process_data(i8 signext %30)
br label %40
33: ; preds = %24
%34 = icmp eq i8 %30, 10
br i1 %34, label %43, label %35
35: ; preds = %33
%36 = load i8, i8* @EOF
%37 = icmp eq i8 %30, %36
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %43
40: ; preds = %31, %35
%41 = add nuw nsw i64 %25, 1
%42 = icmp eq i64 %41, %22
br i1 %42, label %43, label %24
43: ; preds = %33, %40, %38, %18
%44 = call i32 @putchar(i8 signext 10)
%45 = icmp slt i32 %19, 0
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %51
48: ; preds = %43
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%50 = load i32, i32* @EXIT_SUCCESS
br label %51
51: ; preds = %16, %48, %46, %6
%52 = phi i32 [ -1, %6 ], [ -1, %16 ], [ -1, %46 ], [ %50, %48 ]
ret i32 %52
}