#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(int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ rtc_get_time();
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int, int, int);
int get_date_str(char *date) {
  time_t t = rtc_get_time();
  struct tm *tm;
  if (date == NULL)
    return -1;
  tm = gmtime(&t);
  memset(date, 0, 64);
  sprintf(date, "%d-%02d-%02d %02d:%02d:%02d", (tm->tm_year + 1900),
          (tm->tm_mon + 1), tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
  return 0;
}


x86 assembly (clang, -O0):
<get_date_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <rtc_get_time@plt>
mov    %eax,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116d <get_date_str+0x2d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11de <get_date_str+0x9e>
lea    -0x14(%rbp),%rdi
call   1040 <gmtime@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
add    $0x76c,%edx
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%ecx
add    $0x1,%ecx
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0x20(%rbp),%rax
mov    0xc(%rax),%r9d
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%r10d
mov    -0x20(%rbp),%rax
mov    0x14(%rax),%eax
lea    0xe36(%rip),%rsi
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1060 <sprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_date_str>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <rtc_get_time@plt>
mov    %eax,0xc(%rsp)
test   %rbx,%rbx
je     11ad <get_date_str+0x6d>
lea    0xc(%rsp),%rdi
call   1040 <gmtime@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1030 <memset@plt>
mov    $0x76c,%edx
add    0x0(%rbp),%edx
mov    0x4(%rbp),%ecx
mov    0x8(%rbp),%r8d
add    $0x1,%ecx
mov    0xc(%rbp),%r9d
mov    0x10(%rbp),%eax
mov    0x14(%rbp),%ebp
lea    0xe63(%rip),%rsi
mov    %rbx,%rdi
push   %rbp
push   %rax
call   1060 <sprintf@plt>
add    $0x10,%rsp
jmp    11b3 <get_date_str+0x73>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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