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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ getpid();
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  int i;
  int pid;
  int fd;
  char buf[128];
  struct sockaddr_in sa;
  pid = (int)getpid();
  fd = socket(AF_INET, SOCK_STREAM, 0);
  if (-1 == fd) {
    fprintf(stderr, "create socket error...");
    return -1;
  }
  sa.sin_addr.s_addr = inet_addr("127.0.0.1");
  sa.sin_family = AF_INET;
  sa.sin_port = htons(5555);
  fprintf(stdout, "begin to connect to server ...\n");
  if (0 != connect(fd, (struct sockaddr *)&sa, sizeof(sa))) {
    fprintf(stderr, "connect to server failed ...\n");
    return -1;
  }
  fprintf(stdout, "begin to send message to server ...\n");
  for (i = 0; i < 100; ++i) {
    sprintf(buf, "[%d]this is send message > %d", pid, i + 1);
    send(fd, buf, strlen(buf), 0);
    memset(buf, 0, sizeof(buf));
    recv(fd, buf, sizeof(buf), 0);
    fprintf(stdout, "recv: %s\n", buf);
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x18(%rbp)
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x1c(%rbp)
mov    $0xffffffff,%eax
cmp    -0x1c(%rbp),%eax
jne    1230 <main+0x70>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
lea    0xde3(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    139e <main+0x1de>
lea    0xde0(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0xa8(%rbp)
mov    0x2d9f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xac(%rbp)
mov    $0x15b3,%edi
call   1060 <htons@plt>
mov    %eax,-0xb0(%rbp)
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
lea    0xdb0(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x1c(%rbp),%edi
lea    -0xb0(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     12bd <main+0xfd>
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
lea    0xd97(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    139e <main+0x1de>
mov    0x2d04(%rip),%rax
mov    (%rax),%edi
lea    0xd92(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jge    138f <main+0x1cf>
lea    -0xa0(%rbp),%rdi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
lea    0xd88(%rip),%rsi
call   10c0 <sprintf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0xbc(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xb8(%rbp)
lea    -0xa0(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xbc(%rbp),%edi
mov    -0xb8(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1080 <memset@plt>
mov    -0x1c(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    0x2c5e(%rip),%rax
mov    (%rax),%edi
lea    -0xa0(%rbp),%rdx
lea    0xd28(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12db <main+0x11b>
mov    -0x1c(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %rax,%r14
mov    0x2e06(%rip),%rbx
mov    (%rbx),%edi
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
cmp    $0xffffffff,%eax
je     125d <main+0x9d>
mov    %eax,%r12d
lea    0xe14(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0x8(%rsp)
mov    (%rbx),%eax
mov    %eax,0x4(%rsp)
mov    $0x15b3,%edi
call   1060 <htons@plt>
mov    %eax,(%rsp)
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
lea    0xdf2(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %rsp,%rsi
mov    %r12d,%edi
mov    $0xc,%edx
call   10d0 <connect@plt>
test   %rax,%rax
je     127e <main+0xbe>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
lea    0xde6(%rip),%rsi
jmp    126d <main+0xad>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
lea    0xd93(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1320 <main+0x160>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
lea    0xdd1(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%ebx
lea    0xde3(%rip),%r15
lea    0x10(%rsp),%rbp
lea    0xdf5(%rip),%r13
nopl   (%rax)
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
mov    %ebx,%ecx
call   10c0 <sprintf@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1080 <memset@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
mov    %r13,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
add    $0x1,%ebx
cmp    $0x65,%ebx
jne    12b0 <main+0xf0>
mov    %r12d,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"create socket error...\00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@stdout = global i32 0
@.str.2 = [32 x i8] c"begin to connect to server ...\0A\00"
@.str.3 = [30 x i8] c"connect to server failed ...\0A\00"
@.str.4 = [37 x i8] c"begin to send message to server ...\0A\00"
@.str.5 = [30 x i8] c"[%d]this is send message > %d\00"
@.str.6 = [10 x i8] c"recv: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [128 x i8]
%10 = alloca %struct.sockaddr_in
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i64 (...) @getpid()
%12 = trunc i64 %11 to i32
store i32 %12, i32* %7
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = icmp eq i32 -1, %16
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %69
21: ; preds = %2
%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* %10, i32 0, i32 2
%24 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %23, i32 0, i32 0
store i32 %22, i32* %24
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
store i32 %25, i32* %26
%27 = call i32 @htons(i32 5555)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i32 %27, i32* %28
%29 = load i32, i32* @stdout
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32, i32* %8
%32 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%33 = call i64 @connect(i32 %31, %struct.sockaddr* %32, i32 12)
%34 = icmp ne i64 0, %33
br i1 %34, label %35, label %38
35: ; preds = %21
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %69
38: ; preds = %21
%39 = load i32, i32* @stdout
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %6
br label %41
41: ; preds = %63, %38
%42 = load i32, i32* %6
%43 = icmp slt i32 %42, 100
br i1 %43, label %44, label %66
44: ; preds = %41
%45 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%46 = load i32, i32* %7
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
%49 = call i32 @sprintf(i8* %45, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %46, i32 %48)
%50 = load i32, i32* %8
%51 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%52 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%53 = call i32 @strlen(i8* %52)
%54 = call i32 @send(i32 %50, i8* %51, i32 %53, i32 0)
%55 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%56 = call i32 @memset(i8* %55, i32 0, i32 128)
%57 = load i32, i32* %8
%58 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%59 = call i32 @recv(i32 %57, i8* %58, i32 128, i32 0)
%60 = load i32, i32* @stdout
%61 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* %61)
br label %63
63: ; preds = %44
%64 = load i32, i32* %6
%65 = add nsw i32 %64, 1
store i32 %65, i32* %6
br label %41
66: ; preds = %41
%67 = load i32, i32* %8
%68 = call i32 @close(i32 %67)
store i32 0, i32* %3
br label %69
69: ; preds = %66, %35, %18
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"create socket error...\00"
@.str.1 = [10 x i8] c"127.0.0.1\00"
@stdout = global i32 0
@.str.2 = [32 x i8] c"begin to connect to server ...\0A\00"
@.str.3 = [30 x i8] c"connect to server failed ...\0A\00"
@.str.4 = [37 x i8] c"begin to send message to server ...\0A\00"
@.str.5 = [30 x i8] c"[%d]this is send message > %d\00"
@.str.6 = [10 x i8] c"recv: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [128 x i8]
%4 = alloca %struct.sockaddr_in
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = tail call i64 (...) @getpid()
%8 = trunc i64 %7 to i32
%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 eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %47
16: ; preds = %2
%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* %4, i64 0, i32 2, i32 0
store i32 %17, i32* %18
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %19, i32* %20
%21 = tail call i32 @htons(i32 5555)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %21, i32* %22
%23 = load i32, i32* @stdout
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%25 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%26 = call i64 @connect(i32 %11, %struct.sockaddr* %25, i32 12)
%27 = icmp eq i64 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %16
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
br label %47
31: ; preds = %16
%32 = load i32, i32* @stdout
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
br label %34
34: ; preds = %31, %34
%35 = phi i32 [ 0, %31 ], [ %36, %34 ]
%36 = add nuw nsw i32 %35, 1
%37 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %8, i32 %36)
%38 = call i32 @strlen(i8* %5)
%39 = call i32 @send(i32 %11, i8* %5, i32 %38, i32 0)
%40 = call i32 @memset(i8* %5, i32 0, i32 128)
%41 = call i32 @recv(i32 %11, i8* %5, i32 128, i32 0)
%42 = load i32, i32* @stdout
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* %5)
%44 = icmp eq i32 %36, 100
br i1 %44, label %45, label %34
45: ; preds = %34
%46 = call i32 @close(i32 %11)
br label %47
47: ; preds = %45, %28, %13
%48 = phi i32 [ -1, %13 ], [ -1, %28 ], [ 0, %45 ]
ret i32 %48
}