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

/* Variables and functions */
struct tm *gmtime(scalar_t__ *);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
char *kore_time_to_date(time_t now) {
  struct tm *tm;
  static time_t last = 0;
  static char tbuf[32];
  if (now != last) {
    last = now;
    tm = gmtime(&now);
    if (!strftime(tbuf, sizeof(tbuf), "%a, %d %b %Y %T GMT", tm)) {
      ;
      return (NULL);
    }
  }
  return (tbuf);
}


x86 assembly (clang, -O0):
<kore_time_to_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    0x2f09(%rip),%rax
je     118c <kore_time_to_date+0x6c>
mov    -0x10(%rbp),%rax
mov    %rax,0x2ef8(%rip)
lea    -0x10(%rbp),%rdi
call   1040 <gmtime@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
lea    0x2ef0(%rip),%rdi
mov    $0x20,%esi
lea    0xe94(%rip),%rdx
call   1030 <strftime@plt>
cmp    $0x0,%eax
jne    1187 <kore_time_to_date+0x67>
movq   $0x0,-0x8(%rbp)
jmp    1197 <kore_time_to_date+0x77>
jmp    118c <kore_time_to_date+0x6c>
lea    0x2ebd(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kore_time_to_date>:
push   %rax
mov    %rdi,(%rsp)
cmp    %rdi,0x2f14(%rip)
je     115c <kore_time_to_date+0x3c>
mov    %rdi,0x2f0b(%rip)
mov    %rsp,%rdi
call   1040 <gmtime@plt>
lea    0x2f0c(%rip),%rdi
lea    0xeb5(%rip),%rdx
mov    $0x20,%esi
mov    %rax,%rcx
call   1030 <strftime@plt>
test   %eax,%eax
je     1165 <kore_time_to_date+0x45>
lea    0x2eed(%rip),%rax
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@kore_time_to_date.last = internal global i64 0
@kore_time_to_date.tbuf = internal global [32 x i8] zeroinitializer
@.str = [20 x i8] c"%a, %d %b %Y %T GMT\00"
define i8* @kore_time_to_date(i64 %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca %struct.tm*
store i64 %0, i64* %3
%5 = load i64, i64* %3
%6 = load i64, i64* @kore_time_to_date.last
%7 = icmp ne i64 %5, %6
br i1 %7, label %8, label %16
8: ; preds = %1
%9 = load i64, i64* %3
store i64 %9, i64* @kore_time_to_date.last
%10 = call %struct.tm* @gmtime(i64* %3)
store %struct.tm* %10, %struct.tm** %4
%11 = load %struct.tm*, %struct.tm** %4
%12 = call i32 @strftime(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @kore_time_to_date.tbuf, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), %struct.tm* %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %8
store i8* null, i8** %2
br label %17
15: ; preds = %8
br label %16
16: ; preds = %15, %1
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @kore_time_to_date.tbuf, i64 0, i64 0), i8** %2
br label %17
17: ; preds = %16, %14
%18 = load i8*, i8** %2
ret i8* %18
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@kore_time_to_date.last = internal unnamed_addr global i64 0
@kore_time_to_date.tbuf = internal global [32 x i8] zeroinitializer
@.str = [20 x i8] c"%a, %d %b %Y %T GMT\00"
define i8* @kore_time_to_date(i64 %0) {
%2 = alloca i64
store i64 %0, i64* %2
%3 = load i64, i64* @kore_time_to_date.last
%4 = icmp eq i64 %3, %0
br i1 %4, label %9, label %5
5: ; preds = %1
store i64 %0, i64* @kore_time_to_date.last
%6 = call %struct.tm* @gmtime(i64* %2)
%7 = call i32 @strftime(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @kore_time_to_date.tbuf, i64 0, i64 0), i32 32, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), %struct.tm* %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %5, %1
br label %10
10: ; preds = %5, %9
%11 = phi i8* [ getelementptr inbounds ([32 x i8], [32 x i8]* @kore_time_to_date.tbuf, i64 0, i64 0), %9 ], [ null, %5 ]
ret i8* %11
}