#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 */
int /*<<< orphan*/ datetime_localtime_safe(int /*<<< orphan*/, long,
                                           struct tm *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int, int, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void datetime_now(char *res) {
  time_t t;
  struct tm tm;
  if (!res)
    return;
  time(&t);
  datetime_localtime_safe(t, -28800L, &tm);
  sprintf(res, "%04d-%02d-%02dT%02d:%02d:%02d", tm.tm_year + 1900,
          tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
}


x86 assembly (clang, -O0):
<datetime_now>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    114c <datetime_now+0x1c>
jmp    119e <datetime_now+0x6e>
lea    -0xc(%rbp),%rdi
call   1040 <time@plt>
mov    -0xc(%rbp),%edi
mov    $0xffffffffffff8f80,%rsi
lea    -0x28(%rbp),%rdx
call   1030 <datetime_localtime_safe@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%edx
add    $0x76c,%edx
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
mov    -0x20(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
mov    -0x18(%rbp),%r10d
mov    -0x14(%rbp),%eax
lea    0xe6f(%rip),%rsi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1050 <sprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<datetime_now>:
test   %rdi,%rdi
je     1196 <datetime_now+0x66>
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
lea    0x4(%rsp),%rdi
call   1040 <time@plt>
mov    0x4(%rsp),%edi
lea    0x8(%rsp),%rdx
mov    $0xffffffffffff8f80,%rsi
call   1030 <datetime_localtime_safe@plt>
mov    $0x76c,%edx
add    0x8(%rsp),%edx
mov    0xc(%rsp),%ecx
mov    0x10(%rsp),%r8d
add    $0x1,%ecx
mov    0x14(%rsp),%r9d
mov    0x18(%rsp),%r10d
mov    0x1c(%rsp),%eax
lea    0xe7a(%rip),%rsi
mov    %rbx,%rdi
push   %rax
push   %r10
call   1050 <sprintf@plt>
add    $0x30,%rsp
pop    %rbx
ret

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

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