#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 */
struct HTTPResponse {
  int dummy;
};
typedef int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int http_response_append_data(struct HTTPResponse *, char *,
                              int /*<<< orphan*/);
scalar_t__ memory_asprintf(char **, char *, char const *, char const *);
int /*<<< orphan*/ memory_destroy(char *);
int /*<<< orphan*/ strlen(char *);
ssize_t http_response_write_header(struct HTTPResponse *response,
                                   const char *key, const char *value) {
  char *header = NULL;
  ssize_t ret = 0;
  assert(response != NULL);
  assert(key != NULL);
  assert(value != NULL);
  if (memory_asprintf(&header,
                      "%s: %s"
                      "\r\n",
                      key, value) < 0)
    return -1;
  ret = http_response_append_data(response, header, strlen(header));
  memory_destroy(header);
  return ret;
}


x86 assembly (clang, -O0):
<http_response_write_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
cmpq   $0x0,-0x20(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    -0x28(%rbp),%rdi
lea    0xe44(%rip),%rsi
call   1040 <memory_asprintf@plt>
cmp    $0x0,%rax
jge    11d7 <http_response_write_header+0x87>
movl   $0xffffffff,-0x4(%rbp)
jmp    1211 <http_response_write_header+0xc1>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1070 <http_response_append_data@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <memory_destroy@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_response_write_header>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
movq   $0x0,0x8(%rsp)
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1060 <assert@plt>
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1060 <assert@plt>
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1060 <assert@plt>
lea    0xe64(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %rbx,%rdx
mov    %r15,%rcx
call   1040 <memory_asprintf@plt>
test   %rax,%rax
js     11d9 <http_response_write_header+0x89>
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1070 <http_response_append_data@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rdi
call   1050 <memory_destroy@plt>
jmp    11de <http_response_write_header+0x8e>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.HTTPResponse = type { i32 }
@.str = [9 x i8] c"%s: %s\0D\0A\00"
define i32 @http_response_write_header(%struct.HTTPResponse* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.HTTPResponse*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store %struct.HTTPResponse* %0, %struct.HTTPResponse** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* null, i8** %8
store i32 0, i32* %9
%10 = load %struct.HTTPResponse*, %struct.HTTPResponse** %5
%11 = icmp ne %struct.HTTPResponse* %10, null
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i8*, i8** %6
%15 = icmp ne i8* %14, null
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i8*, i8** %7
%19 = icmp ne i8* %18, null
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load i8*, i8** %6
%23 = load i8*, i8** %7
%24 = call i64 @memory_asprintf(i8** %8, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %22, i8* %23)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %3
store i32 -1, i32* %4
br label %36
27: ; preds = %3
%28 = load %struct.HTTPResponse*, %struct.HTTPResponse** %5
%29 = load i8*, i8** %8
%30 = load i8*, i8** %8
%31 = call i32 @strlen(i8* %30)
%32 = call i32 @http_response_append_data(%struct.HTTPResponse* %28, i8* %29, i32 %31)
store i32 %32, i32* %9
%33 = load i8*, i8** %8
%34 = call i32 @memory_destroy(i8* %33)
%35 = load i32, i32* %9
store i32 %35, i32* %4
br label %36
36: ; preds = %27, %26
%37 = load i32, i32* %4
ret i32 %37
}

LLVM IR (-O2):
%struct.HTTPResponse = type { i32 }
@.str = [9 x i8] c"%s: %s\0D\0A\00"
define i32 @http_response_write_header(%struct.HTTPResponse* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%6 = icmp ne %struct.HTTPResponse* %0, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = icmp ne i8* %1, null
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = icmp ne i8* %2, null
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = call i64 @memory_asprintf(i8** %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %2)
%16 = icmp slt i64 %15, 0
br i1 %16, label %23, label %17
17: ; preds = %3
%18 = load i8*, i8** %4
%19 = call i32 @strlen(i8* %18)
%20 = call i32 @http_response_append_data(%struct.HTTPResponse* %0, i8* %18, i32 %19)
%21 = load i8*, i8** %4
%22 = call i32 @memory_destroy(i8* %21)
br label %23
23: ; preds = %3, %17
%24 = phi i32 [ %20, %17 ], [ -1, %3 ]
ret i32 %24
}