#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*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_pton(int /*<<< orphan*/, char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
char *strerror(int);
int /*<<< orphan*/ strlen(char *);
void data_socket(const char *ip, int port, char sendline[]) {
  int sockfd, n, rec_len;
  struct sockaddr_in servaddr;
  printf("sendline ready");
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    printf("create socket error: %s(errno: %d)\n", strerror(errno), errno);
    exit(0);
  }
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(port);
  if (inet_pton(AF_INET, ip, &servaddr.sin_addr) <= 0) {
    printf("inet_pton error for %s\n", ip);
    exit(0);
  }
  printf("send begin");
  if (connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) {
    printf("connect error: %s(errno: %d)\n", strerror(errno), errno);
    exit(0);
  }
  printf("send msg to server: \n");
  printf("buff:%s\n", sendline);
  if (send(sockfd, sendline, strlen(sendline), 0) < 0) {
    printf("send msg error: %s(errno: %d)\n", strerror(errno), errno);
    exit(0);
  }
  printf("send msg end!!\n");
  close(sockfd);
}


x86 assembly (clang, -O0):
<data_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
mov    0x2df7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1225 <data_socket+0x75>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    %rax,%rsi
mov    0x2dc2(%rip),%rax
mov    (%rax),%edx
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    -0x30(%rbp),%rdi
mov    $0xc,%esi
call   1090 <bzero@plt>
mov    0x2dae(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1080 <inet_pton@plt>
cmp    $0x0,%rax
jg     1283 <data_socket+0xd3>
mov    -0x8(%rbp),%rsi
lea    0xdbe(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1c(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <connect@plt>
cmp    $0x0,%rax
jge    12db <data_socket+0x12b>
mov    0x2d1d(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    %rax,%rsi
mov    0x2d0c(%rip),%rax
mov    (%rax),%edx
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    0xd92(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
cmp    $0x0,%rax
jge    135b <data_socket+0x1ab>
mov    0x2c9d(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    %rax,%rsi
mov    0x2c8c(%rip),%rax
mov    (%rax),%edx
lea    0xd46(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    0xd50(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<data_socket>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r15
mov    %esi,%r12d
mov    %rdi,%r14
lea    0xe22(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2dfc(%rip),%rbx
mov    (%rbx),%edi
mov    0x2de3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
test   %eax,%eax
js     12c4 <data_socket+0x104>
mov    %eax,%ebp
lea    0x8(%rsp),%r13
mov    %r13,%rdi
mov    $0xc,%esi
call   10a0 <bzero@plt>
mov    (%rbx),%eax
mov    %eax,0x10(%rsp)
mov    %r12d,%edi
call   1050 <htons@plt>
mov    %eax,0xc(%rsp)
mov    (%rbx),%edi
mov    %r14,%rsi
mov    %r13,%rdx
call   1090 <inet_pton@plt>
test   %rax,%rax
jle    12dd <data_socket+0x11d>
lea    0xe02(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   10c0 <connect@plt>
test   %rax,%rax
js     12f5 <data_socket+0x135>
lea    0xe2b(%rip),%rdi
call   1030 <puts@plt>
lea    0xdf7(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
test   %rax,%rax
js     130e <data_socket+0x14e>
lea    0xe08(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   1080 <close@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d05(%rip),%rbx
mov    (%rbx),%edi
call   10d0 <strerror@plt>
mov    (%rbx),%edx
lea    0xd34(%rip),%rdi
jmp    1325 <data_socket+0x165>
lea    0xd4f(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    0x2cd4(%rip),%rbx
mov    (%rbx),%edi
call   10d0 <strerror@plt>
mov    (%rbx),%edx
lea    0xd4a(%rip),%rdi
jmp    1325 <data_socket+0x165>
mov    0x2cbb(%rip),%rbx
mov    (%rbx),%edi
call   10d0 <strerror@plt>
mov    (%rbx),%edx
lea    0xd58(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [15 x i8] c"sendline ready\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [36 x i8] c"create socket error: %s(errno: %d)\0A\00"
@errno = global i32 0
@.str.2 = [24 x i8] c"inet_pton error for %s\0A\00"
@.str.3 = [11 x i8] c"send begin\00"
@.str.4 = [30 x i8] c"connect error: %s(errno: %d)\0A\00"
@.str.5 = [22 x i8] c"send msg to server: \0A\00"
@.str.6 = [9 x i8] c"buff:%s\0A\00"
@.str.7 = [31 x i8] c"send msg error: %s(errno: %d)\0A\00"
@.str.8 = [16 x i8] c"send msg end!!\0A\00"
define void @data_socket(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = call i32 @socket(i32 %12, i32 %13, i32 0)
store i32 %14, i32* %7
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %3
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = load i32, i32* @errno
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %18, i32 %19)
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %3
%23 = call i32 @bzero(%struct.sockaddr_in* %10, i32 12)
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %24, i32* %25
%26 = load i32, i32* %5
%27 = call i32 @htons(i32 %26)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
store i32 %27, i32* %28
%29 = load i32, i32* @AF_INET
%30 = load i8*, i8** %4
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%32 = call i64 @inet_pton(i32 %29, i8* %30, i32* %31)
%33 = icmp sle i64 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %22
%35 = load i8*, i8** %4
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %35)
%37 = call i32 @exit(i32 0)
unreachable
38: ; preds = %22
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%40 = load i32, i32* %7
%41 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%42 = call i64 @connect(i32 %40, %struct.sockaddr* %41, i32 12)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %50
44: ; preds = %38
%45 = load i32, i32* @errno
%46 = call i8* @strerror(i32 %45)
%47 = load i32, i32* @errno
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %46, i32 %47)
%49 = call i32 @exit(i32 0)
unreachable
50: ; preds = %38
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%52 = load i8*, i8** %6
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %52)
%54 = load i32, i32* %7
%55 = load i8*, i8** %6
%56 = load i8*, i8** %6
%57 = call i32 @strlen(i8* %56)
%58 = call i64 @send(i32 %54, i8* %55, i32 %57, i32 0)
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %66
60: ; preds = %50
%61 = load i32, i32* @errno
%62 = call i8* @strerror(i32 %61)
%63 = load i32, i32* @errno
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i8* %62, i32 %63)
%65 = call i32 @exit(i32 0)
unreachable
66: ; preds = %50
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
%68 = load i32, i32* %7
%69 = call i32 @close(i32 %68)
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [15 x i8] c"sendline ready\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [36 x i8] c"create socket error: %s(errno: %d)\0A\00"
@errno = global i32 0
@.str.2 = [24 x i8] c"inet_pton error for %s\0A\00"
@.str.3 = [11 x i8] c"send begin\00"
@.str.4 = [30 x i8] c"connect error: %s(errno: %d)\0A\00"
@.str.6 = [9 x i8] c"buff:%s\0A\00"
@.str.7 = [31 x i8] c"send msg error: %s(errno: %d)\0A\00"
@str = [21 x i8] c"send msg to server: \00"
@str.9 = [15 x i8] c"send msg end!!\00"
define void @data_socket(i8* %0, i32 %1, i8* %2) {
%4 = alloca %struct.sockaddr_in
%5 = bitcast %struct.sockaddr_in* %4 to i8*
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, 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 %17
11: ; preds = %3
%12 = load i32, i32* @errno
%13 = tail call i8* @strerror(i32 %12)
%14 = load i32, i32* @errno
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %13, i32 %14)
%16 = tail call i32 @exit(i32 0)
unreachable
17: ; preds = %3
%18 = call i32 @bzero(%struct.sockaddr_in* %4, i32 12)
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %19, i32* %20
%21 = tail call i32 @htons(i32 %1)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %21, i32* %22
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%25 = call i64 @inet_pton(i32 %23, i8* %0, i32* %24)
%26 = icmp slt i64 %25, 1
br i1 %26, label %27, label %30
27: ; preds = %17
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%29 = call i32 @exit(i32 0)
unreachable
30: ; preds = %17
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%32 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%33 = call i64 @connect(i32 %9, %struct.sockaddr* %32, i32 12)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %30
%36 = load i32, i32* @errno
%37 = call i8* @strerror(i32 %36)
%38 = load i32, i32* @errno
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i8* %37, i32 %38)
%40 = call i32 @exit(i32 0)
unreachable
41: ; preds = %30
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %2)
%44 = call i32 @strlen(i8* %2)
%45 = call i64 @send(i32 %9, i8* %2, i32 %44, i32 0)
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %53
47: ; preds = %41
%48 = load i32, i32* @errno
%49 = call i8* @strerror(i32 %48)
%50 = load i32, i32* @errno
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i8* %49, i32 %50)
%52 = call i32 @exit(i32 0)
unreachable
53: ; preds = %41
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.9, i64 0, i64 0))
%55 = call i32 @close(i32 %9)
ret void
}