#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 /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, int);
int /*<<< orphan*/ strlen(char *);
char *http_get(const char *url) {
  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;
  if (!url) {
    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");
  }
  sprintf(lpbuf, "GET /%s HTTP/1.1\r\nHOST: %s:%d\r\nAccept: */*\r\n\r\n", file,
          host_addr, port);
  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_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c50,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
movl   $0xffffffff,-0x414(%rbp)
ff ff ff
lea    -0x1420(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
lea    -0x1830(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
lea    -0x1c30(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
movl   $0x0,-0x1c34(%rbp)
movl   $0x0,-0x1c38(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1231 <http_get+0x91>
movq   $0x0,-0x8(%rbp)
jmp    136c <http_get+0x1cc>
mov    -0x10(%rbp),%rdi
lea    -0x1830(%rbp),%rsi
lea    -0x1c30(%rbp),%rdx
lea    -0x1c34(%rbp),%rcx
call   1070 <http_parse_url@plt>
cmp    $0x0,%rax
je     1272 <http_get+0xd2>
lea    0xda0(%rip),%rdi
call   1050 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    136c <http_get+0x1cc>
lea    -0x1830(%rbp),%rdi
mov    -0x1c34(%rbp),%esi
call   10c0 <http_tcpclient_create@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
jge    12a3 <http_get+0x103>
lea    0xd7a(%rip),%rdi
call   1050 <printf@plt>
lea    -0x1420(%rbp),%rdi
lea    -0x1c30(%rbp),%rdx
lea    -0x1830(%rbp),%rcx
mov    -0x1c34(%rbp),%r8d
lea    0xd70(%rip),%rsi
call   10b0 <sprintf@plt>
mov    -0x414(%rbp),%eax
mov    %eax,-0x1c44(%rbp)
lea    -0x1420(%rbp),%rax
mov    %rax,-0x1c40(%rbp)
lea    -0x1420(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x1c44(%rbp),%edi
mov    -0x1c40(%rbp),%rsi
mov    %eax,%edx
call   1030 <http_tcpclient_send@plt>
cmp    $0x0,%rax
jge    1328 <http_get+0x188>
lea    0xd4f(%rip),%rdi
call   1050 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    136c <http_get+0x1cc>
mov    -0x414(%rbp),%edi
lea    -0x1420(%rbp),%rsi
call   1090 <http_tcpclient_recv@plt>
cmp    $0x0,%rax
jg     1351 <http_get+0x1b1>
movq   $0x0,-0x8(%rbp)
jmp    136c <http_get+0x1cc>
mov    -0x414(%rbp),%edi
call   1080 <http_tcpclient_close@plt>
lea    -0x1420(%rbp),%rdi
call   10a0 <http_parse_result@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1c50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_get>:
push   %r14
push   %rbx
sub    $0x1818,%rsp
mov    %rdi,%rbx
lea    0x810(%rsp),%rdi
xor    %r14d,%r14d
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     1224 <http_get+0x84>
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     1232 <http_get+0x92>
lea    0xe4d(%rip),%rdi
call   1030 <puts@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x1818,%rsp
pop    %rbx
pop    %r14
ret
mov    0xc(%rsp),%esi
lea    0x10(%rsp),%rdi
call   10c0 <http_tcpclient_create@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1252 <http_get+0xb2>
lea    0xdff(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%r8d
lea    0xda2(%rip),%rsi
lea    0x810(%rsp),%r14
lea    0x410(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    %r14,%rdi
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     12c8 <http_get+0x128>
lea    0x810(%rsp),%rsi
mov    %ebx,%edi
call   1090 <http_tcpclient_recv@plt>
test   %rax,%rax
jle    1221 <http_get+0x81>
mov    %ebx,%edi
call   1080 <http_tcpclient_close@plt>
lea    0x810(%rsp),%rdi
call   10a0 <http_parse_result@plt>
mov    %rax,%r14
jmp    1224 <http_get+0x84>
lea    0xd60(%rip),%rdi
jmp    121c <http_get+0x7c>

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

LLVM IR (-O2):
@.str.2 = [47 x i8] c"GET /%s HTTP/1.1\0D\0AHOST: %s:%d\0D\0AAccept: */*\0D\0A\0D\0A\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_get(i8* %0) {
%2 = alloca [4096 x i8]
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%9 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%10 = icmp eq i8* %0, null
br i1 %10, label %36, label %11
11: ; preds = %1
%12 = call i64 @http_parse_url(i8* %0, i8* %7, i8* %8, i32* %5)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.5, i64 0, i64 0))
br label %36
16: ; preds = %11
%17 = load i32, i32* %5
%18 = call i32 @http_tcpclient_create(i8* %7, i32 %17)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.4, i64 0, i64 0))
br label %22
22: ; preds = %20, %16
%23 = load i32, i32* %5
%24 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* %8, i8* %7, i32 %23)
%25 = call i32 @strlen(i8* %6)
%26 = call i64 @http_tcpclient_send(i32 %18, i8* %6, i32 %25)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %36
30: ; preds = %22
%31 = call i64 @http_tcpclient_recv(i32 %18, i8* %6)
%32 = icmp slt i64 %31, 1
br i1 %32, label %36, label %33
33: ; preds = %30
%34 = call i32 @http_tcpclient_close(i32 %18)
%35 = call i8* @http_parse_result(i8* %6)
br label %36
36: ; preds = %30, %1, %33, %28, %14
%37 = phi i8* [ null, %14 ], [ null, %28 ], [ %35, %33 ], [ null, %1 ], [ null, %30 ]
ret i8* %37
}