#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 {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef size_t ssize_t;
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);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
size_t 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 clientSocket;
  struct sockaddr_in serverAddr;
  char sendbuf[200];
  char recvbuf[200];
  ssize_t iDataNum;
  if ((clientSocket = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    perror("socket error.");
    return 1;
  }
  serverAddr.sin_family = AF_INET;
  serverAddr.sin_port = htons(5556);
  serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
  if (connect(clientSocket, (struct sockaddr *)&serverAddr,
              sizeof(serverAddr)) < 0) {
    perror("connect error.");
    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    $0x1d0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    120f <main+0x4f>
lea    0xe02(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1357 <main+0x197>
mov    0x2dd2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x15b4,%edi
call   1050 <htons@plt>
mov    %eax,-0x14(%rbp)
lea    0xddf(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
cmp    $0x0,%rax
jge    126a <main+0xaa>
lea    0xdbf(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1357 <main+0x197>
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0xe0(%rbp),%rsi
lea    0xdc8(%rip),%rdi
call   10b0 <scanf@plt>
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c4(%rbp)
lea    -0xe0(%rbp),%rax
mov    %rax,-0x1c0(%rbp)
lea    -0xe0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1c4(%rbp),%edi
mov    -0x1c0(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
lea    -0xe0(%rbp),%rdi
lea    0xd71(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    1302 <main+0x142>
jmp    1348 <main+0x188>
mov    -0x8(%rbp),%edi
lea    -0x1b0(%rbp),%rsi
mov    $0xc8,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,-0x1b8(%rbp)
mov    -0x1b8(%rbp),%rax
movb   $0x0,-0x1b0(%rbp,%rax,1)
lea    -0x1b0(%rbp),%rsi
lea    0xd28(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1278 <main+0xb8>
mov    -0x8(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1d0,%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    0x2df0(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
test   %eax,%eax
js     1309 <main+0x129>
mov    %eax,%ebp
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    $0x15b4,%edi
call   1070 <htons@plt>
mov    %eax,0x4(%rsp)
lea    0xddf(%rip),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   10f0 <connect@plt>
test   %rax,%rax
js     1312 <main+0x132>
lea    0xe0b(%rip),%rdi
call   1050 <puts@plt>
lea    0xdd8(%rip),%r15
lea    0xe0(%rsp),%rbx
lea    0xdcc(%rip),%r12
lea    0x10(%rsp),%r13
lea    0xdc5(%rip),%r14
nopl   (%rax)
lea    0xda0(%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     12ee <main+0x10e>
mov    %ebp,%edi
mov    %r13,%rsi
mov    $0xc8,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
movb   $0x0,0x10(%rsp,%rax,1)
mov    %r14,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
jmp    1280 <main+0xa0>
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    0xcf0(%rip),%rdi
jmp    1319 <main+0x139>
lea    0xcff(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%eax
jmp    12f7 <main+0x117>

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

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