#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 *getDate();
scalar_t__ malloc(int);
int /*<<< orphan*/ realloc(char *, int);
int /*<<< orphan*/ responseText(int, char **, char **);
int /*<<< orphan*/ sprintf(char *, char *, int, char *, char *, int, char *);
int strlen(char *);
char *generateResponse(int status, char *fileContent) {
  char *requestResponse;
  responseText(status, &requestResponse, &fileContent);
  char *date = getDate();
  char *out = (char *)malloc(strlen(fileContent) + strlen(requestResponse) +
                             strlen(date) + 100);
  sprintf(out,
          "HTTP/1.1 %d %s\nDate: %s\nContent-Type: text/html\nContent-Length: "
          "%d\n\n%s",
          status, requestResponse, date, strlen(fileContent) + 1, fileContent);
  realloc(out, strlen(out) + 1);
  return out;
}


x86 assembly (clang, -O0):
<generateResponse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1040 <responseText@plt>
mov    $0x0,%al
call   1030 <getDate@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x58(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x54(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x54(%rbp),%edi
add    %eax,%edi
add    $0x64,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    -0x44(%rbp),%edx
mov    -0x40(%rbp),%rcx
mov    -0x38(%rbp),%r8
mov    %eax,%r9d
add    $0x1,%r9d
mov    -0x10(%rbp),%rax
lea    0xdf5(%rip),%rsi
mov    %rax,(%rsp)
call   1080 <sprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
add    $0x1,%esi
call   1070 <realloc@plt>
mov    -0x28(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generateResponse>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r14d
mov    %rsi,0x8(%rsp)
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1040 <responseText@plt>
xor    %eax,%eax
call   1030 <getDate@plt>
mov    %rax,%r15
mov    0x8(%rsp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    0x10(%rsp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1050 <strlen@plt>
add    %ebp,%ebx
lea    (%rax,%rbx,1),%edi
add    $0x64,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
mov    0x10(%rsp),%rbx
mov    0x8(%rsp),%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%r9d
mov    0x8(%rsp),%rax
mov    %rax,(%rsp)
lea    0xe22(%rip),%rsi
mov    %rbp,%rdi
mov    %r14d,%edx
mov    %rbx,%rcx
mov    %r15,%r8
call   1080 <sprintf@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%esi
mov    %rbp,%rdi
call   1070 <realloc@plt>
mov    %rbp,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [71 x i8] c"HTTP/1.1 %d %s\0ADate: %s\0AContent-Type: text/html\0AContent-Length: %d\0A\0A%s\00"
define i8* @generateResponse(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%8 = load i32, i32* %3
%9 = call i32 @responseText(i32 %8, i8** %5, i8** %4)
%10 = call i8* (...) @getDate()
store i8* %10, i8** %6
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
%13 = load i8*, i8** %5
%14 = call i32 @strlen(i8* %13)
%15 = add nsw i32 %12, %14
%16 = load i8*, i8** %6
%17 = call i32 @strlen(i8* %16)
%18 = add nsw i32 %15, %17
%19 = add nsw i32 %18, 100
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %7
%22 = load i8*, i8** %7
%23 = load i32, i32* %3
%24 = load i8*, i8** %5
%25 = load i8*, i8** %6
%26 = load i8*, i8** %4
%27 = call i32 @strlen(i8* %26)
%28 = add nsw i32 %27, 1
%29 = load i8*, i8** %4
%30 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0), i32 %23, i8* %24, i8* %25, i32 %28, i8* %29)
%31 = load i8*, i8** %7
%32 = load i8*, i8** %7
%33 = call i32 @strlen(i8* %32)
%34 = add nsw i32 %33, 1
%35 = call i32 @realloc(i8* %31, i32 %34)
%36 = load i8*, i8** %7
ret i8* %36
}

LLVM IR (-O2):
@.str = [71 x i8] c"HTTP/1.1 %d %s\0ADate: %s\0AContent-Type: text/html\0AContent-Length: %d\0A\0A%s\00"
define i8* @generateResponse(i32 %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
store i8* %1, i8** %3
%5 = bitcast i8** %4 to i8*
%6 = call i32 @responseText(i32 %0, i8** %4, i8** %3)
%7 = call i8* (...) @getDate()
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %10)
%12 = call i32 @strlen(i8* %7)
%13 = add i32 %9, 100
%14 = add i32 %13, %11
%15 = add i32 %14, %12
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i8*
%18 = load i8*, i8** %4
%19 = load i8*, i8** %3
%20 = call i32 @strlen(i8* %19)
%21 = add nsw i32 %20, 1
%22 = load i8*, i8** %3
%23 = call i32 @sprintf(i8* dereferenceable(1) %17, i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0), i32 %0, i8* %18, i8* %7, i32 %21, i8* %22)
%24 = call i32 @strlen(i8* %17)
%25 = add nsw i32 %24, 1
%26 = call i32 @realloc(i8* %17, i32 %25)
ret i8* %17
}