#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*/ http_free(char *);
scalar_t__ http_malloc(scalar_t__);
char *itoa(int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, char *, char *);
scalar_t__ strlen(char *);
char *http_post_header(char *host, char *resource, char *type, int data_len) {
  char *len_str = itoa(data_len);
  char *header = (char *)http_malloc(
      strlen("POST ") + strlen(resource) + strlen(" HTTP/1.1\r\nHost: ") +
      strlen(host) + strlen("\r\nContent-Type: ") + strlen(type) +
      strlen("\r\nContent-Length: ") + strlen(len_str) + strlen("\r\n\r\n") +
      1);
  sprintf(header,
          "POST %s HTTP/1.1\r\nHost: %s\r\nContent-Type: %s\r\nContent-Length: "
          "%s\r\n\r\n",
          resource, host, type, len_str);
  http_free(len_str);
  return header;
}


x86 assembly (clang, -O0):
<http_post_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1070 <itoa@plt>
mov    %rax,-0x28(%rbp)
lea    0xe86(%rip),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x70(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x70(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x68(%rbp)
lea    0xe65(%rip),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x68(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x60(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x60(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x58(%rbp)
lea    0xe46(%rip),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
lea    0xe26(%rip),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
lea    0xe48(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1040 <http_malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    -0x28(%rbp),%r9
lea    0xdd4(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x28(%rbp),%rdi
call   1050 <http_free@plt>
mov    -0x30(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_post_header>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %rdi,%rbp
mov    %rdi,(%rsp)
mov    %ecx,%edi
call   1070 <itoa@plt>
mov    %rax,%r15
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %rax,%r13
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1030 <strlen@plt>
add    %r13,%rbp
add    %r14,%rbp
lea    (%rax,%rbp,1),%rdi
add    $0x3d,%rdi
call   1040 <http_malloc@plt>
mov    %rax,%rbp
lea    0xe48(%rip),%rsi
mov    %rax,%rdi
mov    %r12,%rdx
mov    (%rsp),%rcx
mov    %rbx,%r8
mov    %r15,%r9
call   1060 <sprintf@plt>
mov    %r15,%rdi
call   1050 <http_free@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"POST \00"
@.str.1 = [18 x i8] c" HTTP/1.1\0D\0AHost: \00"
@.str.2 = [17 x i8] c"\0D\0AContent-Type: \00"
@.str.3 = [19 x i8] c"\0D\0AContent-Length: \00"
@.str.4 = [5 x i8] c"\0D\0A\0D\0A\00"
@.str.5 = [69 x i8] c"POST %s HTTP/1.1\0D\0AHost: %s\0D\0AContent-Type: %s\0D\0AContent-Length: %s\0D\0A\0D\0A\00"
define i8* @http_post_header(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%11 = load i32, i32* %8
%12 = call i8* @itoa(i32 %11)
store i8* %12, i8** %9
%13 = call i64 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%14 = load i8*, i8** %6
%15 = call i64 @strlen(i8* %14)
%16 = add nsw i64 %13, %15
%17 = call i64 @strlen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%18 = add nsw i64 %16, %17
%19 = load i8*, i8** %5
%20 = call i64 @strlen(i8* %19)
%21 = add nsw i64 %18, %20
%22 = call i64 @strlen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%23 = add nsw i64 %21, %22
%24 = load i8*, i8** %7
%25 = call i64 @strlen(i8* %24)
%26 = add nsw i64 %23, %25
%27 = call i64 @strlen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%28 = add nsw i64 %26, %27
%29 = load i8*, i8** %9
%30 = call i64 @strlen(i8* %29)
%31 = add nsw i64 %28, %30
%32 = call i64 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%33 = add nsw i64 %31, %32
%34 = add nsw i64 %33, 1
%35 = call i64 @http_malloc(i64 %34)
%36 = inttoptr i64 %35 to i8*
store i8* %36, i8** %10
%37 = load i8*, i8** %10
%38 = load i8*, i8** %6
%39 = load i8*, i8** %5
%40 = load i8*, i8** %7
%41 = load i8*, i8** %9
%42 = call i32 @sprintf(i8* %37, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.5, i64 0, i64 0), i8* %38, i8* %39, i8* %40, i8* %41)
%43 = load i8*, i8** %9
%44 = call i32 @http_free(i8* %43)
%45 = load i8*, i8** %10
ret i8* %45
}

LLVM IR (-O2):
@.str.5 = [69 x i8] c"POST %s HTTP/1.1\0D\0AHost: %s\0D\0AContent-Type: %s\0D\0AContent-Length: %s\0D\0A\0D\0A\00"
define i8* @http_post_header(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = tail call i8* @itoa(i32 %3)
%6 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%7 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%8 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%9 = tail call i64 @strlen(i8* dereferenceable(1) %5)
%10 = add i64 %6, 61
%11 = add i64 %10, %7
%12 = add i64 %11, %8
%13 = add i64 %12, %9
%14 = tail call i64 @http_malloc(i64 %13)
%15 = inttoptr i64 %14 to i8*
%16 = tail call i32 @sprintf(i8* dereferenceable(1) %15, i8* dereferenceable(1) getelementptr inbounds ([69 x i8], [69 x i8]* @.str.5, i64 0, i64 0), i8* %1, i8* %0, i8* %2, i8* %5)
%17 = tail call i32 @http_free(i8* %5)
ret i8* %15
}