#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 */
scalar_t__ http_malloc(scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
scalar_t__ strlen(char *);
char *http_get_header(char *host, char *resource) {
  char *header = (char *)http_malloc(strlen("GET ") + strlen(resource) +
                                     strlen(" HTTP/1.1\r\nHost: ") +
                                     strlen(host) + strlen("\r\n\r\n") + 1);
  sprintf(header, "GET %s HTTP/1.1\r\nHost: %s\r\n\r\n", resource, host);
  return header;
}


x86 assembly (clang, -O0):
<http_get_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeb9(%rip),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
lea    0xe97(%rip),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
lea    0xe91(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1040 <http_malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    0xe4c(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_get_header>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x1a,%rdi
call   1040 <http_malloc@plt>
mov    %rax,%rbx
lea    0xe9b(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
call   1050 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"GET \00"
@.str.1 = [18 x i8] c" HTTP/1.1\0D\0AHost: \00"
@.str.2 = [5 x i8] c"\0D\0A\0D\0A\00"
@.str.3 = [30 x i8] c"GET %s HTTP/1.1\0D\0AHost: %s\0D\0A\0D\0A\00"
define i8* @http_get_header(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = call i64 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%7 = load i8*, i8** %4
%8 = call i64 @strlen(i8* %7)
%9 = add nsw i64 %6, %8
%10 = call i64 @strlen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%11 = add nsw i64 %9, %10
%12 = load i8*, i8** %3
%13 = call i64 @strlen(i8* %12)
%14 = add nsw i64 %11, %13
%15 = call i64 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%16 = add nsw i64 %14, %15
%17 = add nsw i64 %16, 1
%18 = call i64 @http_malloc(i64 %17)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %5
%20 = load i8*, i8** %5
%21 = load i8*, i8** %4
%22 = load i8*, i8** %3
%23 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %21, i8* %22)
%24 = load i8*, i8** %5
ret i8* %24
}

LLVM IR (-O2):
@.str.3 = [30 x i8] c"GET %s HTTP/1.1\0D\0AHost: %s\0D\0A\0D\0A\00"
define i8* @http_get_header(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = add i64 %3, 26
%6 = add i64 %5, %4
%7 = tail call i64 @http_malloc(i64 %6)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32 @sprintf(i8* dereferenceable(1) %8, i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* %0)
ret i8* %8
}