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

/* Variables and functions */
struct tm *localtime(int /*<<< orphan*/ const *);
size_t snprintf(char *, size_t, char *, int, int, int, int, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
size_t date(char *restrict str, size_t size) {
  const time_t t = time(NULL);
  const struct tm tm = *localtime(&t);
  return snprintf(str, size, "%04d-%02d-%02d %02d:%02d", tm.tm_year + 1900,
                  tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min);
}


x86 assembly (clang, -O0):
<date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x14(%rbp)
lea    -0x14(%rbp),%rdi
call   1030 <localtime@plt>
mov    (%rax),%rcx
mov    %rcx,-0x28(%rbp)
mov    0x8(%rax),%rcx
mov    %rcx,-0x20(%rbp)
mov    0x10(%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%ecx
add    $0x76c,%ecx
mov    -0x24(%rbp),%r8d
add    $0x1,%r8d
mov    -0x20(%rbp),%r9d
mov    -0x1c(%rbp),%r10d
mov    -0x18(%rbp),%eax
lea    0xe6b(%rip),%rdx
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1040 <snprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<date>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
mov    0x4(%rax),%r8d
mov    0x8(%rax),%r9d
mov    0xc(%rax),%r10d
mov    0x10(%rax),%ebx
mov    $0x76c,%ecx
add    (%rax),%ecx
add    $0x1,%r8d
lea    0xe8b(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
push   %rbx
push   %r10
call   1040 <snprintf@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32 }
@.str = [25 x i8] c"%04d-%02d-%02d %02d:%02d\00"
define i64 @date(i8* noalias %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca %struct.tm
store i8* %0, i8** %3
store i64 %1, i64* %4
%7 = call i32 @time(i32* null)
store i32 %7, i32* %5
%8 = call %struct.tm* @localtime(i32* %5)
%9 = bitcast %struct.tm* %6 to i8*
%10 = bitcast %struct.tm* %8 to i8*
%11 = load i8*, i8** %3
%12 = load i64, i64* %4
%13 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 0
%14 = load i32, i32* %13
%15 = add nsw i32 %14, 1900
%16 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 1
%17 = load i32, i32* %16
%18 = add nsw i32 %17, 1
%19 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 2
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 3
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 4
%24 = load i32, i32* %23
%25 = call i64 @snprintf(i8* %11, i64 %12, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %18, i32 %20, i32 %22, i32 %24)
ret i64 %25
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32 }
@.str = [25 x i8] c"%04d-%02d-%02d %02d:%02d\00"
define i64 @date(i8* noalias %0, i64 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @time(i32* null)
store i32 %5, i32* %3
%6 = call %struct.tm* @localtime(i32* %3)
%7 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 0
%8 = load i32, i32* %7
%9 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 1
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 2
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 3
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.tm, %struct.tm* %6, i64 0, i32 4
%16 = load i32, i32* %15
%17 = add nsw i32 %8, 1900
%18 = add nsw i32 %10, 1
%19 = call i64 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %18, i32 %12, i32 %14, i32 %16)
ret i64 %19
}