#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;
char *secPrint2String(char *, char const *);
int /*<<< orphan*/ strAppend(char **, char *);
int /*<<< orphan*/ strAppendFormatString(char **, char *, ...);
int writeStringToFile(int /*<<< orphan*/, char *);
int sendHTTPResponseHeaderExplicit(const char *ccp_status,
                                   const char *ccp_content_type,
                                   int i_content_length) {
  int i_success = 0;
  char *cp_http_response_header = NULL;
  if (ccp_content_type == NULL || ccp_status == NULL)
    return -1;
  cp_http_response_header = secPrint2String("HTTP/1.1 %s\n", ccp_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",
                        ccp_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):
<sendHTTPResponseHeaderExplicit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1178 <sendHTTPResponseHeaderExplicit+0x38>
cmpq   $0x0,-0x10(%rbp)
jne    1184 <sendHTTPResponseHeaderExplicit+0x44>
movl   $0xffffffff,-0x4(%rbp)
jmp    1218 <sendHTTPResponseHeaderExplicit+0xd8>
mov    -0x10(%rbp),%rsi
lea    0xe71(%rip),%rdi
call   1060 <secPrint2String@plt>
mov    %rax,-0x28(%rbp)
lea    -0x28(%rbp),%rdi
lea    0xe6a(%rip),%rsi
call   1050 <strAppend@plt>
lea    -0x28(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1050 <strAppend@plt>
mov    -0x18(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    0xe6e(%rip),%rsi
mov    $0x0,%al
call   1030 <strAppendFormatString@plt>
cmpl   $0x0,-0x1c(%rbp)
jl     11ed <sendHTTPResponseHeaderExplicit+0xad>
mov    -0x1c(%rbp),%edx
lea    -0x28(%rbp),%rdi
lea    0xe61(%rip),%rsi
mov    $0x0,%al
call   1030 <strAppendFormatString@plt>
lea    -0x28(%rbp),%rdi
lea    0xe28(%rip),%rsi
call   1050 <strAppend@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rsi
call   1040 <writeStringToFile@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendHTTPResponseHeaderExplicit>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0xffffffff,%eax
test   %rdi,%rdi
je     11ef <sendHTTPResponseHeaderExplicit+0xaf>
mov    %rsi,%rbx
test   %rsi,%rsi
je     11ef <sendHTTPResponseHeaderExplicit+0xaf>
mov    %edx,%r14d
mov    %rdi,%rsi
lea    0xe91(%rip),%rdi
call   1060 <secPrint2String@plt>
mov    %rax,0x8(%rsp)
lea    0xe8d(%rip),%rsi
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
call   1050 <strAppend@plt>
lea    0xe8e(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strAppend@plt>
lea    0xe92(%rip),%rsi
mov    %rbp,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <strAppendFormatString@plt>
test   %r14d,%r14d
js     11cb <sendHTTPResponseHeaderExplicit+0x8b>
lea    0xe8b(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %r14d,%edx
xor    %eax,%eax
call   1030 <strAppendFormatString@plt>
lea    0xe4e(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1050 <strAppend@plt>
mov    0x2e0d(%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 @sendHTTPResponseHeaderExplicit(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 0, i32* %8
store i8* null, i8** %9
%10 = load i8*, i8** %6
%11 = icmp eq i8* %10, null
br i1 %11, label %15, label %12
12: ; preds = %3
%13 = load i8*, i8** %5
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %12, %3
store i32 -1, i32* %4
br label %34
16: ; preds = %12
%17 = load i8*, i8** %5
%18 = call i8* @secPrint2String(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %17)
store i8* %18, i8** %9
%19 = call i32 @strAppend(i8** %9, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @strAppend(i8** %9, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%21 = load i8*, i8** %6
%22 = call i32 (i8**, i8*, ...) @strAppendFormatString(i8** %9, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %21)
%23 = load i32, i32* %7
%24 = icmp sge i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %16
%26 = load i32, i32* %7
%27 = call i32 (i8**, i8*, ...) @strAppendFormatString(i8** %9, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %25, %16
%29 = call i32 @strAppend(i8** %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%30 = load i32, i32* @STDOUT_FILENO
%31 = load i8*, i8** %9
%32 = call i32 @writeStringToFile(i32 %30, i8* %31)
store i32 %32, i32* %8
%33 = load i32, i32* %8
store i32 %33, i32* %4
br label %34
34: ; preds = %28, %15
%35 = load i32, i32* %4
ret i32 %35
}

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 @sendHTTPResponseHeaderExplicit(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = icmp eq i8* %1, null
%7 = icmp eq i8* %0, null
%8 = or i1 %7, %6
br i1 %8, label %22, label %9
9: ; preds = %3
%10 = tail call i8* @secPrint2String(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %0)
store i8* %10, i8** %4
%11 = call i32 @strAppend(i8** %4, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @strAppend(i8** %4, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 (i8**, i8*, ...) @strAppendFormatString(i8** %4, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %1)
%14 = icmp sgt i32 %2, -1
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = call i32 (i8**, i8*, ...) @strAppendFormatString(i8** %4, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %2)
br label %17
17: ; preds = %15, %9
%18 = call i32 @strAppend(i8** %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%19 = load i32, i32* @STDOUT_FILENO
%20 = load i8*, i8** %4
%21 = call i32 @writeStringToFile(i32 %19, i8* %20)
br label %22
22: ; preds = %3, %17
%23 = phi i32 [ %21, %17 ], [ -1, %3 ]
ret i32 %23
}