#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 */
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, int /*<<< orphan*/,
                           char *);
int /*<<< orphan*/ strlen(char *);
char *build_http_message(char *host, char *page, char *data, char *query) {
  char *tpl =
      "POST /%s HTTP/1.1\r\nHost: %s\r\nConnection: "
      "keep-alive\r\nContent-Length: %d\r\nContent-Type: "
      "application/x-www-form-urlencoded; charset=UTF-8\r\n\r\n%s\r\n\0";
  sprintf(query, tpl, page, host, strlen(data), data);
  return query;
}


x86 assembly (clang, -O0):
<build_http_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    0xec1(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    %eax,%r8d
mov    -0x18(%rbp),%r9
call   1040 <sprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_http_message>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rdx,%rdi
call   1030 <strlen@plt>
lea    0xebd(%rip),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %eax,%r8d
mov    %rbx,%r9
call   1040 <sprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [145 x i8] c"POST /%s HTTP/1.1\0D\0AHost: %s\0D\0AConnection: keep-alive\0D\0AContent-Length: %d\0D\0AContent-Type: application/x-www-form-urlencoded; charset=UTF-8\0D\0A\0D\0A%s\0D\0A\00\00"
define i8* @build_http_message(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
store i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str, i64 0, i64 0), i8** %9
%10 = load i8*, i8** %8
%11 = load i8*, i8** %9
%12 = load i8*, i8** %6
%13 = load i8*, i8** %5
%14 = load i8*, i8** %7
%15 = call i32 @strlen(i8* %14)
%16 = load i8*, i8** %7
%17 = call i32 @sprintf(i8* %10, i8* %11, i8* %12, i8* %13, i32 %15, i8* %16)
%18 = load i8*, i8** %8
ret i8* %18
}

LLVM IR (-O2):
@.str = [145 x i8] c"POST /%s HTTP/1.1\0D\0AHost: %s\0D\0AConnection: keep-alive\0D\0AContent-Length: %d\0D\0AContent-Type: application/x-www-form-urlencoded; charset=UTF-8\0D\0A\0D\0A%s\0D\0A\00\00"
define i8* @build_http_message(i8* %0, i8* %1, i8* %2, i8* returned writeonly %3) {
%5 = tail call i32 @strlen(i8* %2)
%6 = tail call i32 @sprintf(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([145 x i8], [145 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %0, i32 %5, i8* %2)
ret i8* %3
}