#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__ {
  void *s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ serverAddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
void *inet_addr(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  int clientSocket;
  struct sockaddr_in serverAddr;
  char sendbuf[200];
  char recvbuf[200];
  int iDataNum;
  if ((clientSocket = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    perror("socket");
    return 1;
  }
  serverAddr.sin_family = AF_INET;
  serverAddr.sin_port = htons(5555);
  if (argc == 2) {
    printf("s_addr...............%s\n", argv[1]);
    serverAddr.sin_addr.s_addr = inet_addr(argv[1]);
  } else {
    serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
  }
  if (connect(clientSocket, (struct sockaddr *)&serverAddr,
              sizeof(serverAddr)) < 0) {
    perror("connect");
    return 1;
  }
  printf("connect with destination host...\n");
  while (1) {
    printf("Input your world:>");
    scanf("%s", sendbuf);
    printf("\n");
    send(clientSocket, sendbuf, strlen(sendbuf), 0);
    if (strcmp(sendbuf, "quit") == 0)
      break;
    iDataNum = recv(clientSocket, recvbuf, 200, 0);
    recvbuf[iDataNum] = '\0';
    printf("recv data of my world is: %s\n", recvbuf);
  }
  close(clientSocket);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1e0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
mov    0x2def(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1216 <main+0x56>
lea    0xdfb(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1394 <main+0x1d4>
mov    0x2dcb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x15b3,%edi
call   1050 <htons@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1265 <main+0xa5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <inet_addr@plt>
mov    %rax,-0x28(%rbp)
jmp    1275 <main+0xb5>
lea    0xdb4(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x10,%edx
call   10d0 <connect@plt>
cmp    $0x0,%rax
jge    12a8 <main+0xe8>
lea    0xd93(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1394 <main+0x1d4>
lea    0xd83(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0xf0(%rbp),%rsi
lea    0xd95(%rip),%rdi
call   10b0 <scanf@plt>
lea    0xd74(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1d4(%rbp)
lea    -0xf0(%rbp),%rax
mov    %rax,-0x1d0(%rbp)
lea    -0xf0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1d4(%rbp),%edi
mov    -0x1d0(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
lea    -0xf0(%rbp),%rdi
lea    0xd3e(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    1340 <main+0x180>
jmp    1385 <main+0x1c5>
mov    -0x14(%rbp),%edi
lea    -0x1c0(%rbp),%rsi
mov    $0xc8,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x1c4(%rbp)
movslq -0x1c4(%rbp),%rax
movb   $0x0,-0x1c0(%rbp,%rax,1)
lea    -0x1c0(%rbp),%rsi
lea    0xcf6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    12b6 <main+0xf6>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1a8,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
mov    0x2deb(%rip),%r15
mov    (%r15),%edi
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
test   %eax,%eax
js     133b <main+0x15b>
mov    %eax,%ebp
mov    (%r15),%eax
mov    %eax,0xc(%rsp)
mov    $0x15b3,%edi
call   1070 <htons@plt>
mov    %eax,0x8(%rsp)
cmp    $0x2,%ebx
jne    124c <main+0x6c>
mov    0x8(%r14),%rsi
lea    0xdc8(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    0x8(%r14),%rdi
jmp    1253 <main+0x73>
lea    0xdcd(%rip),%rdi
call   10b0 <inet_addr@plt>
mov    %rax,(%rsp)
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x10,%edx
call   10f0 <connect@plt>
test   %rax,%rax
js     1344 <main+0x164>
lea    0xdf0(%rip),%rdi
call   1050 <puts@plt>
lea    0xdbe(%rip),%r15
lea    0xe0(%rsp),%rbx
lea    0xdb2(%rip),%r12
lea    0x10(%rsp),%r13
lea    0xdab(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xd7b(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   10d0 <scanf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     1320 <main+0x140>
mov    %ebp,%edi
mov    %r13,%rsi
mov    $0xc8,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cltq
movb   $0x0,0x10(%rsp,%rax,1)
mov    %r14,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
jmp    12b0 <main+0xd0>
mov    %ebp,%edi
call   10a0 <close@plt>
xor    %eax,%eax
add    $0x1a8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcbe(%rip),%rdi
jmp    134b <main+0x16b>
lea    0xcdf(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%eax
jmp    1329 <main+0x149>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i8* }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [25 x i8] c"s_addr...............%s\0A\00"
@.str.2 = [10 x i8] c"127.0.0.1\00"
@.str.3 = [8 x i8] c"connect\00"
@.str.4 = [34 x i8] c"connect with destination host...\0A\00"
@.str.5 = [19 x i8] c"Input your world:>\00"
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [2 x i8] c"\0A\00"
@.str.8 = [5 x i8] c"quit\00"
@.str.9 = [30 x i8] c"recv data of my world is: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca [200 x i8]
%9 = alloca [200 x i8]
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %6
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %74
17: ; preds = %2
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %18, i32* %19
%20 = call i32 @htons(i32 5555)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %20, i32* %21
%22 = load i32, i32* %4
%23 = icmp eq i32 %22, 2
br i1 %23, label %24, label %35
24: ; preds = %17
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i8* @inet_addr(i8* %31)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%34 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %33, i32 0, i32 0
store i8* %32, i8** %34
br label %39
35: ; preds = %17
%36 = call i8* @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%38 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %37, i32 0, i32 0
store i8* %36, i8** %38
br label %39
39: ; preds = %35, %24
%40 = load i32, i32* %6
%41 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%42 = call i64 @connect(i32 %40, %struct.sockaddr* %41, i32 16)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %39
%45 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %74
46: ; preds = %39
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
br label %48
48: ; preds = %46, %62
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%50 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%51 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %50)
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%53 = load i32, i32* %6
%54 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%55 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%56 = call i32 @strlen(i8* %55)
%57 = call i32 @send(i32 %53, i8* %54, i32 %56, i32 0)
%58 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%59 = call i64 @strcmp(i8* %58, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %62
61: ; preds = %48
br label %71
62: ; preds = %48
%63 = load i32, i32* %6
%64 = getelementptr inbounds [200 x i8], [200 x i8]* %9, i64 0, i64 0
%65 = call i32 @recv(i32 %63, i8* %64, i32 200, i32 0)
store i32 %65, i32* %10
%66 = load i32, i32* %10
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [200 x i8], [200 x i8]* %9, i64 0, i64 %67
store i8 0, i8* %68
%69 = getelementptr inbounds [200 x i8], [200 x i8]* %9, i64 0, i64 0
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0), i8* %69)
br label %48
71: ; preds = %61
%72 = load i32, i32* %6
%73 = call i32 @close(i32 %72)
store i32 0, i32* %3
br label %74
74: ; preds = %71, %44, %15
%75 = load i32, i32* %3
ret i32 %75
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i8* }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"socket\00"
@.str.1 = [25 x i8] c"s_addr...............%s\0A\00"
@.str.2 = [10 x i8] c"127.0.0.1\00"
@.str.3 = [8 x i8] c"connect\00"
@.str.5 = [19 x i8] c"Input your world:>\00"
@.str.6 = [3 x i8] c"%s\00"
@.str.8 = [5 x i8] c"quit\00"
@.str.9 = [30 x i8] c"recv data of my world is: %s\0A\00"
@str = [33 x i8] c"connect with destination host...\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [200 x i8]
%5 = alloca [200 x i8]
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%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 = %2
%14 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %52
15: ; preds = %2
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %16, i32* %17
%18 = tail call i32 @htons(i32 5555)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %18, i32* %19
%20 = icmp eq i32 %0, 2
br i1 %20, label %21, label %26
21: ; preds = %15
%22 = getelementptr inbounds i8*, i8** %1, i64 1
%23 = load i8*, i8** %22
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = load i8*, i8** %22
br label %26
26: ; preds = %15, %21
%27 = phi i8* [ %25, %21 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), %15 ]
%28 = tail call i8* @inet_addr(i8* %27)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i8* %28, i8** %29
%30 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%31 = call i64 @connect(i32 %11, %struct.sockaddr* %30, i32 16)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %26
%34 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %52
35: ; preds = %26
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
br label %37
37: ; preds = %45, %35
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%39 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %7)
%40 = call i32 @putchar(i32 10)
%41 = call i32 @strlen(i8* %7)
%42 = call i32 @send(i32 %11, i8* %7, i32 %41, i32 0)
%43 = call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%44 = icmp eq i64 %43, 0
br i1 %44, label %50, label %45
45: ; preds = %37
%46 = call i32 @recv(i32 %11, i8* %8, i32 200, i32 0)
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 %47
store i8 0, i8* %48
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0), i8* %8)
br label %37
50: ; preds = %37
%51 = call i32 @close(i32 %11)
br label %52
52: ; preds = %50, %33, %13
%53 = phi i32 [ 1, %13 ], [ 1, %33 ], [ 0, %50 ]
ret i32 %53
}