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

/* Variables and functions */
int /*<<< orphan*/ SIGPIPE;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ _IONBF;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit(int);
char *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
scalar_t__ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ setvbuf(int /*<<< orphan*/, char *, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
char *strerror(int);
int /*<<< orphan*/ strlen(char *);
int tcpconn(char *, int /*<<< orphan*/, int);
int main(int argc, char **argv) {
  int sock, bytes, i;
  char buff[1024], *p;
  if (argc != 3) {
    printf("Usage: %s <ip> <port>\n", argv[0]);
    exit(1);
  }
  setvbuf(stdout, (char *)NULL, _IONBF, 0);
  signal(SIGPIPE, SIG_IGN);
  sock = tcpconn(argv[1], atoi(argv[2]), 3);
  if (sock < 0) {
    printf("connect error: %s[%d]\n", strerror(errno), errno);
    exit(1);
  }
  printf("connect server success\n");
  while (1) {
    printf("<<< ");
    p = fgets(buff, sizeof(buff), stdin);
    if (p == NULL)
      continue;
    if (send(sock, p, strlen(p), 0) < 0) {
      printf("%s\n", strerror(errno));
      break;
    }
    bytes = recv(sock, buff, sizeof(buff), 0);
    if (bytes <= 0) {
      printf("%s\n", strerror(errno));
      break;
    }
    printf(">>> ");
    for (i = 0; i < bytes; i++)
      printf("%c", buff[i]);
  }
  close(sock);
  printf("test finish\n");
  return 0;
}


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   $0x3,-0x8(%rbp)
je     1202 <main+0x42>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
mov    0x2dce(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   10a0 <setvbuf@plt>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
mov    0x2da9(%rip),%rax
mov    (%rax),%esi
call   1090 <signal@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x430(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <atoi@plt>
mov    -0x430(%rbp),%rdi
mov    %eax,%esi
mov    $0x3,%edx
call   10e0 <tcpconn@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12a4 <main+0xe4>
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
mov    0x2d36(%rip),%rax
mov    (%rax),%edx
lea    0xd84(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    0xd83(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd8d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x420(%rbp),%rdi
mov    0x2d1a(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1080 <fgets@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
jne    12f4 <main+0x134>
jmp    12b2 <main+0xf2>
mov    -0x14(%rbp),%eax
mov    %eax,-0x43c(%rbp)
mov    -0x428(%rbp),%rax
mov    %rax,-0x438(%rbp)
mov    -0x428(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x43c(%rbp),%edi
mov    -0x438(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
cmp    $0x0,%rax
jge    135b <main+0x19b>
mov    0x2c82(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xcfc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    13f0 <main+0x230>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jg     13a2 <main+0x1e2>
mov    0x2c3b(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xcb5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    13f0 <main+0x230>
lea    0xca6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    13eb <main+0x22b>
movslq -0x1c(%rbp),%rax
movsbl -0x420(%rbp,%rax,1),%esi
ff
lea    0xc7e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    13b7 <main+0x1f7>
jmp    12b2 <main+0xf2>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
lea    0xc58(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%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    $0x408,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1345 <main+0x165>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
mov    0x2dd3(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   10c0 <setvbuf@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
mov    0x2db0(%rip),%rax
mov    (%rax),%esi
call   10b0 <signal@plt>
mov    0x8(%rbx),%rbp
mov    0x10(%rbx),%rdi
call   10d0 <atoi@plt>
mov    %rbp,%rdi
mov    %eax,%esi
mov    $0x3,%edx
call   1100 <tcpconn@plt>
test   %eax,%eax
js     1360 <main+0x180>
mov    %eax,%ebp
lea    0xddc(%rip),%rdi
call   1050 <puts@plt>
lea    0xdc6(%rip),%r14
mov    0x2d79(%rip),%r13
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x0(%r13),%edx
mov    %r15,%rdi
mov    $0x400,%esi
call   10a0 <fgets@plt>
test   %rax,%rax
je     1280 <main+0xa0>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
test   %rax,%rax
js     1308 <main+0x128>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    1308 <main+0x128>
mov    %eax,%ebx
lea    0xd57(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %ebx,%ebx
xor    %r12d,%r12d
nopl   0x0(%rax,%rax,1)
movsbl (%rsp,%r12,1),%edi
call   1040 <putchar@plt>
add    $0x1,%r12
cmp    %r12,%rbx
jne    12f0 <main+0x110>
jmp    1280 <main+0xa0>
mov    0x2cb1(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    %rax,%rdi
call   1050 <puts@plt>
mov    %ebp,%edi
call   1090 <close@plt>
lea    0xd23(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0xcb1(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2c59(%rip),%rbx
mov    (%rbx),%edi
call   10f0 <strerror@plt>
mov    (%rbx),%edx
lea    0xca0(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"Usage: %s <ip> <port>\0A\00"
@stdout = global i32 0
@_IONBF = global i32 0
@SIGPIPE = global i32 0
@SIG_IGN = global i32 0
@.str.1 = [23 x i8] c"connect error: %s[%d]\0A\00"
@errno = global i32 0
@.str.2 = [24 x i8] c"connect server success\0A\00"
@.str.3 = [5 x i8] c"<<< \00"
@stdin = global i32 0
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [5 x i8] c">>> \00"
@.str.6 = [3 x i8] c"%c\00"
@.str.7 = [13 x i8] c"test finish\0A\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 [1024 x i8]
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i32, i32* @stdout
%21 = load i32, i32* @_IONBF
%22 = call i32 @setvbuf(i32 %20, i8* null, i32 %21, i32 0)
%23 = load i32, i32* @SIGPIPE
%24 = load i32, i32* @SIG_IGN
%25 = call i32 @signal(i32 %23, i32 %24)
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i32 @atoi(i8* %31)
%33 = call i32 @tcpconn(i8* %28, i32 %32, i32 3)
store i32 %33, i32* %6
%34 = load i32, i32* %6
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %19
%37 = load i32, i32* @errno
%38 = call i8* @strerror(i32 %37)
%39 = load i32, i32* @errno
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %38, i32 %39)
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %19
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %44
44: ; preds = %42, %51, %89
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%47 = load i32, i32* @stdin
%48 = call i8* @fgets(i8* %46, i32 1024, i32 %47)
store i8* %48, i8** %10
%49 = load i8*, i8** %10
%50 = icmp eq i8* %49, null
br i1 %50, label %51, label %52
51: ; preds = %44
br label %44
52: ; preds = %44
%53 = load i32, i32* %6
%54 = load i8*, i8** %10
%55 = load i8*, i8** %10
%56 = call i32 @strlen(i8* %55)
%57 = call i64 @send(i32 %53, i8* %54, i32 %56, i32 0)
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %63
59: ; preds = %52
%60 = load i32, i32* @errno
%61 = call i8* @strerror(i32 %60)
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %61)
br label %90
63: ; preds = %52
%64 = load i32, i32* %6
%65 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%66 = call i32 @recv(i32 %64, i8* %65, i32 1024, i32 0)
store i32 %66, i32* %7
%67 = load i32, i32* %7
%68 = icmp sle i32 %67, 0
br i1 %68, label %69, label %73
69: ; preds = %63
%70 = load i32, i32* @errno
%71 = call i8* @strerror(i32 %70)
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %71)
br label %90
73: ; preds = %63
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %8
br label %75
75: ; preds = %86, %73
%76 = load i32, i32* %8
%77 = load i32, i32* %7
%78 = icmp slt i32 %76, %77
br i1 %78, label %79, label %89
79: ; preds = %75
%80 = load i32, i32* %8
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 %81
%83 = load i8, i8* %82
%84 = sext i8 %83 to i32
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %84)
br label %86
86: ; preds = %79
%87 = load i32, i32* %8
%88 = add nsw i32 %87, 1
store i32 %88, i32* %8
br label %75
89: ; preds = %75
br label %44
90: ; preds = %69, %59
%91 = load i32, i32* %6
%92 = call i32 @close(i32 %91)
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [23 x i8] c"Usage: %s <ip> <port>\0A\00"
@stdout = global i32 0
@_IONBF = global i32 0
@SIGPIPE = global i32 0
@SIG_IGN = global i32 0
@.str.1 = [23 x i8] c"connect error: %s[%d]\0A\00"
@errno = global i32 0
@.str.3 = [5 x i8] c"<<< \00"
@stdin = global i32 0
@.str.5 = [5 x i8] c">>> \00"
@str = [23 x i8] c"connect server success\00"
@str.8 = [12 x i8] c"test finish\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 eq i32 %0, 3
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = load i32, i32* @stdout
%12 = load i32, i32* @_IONBF
%13 = tail call i32 @setvbuf(i32 %11, i8* null, i32 %12, i32 0)
%14 = load i32, i32* @SIGPIPE
%15 = load i32, i32* @SIG_IGN
%16 = tail call i32 @signal(i32 %14, i32 %15)
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i32 @atoi(i8* %20)
%22 = tail call i32 @tcpconn(i8* %18, i32 %21, i32 3)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %10
%25 = load i32, i32* @errno
%26 = tail call i8* @strerror(i32 %25)
%27 = load i32, i32* @errno
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %26, i32 %27)
%29 = tail call i32 @exit(i32 1)
unreachable
30: ; preds = %10
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %32
32: ; preds = %37, %30
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%34 = load i32, i32* @stdin
%35 = call i8* @fgets(i8* %4, i32 1024, i32 %34)
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %38
37: ; preds = %48, %32
br label %32
38: ; preds = %32
%39 = call i32 @strlen(i8* %35)
%40 = call i64 @send(i32 %22, i8* %35, i32 %39, i32 0)
%41 = icmp slt i64 %40, 0
br i1 %41, label %56, label %42
42: ; preds = %38
%43 = call i32 @recv(i32 %22, i8* %4, i32 1024, i32 0)
%44 = icmp slt i32 %43, 1
br i1 %44, label %56, label %45
45: ; preds = %42
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%47 = zext i32 %43 to i64
br label %48
48: ; preds = %45, %48
%49 = phi i64 [ 0, %45 ], [ %54, %48 ]
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %49
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = call i32 @putchar(i32 %52)
%54 = add nuw nsw i64 %49, 1
%55 = icmp eq i64 %54, %47
br i1 %55, label %37, label %48
56: ; preds = %42, %38
%57 = load i32, i32* @errno
%58 = call i8* @strerror(i32 %57)
%59 = call i32 @puts(i8* dereferenceable(1) %58)
%60 = call i32 @close(i32 %22)
%61 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.8, i64 0, i64 0))
ret i32 0
}