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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ puts(char *);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(void) {
  int server = 0;
  char readBuf[64] = {0};
  struct sockaddr_in servAddr;
  if ((server = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    fprintf(stderr, "Can't not open socket.\n");
    exit(1);
  }
  memset(&servAddr, 0, sizeof(servAddr));
  servAddr.sin_family = AF_INET;
  servAddr.sin_port = htons(9527);
  if (inet_pton(AF_INET, "127.0.0.1", &servAddr.sin_addr) <= 0) {
    fprintf(stderr, "inet_pton error for %s\n", "127.0.0.1");
    exit(1);
  }
  if (connect(server, (struct sockaddr *)&servAddr, sizeof(servAddr)) < 0) {
    fprintf(stderr, "Connect error\n");
  }
  for (int cnt = 0; (cnt = read(server, readBuf, 63)) > 0;) {
    readBuf[cnt] = 0;
    puts(readBuf);
  }
  close(server);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1050 <memset@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    120c <main+0x6c>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
lea    0xe05(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    $0x2537,%edi
call   1040 <htons@plt>
mov    %eax,-0x5c(%rbp)
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
lea    -0x60(%rbp),%rdx
lea    0xdcf(%rip),%rsi
call   1090 <inet_pton@plt>
cmp    $0x0,%rax
jg     1280 <main+0xe0>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
lea    0xdba(%rip),%rsi
lea    0xda9(%rip),%rdx
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <connect@plt>
cmp    $0x0,%rax
jge    12b2 <main+0x112>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
lea    0xd8f(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x0,-0x64(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x3f,%edx
call   1070 <read@plt>
mov    %eax,-0x64(%rbp)
cmp    $0x0,%eax
jle    12ed <main+0x14d>
movslq -0x64(%rbp),%rax
movb   $0x0,-0x50(%rbp,%rax,1)
lea    -0x50(%rbp),%rdi
call   1030 <puts@plt>
jmp    12b9 <main+0x119>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
mov    0x2e22(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
test   %eax,%eax
js     12a4 <main+0x104>
mov    %eax,%ebp
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    $0x2537,%edi
call   1040 <htons@plt>
mov    %eax,0x4(%rsp)
mov    (%rbx),%edi
lea    0xe07(%rip),%rsi
mov    %r14,%rdx
call   1090 <inet_pton@plt>
test   %rax,%rax
jle    12c5 <main+0x125>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   10b0 <connect@plt>
test   %rax,%rax
jns    124d <main+0xad>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
lea    0xdf4(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x3f,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    1292 <main+0xf2>
lea    0x10(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    %eax,%eax
movb   $0x0,0x10(%rsp,%rax,1)
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x3f,%edx
call   1070 <read@plt>
test   %eax,%eax
jg     1270 <main+0xd0>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
lea    0xd4c(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2d0c(%rip),%rax
mov    (%rax),%edi
lea    0xd4d(%rip),%rsi
lea    0xd3c(%rip),%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [24 x i8] c"Can't not open socket.\0A\00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [24 x i8] c"inet_pton error for %s\0A\00"
@.str.3 = [15 x i8] c"Connect error\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [64 x i8]
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%6 = bitcast [64 x i8]* %3 to i8*
%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 %15
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 12)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %17, i32* %18
%19 = call i32 @htons(i32 9527)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
store i32 %19, i32* %20
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%23 = call i64 @inet_pton(i32 %21, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %22)
%24 = icmp sle i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %15
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %15
%30 = load i32, i32* %2
%31 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%32 = call i64 @connect(i32 %30, %struct.sockaddr* %31, i32 12)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %37
37: ; preds = %34, %29
store i32 0, i32* %5
br label %38
38: ; preds = %43, %37
%39 = load i32, i32* %2
%40 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%41 = call i32 @read(i32 %39, i8* %40, i32 63)
store i32 %41, i32* %5
%42 = icmp sgt i32 %41, 0
br i1 %42, label %43, label %49
43: ; preds = %38
%44 = load i32, i32* %5
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 %45
store i8 0, i8* %46
%47 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%48 = call i32 @puts(i8* %47)
br label %38
49: ; preds = %38
%50 = load i32, i32* %2
%51 = call i32 @close(i32 %50)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [24 x i8] c"Can't not open socket.\0A\00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [24 x i8] c"inet_pton error for %s\0A\00"
@.str.3 = [15 x i8] c"Connect error\0A\00"
define i32 @main() {
%1 = alloca [64 x i8]
%2 = alloca %struct.sockaddr_in
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%4 = bitcast %struct.sockaddr_in* %2 to i8*
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = call i32 @memset(%struct.sockaddr_in* %2, i32 0, i32 12)
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %15, i32* %16
%17 = call i32 @htons(i32 9527)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %17, i32* %18
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
%21 = call i64 @inet_pton(i32 %19, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %20)
%22 = icmp slt i64 %21, 1
br i1 %22, label %23, label %27
23: ; preds = %13
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %13
%28 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%29 = call i64 @connect(i32 %7, %struct.sockaddr* %28, i32 12)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %31, %27
%35 = call i32 @read(i32 %7, i8* %3, i32 63)
%36 = icmp sgt i32 %35, 0
br i1 %36, label %39, label %37
37: ; preds = %39, %34
%38 = call i32 @close(i32 %7)
ret i32 0
39: ; preds = %34, %39
%40 = phi i32 [ %44, %39 ], [ %35, %34 ]
%41 = zext i32 %40 to i64
%42 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 %41
store i8 0, i8* %42
%43 = call i32 @puts(i8* %3)
%44 = call i32 @read(i32 %7, i8* %3, i32 63)
%45 = icmp sgt i32 %44, 0
br i1 %45, label %39, label %37
}