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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(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 *, ...);
scalar_t__ read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int port = 8989;
  if (argc > 1)
    port = atoi(argv[1]);
  int sock_client = socket(AF_INET, SOCK_STREAM, 0);
  struct sockaddr_in addr;
  memset(&addr, 0, sizeof(addr));
  addr.sin_family = AF_INET;
  addr.sin_port = htons(port);
  addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  if (connect(sock_client, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
    perror("connect");
    exit(1);
  }
  printf("sock_client = %d\n", sock_client);
  char *req = "POST / HTTP/1.1\r\nContent-Length: 84\r\nCookie: "
              "wanglei=123456\r\n\r\nsubmit_transfer=Transfer&transfer_from="
              "wanglei&transfer_to=xiaohua&transfer_money=50";
  write(sock_client, req, strlen(req));
  char resp[1024];
  int num = 0;
  while (read(sock_client, &resp[num], 1))
    num++;
  resp[num] = 0;
  printf("Response = %s\n", resp);
  close(sock_client);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x231d,-0x14(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    120a <main+0x3a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
mov    0x2dbe(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x18(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x24(%rbp)
lea    0xdac(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   10e0 <connect@plt>
cmp    $0x0,%rax
jge    128d <main+0xbd>
lea    0xd8c(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x18(%rbp),%esi
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd7f(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x444(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x440(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x444(%rbp),%edi
mov    -0x440(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
movl   $0x0,-0x434(%rbp)
mov    -0x18(%rbp),%edi
movslq -0x434(%rbp),%rax
lea    -0x430(%rbp),%rsi
add    %rax,%rsi
mov    $0x1,%edx
call   1090 <read@plt>
cmp    $0x0,%rax
je     1320 <main+0x150>
mov    -0x434(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x434(%rbp)
jmp    12e4 <main+0x114>
movslq -0x434(%rbp),%rax
movb   $0x0,-0x430(%rbp,%rax,1)
lea    -0x430(%rbp),%rsi
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x418,%rsp
mov    $0x231d,%ebp
cmp    $0x2,%edi
jl     11f2 <main+0x22>
mov    0x8(%rsi),%rdi
call   10c0 <atoi@plt>
mov    %eax,%ebp
mov    0x2def(%rip),%r15
mov    (%r15),%edi
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    (%r15),%eax
mov    %eax,0x8(%rsp)
mov    %ebp,%edi
call   1050 <htons@plt>
mov    %eax,0x4(%rsp)
lea    0xdc7(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   10e0 <connect@plt>
test   %rax,%rax
js     12d6 <main+0x106>
lea    0xdb2(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdb4(%rip),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    0x10(%rsp),%rbp
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1090 <read@plt>
add    $0x1,%rbp
test   %rax,%rax
jne    1290 <main+0xc0>
movb   $0x0,-0x1(%rbp)
lea    0xe05(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd2d(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [8 x i8] c"connect\00"
@.str.2 = [18 x i8] c"sock_client = %d\0A\00"
@.str.3 = [148 x i8] c"POST / HTTP/1.1\0D\0AContent-Length: 84\0D\0ACookie: wanglei=123456\0D\0A\0D\0Asubmit_transfer=Transfer&transfer_from=wanglei&transfer_to=xiaohua&transfer_money=50\00"
@.str.4 = [15 x i8] c"Response = %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 %struct.sockaddr_in
%9 = alloca i8*
%10 = alloca [1024 x i8]
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 8989, i32* %6
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 1
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %6
br label %19
19: ; preds = %14, %2
%20 = load i32, i32* @AF_INET
%21 = load i32, i32* @SOCK_STREAM
%22 = call i32 @socket(i32 %20, i32 %21, i32 0)
store i32 %22, i32* %7
%23 = call i32 @memset(%struct.sockaddr_in* %8, i32 0, i32 12)
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %24, i32* %25
%26 = load i32, i32* %6
%27 = call i32 @htons(i32 %26)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %27, i32* %28
%29 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%31 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %30, i32 0, i32 0
store i32 %29, i32* %31
%32 = load i32, i32* %7
%33 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%34 = call i64 @connect(i32 %32, %struct.sockaddr* %33, i32 12)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %19
%37 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %19
%40 = load i32, i32* %7
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %40)
store i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.3, i64 0, i64 0), i8** %9
%42 = load i32, i32* %7
%43 = load i8*, i8** %9
%44 = load i8*, i8** %9
%45 = call i32 @strlen(i8* %44)
%46 = call i32 @write(i32 %42, i8* %43, i32 %45)
store i32 0, i32* %11
br label %47
47: ; preds = %54, %39
%48 = load i32, i32* %7
%49 = load i32, i32* %11
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 %50
%52 = call i64 @read(i32 %48, i8* %51, i32 1)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %47
%55 = load i32, i32* %11
%56 = add nsw i32 %55, 1
store i32 %56, i32* %11
br label %47
57: ; preds = %47
%58 = load i32, i32* %11
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 %59
store i8 0, i8* %60
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %61)
%63 = load i32, i32* %7
%64 = call i32 @close(i32 %63)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [8 x i8] c"connect\00"
@.str.2 = [18 x i8] c"sock_client = %d\0A\00"
@.str.3 = [148 x i8] c"POST / HTTP/1.1\0D\0AContent-Length: 84\0D\0ACookie: wanglei=123456\0D\0A\0D\0Asubmit_transfer=Transfer&transfer_from=wanglei&transfer_to=xiaohua&transfer_money=50\00"
@.str.4 = [15 x i8] c"Response = %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [1024 x i8]
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atoi(i8* %8)
br label %10
10: ; preds = %6, %2
%11 = phi i32 [ %9, %6 ], [ 8989, %2 ]
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = tail call i32 @socket(i32 %12, i32 %13, i32 0)
%15 = bitcast %struct.sockaddr_in* %3 to i8*
%16 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %17, i32* %18
%19 = call i32 @htons(i32 %11)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %19, i32* %20
%21 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %21, i32* %22
%23 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%24 = call i64 @connect(i32 %14, %struct.sockaddr* %23, i32 12)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %10
%27 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %10
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%31 = call i32 @strlen(i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @write(i32 %14, i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.3, i64 0, i64 0), i32 %31)
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
br label %34
34: ; preds = %34, %29
%35 = phi i64 [ %39, %34 ], [ 0, %29 ]
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %35
%37 = call i64 @read(i32 %14, i8* %36, i32 1)
%38 = icmp eq i64 %37, 0
%39 = add nuw i64 %35, 1
br i1 %38, label %40, label %34
40: ; preds = %34
store i8 0, i8* %36
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %33)
%42 = call i32 @close(i32 %14)
ret i32 0
}