#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 *CopyString(char *);
char *HTParse(char const *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ free(void *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
char *ConstructSendBuffer(const char *url) {
  char *ret = NULL;
  char *host = HTParse(url, NULL, 8);
  char *path = HTParse(url, NULL, 4 | 1);
  if (host && path) {
    char buffer[512];
    sprintf(buffer,
            "GET %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: Mozilla/5.0 (Windows "
            "NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) "
            "Chrome/70.0.3538.102 Safari/537.36\r\nAccept: "
            "text/html,application/xhtml+xml,application/xml\r\n\r\n",
            path, host);
    ret = CopyString(buffer);
  }
  if (host)
    free((void *)host);
  if (path)
    free((void *)path);
  return ret;
}


x86 assembly (clang, -O0):
<ConstructSendBuffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x8,%edx
call   1050 <HTParse@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x5,%edx
call   1050 <HTParse@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11c4 <ConstructSendBuffer+0x84>
cmpq   $0x0,-0x20(%rbp)
je     11c4 <ConstructSendBuffer+0x84>
lea    -0x220(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe51(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x220(%rbp),%rdi
call   1040 <CopyString@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11d8 <ConstructSendBuffer+0x98>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x20(%rbp)
je     11ec <ConstructSendBuffer+0xac>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ConstructSendBuffer>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %rdi,%rbx
xor    %r14d,%r14d
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <HTParse@plt>
mov    %rax,%r12
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1050 <HTParse@plt>
mov    %rax,%r15
test   %r12,%r12
je     11a2 <ConstructSendBuffer+0x62>
test   %r15,%r15
je     11a2 <ConstructSendBuffer+0x62>
lea    0xe7a(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r12,%rcx
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <CopyString@plt>
mov    %rax,%r14
test   %r12,%r12
je     11af <ConstructSendBuffer+0x6f>
mov    %r12,%rdi
call   1030 <free@plt>
test   %r15,%r15
je     11bc <ConstructSendBuffer+0x7c>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [211 x i8] c"GET %s HTTP/1.1\0D\0AHost: %s\0D\0AUser-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36\0D\0AAccept: text/html,application/xhtml+xml,application/xml\0D\0A\0D\0A\00"
define i8* @ConstructSendBuffer(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [512 x i8]
store i8* %0, i8** %2
store i8* null, i8** %3
%7 = load i8*, i8** %2
%8 = call i8* @HTParse(i8* %7, i32* null, i32 8)
store i8* %8, i8** %4
%9 = load i8*, i8** %2
%10 = call i8* @HTParse(i8* %9, i32* null, i32 5)
store i8* %10, i8** %5
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %23
13: ; preds = %1
%14 = load i8*, i8** %5
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%18 = load i8*, i8** %5
%19 = load i8*, i8** %4
%20 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([211 x i8], [211 x i8]* @.str, i64 0, i64 0), i8* %18, i8* %19)
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%22 = call i8* @CopyString(i8* %21)
store i8* %22, i8** %3
br label %23
23: ; preds = %16, %13, %1
%24 = load i8*, i8** %4
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i8*, i8** %4
%28 = call i32 @free(i8* %27)
br label %29
29: ; preds = %26, %23
%30 = load i8*, i8** %5
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i8*, i8** %5
%34 = call i32 @free(i8* %33)
br label %35
35: ; preds = %32, %29
%36 = load i8*, i8** %3
ret i8* %36
}

LLVM IR (-O2):
@.str = [211 x i8] c"GET %s HTTP/1.1\0D\0AHost: %s\0D\0AUser-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36\0D\0AAccept: text/html,application/xhtml+xml,application/xml\0D\0A\0D\0A\00"
define i8* @ConstructSendBuffer(i8* %0) {
%2 = alloca [512 x i8]
%3 = tail call i8* @HTParse(i8* %0, i32* null, i32 8)
%4 = tail call i8* @HTParse(i8* %0, i32* null, i32 5)
%5 = icmp ne i8* %3, null
%6 = icmp ne i8* %4, null
%7 = select i1 %5, i1 %6, i1 false
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%10 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([211 x i8], [211 x i8]* @.str, i64 0, i64 0), i8* %4, i8* %3)
%11 = call i8* @CopyString(i8* %9)
br label %12
12: ; preds = %8, %1
%13 = phi i8* [ %11, %8 ], [ null, %1 ]
br i1 %5, label %14, label %16
14: ; preds = %12
%15 = call i32 @free(i8* %3)
br label %16
16: ; preds = %14, %12
br i1 %6, label %17, label %19
17: ; preds = %16
%18 = call i32 @free(i8* %4)
br label %19
19: ; preds = %17, %16
ret i8* %13
}