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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int BUFSIZ;
int /*<<< orphan*/ PF_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*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ scanf(char *, char *);
int send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  int client_sockfd;
  int len;
  struct sockaddr_in remote_addr;
  char buf[BUFSIZ];
  memset(&remote_addr, 0, sizeof(remote_addr));
  remote_addr.sin_family = AF_INET;
  remote_addr.sin_addr.s_addr = inet_addr("192.168.6.150");
  remote_addr.sin_port = htons(3001);
  printf("start to connect server/n");
  if ((client_sockfd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
    perror("socket");
    return 1;
  }
  if (connect(client_sockfd, (struct sockaddr *)&remote_addr,
              sizeof(struct sockaddr)) < 0) {
    perror("connect");
    return 1;
  }
  printf("connected to server/n");
  len = recv(client_sockfd, buf, BUFSIZ, 0);
  buf[len] = '/0';
  printf("server buf %s", buf);
  while (1) {
    printf("Enter string to send:");
    scanf("%s", buf);
    if (!strcmp(buf, "quit")) {
      break;
    }
    len = send(client_sockfd, buf, strlen(buf), 0);
    buf[len] = '/0';
    printf("received:%s/n", buf);
  }
  close(client_sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2de3(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
lea    0xdcb(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x24(%rbp)
mov    $0xbb9,%edi
call   1050 <htons@plt>
mov    %eax,-0x28(%rbp)
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
mov    0x2d70(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    129c <main+0xcc>
lea    0xda4(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    13b0 <main+0x1e0>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   10e0 <connect@plt>
cmp    $0x0,%rax
jge    12d6 <main+0x106>
lea    0xd71(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    13b0 <main+0x1e0>
lea    0xd5a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x48(%rbp),%rsi
mov    -0x14(%rbp),%edi
mov    0x2cde(%rip),%rax
mov    (%rax),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    -0x48(%rbp),%rsi
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
movb   $0x30,(%rsi,%rax,1)
lea    0xd3c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    131d <main+0x14d>
lea    0xd37(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x48(%rbp),%rsi
lea    0xd22(%rip),%rdi
call   10c0 <scanf@plt>
mov    -0x48(%rbp),%rdi
lea    0xd2b(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%eax
jne    1359 <main+0x189>
jmp    139a <main+0x1ca>
mov    -0x48(%rbp),%rdi
mov    -0x14(%rbp),%eax
mov    %eax,-0x4c(%rbp)
call   1040 <strlen@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    -0x48(%rbp),%rsi
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
movb   $0x30,(%rsi,%rax,1)
lea    0xce8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1318 <main+0x148>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsp,%r12
mov    0x2de5(%rip),%r15
mov    (%r15),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2dd2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
lea    0xdde(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x34(%rbp)
mov    $0xbb9,%edi
call   1050 <htons@plt>
mov    %eax,-0x38(%rbp)
lea    0xdd0(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
mov    0x2d83(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
test   %eax,%eax
js     1372 <main+0x1a2>
mov    %eax,%r14d
lea    -0x38(%rbp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   10e0 <connect@plt>
test   %rax,%rax
js     137b <main+0x1ab>
mov    %r12,-0x40(%rbp)
lea    0xdaa(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    (%r15),%edx
mov    %r14d,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1030 <recv@plt>
cltq
movb   $0x30,(%rbx,%rax,1)
lea    0xd9c(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd99(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd88(%rip),%rdi
mov    %rbx,%rsi
call   10c0 <scanf@plt>
lea    0xd92(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <strcmp@plt>
test   %eax,%eax
je     1352 <main+0x182>
lea    0xd69(%rip),%r13
lea    0xd5f(%rip),%r15
lea    0xd71(%rip),%r12
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
cltq
movb   $0x30,(%rbx,%rax,1)
lea    0xd52(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r13,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   10c0 <scanf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10b0 <strcmp@plt>
test   %eax,%eax
jne    1300 <main+0x130>
mov    %r14d,%edi
call   1090 <close@plt>
mov    -0x40(%rbp),%r12
xor    %eax,%eax
mov    %r12,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcaf(%rip),%rdi
jmp    1382 <main+0x1b2>
lea    0xcad(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%eax
jmp    1360 <main+0x190>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@BUFSIZ = global i32 0
@AF_INET = global i32 0
@.str = [14 x i8] c"192.168.6.150\00"
@.str.1 = [26 x i8] c"start to connect server/n\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@.str.3 = [8 x i8] c"connect\00"
@.str.4 = [22 x i8] c"connected to server/n\00"
@.str.5 = [14 x i8] c"server buf %s\00"
@.str.6 = [22 x i8] c"Enter string to send:\00"
@.str.7 = [3 x i8] c"%s\00"
@.str.8 = [5 x i8] c"quit\00"
@.str.9 = [14 x i8] c"received:%s/n\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 %struct.sockaddr_in
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* @BUFSIZ
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %9
%15 = alloca i8, i64 %13
store i64 %13, i64* %10
%16 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 12)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %17, i32* %18
%19 = call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%21 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %20, i32 0, i32 0
store i32 %19, i32* %21
%22 = call i32 @htons(i32 3001)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %22, i32* %23
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* @PF_INET
%26 = load i32, i32* @SOCK_STREAM
%27 = call i32 @socket(i32 %25, i32 %26, i32 0)
store i32 %27, i32* %6
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %2
%30 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %11
br label %65
31: ; preds = %2
%32 = load i32, i32* %6
%33 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%34 = call i64 @connect(i32 %32, %struct.sockaddr* %33, i32 4)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %11
br label %65
38: ; preds = %31
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%40 = load i32, i32* %6
%41 = load i32, i32* @BUFSIZ
%42 = call i32 @recv(i32 %40, i8* %15, i32 %41, i32 0)
store i32 %42, i32* %7
%43 = load i32, i32* %7
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %15, i64 %44
store i8 48, i8* %45
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %15)
br label %47
47: ; preds = %54, %38
br label %48
48: ; preds = %47
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%50 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %15)
%51 = call i32 @strcmp(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%52 = icmp ne i32 %51, 0
br i1 %52, label %54, label %53
53: ; preds = %48
br label %62
54: ; preds = %48
%55 = load i32, i32* %6
%56 = call i32 @strlen(i8* %15)
%57 = call i32 @send(i32 %55, i8* %15, i32 %56, i32 0)
store i32 %57, i32* %7
%58 = load i32, i32* %7
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %15, i64 %59
store i8 48, i8* %60
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0), i8* %15)
br label %47
62: ; preds = %53
%63 = load i32, i32* %6
%64 = call i32 @close(i32 %63)
store i32 0, i32* %3
store i32 1, i32* %11
br label %65
65: ; preds = %62, %36, %29
%66 = load i8*, i8** %9
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@BUFSIZ = global i32 0
@AF_INET = global i32 0
@.str = [14 x i8] c"192.168.6.150\00"
@.str.1 = [26 x i8] c"start to connect server/n\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@.str.3 = [8 x i8] c"connect\00"
@.str.4 = [22 x i8] c"connected to server/n\00"
@.str.5 = [14 x i8] c"server buf %s\00"
@.str.6 = [22 x i8] c"Enter string to send:\00"
@.str.7 = [3 x i8] c"%s\00"
@.str.8 = [5 x i8] c"quit\00"
@.str.9 = [14 x i8] c"received:%s/n\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = load i32, i32* @BUFSIZ
%6 = zext i32 %5 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
%9 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %10, i32* %11
%12 = call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %12, i32* %13
%14 = call i32 @htons(i32 3001)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %14, i32* %15
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @PF_INET
%18 = load i32, i32* @SOCK_STREAM
%19 = call i32 @socket(i32 %17, i32 %18, i32 0)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %2
%22 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %52
23: ; preds = %2
%24 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%25 = call i64 @connect(i32 %19, %struct.sockaddr* %24, i32 4)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %52
29: ; preds = %23
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%31 = load i32, i32* @BUFSIZ
%32 = call i32 @recv(i32 %19, i8* %8, i32 %31, i32 0)
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %8, i64 %33
store i8 48, i8* %34
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %8)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%37 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %8)
%38 = call i32 @strcmp(i8* %8, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%39 = icmp eq i32 %38, 0
br i1 %39, label %50, label %40
40: ; preds = %29, %40
%41 = call i32 @strlen(i8* %8)
%42 = call i32 @send(i32 %19, i8* %8, i32 %41, i32 0)
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %8, i64 %43
store i8 48, i8* %44
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0), i8* %8)
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%47 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %8)
%48 = call i32 @strcmp(i8* %8, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %40
50: ; preds = %40, %29
%51 = call i32 @close(i32 %19)
br label %52
52: ; preds = %50, %27, %21
%53 = phi i32 [ 1, %21 ], [ 1, %27 ], [ 0, %50 ]
ret i32 %53
}