#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 */

/* Type definitions */

/* Variables and functions */
char *http_parse_result(char *);
scalar_t__ http_parse_url(char const *, char *, char *, int *);
int /*<<< orphan*/ http_tcpclient_close(int);
int http_tcpclient_create(char *, int);
scalar_t__ http_tcpclient_recv(int, char *);
scalar_t__ http_tcpclient_send(int, char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, int, int,
                           char const *);
int strlen(char const *);
char *http_post(const char *url, const char *post_str) {
  char post[1024] = {'\0'};
  int socket_fd = -1;
  char lpbuf[1024 * 4] = {'\0'};
  char *ptmp;
  char host_addr[1024] = {'\0'};
  char file[1024] = {'\0'};
  int port = 0;
  int len = 0;
  char *response = NULL;
  if (!url || !post_str) {
    return NULL;
  }
  if (http_parse_url(url, host_addr, file, &port)) {
    printf("http_parse_url failed!\n");
    return NULL;
  }
  socket_fd = http_tcpclient_create(host_addr, port);
  if (socket_fd < 0) {
    printf("http_tcpclient_create failed\n");
    return 0;
  }
  sprintf(lpbuf,
          "POST /%s HTTP/1.1\r\nHOST: %s:%d\r\nAccept: */*\r\n"
          "Content-Type:application/x-www-form-urlencoded\r\nContent-Length: "
          "%d\r\n\r\n%s",
          file, host_addr, port, strlen(post_str), post_str);
  if (http_tcpclient_send(socket_fd, lpbuf, strlen(lpbuf)) < 0) {
    printf("http_tcpclient_send failed..\n");
    return NULL;
  }
  if (http_tcpclient_recv(socket_fd, lpbuf) <= 0) {
    return NULL;
  }
  http_tcpclient_close(socket_fd);
  return http_parse_result(lpbuf);
}


x86 assembly (clang, -O0):
<http_post>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
movl   $0xffffffff,-0x424(%rbp)
ff ff ff
lea    -0x1430(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
lea    -0x1840(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
lea    -0x1c40(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
movl   $0x0,-0x1c44(%rbp)
movl   $0x0,-0x1c48(%rbp)
movq   $0x0,-0x1c50(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     123e <http_post+0x9e>
cmpq   $0x0,-0x18(%rbp)
jne    124b <http_post+0xab>
movq   $0x0,-0x8(%rbp)
jmp    13dd <http_post+0x23d>
mov    -0x10(%rbp),%rdi
lea    -0x1840(%rbp),%rsi
lea    -0x1c40(%rbp),%rdx
lea    -0x1c44(%rbp),%rcx
call   1070 <http_parse_url@plt>
cmp    $0x0,%rax
je     128c <http_post+0xec>
lea    0xd86(%rip),%rdi
call   1050 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    13dd <http_post+0x23d>
lea    -0x1840(%rbp),%rdi
mov    -0x1c44(%rbp),%esi
call   10c0 <http_tcpclient_create@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0x0,-0x424(%rbp)
jge    12ca <http_post+0x12a>
lea    0xd60(%rip),%rdi
call   1050 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    13dd <http_post+0x23d>
lea    -0x1430(%rbp),%rax
mov    %rax,-0x1c78(%rbp)
lea    -0x1c40(%rbp),%rax
mov    %rax,-0x1c70(%rbp)
lea    -0x1840(%rbp),%rax
mov    %rax,-0x1c68(%rbp)
mov    -0x1c44(%rbp),%eax
mov    %eax,-0x1c60(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1c78(%rbp),%rdi
mov    -0x1c70(%rbp),%rdx
mov    -0x1c68(%rbp),%rcx
mov    -0x1c60(%rbp),%r8d
mov    %eax,%r9d
mov    -0x18(%rbp),%rax
lea    0xd03(%rip),%rsi
mov    %rax,(%rsp)
call   10b0 <sprintf@plt>
mov    -0x424(%rbp),%eax
mov    %eax,-0x1c5c(%rbp)
lea    -0x1430(%rbp),%rax
mov    %rax,-0x1c58(%rbp)
lea    -0x1430(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1c5c(%rbp),%edi
mov    -0x1c58(%rbp),%rsi
mov    %eax,%edx
call   1030 <http_tcpclient_send@plt>
cmp    $0x0,%rax
jge    1399 <http_post+0x1f9>
lea    0xd25(%rip),%rdi
call   1050 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    13dd <http_post+0x23d>
mov    -0x424(%rbp),%edi
lea    -0x1430(%rbp),%rsi
call   1090 <http_tcpclient_recv@plt>
cmp    $0x0,%rax
jg     13c2 <http_post+0x222>
movq   $0x0,-0x8(%rbp)
jmp    13dd <http_post+0x23d>
mov    -0x424(%rbp),%edi
call   1080 <http_tcpclient_close@plt>
lea    -0x1430(%rbp),%rdi
call   10a0 <http_parse_result@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1c80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_post>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1818,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x810(%rsp),%rdi
xor    %r15d,%r15d
mov    $0x1000,%edx
xor    %esi,%esi
call   1060 <memset@plt>
lea    0x10(%rsp),%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1060 <memset@plt>
lea    0x410(%rsp),%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1060 <memset@plt>
movl   $0x0,0xc(%rsp)
test   %rbx,%rbx
je     122f <http_post+0x8f>
test   %r14,%r14
je     122f <http_post+0x8f>
lea    0x10(%rsp),%rsi
lea    0x410(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rbx,%rdi
call   1070 <http_parse_url@plt>
test   %rax,%rax
je     1240 <http_post+0xa0>
lea    0xe89(%rip),%rdi
call   1030 <puts@plt>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x1818,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0xc(%rsp),%esi
lea    0x10(%rsp),%rdi
call   10c0 <http_tcpclient_create@plt>
test   %eax,%eax
js     12df <http_post+0x13f>
mov    %eax,%ebx
mov    0xc(%rsp),%ebp
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %r14,(%rsp)
lea    0xd91(%rip),%rsi
lea    0x810(%rsp),%r14
lea    0x410(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    %r14,%rdi
mov    %ebp,%r8d
mov    %eax,%r9d
call   10b0 <sprintf@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <http_tcpclient_send@plt>
test   %rax,%rax
js     12eb <http_post+0x14b>
lea    0x810(%rsp),%rsi
mov    %ebx,%edi
call   1090 <http_tcpclient_recv@plt>
test   %rax,%rax
jle    122c <http_post+0x8c>
mov    %ebx,%edi
call   1080 <http_tcpclient_close@plt>
lea    0x810(%rsp),%rdi
call   10a0 <http_parse_result@plt>
mov    %rax,%r15
jmp    122f <http_post+0x8f>
lea    0xdad(%rip),%rdi
jmp    1227 <http_post+0x87>
lea    0xd84(%rip),%rdi
jmp    1227 <http_post+0x87>

LLVM IR (-O0):
@.str = [24 x i8] c"http_parse_url failed!\0A\00"
@.str.1 = [30 x i8] c"http_tcpclient_create failed\0A\00"
@.str.2 = [118 x i8] c"POST /%s HTTP/1.1\0D\0AHOST: %s:%d\0D\0AAccept: */*\0D\0AContent-Type:application/x-www-form-urlencoded\0D\0AContent-Length: %d\0D\0A\0D\0A%s\00"
@.str.3 = [30 x i8] c"http_tcpclient_send failed..\0A\00"
define i8* @http_post(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [1024 x i8]
%7 = alloca i32
%8 = alloca [4096 x i8]
%9 = alloca i8*
%10 = alloca [1024 x i8]
%11 = alloca [1024 x i8]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%15 = bitcast [1024 x i8]* %6 to i8*
store i32 -1, i32* %7
%16 = bitcast [4096 x i8]* %8 to i8*
%17 = bitcast [1024 x i8]* %10 to i8*
%18 = bitcast [1024 x i8]* %11 to i8*
store i32 0, i32* %12
store i32 0, i32* %13
store i8* null, i8** %14
%19 = load i8*, i8** %4
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %2
%22 = load i8*, i8** %5
%23 = icmp ne i8* %22, null
br i1 %23, label %25, label %24
24: ; preds = %21, %2
store i8* null, i8** %3
br label %69
25: ; preds = %21
%26 = load i8*, i8** %4
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%29 = call i64 @http_parse_url(i8* %26, i8* %27, i8* %28, i32* %12)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %25
%32 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %3
br label %69
33: ; preds = %25
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%35 = load i32, i32* %12
%36 = call i32 @http_tcpclient_create(i8* %34, i32 %35)
store i32 %36, i32* %7
%37 = load i32, i32* %7
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %33
%40 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %3
br label %69
41: ; preds = %33
%42 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%45 = load i32, i32* %12
%46 = load i8*, i8** %5
%47 = call i32 @strlen(i8* %46)
%48 = load i8*, i8** %5
%49 = call i32 @sprintf(i8* %42, i8* getelementptr inbounds ([118 x i8], [118 x i8]* @.str.2, i64 0, i64 0), i8* %43, i8* %44, i32 %45, i32 %47, i8* %48)
%50 = load i32, i32* %7
%51 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%52 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%53 = call i32 @strlen(i8* %52)
%54 = call i64 @http_tcpclient_send(i32 %50, i8* %51, i32 %53)
%55 = icmp slt i64 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %41
%57 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
store i8* null, i8** %3
br label %69
58: ; preds = %41
%59 = load i32, i32* %7
%60 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%61 = call i64 @http_tcpclient_recv(i32 %59, i8* %60)
%62 = icmp sle i64 %61, 0
br i1 %62, label %63, label %64
63: ; preds = %58
store i8* null, i8** %3
br label %69
64: ; preds = %58
%65 = load i32, i32* %7
%66 = call i32 @http_tcpclient_close(i32 %65)
%67 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%68 = call i8* @http_parse_result(i8* %67)
store i8* %68, i8** %3
br label %69
69: ; preds = %64, %63, %56, %39, %31, %24
%70 = load i8*, i8** %3
ret i8* %70
}

LLVM IR (-O2):
@.str.2 = [118 x i8] c"POST /%s HTTP/1.1\0D\0AHOST: %s:%d\0D\0AAccept: */*\0D\0AContent-Type:application/x-www-form-urlencoded\0D\0AContent-Length: %d\0D\0A\0D\0A%s\00"
@str = [29 x i8] c"http_tcpclient_send failed..\00"
@str.4 = [29 x i8] c"http_tcpclient_create failed\00"
@str.5 = [23 x i8] c"http_parse_url failed!\00"
define i8* @http_post(i8* %0, i8* %1) {
%3 = alloca [4096 x i8]
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca i32
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%10 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%11 = icmp ne i8* %0, null
%12 = icmp ne i8* %1, null
%13 = and i1 %11, %12
br i1 %13, label %14, label %40
14: ; preds = %2
%15 = call i64 @http_parse_url(i8* %0, i8* %8, i8* %9, i32* %6)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.5, i64 0, i64 0))
br label %40
19: ; preds = %14
%20 = load i32, i32* %6
%21 = call i32 @http_tcpclient_create(i8* %8, i32 %20)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.4, i64 0, i64 0))
br label %40
25: ; preds = %19
%26 = load i32, i32* %6
%27 = call i32 @strlen(i8* %1)
%28 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([118 x i8], [118 x i8]* @.str.2, i64 0, i64 0), i8* %9, i8* %8, i32 %26, i32 %27, i8* %1)
%29 = call i32 @strlen(i8* %7)
%30 = call i64 @http_tcpclient_send(i32 %21, i8* %7, i32 %29)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %25
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %40
34: ; preds = %25
%35 = call i64 @http_tcpclient_recv(i32 %21, i8* %7)
%36 = icmp slt i64 %35, 1
br i1 %36, label %40, label %37
37: ; preds = %34
%38 = call i32 @http_tcpclient_close(i32 %21)
%39 = call i8* @http_parse_result(i8* %7)
br label %40
40: ; preds = %34, %2, %37, %32, %23, %17
%41 = phi i8* [ null, %17 ], [ null, %23 ], [ null, %32 ], [ %39, %37 ], [ null, %2 ], [ null, %34 ]
ret i8* %41
}