#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 *malloc(size_t);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *make_http_response(char *status_code, char *reason, char *message) {
  printf("MAKING RESPONSE\n");
  char *httpversion = "HTTP/1.1";
  size_t length = 0;
  length += strlen(status_code);
  length += strlen(reason);
  length += strlen(message);
  length += strlen(httpversion);
  length += 7;
  char *response = malloc(length);
  strcpy(response, httpversion);
  strcat(response, " ");
  strcat(response, status_code);
  strcat(response, " ");
  strcat(response, reason);
  strcat(response, "\r\n\r\n");
  strcat(response, message);
  strcat(response, "\r\n");
  return response;
}


x86 assembly (clang, -O0):
<make_http_response>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xe95(%rip),%rdi
call   1050 <printf@plt>
lea    0xe9a(%rip),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x7,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rdi
lea    0xe22(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x30(%rbp),%rdi
lea    0xe05(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x30(%rbp),%rdi
lea    0xdea(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x30(%rbp),%rdi
lea    0xdcf(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_http_response>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xea7(%rip),%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %rax,%r13
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <strlen@plt>
add    %r13,%rbx
lea    (%rax,%rbx,1),%rdi
add    $0xf,%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0xe5a(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
lea    0xe54(%rip),%r13
mov    %rbx,%rdi
mov    %r13,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <strcat@plt>
lea    0xe23(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
lea    0xe0b(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [17 x i8] c"MAKING RESPONSE\0A\00"
@.str.1 = [9 x i8] c"HTTP/1.1\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [5 x i8] c"\0D\0A\0D\0A\00"
@.str.4 = [3 x i8] c"\0D\0A\00"
define i8* @make_http_response(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%10 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8** %7
store i64 0, i64* %8
%11 = load i8*, i8** %4
%12 = call i64 @strlen(i8* %11)
%13 = load i64, i64* %8
%14 = add i64 %13, %12
store i64 %14, i64* %8
%15 = load i8*, i8** %5
%16 = call i64 @strlen(i8* %15)
%17 = load i64, i64* %8
%18 = add i64 %17, %16
store i64 %18, i64* %8
%19 = load i8*, i8** %6
%20 = call i64 @strlen(i8* %19)
%21 = load i64, i64* %8
%22 = add i64 %21, %20
store i64 %22, i64* %8
%23 = load i8*, i8** %7
%24 = call i64 @strlen(i8* %23)
%25 = load i64, i64* %8
%26 = add i64 %25, %24
store i64 %26, i64* %8
%27 = load i64, i64* %8
%28 = add i64 %27, 7
store i64 %28, i64* %8
%29 = load i64, i64* %8
%30 = call i8* @malloc(i64 %29)
store i8* %30, i8** %9
%31 = load i8*, i8** %9
%32 = load i8*, i8** %7
%33 = call i32 @strcpy(i8* %31, i8* %32)
%34 = load i8*, i8** %9
%35 = call i32 @strcat(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%36 = load i8*, i8** %9
%37 = load i8*, i8** %4
%38 = call i32 @strcat(i8* %36, i8* %37)
%39 = load i8*, i8** %9
%40 = call i32 @strcat(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%41 = load i8*, i8** %9
%42 = load i8*, i8** %5
%43 = call i32 @strcat(i8* %41, i8* %42)
%44 = load i8*, i8** %9
%45 = call i32 @strcat(i8* %44, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%46 = load i8*, i8** %9
%47 = load i8*, i8** %6
%48 = call i32 @strcat(i8* %46, i8* %47)
%49 = load i8*, i8** %9
%50 = call i32 @strcat(i8* %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%51 = load i8*, i8** %9
ret i8* %51
}

LLVM IR (-O2):
@.str.1 = [9 x i8] c"HTTP/1.1\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [5 x i8] c"\0D\0A\0D\0A\00"
@.str.4 = [3 x i8] c"\0D\0A\00"
@str = [16 x i8] c"MAKING RESPONSE\00"
define i8* @make_http_response(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%6 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%7 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%8 = add i64 %5, 15
%9 = add i64 %8, %6
%10 = add i64 %9, %7
%11 = tail call i8* @malloc(i64 %10)
%12 = tail call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 @strcat(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = tail call i32 @strcat(i8* %11, i8* %0)
%15 = tail call i32 @strcat(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%16 = tail call i32 @strcat(i8* %11, i8* %1)
%17 = tail call i32 @strcat(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%18 = tail call i32 @strcat(i8* %11, i8* %2)
%19 = tail call i32 @strcat(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
ret i8* %11
}