#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*/ time_t;
struct tm {
  int dummy;
};
struct HTTPRequest {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
struct tm *gmtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ log_exit(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void output_common_header_fields(struct HTTPRequest *req, FILE *out,
                                 char *status) {
  time_t t;
  struct tm *tm;
  char buf[64];
  t = time(NULL);
  tm = gmtime(&t);
  if (!tm) {
    log_exit("gmtime() failed: %s\n", strerror(errno));
  }
  strftime(buf, 64, "%a, %d %b %Y %H:%M:%S GMT", tm);
  fprintf(out, "HTTP/1.%d %s\r\n", 0, status);
  fprintf(out, "Date: %s\r\n", buf);
  fprintf(out, "Server: %s/%s\r\n", "LittleHTTP", "1.0");
  fprintf(out, "Connection: close\r\n");
  fflush(out);
}


x86 assembly (clang, -O0):
<output_common_header_fields>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x1c(%rbp),%rdi
call   1070 <gmtime@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11c4 <output_common_header_fields+0x54>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %eax,%esi
lea    0xe41(%rip),%rdi
call   1080 <log_exit@plt>
lea    -0x70(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x40,%esi
lea    0xe3d(%rip),%rdx
call   1060 <strftime@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rcx
lea    0xe43(%rip),%rsi
xor    %edx,%edx
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x70(%rbp),%rdx
lea    0xe3a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe33(%rip),%rsi
lea    0xe3c(%rip),%rdx
lea    0xe40(%rip),%rcx
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe32(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fflush@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output_common_header_fields>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1070 <gmtime@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11ca <output_common_header_fields+0x4a>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xe3d(%rip),%rdi
mov    %eax,%esi
call   1080 <log_exit@plt>
lea    0xe44(%rip),%rdx
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    $0x40,%esi
mov    %rbx,%rcx
call   1060 <strftime@plt>
lea    0xe42(%rip),%rsi
mov    %r15,%rdi
xor    %edx,%edx
mov    %r14,%rcx
xor    %eax,%eax
call   1030 <fprintf@plt>
lea    0xe3b(%rip),%rsi
mov    %r15,%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
lea    0xe32(%rip),%rsi
lea    0xe3b(%rip),%rdx
lea    0xe3f(%rip),%rcx
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <fprintf@plt>
lea    0xe32(%rip),%rdi
mov    $0x13,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1090 <fwrite@plt>
mov    %r15,%rdi
call   1050 <fflush@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.HTTPRequest = type { i32 }
%struct.tm = type { i32 }
@.str = [21 x i8] c"gmtime() failed: %s\0A\00"
@errno = global i32 0
@.str.1 = [26 x i8] c"%a, %d %b %Y %H:%M:%S GMT\00"
@.str.2 = [15 x i8] c"HTTP/1.%d %s\0D\0A\00"
@.str.3 = [11 x i8] c"Date: %s\0D\0A\00"
@.str.4 = [16 x i8] c"Server: %s/%s\0D\0A\00"
@.str.5 = [11 x i8] c"LittleHTTP\00"
@.str.6 = [4 x i8] c"1.0\00"
@.str.7 = [20 x i8] c"Connection: close\0D\0A\00"
define void @output_common_header_fields(%struct.HTTPRequest* %0, i32* %1, i8* %2) {
%4 = alloca %struct.HTTPRequest*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.tm*
%9 = alloca [64 x i8]
store %struct.HTTPRequest* %0, %struct.HTTPRequest** %4
store i32* %1, i32** %5
store i8* %2, i8** %6
%10 = call i32 @time(i32* null)
store i32 %10, i32* %7
%11 = call %struct.tm* @gmtime(i32* %7)
store %struct.tm* %11, %struct.tm** %8
%12 = load %struct.tm*, %struct.tm** %8
%13 = icmp ne %struct.tm* %12, null
br i1 %13, label %18, label %14
14: ; preds = %3
%15 = load i32, i32* @errno
%16 = call i32 @strerror(i32 %15)
%17 = call i32 @log_exit(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %14, %3
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%20 = load %struct.tm*, %struct.tm** %8
%21 = call i32 @strftime(i8* %19, i32 64, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %20)
%22 = load i32*, i32** %5
%23 = load i8*, i8** %6
%24 = call i32 (i32*, i8*, ...) @fprintf(i32* %22, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 0, i8* %23)
%25 = load i32*, i32** %5
%26 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%27 = call i32 (i32*, i8*, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %26)
%28 = load i32*, i32** %5
%29 = call i32 (i32*, i8*, ...) @fprintf(i32* %28, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%30 = load i32*, i32** %5
%31 = call i32 (i32*, i8*, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
%32 = load i32*, i32** %5
%33 = call i32 @fflush(i32* %32)
ret void
}

LLVM IR (-O2):
%struct.HTTPRequest = type { i32 }
%struct.tm = type { i32 }
@.str = [21 x i8] c"gmtime() failed: %s\0A\00"
@errno = global i32 0
@.str.1 = [26 x i8] c"%a, %d %b %Y %H:%M:%S GMT\00"
@.str.2 = [15 x i8] c"HTTP/1.%d %s\0D\0A\00"
@.str.3 = [11 x i8] c"Date: %s\0D\0A\00"
@.str.4 = [16 x i8] c"Server: %s/%s\0D\0A\00"
@.str.5 = [11 x i8] c"LittleHTTP\00"
@.str.6 = [4 x i8] c"1.0\00"
@.str.7 = [20 x i8] c"Connection: close\0D\0A\00"
define void @output_common_header_fields(%struct.HTTPRequest* nocapture readnone %0, i32* nocapture %1, i8* %2) {
%4 = alloca i32
%5 = alloca [64 x i8]
%6 = bitcast i32* %4 to i8*
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%8 = tail call i32 @time(i32* null)
store i32 %8, i32* %4
%9 = call %struct.tm* @gmtime(i32* %4)
%10 = icmp eq %struct.tm* %9, null
br i1 %10, label %11, label %15
11: ; preds = %3
%12 = load i32, i32* @errno
%13 = call i32 @strerror(i32 %12)
%14 = call i32 @log_exit(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %11, %3
%16 = call i32 @strftime(i8* %7, i32 64, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %9)
%17 = call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 0, i8* %2)
%18 = call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%19 = call i32 (i32*, i8*, ...) @fprintf(i32* %1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%20 = call i64 @fwrite(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i64 19, i64 1, i32* %1)
%21 = call i32 @fflush(i32* %1)
ret void
}