#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;

/* Variables and functions */
char *calloc(size_t, int);
int /*<<< orphan*/ gmtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ strftime(char *, size_t, char *, int /*<<< orphan*/);
size_t strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/);
char *get_http_date_str(void) {
  char *rfc1123_date = "Sun, 06 Nov 1994 08:49:37 GMT\n";
  size_t rfc1123_date_len = strlen(rfc1123_date);
  char *date = calloc(rfc1123_date_len + 1, sizeof(char));
  if (!date)
    return NULL;
  time_t now = time(0);
  if (!strftime(date, rfc1123_date_len + 1, "%a, %d %b %Y %H:%M:%S %Z",
                gmtime(&now)))
    return NULL;
  return date;
}


x86 assembly (clang, -O0):
<get_http_date_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    0xea1(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119e <get_http_date_str+0x4e>
movq   $0x0,-0x8(%rbp)
jmp    11f9 <get_http_date_str+0xa9>
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
lea    -0x24(%rbp),%rdi
call   1070 <gmtime@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%ecx
lea    0xe49(%rip),%rdx
call   1060 <strftime@plt>
cmp    $0x0,%eax
jne    11f1 <get_http_date_str+0xa1>
movq   $0x0,-0x8(%rbp)
jmp    11f9 <get_http_date_str+0xa9>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_http_date_str>:
push   %r14
push   %rbx
push   %rax
mov    $0x1f,%edi
mov    $0x1,%esi
call   1030 <calloc@plt>
test   %rax,%rax
je     1191 <get_http_date_str+0x51>
mov    %rax,%rbx
xor    %r14d,%r14d
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1060 <gmtime@plt>
lea    0xe86(%rip),%rdx
mov    $0x1f,%esi
mov    %rbx,%rdi
mov    %eax,%ecx
call   1050 <strftime@plt>
test   %eax,%eax
cmovne %rbx,%r14
jmp    1194 <get_http_date_str+0x54>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Sun, 06 Nov 1994 08:49:37 GMT\0A\00"
@.str.1 = [25 x i8] c"%a, %d %b %Y %H:%M:%S %Z\00"
define i8* @get_http_date_str() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i32
store i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8** %2
%6 = load i8*, i8** %2
%7 = call i64 @strlen(i8* %6)
store i64 %7, i64* %3
%8 = load i64, i64* %3
%9 = add i64 %8, 1
%10 = call i8* @calloc(i64 %9, i32 1)
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %0
store i8* null, i8** %1
br label %25
14: ; preds = %0
%15 = call i32 @time(i32 0)
store i32 %15, i32* %5
%16 = load i8*, i8** %4
%17 = load i64, i64* %3
%18 = add i64 %17, 1
%19 = call i32 @gmtime(i32* %5)
%20 = call i32 @strftime(i8* %16, i64 %18, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %14
store i8* null, i8** %1
br label %25
23: ; preds = %14
%24 = load i8*, i8** %4
store i8* %24, i8** %1
br label %25
25: ; preds = %23, %22, %13
%26 = load i8*, i8** %1
ret i8* %26
}

LLVM IR (-O2):
@.str.1 = [25 x i8] c"%a, %d %b %Y %H:%M:%S %Z\00"
define i8* @get_http_date_str() {
%1 = alloca i32
%2 = tail call i8* @calloc(i64 31, i32 1)
%3 = icmp eq i8* %2, null
br i1 %3, label %11, label %4
4: ; preds = %0
%5 = bitcast i32* %1 to i8*
%6 = tail call i32 @time(i32 0)
store i32 %6, i32* %1
%7 = call i32 @gmtime(i32* %1)
%8 = call i32 @strftime(i8* %2, i64 31, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = icmp eq i32 %8, 0
%10 = select i1 %9, i8* null, i8* %2
br label %11
11: ; preds = %0, %4
%12 = phi i8* [ %10, %4 ], [ null, %0 ]
ret i8* %12
}