#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 stat {
  int /*<<< orphan*/ st_mtime;
};
typedef int /*<<< orphan*/ modified;

/* Variables and functions */
int /*<<< orphan*/ generate_timeString(int /*<<< orphan*/, char *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ stat(char const *, struct stat *);
scalar_t__ strstr(char const *, char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void generate_okHeader(const char *filepath, char *output) {
  time_t timer;
  time(&timer);
  char now[32];
  generate_timeString(timer, now);
  char modified[32];
  if (filepath != NULL) {
    struct stat attr;
    stat(filepath, &attr);
    generate_timeString(attr.st_mtime, modified);
  } else {
    memcpy(modified, now, sizeof(modified));
  }
  if (strstr(filepath, ".png")) {
    sprintf(output,
            "HTTP/1.1 200 OK\nDate: %s\nLast-Modified: %s\nContent-Language: "
            "de\nContent-Type: image/png; charset=utf-8\r\n\r\n",
            now, modified);
  } else {
    sprintf(output,
            "HTTP/1.1 200 OK\nDate: %s\nLast-Modified: %s\nContent-Language: "
            "de\nContent-Type: text/html; charset=utf-8\r\n\r\n",
            now, modified);
  }
}


x86 assembly (clang, -O0):
<generate_okHeader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
call   1050 <time@plt>
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   1070 <generate_timeString@plt>
cmpq   $0x0,-0x8(%rbp)
je     11ae <generate_okHeader+0x4e>
mov    -0x8(%rbp),%rdi
lea    -0x68(%rbp),%rsi
call   1030 <stat@plt>
mov    -0x68(%rbp),%edi
lea    -0x60(%rbp),%rsi
call   1070 <generate_timeString@plt>
jmp    11c0 <generate_okHeader+0x60>
lea    -0x60(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x20,%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rdi
lea    0xe35(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     11f7 <generate_okHeader+0x97>
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    -0x60(%rbp),%rcx
lea    0xe18(%rip),%rsi
call   1060 <sprintf@plt>
jmp    120f <generate_okHeader+0xaf>
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    -0x60(%rbp),%rcx
lea    0xe66(%rip),%rsi
call   1060 <sprintf@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_okHeader>:
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xc(%rsp),%rdi
call   1050 <time@plt>
mov    0xc(%rsp),%edi
lea    0x30(%rsp),%rsi
call   1070 <generate_timeString@plt>
test   %rbx,%rbx
je     11a7 <generate_okHeader+0x47>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <stat@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rsi
call   1070 <generate_timeString@plt>
jmp    11bb <generate_okHeader+0x5b>
lea    0x10(%rsp),%rdi
lea    0x30(%rsp),%rsi
mov    $0x20,%edx
call   1040 <memcpy@plt>
lea    0xe3e(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strstr@plt>
test   %rax,%rax
lea    0xe9c(%rip),%rax
lea    0xe2a(%rip),%rsi
cmove  %rax,%rsi
lea    0x30(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    %r14,%rdi
call   1060 <sprintf@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [5 x i8] c".png\00"
@.str.1 = [107 x i8] c"HTTP/1.1 200 OK\0ADate: %s\0ALast-Modified: %s\0AContent-Language: de\0AContent-Type: image/png; charset=utf-8\0D\0A\0D\0A\00"
@.str.2 = [107 x i8] c"HTTP/1.1 200 OK\0ADate: %s\0ALast-Modified: %s\0AContent-Language: de\0AContent-Type: text/html; charset=utf-8\0D\0A\0D\0A\00"
define void @generate_okHeader(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [32 x i8]
%7 = alloca [32 x i8]
%8 = alloca %struct.stat
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = call i32 @time(i32* %5)
%10 = load i32, i32* %5
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%12 = call i32 @generate_timeString(i32 %10, i8* %11)
%13 = load i8*, i8** %3
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %22
15: ; preds = %2
%16 = load i8*, i8** %3
%17 = call i32 @stat(i8* %16, %struct.stat* %8)
%18 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%19 = load i32, i32* %18
%20 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%21 = call i32 @generate_timeString(i32 %19, i8* %20)
br label %26
22: ; preds = %2
%23 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%24 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%25 = call i32 @memcpy(i8* %23, i8* %24, i32 32)
br label %26
26: ; preds = %22, %15
%27 = load i8*, i8** %3
%28 = call i64 @strstr(i8* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %26
%31 = load i8*, i8** %4
%32 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%33 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%34 = call i32 @sprintf(i8* %31, i8* getelementptr inbounds ([107 x i8], [107 x i8]* @.str.1, i64 0, i64 0), i8* %32, i8* %33)
br label %40
35: ; preds = %26
%36 = load i8*, i8** %4
%37 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%38 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%39 = call i32 @sprintf(i8* %36, i8* getelementptr inbounds ([107 x i8], [107 x i8]* @.str.2, i64 0, i64 0), i8* %37, i8* %38)
br label %40
40: ; preds = %35, %30
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [5 x i8] c".png\00"
@.str.1 = [107 x i8] c"HTTP/1.1 200 OK\0ADate: %s\0ALast-Modified: %s\0AContent-Language: de\0AContent-Type: image/png; charset=utf-8\0D\0A\0D\0A\00"
@.str.2 = [107 x i8] c"HTTP/1.1 200 OK\0ADate: %s\0ALast-Modified: %s\0AContent-Language: de\0AContent-Type: text/html; charset=utf-8\0D\0A\0D\0A\00"
define void @generate_okHeader(i8* %0, i8* nocapture writeonly %1) {
%3 = alloca i32
%4 = alloca [32 x i8]
%5 = alloca [32 x i8]
%6 = alloca %struct.stat
%7 = bitcast i32* %3 to i8*
%8 = call i32 @time(i32* %3)
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%10 = load i32, i32* %3
%11 = call i32 @generate_timeString(i32 %10, i8* %9)
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%13 = icmp eq i8* %0, null
br i1 %13, label %20, label %14
14: ; preds = %2
%15 = bitcast %struct.stat* %6 to i8*
%16 = call i32 @stat(i8* %0, %struct.stat* %6)
%17 = getelementptr inbounds %struct.stat, %struct.stat* %6, i64 0, i32 0
%18 = load i32, i32* %17
%19 = call i32 @generate_timeString(i32 %18, i8* %12)
br label %22
20: ; preds = %2
%21 = call i32 @memcpy(i8* %12, i8* %9, i32 32)
br label %22
22: ; preds = %20, %14
%23 = call i64 @strstr(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
%25 = select i1 %24, i8* getelementptr inbounds ([107 x i8], [107 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([107 x i8], [107 x i8]* @.str.1, i64 0, i64 0)
%26 = call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) %25, i8* %9, i8* %12)
ret void
}