#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*/ sprintf(char *, char *, ...);
char *vn_status_message(int);
void vn_build_resp_headers(char *headers, int code, const char *reason,
                           const char *content_type,
                           unsigned int content_length, short keep_alive) {
  char *conn;
  if (NULL == reason) {
    reason = vn_status_message(code);
  }
  conn = (keep_alive == 1) ? "keep-alive" : "close";
  sprintf(headers, "HTTP/1.1 %d %s\r\n", code, reason);
  sprintf(headers, "%sServer: Vino\r\n", headers);
  sprintf(headers, "%sContent-type: %s\r\n", headers, content_type);
  sprintf(headers, "%sConnection: %s\r\n", headers, conn);
  sprintf(headers, "%sContent-length: %d\r\n", headers, (int)content_length);
  sprintf(headers, "%s\r\n", headers);
}


x86 assembly (clang, -O0):
<vn_build_resp_headers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %r9w,%ax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %ax,-0x26(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    115b <vn_build_resp_headers+0x3b>
mov    -0xc(%rbp),%edi
call   1030 <vn_status_message@plt>
mov    %rax,-0x18(%rbp)
movswl -0x26(%rbp),%edx
lea    0xea5(%rip),%rax
lea    0xe93(%rip),%rcx
cmp    $0x1,%edx
cmove  %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rcx
lea    0xe87(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe82(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x30(%rbp),%rcx
lea    0xe74(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x24(%rbp),%ecx
lea    0xe6e(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vn_build_resp_headers>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r9d,%ebp
mov    %r8d,%r14d
mov    %rcx,%r15
mov    %rdx,%rcx
mov    %esi,%r12d
mov    %rdi,%rbx
test   %rdx,%rdx
jne    114a <vn_build_resp_headers+0x2a>
mov    %r12d,%edi
call   1030 <vn_status_message@plt>
mov    %rax,%rcx
cmp    $0x1,%bp
lea    0xeab(%rip),%rax
lea    0xeaf(%rip),%rbp
cmove  %rax,%rbp
lea    0xeaa(%rip),%rsi
mov    %rbx,%rdi
mov    %r12d,%edx
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0xea7(%rip),%rsi
mov    %rbx,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0xea4(%rip),%rsi
mov    %rbx,%rdi
mov    %rbx,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0xea2(%rip),%rsi
mov    %rbx,%rdi
mov    %rbx,%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0xe9e(%rip),%rsi
mov    %rbx,%rdi
mov    %rbx,%rdx
mov    %r14d,%ecx
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0xe6f(%rip),%rsi
mov    %rbx,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <sprintf@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"keep-alive\00"
@.str.1 = [6 x i8] c"close\00"
@.str.2 = [17 x i8] c"HTTP/1.1 %d %s\0D\0A\00"
@.str.3 = [17 x i8] c"%sServer: Vino\0D\0A\00"
@.str.4 = [21 x i8] c"%sContent-type: %s\0D\0A\00"
@.str.5 = [19 x i8] c"%sConnection: %s\0D\0A\00"
@.str.6 = [23 x i8] c"%sContent-length: %d\0D\0A\00"
@.str.7 = [5 x i8] c"%s\0D\0A\00"
define void @vn_build_resp_headers(i8* %0, i32 %1, i8* %2, i8* %3, i32 %4, i16 signext %5) {
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i16
%13 = alloca i8*
store i8* %0, i8** %7
store i32 %1, i32* %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i32 %4, i32* %11
store i16 %5, i16* %12
%14 = load i8*, i8** %9
%15 = icmp eq i8* null, %14
br i1 %15, label %16, label %19
16: ; preds = %6
%17 = load i32, i32* %8
%18 = call i8* @vn_status_message(i32 %17)
store i8* %18, i8** %9
br label %19
19: ; preds = %16, %6
%20 = load i16, i16* %12
%21 = sext i16 %20 to i32
%22 = icmp eq i32 %21, 1
%23 = zext i1 %22 to i64
%24 = select i1 %22, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0)
store i8* %24, i8** %13
%25 = load i8*, i8** %7
%26 = load i32, i32* %8
%27 = load i8*, i8** %9
%28 = call i32 (i8*, i8*, ...) @sprintf(i8* %25, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %26, i8* %27)
%29 = load i8*, i8** %7
%30 = load i8*, i8** %7
%31 = call i32 (i8*, i8*, ...) @sprintf(i8* %29, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %30)
%32 = load i8*, i8** %7
%33 = load i8*, i8** %7
%34 = load i8*, i8** %10
%35 = call i32 (i8*, i8*, ...) @sprintf(i8* %32, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %33, i8* %34)
%36 = load i8*, i8** %7
%37 = load i8*, i8** %7
%38 = load i8*, i8** %13
%39 = call i32 (i8*, i8*, ...) @sprintf(i8* %36, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %37, i8* %38)
%40 = load i8*, i8** %7
%41 = load i8*, i8** %7
%42 = load i32, i32* %11
%43 = call i32 (i8*, i8*, ...) @sprintf(i8* %40, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* %41, i32 %42)
%44 = load i8*, i8** %7
%45 = load i8*, i8** %7
%46 = call i32 (i8*, i8*, ...) @sprintf(i8* %44, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* %45)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"keep-alive\00"
@.str.1 = [6 x i8] c"close\00"
@.str.2 = [17 x i8] c"HTTP/1.1 %d %s\0D\0A\00"
@.str.3 = [17 x i8] c"%sServer: Vino\0D\0A\00"
@.str.4 = [21 x i8] c"%sContent-type: %s\0D\0A\00"
@.str.5 = [19 x i8] c"%sConnection: %s\0D\0A\00"
@.str.6 = [23 x i8] c"%sContent-length: %d\0D\0A\00"
@.str.7 = [5 x i8] c"%s\0D\0A\00"
define void @vn_build_resp_headers(i8* %0, i32 %1, i8* %2, i8* %3, i32 %4, i16 signext %5) {
%7 = icmp eq i8* %2, null
br i1 %7, label %8, label %10
8: ; preds = %6
%9 = tail call i8* @vn_status_message(i32 %1)
br label %10
10: ; preds = %8, %6
%11 = phi i8* [ %9, %8 ], [ %2, %6 ]
%12 = icmp eq i16 %5, 1
%13 = select i1 %12, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0)
%14 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %1, i8* %11)
%15 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%16 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %3)
%17 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %0, i8* %13)
%18 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* %0, i32 %4)
%19 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* %0)
ret void
}