#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 tm_year;
  int tm_mon;
  int tm_mday;
  int tm_hour;
  int tm_min;
  int tm_sec;
};

/* Variables and functions */
struct tm *gmtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void psf_get_date_str(char *str, int maxlen) {
  time_t current;
  struct tm timedata, *tmptr;
  time(&current);
  tmptr = gmtime_r(&current, &timedata);
  if (tmptr)
    snprintf(str, maxlen, "%4d-%02d-%02d %02d:%02d:%02d UTC",
             1900 + timedata.tm_year, timedata.tm_mon, timedata.tm_mday,
             timedata.tm_hour, timedata.tm_min, timedata.tm_sec);
  else
    snprintf(str, maxlen, "Unknown date");
  return;
}


x86 assembly (clang, -O0):
<psf_get_date_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x10(%rbp),%rdi
call   1050 <time@plt>
lea    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <gmtime_r@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11a7 <psf_get_date_str+0x77>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x28(%rbp),%ecx
add    $0x76c,%ecx
mov    -0x24(%rbp),%r8d
mov    -0x20(%rbp),%r9d
mov    -0x1c(%rbp),%r11d
mov    -0x18(%rbp),%r10d
mov    -0x14(%rbp),%eax
lea    0xe72(%rip),%rdx
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %eax,0x10(%rsp)
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    11bc <psf_get_date_str+0x8c>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    0xe6c(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<psf_get_date_str>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0x1c(%rsp),%rbp
mov    %rbp,%rdi
call   1050 <time@plt>
mov    %rsp,%rsi
mov    %rbp,%rdi
call   1040 <gmtime_r@plt>
test   %rax,%rax
je     119e <psf_get_date_str+0x6e>
mov    $0x76c,%ecx
add    (%rsp),%ecx
mov    0x4(%rsp),%r8d
mov    0x8(%rsp),%r9d
mov    0xc(%rsp),%r10d
mov    0x10(%rsp),%r11d
mov    0x14(%rsp),%ebp
sub    $0x8,%rsp
lea    0xe7a(%rip),%rdx
mov    %rbx,%rdi
mov    %r14d,%esi
xor    %eax,%eax
push   %rbp
push   %r11
push   %r10
call   1030 <snprintf@plt>
add    $0x20,%rsp
jmp    11b2 <psf_get_date_str+0x82>
lea    0xe7c(%rip),%rdx
mov    %rbx,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <snprintf@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [33 x i8] c"%4d-%02d-%02d %02d:%02d:%02d UTC\00"
@.str.1 = [13 x i8] c"Unknown date\00"
define void @psf_get_date_str(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.tm
%7 = alloca %struct.tm*
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = call i32 @time(i32* %5)
%9 = call %struct.tm* @gmtime_r(i32* %5, %struct.tm* %6)
store %struct.tm* %9, %struct.tm** %7
%10 = load %struct.tm*, %struct.tm** %7
%11 = icmp ne %struct.tm* %10, null
br i1 %11, label %12, label %29
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = load i32, i32* %4
%15 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 0
%16 = load i32, i32* %15
%17 = add nsw i32 1900, %16
%18 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 1
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 2
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 3
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 4
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 5
%27 = load i32, i32* %26
%28 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %13, i32 %14, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %19, i32 %21, i32 %23, i32 %25, i32 %27)
br label %33
29: ; preds = %2
%30 = load i8*, i8** %3
%31 = load i32, i32* %4
%32 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %30, i32 %31, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %29, %12
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [33 x i8] c"%4d-%02d-%02d %02d:%02d:%02d UTC\00"
@.str.1 = [13 x i8] c"Unknown date\00"
define void @psf_get_date_str(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.tm
%5 = bitcast i32* %3 to i8*
%6 = bitcast %struct.tm* %4 to i8*
%7 = call i32 @time(i32* %3)
%8 = call %struct.tm* @gmtime_r(i32* %3, %struct.tm* %4)
%9 = icmp eq %struct.tm* %8, null
br i1 %9, label %25, label %10
10: ; preds = %2
%11 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 0
%12 = load i32, i32* %11
%13 = add nsw i32 %12, 1900
%14 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 1
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 2
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 3
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 4
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 5
%23 = load i32, i32* %22
%24 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %15, i32 %17, i32 %19, i32 %21, i32 %23)
br label %27
25: ; preds = %2
%26 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %10
ret void
}