#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 int socklen_t;
typedef int /*<<< orphan*/ s_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  int s;
  struct sockaddr_in s_addr;
  socklen_t len = sizeof(s_addr);
  s = socket(AF_INET, SOCK_STREAM, 0);
  if (s == -1) {
    perror("socket failed  ");
    return -1;
  }
  s_addr.sin_family = AF_INET;
  s_addr.sin_port = htons(9527);
  s_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  if (connect(s, (struct sockaddr *)&s_addr, len) == -1) {
    perror("connect fail  ");
    return -1;
  }
  char pcContent[1030] = {0};
  write(s, pcContent, 1030);
  sleep(1);
  close(s);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xc,-0x24(%rbp)
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11ee <main+0x5e>
lea    0xe23(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    127f <main+0xef>
mov    0x2df3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x2537,%edi
call   1040 <htons@plt>
mov    %eax,-0x1c(%rbp)
lea    0xe02(%rip),%rdi
call   1070 <inet_addr@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1090 <connect@plt>
cmp    $0xffffffff,%eax
jne    1246 <main+0xb6>
lea    0xde5(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    127f <main+0xef>
lea    -0x430(%rbp),%rdi
xor    %esi,%esi
mov    $0x406,%edx
call   1050 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x406,%edx
call   1030 <write@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x420,%rsp
mov    0x2e46(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
cmp    $0xffffffff,%eax
je     123e <main+0xae>
mov    %eax,%ebx
mov    0x0(%rbp),%eax
mov    %eax,0x8(%rsp)
mov    $0x2537,%edi
call   1040 <htons@plt>
mov    %eax,0x4(%rsp)
lea    0xe34(%rip),%rdi
call   1070 <inet_addr@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1090 <connect@plt>
cmp    $0xffffffff,%eax
je     1247 <main+0xb7>
lea    0x10(%rsp),%rbp
xor    %r14d,%r14d
mov    $0x406,%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x406,%edx
call   1030 <write@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    %r14d,%eax
add    $0x420,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdbb(%rip),%rdi
jmp    124e <main+0xbe>
lea    0xdcc(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%r14d
jmp    122f <main+0x9f>

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 = [16 x i8] c"socket failed \00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [15 x i8] c"connect fail \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 i32
%9 = alloca [1030 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 12, i32* %8
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %40
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 9527)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %20, i32* %21
%22 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%24 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %23, i32 0, i32 0
store i32 %22, i32* %24
%25 = load i32, i32* %6
%26 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%27 = load i32, i32* %8
%28 = call i32 @connect(i32 %25, %struct.sockaddr* %26, i32 %27)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %17
%31 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %40
32: ; preds = %17
%33 = bitcast [1030 x i8]* %9 to i8*
%34 = load i32, i32* %6
%35 = getelementptr inbounds [1030 x i8], [1030 x i8]* %9, i64 0, i64 0
%36 = call i32 @write(i32 %34, i8* %35, i32 1030)
%37 = call i32 @sleep(i32 1)
%38 = load i32, i32* %6
%39 = call i32 @close(i32 %38)
br label %40
40: ; preds = %32, %30, %15
%41 = load i32, i32* %3
ret i32 %41
}

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 = [16 x i8] c"socket failed \00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [15 x i8] c"connect fail \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [1030 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_STREAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %29
12: ; preds = %2
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %13, i32* %14
%15 = tail call i32 @htons(i32 9527)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %15, i32* %16
%17 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %17, i32* %18
%19 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%20 = call i32 @connect(i32 %8, %struct.sockaddr* %19, i32 12)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %12
%23 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %29
24: ; preds = %12
%25 = getelementptr inbounds [1030 x i8], [1030 x i8]* %4, i64 0, i64 0
%26 = call i32 @write(i32 %8, i8* %25, i32 1030)
%27 = call i32 @sleep(i32 1)
%28 = call i32 @close(i32 %8)
br label %29
29: ; preds = %24, %22, %10
%30 = phi i32 [ -1, %10 ], [ -1, %22 ], [ 0, %24 ]
ret i32 %30
}