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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int BUFSIZ;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(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*/ strlen(char *);
int main(int argc, char *argv[]) {
  int sockfd, numbytes;
  char buf[BUFSIZ];
  struct sockaddr_in their_addr;
  printf("break!");
  while ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
    ;
  printf("We get the sockfd~\n");
  their_addr.sin_family = AF_INET;
  their_addr.sin_port = htons(8000);
  their_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  bzero(&(their_addr.sin_zero), 8);
  while (connect(sockfd, (struct sockaddr *)&their_addr,
                 sizeof(struct sockaddr)) == -1)
    ;
  printf("Get the Server~Cheers!\n");
  numbytes = recv(sockfd, buf, BUFSIZ, 0);
  buf[numbytes] = '\0';
  printf("%s", buf);
  while (1) {
    printf("Entersome thing:");
    scanf("%s", buf);
    numbytes = send(sockfd, buf, strlen(buf), 0);
    numbytes = recv(sockfd, buf, BUFSIZ, 0);
    buf[numbytes] = '\0';
    printf("received:%s\n", buf);
  }
  close(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    0x2e13(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
mov    0x2dd8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    121a <main+0x7a>
jmp    11f0 <main+0x50>
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    $0x1f40,%edi
call   1050 <htons@plt>
mov    %eax,-0x30(%rbp)
lea    0xdd3(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x34(%rbp)
lea    -0x38(%rbp),%rdi
mov    $0x8,%esi
call   10a0 <bzero@plt>
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0x4,%edx
call   10b0 <connect@plt>
cmp    $0xffffffff,%eax
jne    127d <main+0xdd>
jmp    125e <main+0xbe>
lea    0xda1(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x40(%rbp),%rsi
mov    -0x14(%rbp),%edi
mov    0x2d37(%rip),%rax
mov    (%rax),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    -0x40(%rbp),%rsi
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
movb   $0x0,(%rsi,%rax,1)
lea    0xd85(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    12c4 <main+0x124>
lea    0xd75(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x40(%rbp),%rsi
lea    0xd60(%rip),%rdi
call   1090 <scanf@plt>
mov    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%eax
mov    %eax,-0x44(%rbp)
call   1040 <strlen@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    -0x40(%rbp),%rsi
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2cbe(%rip),%rax
mov    (%rax),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    -0x40(%rbp),%rsi
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
movb   $0x0,(%rsi,%rax,1)
lea    0xd20(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    12bf <main+0x11f>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e08(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe1c(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x2df6(%rip),%r15
mov    0x2ddf(%rip),%r12
nopl   0x0(%rax)
mov    (%r15),%edi
mov    (%r12),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
cmp    $0xffffffff,%eax
je     1200 <main+0x50>
mov    %eax,%r14d
lea    0xe15(%rip),%rdi
call   1040 <puts@plt>
mov    (%r15),%eax
mov    %eax,-0x2c(%rbp)
mov    $0x1f40,%edi
call   1060 <htons@plt>
mov    %eax,-0x30(%rbp)
lea    0xdcb(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x34(%rbp)
lea    -0x38(%rbp),%r15
mov    %r15,%rdi
mov    $0x8,%esi
call   10b0 <bzero@plt>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0x4,%edx
call   10c0 <connect@plt>
cmp    $0xffffffff,%eax
je     1260 <main+0xb0>
lea    0xdc9(%rip),%rdi
call   1040 <puts@plt>
mov    0x0(%r13),%edx
mov    %r14d,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1030 <recv@plt>
cltq
movb   $0x0,(%rbx,%rax,1)
lea    0xd72(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xd64(%rip),%r12
mov    %r13,%r15
lea    0xd6b(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xd40(%rip),%rdi
mov    %rbx,%rsi
call   10a0 <scanf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    (%r15),%edx
mov    %r14d,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1030 <recv@plt>
cltq
movb   $0x0,(%rbx,%rax,1)
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    12c0 <main+0x110>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@BUFSIZ = global i32 0
@.str = [7 x i8] c"break!\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [20 x i8] c"We get the sockfd~\0A\00"
@.str.2 = [10 x i8] c"127.0.0.1\00"
@.str.3 = [24 x i8] c"Get the Server~Cheers!\0A\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [17 x i8] c"Entersome thing:\00"
@.str.6 = [13 x i8] c"received:%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 i8*
%9 = alloca i64
%10 = alloca %struct.sockaddr_in
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @BUFSIZ
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %8
%14 = alloca i8, i64 %12
store i64 %12, i64* %9
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %21, %2
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @SOCK_STREAM
%19 = call i32 @socket(i32 %17, i32 %18, i32 0)
store i32 %19, i32* %6
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %22
21: ; preds = %16
br label %16
22: ; preds = %16
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 3
store i32 %24, i32* %25
%26 = call i32 @htons(i32 8000)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %26, i32* %27
%28 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%30 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %29, i32 0, i32 0
store i32 %28, i32* %30
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%32 = call i32 @bzero(i32* %31, i32 8)
br label %33
33: ; preds = %38, %22
%34 = load i32, i32* %6
%35 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%36 = call i32 @connect(i32 %34, %struct.sockaddr* %35, i32 4)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %39
38: ; preds = %33
br label %33
39: ; preds = %33
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%41 = load i32, i32* %6
%42 = load i32, i32* @BUFSIZ
%43 = call i32 @recv(i32 %41, i8* %14, i32 %42, i32 0)
store i32 %43, i32* %7
%44 = load i32, i32* %7
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %14, i64 %45
store i8 0, i8* %46
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %14)
br label %48
48: ; preds = %49, %39
br label %49
49: ; preds = %48
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%51 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %14)
%52 = load i32, i32* %6
%53 = call i32 @strlen(i8* %14)
%54 = call i32 @send(i32 %52, i8* %14, i32 %53, i32 0)
store i32 %54, i32* %7
%55 = load i32, i32* %6
%56 = load i32, i32* @BUFSIZ
%57 = call i32 @recv(i32 %55, i8* %14, 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* %14, i64 %59
store i8 0, i8* %60
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* %14)
br label %48
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@BUFSIZ = global i32 0
@.str = [7 x i8] c"break!\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [10 x i8] c"127.0.0.1\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [17 x i8] c"Entersome thing:\00"
@.str.6 = [13 x i8] c"received:%s\0A\00"
@str = [19 x i8] c"We get the sockfd~\00"
@str.7 = [23 x i8] c"Get the Server~Cheers!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = load i32, i32* @BUFSIZ
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %9, %2
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = tail call i32 @socket(i32 %10, i32 %11, i32 0)
%13 = icmp eq i32 %12, -1
br i1 %13, label %9, label %14
14: ; preds = %9
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 3
store i32 %16, i32* %17
%18 = tail call i32 @htons(i32 8000)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %18, i32* %19
%20 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %20, i32* %21
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%23 = call i32 @bzero(i32* %22, i32 8)
%24 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %25
25: ; preds = %25, %14
%26 = call i32 @connect(i32 %12, %struct.sockaddr* %24, i32 4)
%27 = icmp eq i32 %26, -1
br i1 %27, label %25, label %28
28: ; preds = %25
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.7, i64 0, i64 0))
%30 = load i32, i32* @BUFSIZ
%31 = call i32 @recv(i32 %12, i8* %6, i32 %30, i32 0)
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %6, i64 %32
store i8 0, i8* %33
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %6)
br label %35
35: ; preds = %35, %28
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%37 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%38 = call i32 @strlen(i8* %6)
%39 = call i32 @send(i32 %12, i8* %6, i32 %38, i32 0)
%40 = load i32, i32* @BUFSIZ
%41 = call i32 @recv(i32 %12, i8* %6, i32 %40, i32 0)
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %6, i64 %42
store i8 0, i8* %43
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* %6)
br label %35
}