#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 */
typedef int /*<<< orphan*/ timebuf;
typedef scalar_t__ time_t;

/* Variables and functions */
int /*<<< orphan*/ gmtime(scalar_t__ *);
scalar_t__ printf(char *, char *, ...);
scalar_t__ sprintf(char *, char *, ...);
int /*<<< orphan*/ strftime(char *, int, char *, int /*<<< orphan*/);
scalar_t__ time(scalar_t__ *);
int build_headers(char *buffer, int status, char *title, char *mime_type,
                  int length, time_t mod) {
  time_t now;
  char timebuf[100];
  int index = 0;
  index += sprintf(buffer + index, "%s %d %s\r\n", "HTTP/1.0", status, title);
  index += sprintf(buffer + index, "Server: %s\r\n", "micro_proxy");
  now = time((time_t *)0);
  strftime(timebuf, sizeof(timebuf), "%a, %d %b %Y %H:%M:%S GMT", gmtime(&now));
  index += sprintf(buffer + index, "Date: %s\r\n", timebuf);
  if (mime_type != (char *)0)
    index += sprintf(buffer + index, "Content-Type: %s\r\n", mime_type);
  if (length >= 0)
    index += sprintf(buffer + index, "Content-Length: %d\r\n", length);
  if (mod != (time_t)-1) {
    strftime(timebuf, sizeof(timebuf), "%a, %d %b %Y %H:%M:%S GMT",
             gmtime(&mod));
    index += printf(buffer + index, "Last-Modified: %s\r\n", timebuf);
  }
  index += sprintf(buffer + index, "Connection: close\r\n");
  index += printf(buffer + index, "\r\n");
  return index;
}


x86 assembly (clang, -O0):
<build_headers>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x0,-0xa4(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0xa4(%rbp),%rax
add    %rax,%rdi
mov    -0xc(%rbp),%ecx
mov    -0x18(%rbp),%r8
lea    0xe68(%rip),%rsi
lea    0xe6c(%rip),%rdx
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    %rax,%rcx
movslq -0xa4(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xa4(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0xa4(%rbp),%rax
add    %rax,%rdi
lea    0xe46(%rip),%rsi
lea    0xe4c(%rip),%rdx
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    %rax,%rcx
movslq -0xa4(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xa4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %rax,-0x38(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xb0(%rbp)
lea    -0x38(%rbp),%rdi
call   1060 <gmtime@plt>
mov    -0xb0(%rbp),%rdi
mov    %eax,%ecx
mov    $0x64,%esi
lea    0xe05(%rip),%rdx
call   1050 <strftime@plt>
mov    -0x8(%rbp),%rdi
movslq -0xa4(%rbp),%rax
add    %rax,%rdi
lea    -0xa0(%rbp),%rdx
lea    0xdfe(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    %rax,%rcx
movslq -0xa4(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xa4(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     12a1 <build_headers+0x151>
mov    -0x8(%rbp),%rdi
movslq -0xa4(%rbp),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rdx
lea    0xdcb(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    %rax,%rcx
movslq -0xa4(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xa4(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     12dd <build_headers+0x18d>
mov    -0x8(%rbp),%rdi
movslq -0xa4(%rbp),%rax
add    %rax,%rdi
mov    -0x24(%rbp),%edx
lea    0xda2(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    %rax,%rcx
movslq -0xa4(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xa4(%rbp)
cmpq   $0xffffffffffffffff,-0x30(%rbp)
je     134f <build_headers+0x1ff>
lea    -0xa0(%rbp),%rax
mov    %rax,-0xb8(%rbp)
lea    -0x30(%rbp),%rdi
call   1060 <gmtime@plt>
mov    -0xb8(%rbp),%rdi
mov    %eax,%ecx
mov    $0x64,%esi
lea    0xd19(%rip),%rdx
call   1050 <strftime@plt>
mov    -0x8(%rbp),%rdi
movslq -0xa4(%rbp),%rax
add    %rax,%rdi
lea    -0xa0(%rbp),%rdx
lea    0xd45(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    %rax,%rcx
movslq -0xa4(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xa4(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0xa4(%rbp),%rax
add    %rax,%rdi
lea    0xd2a(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    %rax,%rcx
movslq -0xa4(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xa4(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0xa4(%rbp),%rax
add    %rax,%rdi
lea    0xce4(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    %rax,%rcx
movslq -0xa4(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xa4(%rbp)
mov    -0xa4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_headers>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %r9,%r14
mov    %r8d,%r15d
mov    %rcx,%r12
mov    %rdx,%r8
mov    %esi,%ecx
mov    %rdi,%r13
mov    %r9,0x8(%rsp)
lea    0xe85(%rip),%rsi
lea    0xe89(%rip),%rdx
xor    %eax,%eax
call   1070 <sprintf@plt>
mov    %rax,%rbp
movslq %ebp,%rdi
add    %r13,%rdi
lea    0xe7b(%rip),%rsi
lea    0xe81(%rip),%rdx
xor    %eax,%eax
call   1070 <sprintf@plt>
mov    %rax,%rbx
add    %rbp,%rbx
xor    %edi,%edi
call   1040 <time@plt>
mov    %rax,(%rsp)
mov    %rsp,%rdi
call   1060 <gmtime@plt>
lea    0xe66(%rip),%rdx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x64,%esi
mov    %eax,%ecx
call   1050 <strftime@plt>
movslq %ebx,%rdi
add    %r13,%rdi
lea    0xe5f(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1070 <sprintf@plt>
mov    %rax,%rbp
add    %rbx,%rbp
test   %r12,%r12
je     1217 <build_headers+0xc7>
movslq %ebp,%rdi
add    %r13,%rdi
lea    0xe48(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1070 <sprintf@plt>
add    %rax,%rbp
test   %r15d,%r15d
js     1237 <build_headers+0xe7>
movslq %ebp,%rdi
add    %r13,%rdi
lea    0xe3c(%rip),%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1070 <sprintf@plt>
add    %ebp,%eax
mov    %eax,%ebp
cmp    $0xffffffffffffffff,%r14
je     127e <build_headers+0x12e>
lea    0x8(%rsp),%rdi
call   1060 <gmtime@plt>
lea    0xddf(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %eax,%ecx
call   1050 <strftime@plt>
movslq %ebp,%rbp
mov    %r13,%rdi
add    %rbp,%rdi
lea    0xe08(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
add    %eax,%ebp
movslq %ebp,%rbx
lea    (%rbx,%r13,1),%rdi
lea    0xe02(%rip),%rsi
xor    %eax,%eax
call   1070 <sprintf@plt>
add    %eax,%ebx
movslq %ebx,%rbx
add    %rbx,%r13
lea    0xdd5(%rip),%rsi
mov    %r13,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    %ebx,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"%s %d %s\0D\0A\00"
@.str.1 = [9 x i8] c"HTTP/1.0\00"
@.str.2 = [13 x i8] c"Server: %s\0D\0A\00"
@.str.3 = [12 x i8] c"micro_proxy\00"
@.str.4 = [26 x i8] c"%a, %d %b %Y %H:%M:%S GMT\00"
@.str.5 = [11 x i8] c"Date: %s\0D\0A\00"
@.str.6 = [19 x i8] c"Content-Type: %s\0D\0A\00"
@.str.7 = [21 x i8] c"Content-Length: %d\0D\0A\00"
@.str.8 = [20 x i8] c"Last-Modified: %s\0D\0A\00"
@.str.9 = [20 x i8] c"Connection: close\0D\0A\00"
@.str.10 = [3 x i8] c"\0D\0A\00"
define i32 @build_headers(i8* %0, i32 %1, i8* %2, i8* %3, i32 %4, i64 %5) {
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i64
%13 = alloca i64
%14 = alloca [100 x i8]
%15 = alloca i32
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 i64 %5, i64* %12
store i32 0, i32* %15
%16 = load i8*, i8** %7
%17 = load i32, i32* %15
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i32, i32* %8
%21 = load i8*, i8** %9
%22 = call i64 (i8*, i8*, ...) @sprintf(i8* %19, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %20, i8* %21)
%23 = load i32, i32* %15
%24 = sext i32 %23 to i64
%25 = add nsw i64 %24, %22
%26 = trunc i64 %25 to i32
store i32 %26, i32* %15
%27 = load i8*, i8** %7
%28 = load i32, i32* %15
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = call i64 (i8*, i8*, ...) @sprintf(i8* %30, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%32 = load i32, i32* %15
%33 = sext i32 %32 to i64
%34 = add nsw i64 %33, %31
%35 = trunc i64 %34 to i32
store i32 %35, i32* %15
%36 = call i64 @time(i64* null)
store i64 %36, i64* %13
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%38 = call i32 @gmtime(i64* %13)
%39 = call i32 @strftime(i8* %37, i32 100, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %38)
%40 = load i8*, i8** %7
%41 = load i32, i32* %15
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%45 = call i64 (i8*, i8*, ...) @sprintf(i8* %43, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %44)
%46 = load i32, i32* %15
%47 = sext i32 %46 to i64
%48 = add nsw i64 %47, %45
%49 = trunc i64 %48 to i32
store i32 %49, i32* %15
%50 = load i8*, i8** %10
%51 = icmp ne i8* %50, null
br i1 %51, label %52, label %63
52: ; preds = %6
%53 = load i8*, i8** %7
%54 = load i32, i32* %15
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
%57 = load i8*, i8** %10
%58 = call i64 (i8*, i8*, ...) @sprintf(i8* %56, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %57)
%59 = load i32, i32* %15
%60 = sext i32 %59 to i64
%61 = add nsw i64 %60, %58
%62 = trunc i64 %61 to i32
store i32 %62, i32* %15
br label %63
63: ; preds = %52, %6
%64 = load i32, i32* %11
%65 = icmp sge i32 %64, 0
br i1 %65, label %66, label %77
66: ; preds = %63
%67 = load i8*, i8** %7
%68 = load i32, i32* %15
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8, i8* %67, i64 %69
%71 = load i32, i32* %11
%72 = call i64 (i8*, i8*, ...) @sprintf(i8* %70, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i32 %71)
%73 = load i32, i32* %15
%74 = sext i32 %73 to i64
%75 = add nsw i64 %74, %72
%76 = trunc i64 %75 to i32
store i32 %76, i32* %15
br label %77
77: ; preds = %66, %63
%78 = load i64, i64* %12
%79 = icmp ne i64 %78, -1
br i1 %79, label %80, label %94
80: ; preds = %77
%81 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%82 = call i32 @gmtime(i64* %12)
%83 = call i32 @strftime(i8* %81, i32 100, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %82)
%84 = load i8*, i8** %7
%85 = load i32, i32* %15
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i8, i8* %84, i64 %86
%88 = getelementptr inbounds [100 x i8], [100 x i8]* %14, i64 0, i64 0
%89 = call i64 (i8*, i8*, ...) @printf(i8* %87, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i8* %88)
%90 = load i32, i32* %15
%91 = sext i32 %90 to i64
%92 = add nsw i64 %91, %89
%93 = trunc i64 %92 to i32
store i32 %93, i32* %15
br label %94
94: ; preds = %80, %77
%95 = load i8*, i8** %7
%96 = load i32, i32* %15
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i8, i8* %95, i64 %97
%99 = call i64 (i8*, i8*, ...) @sprintf(i8* %98, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0))
%100 = load i32, i32* %15
%101 = sext i32 %100 to i64
%102 = add nsw i64 %101, %99
%103 = trunc i64 %102 to i32
store i32 %103, i32* %15
%104 = load i8*, i8** %7
%105 = load i32, i32* %15
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds i8, i8* %104, i64 %106
%108 = call i64 (i8*, i8*, ...) @printf(i8* %107, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
%109 = load i32, i32* %15
%110 = sext i32 %109 to i64
%111 = add nsw i64 %110, %108
%112 = trunc i64 %111 to i32
store i32 %112, i32* %15
%113 = load i32, i32* %15
ret i32 %113
}

LLVM IR (-O2):
@.str = [11 x i8] c"%s %d %s\0D\0A\00"
@.str.1 = [9 x i8] c"HTTP/1.0\00"
@.str.2 = [13 x i8] c"Server: %s\0D\0A\00"
@.str.3 = [12 x i8] c"micro_proxy\00"
@.str.4 = [26 x i8] c"%a, %d %b %Y %H:%M:%S GMT\00"
@.str.5 = [11 x i8] c"Date: %s\0D\0A\00"
@.str.6 = [19 x i8] c"Content-Type: %s\0D\0A\00"
@.str.7 = [21 x i8] c"Content-Length: %d\0D\0A\00"
@.str.8 = [20 x i8] c"Last-Modified: %s\0D\0A\00"
@.str.9 = [20 x i8] c"Connection: close\0D\0A\00"
@.str.10 = [3 x i8] c"\0D\0A\00"
define i32 @build_headers(i8* %0, i32 %1, i8* %2, i8* %3, i32 %4, i64 %5) {
%7 = alloca i64
%8 = alloca i64
%9 = alloca [100 x i8]
store i64 %5, i64* %7
%10 = bitcast i64* %8 to i8*
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%12 = tail call i64 (i8*, i8*, ...) @sprintf(i8* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %1, i8* %2)
%13 = shl i64 %12, 32
%14 = ashr exact i64 %13, 32
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = tail call i64 (i8*, i8*, ...) @sprintf(i8* %15, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%17 = add i64 %16, %12
%18 = tail call i64 @time(i64* null)
store i64 %18, i64* %8
%19 = call i32 @gmtime(i64* %8)
%20 = call i32 @strftime(i8* %11, i32 100, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %19)
%21 = shl i64 %17, 32
%22 = ashr exact i64 %21, 32
%23 = getelementptr inbounds i8, i8* %0, i64 %22
%24 = call i64 (i8*, i8*, ...) @sprintf(i8* %23, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %11)
%25 = add i64 %24, %17
%26 = icmp eq i8* %3, null
br i1 %26, label %33, label %27
27: ; preds = %6
%28 = shl i64 %25, 32
%29 = ashr exact i64 %28, 32
%30 = getelementptr inbounds i8, i8* %0, i64 %29
%31 = call i64 (i8*, i8*, ...) @sprintf(i8* %30, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %3)
%32 = add i64 %31, %25
br label %33
33: ; preds = %27, %6
%34 = phi i64 [ %32, %27 ], [ %25, %6 ]
%35 = trunc i64 %34 to i32
%36 = icmp sgt i32 %4, -1
br i1 %36, label %37, label %44
37: ; preds = %33
%38 = shl i64 %34, 32
%39 = ashr exact i64 %38, 32
%40 = getelementptr inbounds i8, i8* %0, i64 %39
%41 = call i64 (i8*, i8*, ...) @sprintf(i8* %40, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i32 %4)
%42 = trunc i64 %41 to i32
%43 = add i32 %42, %35
br label %44
44: ; preds = %37, %33
%45 = phi i32 [ %43, %37 ], [ %35, %33 ]
%46 = icmp eq i64 %5, -1
br i1 %46, label %55, label %47
47: ; preds = %44
%48 = call i32 @gmtime(i64* %7)
%49 = call i32 @strftime(i8* %11, i32 100, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i32 %48)
%50 = sext i32 %45 to i64
%51 = getelementptr inbounds i8, i8* %0, i64 %50
%52 = call i64 (i8*, i8*, ...) @printf(i8* %51, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i8* %11)
%53 = trunc i64 %52 to i32
%54 = add i32 %45, %53
br label %55
55: ; preds = %47, %44
%56 = phi i32 [ %54, %47 ], [ %45, %44 ]
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %0, i64 %57
%59 = call i64 (i8*, i8*, ...) @sprintf(i8* %58, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0))
%60 = trunc i64 %59 to i32
%61 = add i32 %56, %60
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %0, i64 %62
%64 = call i64 (i8*, i8*, ...) @printf(i8* %63, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
%65 = trunc i64 %64 to i32
%66 = add i32 %61, %65
ret i32 %66
}