#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*/ STDOUT_FILENO;
int getContentType(int);
int /*<<< orphan*/ getStatusCode(int);
char *secPrint2String(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strAppend(char **, char *);
int /*<<< orphan*/ strAppendFormatString(char **, char *, int);
int writeStringToFile(int /*<<< orphan*/, char *);
int sendHTTPResponseHeader(int i_status, int i_content_type,
                           int i_content_length) {
  int i_success = 0;
  char *cp_http_response_header = NULL;
  cp_http_response_header =
      secPrint2String("HTTP/1.1 %s\n", getStatusCode(i_status));
  strAppend(&cp_http_response_header, "Server: tiniweb/1.0\n");
  strAppend(&cp_http_response_header, "Connection: close\n");
  strAppendFormatString(&cp_http_response_header, "Content-Type: %s\n",
                        getContentType(i_content_type));
  if (i_content_length >= 0) {
    strAppendFormatString(&cp_http_response_header, "Content-Length: %i\n",
                          i_content_length);
  }
  strAppend(&cp_http_response_header, "\n");
  i_success = writeStringToFile(STDOUT_FILENO, cp_http_response_header);
  return i_success;
}


x86 assembly (clang, -O0):
<sendHTTPResponseHeader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <getStatusCode@plt>
mov    %eax,%esi
lea    0xe6f(%rip),%rdi
call   1080 <secPrint2String@plt>
mov    %rax,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
lea    0xe68(%rip),%rsi
call   1070 <strAppend@plt>
lea    -0x18(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1070 <strAppend@plt>
mov    -0x8(%rbp),%edi
call   1060 <getContentType@plt>
mov    %eax,%edx
lea    -0x18(%rbp),%rdi
lea    0xe66(%rip),%rsi
call   1030 <strAppendFormatString@plt>
cmpl   $0x0,-0xc(%rbp)
jl     11f1 <sendHTTPResponseHeader+0x91>
mov    -0xc(%rbp),%edx
lea    -0x18(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1030 <strAppendFormatString@plt>
lea    -0x18(%rbp),%rdi
lea    0xe24(%rip),%rsi
call   1070 <strAppend@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
call   1040 <writeStringToFile@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendHTTPResponseHeader>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %esi,%ebp
call   1050 <getStatusCode@plt>
lea    0xe87(%rip),%rdi
mov    %eax,%esi
call   1080 <secPrint2String@plt>
mov    %rax,0x8(%rsp)
lea    0xe81(%rip),%rsi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <strAppend@plt>
lea    0xe82(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strAppend@plt>
mov    %ebp,%edi
call   1060 <getContentType@plt>
lea    0xe7f(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1030 <strAppendFormatString@plt>
test   %r14d,%r14d
js     11d9 <sendHTTPResponseHeader+0x79>
lea    0xe7b(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %r14d,%edx
call   1030 <strAppendFormatString@plt>
lea    0xe40(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1070 <strAppend@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%rsi
call   1040 <writeStringToFile@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"HTTP/1.1 %s\0A\00"
@.str.1 = [21 x i8] c"Server: tiniweb/1.0\0A\00"
@.str.2 = [19 x i8] c"Connection: close\0A\00"
@.str.3 = [18 x i8] c"Content-Type: %s\0A\00"
@.str.4 = [20 x i8] c"Content-Length: %i\0A\00"
@.str.5 = [2 x i8] c"\0A\00"
@STDOUT_FILENO = global i32 0
define i32 @sendHTTPResponseHeader(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
store i8* null, i8** %8
%9 = load i32, i32* %4
%10 = call i32 @getStatusCode(i32 %9)
%11 = call i8* @secPrint2String(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %10)
store i8* %11, i8** %8
%12 = call i32 @strAppend(i8** %8, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @strAppend(i8** %8, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%14 = load i32, i32* %5
%15 = call i32 @getContentType(i32 %14)
%16 = call i32 @strAppendFormatString(i8** %8, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %6
%18 = icmp sge i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %3
%20 = load i32, i32* %6
%21 = call i32 @strAppendFormatString(i8** %8, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %19, %3
%23 = call i32 @strAppend(i8** %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%24 = load i32, i32* @STDOUT_FILENO
%25 = load i8*, i8** %8
%26 = call i32 @writeStringToFile(i32 %24, i8* %25)
store i32 %26, i32* %7
%27 = load i32, i32* %7
ret i32 %27
}

LLVM IR (-O2):
@.str = [13 x i8] c"HTTP/1.1 %s\0A\00"
@.str.1 = [21 x i8] c"Server: tiniweb/1.0\0A\00"
@.str.2 = [19 x i8] c"Connection: close\0A\00"
@.str.3 = [18 x i8] c"Content-Type: %s\0A\00"
@.str.4 = [20 x i8] c"Content-Length: %i\0A\00"
@.str.5 = [2 x i8] c"\0A\00"
@STDOUT_FILENO = global i32 0
define i32 @sendHTTPResponseHeader(i32 %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = tail call i32 @getStatusCode(i32 %0)
%7 = tail call i8* @secPrint2String(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %6)
store i8* %7, i8** %4
%8 = call i32 @strAppend(i8** %4, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @strAppend(i8** %4, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @getContentType(i32 %1)
%11 = call i32 @strAppendFormatString(i8** %4, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %10)
%12 = icmp sgt i32 %2, -1
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = call i32 @strAppendFormatString(i8** %4, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %2)
br label %15
15: ; preds = %13, %3
%16 = call i32 @strAppend(i8** %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%17 = load i32, i32* @STDOUT_FILENO
%18 = load i8*, i8** %4
%19 = call i32 @writeStringToFile(i32 %17, i8* %18)
ret i32 %19
}