#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 /*<<< 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, unsigned char *, int, int /*<<< orphan*/);
int send(int, unsigned char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int upload_data(unsigned char *packed_data, int data_len) {
  int ret = 0;
  int sockfd, numbytes;
  unsigned char recv_data[512] = {'\0'};
  struct sockaddr_in their_addr;
  printf("break!");
  while ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
    ;
  printf("socket creat success\n");
  their_addr.sin_family = AF_INET;
  their_addr.sin_port = htons(28100);
  their_addr.sin_addr.s_addr = inet_addr("180.169.48.172");
  bzero(&(their_addr.sin_zero), 8);
  while (connect(sockfd, (struct sockaddr *)&their_addr,
                 sizeof(struct sockaddr)) == -1)
    ;
  printf("connect success\r\n");
  ret = send(sockfd, packed_data, data_len, 0);
  if (ret < 0) {
    printf("send error\r\n");
    close(sockfd);
    return -1;
  }
  ret = recv(sockfd, recv_data, 512, 0);
  if (ret < 0) {
    printf("recv error\r\n");
    close(sockfd);
    return -2;
  } else {
    printf("recv_len is %d -- recv_data is %02x %02x \r\n", ret, recv_data[2],
           recv_data[3]);
  }
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<upload_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1070 <memset@plt>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    1204 <upload_data+0x64>
jmp    11da <upload_data+0x3a>
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2dcf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x224(%rbp)
mov    $0x6dc4,%edi
call   1040 <htons@plt>
mov    %eax,-0x228(%rbp)
lea    0xde5(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x22c(%rbp)
lea    -0x230(%rbp),%rdi
mov    $0x8,%esi
call   10a0 <bzero@plt>
mov    -0x1c(%rbp),%edi
lea    -0x230(%rbp),%rsi
mov    $0x4,%edx
call   10b0 <connect@plt>
cmp    $0xffffffff,%eax
jne    1276 <upload_data+0xd6>
jmp    1254 <upload_data+0xb4>
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    12c4 <upload_data+0x124>
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1337 <upload_data+0x197>
mov    -0x1c(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1309 <upload_data+0x169>
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1337 <upload_data+0x197>
mov    -0x18(%rbp),%esi
movzbl -0x21e(%rbp),%edx
movzbl -0x21d(%rbp),%ecx
lea    0xd37(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<upload_data>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x210,%rsp
mov    %esi,%r14d
mov    %rdi,%r15
lea    0x10(%rsp),%rdi
mov    $0x200,%edx
xor    %esi,%esi
call   1080 <memset@plt>
lea    0xe23(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2dfd(%rip),%r12
mov    0x2de6(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r12),%edi
mov    0x0(%rbp),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
cmp    $0xffffffff,%eax
je     1200 <upload_data+0x50>
mov    %eax,%ebx
lea    0xe26(%rip),%rdi
call   1040 <puts@plt>
mov    (%r12),%eax
mov    %eax,0xc(%rsp)
mov    $0x6dc4,%edi
call   1050 <htons@plt>
mov    %eax,0x8(%rsp)
lea    0xdc9(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x8,%esi
call   10b0 <bzero@plt>
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x4,%edx
call   10c0 <connect@plt>
cmp    $0xffffffff,%eax
je     1260 <upload_data+0xb0>
lea    0xddc(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r14d,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
test   %eax,%eax
js     12c8 <upload_data+0x118>
lea    0x10(%rsp),%rsi
xor    %ebp,%ebp
mov    %ebx,%edi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
js     12db <upload_data+0x12b>
movzbl 0x12(%rsp),%edx
movzbl 0x13(%rsp),%ecx
lea    0xd59(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    12ec <upload_data+0x13c>
lea    0xda5(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%ebp
jmp    12ec <upload_data+0x13c>
lea    0xd86(%rip),%rdi
call   1040 <puts@plt>
mov    $0xfffffffe,%ebp
mov    %ebx,%edi
call   1090 <close@plt>
mov    %ebp,%eax
add    $0x210,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [7 x i8] c"break!\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [22 x i8] c"socket creat success\0A\00"
@.str.2 = [15 x i8] c"180.169.48.172\00"
@.str.3 = [18 x i8] c"connect success\0D\0A\00"
@.str.4 = [13 x i8] c"send error\0D\0A\00"
@.str.5 = [13 x i8] c"recv error\0D\0A\00"
@.str.6 = [44 x i8] c"recv_len is %d -- recv_data is %02x %02x \0D\0A\00"
define i32 @upload_data(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [512 x i8]
%10 = alloca %struct.sockaddr_in
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 0, i32* %6
%11 = bitcast [512 x i8]* %9 to i8*
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %18, %2
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
store i32 %16, i32* %7
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %19
18: ; preds = %13
br label %13
19: ; preds = %13
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 3
store i32 %21, i32* %22
%23 = call i32 @htons(i32 28100)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %23, i32* %24
%25 = call i32 @inet_addr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%27 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %26, i32 0, i32 0
store i32 %25, i32* %27
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%29 = call i32 @bzero(i32* %28, i32 8)
br label %30
30: ; preds = %35, %19
%31 = load i32, i32* %7
%32 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%33 = call i32 @connect(i32 %31, %struct.sockaddr* %32, i32 4)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %36
35: ; preds = %30
br label %30
36: ; preds = %30
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%38 = load i32, i32* %7
%39 = load i8*, i8** %4
%40 = load i32, i32* %5
%41 = call i32 @send(i32 %38, i8* %39, i32 %40, i32 0)
store i32 %41, i32* %6
%42 = load i32, i32* %6
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %36
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%46 = load i32, i32* %7
%47 = call i32 @close(i32 %46)
store i32 -1, i32* %3
br label %70
48: ; preds = %36
%49 = load i32, i32* %7
%50 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%51 = call i32 @recv(i32 %49, i8* %50, i32 512, i32 0)
store i32 %51, i32* %6
%52 = load i32, i32* %6
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %48
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%56 = load i32, i32* %7
%57 = call i32 @close(i32 %56)
store i32 -2, i32* %3
br label %70
58: ; preds = %48
%59 = load i32, i32* %6
%60 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 2
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 3
%64 = load i8, i8* %63
%65 = zext i8 %64 to i32
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0), i32 %59, i32 %62, i32 %65)
br label %67
67: ; preds = %58
%68 = load i32, i32* %7
%69 = call i32 @close(i32 %68)
store i32 0, i32* %3
br label %70
70: ; preds = %67, %54, %44
%71 = load i32, i32* %3
ret i32 %71
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [7 x i8] c"break!\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [15 x i8] c"180.169.48.172\00"
@.str.6 = [44 x i8] c"recv_len is %d -- recv_data is %02x %02x \0D\0A\00"
@str = [21 x i8] c"socket creat success\00"
@str.7 = [17 x i8] c"connect success\0D\00"
@str.8 = [12 x i8] c"recv error\0D\00"
@str.9 = [12 x i8] c"send error\0D\00"
define i32 @upload_data(i8* %0, i32 %1) {
%3 = alloca [512 x i8]
%4 = alloca %struct.sockaddr_in
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %8, %2
%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 %8, label %13
13: ; preds = %8
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 3
store i32 %15, i32* %16
%17 = tail call i32 @htons(i32 28100)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %17, i32* %18
%19 = tail call i32 @inet_addr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %19, i32* %20
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%22 = call i32 @bzero(i32* %21, i32 8)
%23 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
br label %24
24: ; preds = %24, %13
%25 = call i32 @connect(i32 %11, %struct.sockaddr* %23, i32 4)
%26 = icmp eq i32 %25, -1
br i1 %26, label %24, label %27
27: ; preds = %24
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.7, i64 0, i64 0))
%29 = call i32 @send(i32 %11, i8* %0, i32 %1, i32 0)
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.9, i64 0, i64 0))
br label %46
33: ; preds = %27
%34 = call i32 @recv(i32 %11, i8* %5, i32 512, i32 0)
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.8, i64 0, i64 0))
br label %46
38: ; preds = %33
%39 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 2
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 3
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0), i32 %34, i32 %41, i32 %44)
br label %46
46: ; preds = %38, %36, %31
%47 = phi i32 [ -1, %31 ], [ -2, %36 ], [ 0, %38 ]
%48 = call i32 @close(i32 %11)
ret i32 %47
}