#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 time_t;
struct tm {
  int dummy;
};

/* Variables and functions */
struct tm *localtime(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int const);
scalar_t__ strftime(char *, int, char *, struct tm *);
int time(int /*<<< orphan*/ *);
char *currdatetime() {
  const int size = 20;
  char *cdt = (char *)malloc(sizeof(char) * size);
  if (cdt == NULL) {
    return NULL;
  }
  memset(cdt, 0, size);
  time_t currDateTime;
  currDateTime = time(NULL);
  if (currDateTime == -1) {
    return NULL;
  }
  struct tm *timeinfo = localtime(&currDateTime);
  if (strftime(cdt, 20, "%d_%m_%y_%H_%M", timeinfo) == 0) {
    return NULL;
  }
  return cdt;
}


x86 assembly (clang, -O0):
<currdatetime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x14,-0xc(%rbp)
mov    $0x14,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1185 <currdatetime+0x35>
movq   $0x0,-0x8(%rbp)
jmp    11fd <currdatetime+0xad>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11b8 <currdatetime+0x68>
movq   $0x0,-0x8(%rbp)
jmp    11fd <currdatetime+0xad>
lea    -0x1c(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x14,%esi
lea    0xe27(%rip),%rdx
call   1070 <strftime@plt>
cmp    $0x0,%rax
jne    11f5 <currdatetime+0xa5>
movq   $0x0,-0x8(%rbp)
jmp    11fd <currdatetime+0xad>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<currdatetime>:
push   %r14
push   %rbx
push   %rax
mov    $0x14,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11b5 <currdatetime+0x65>
mov    %rax,%rbx
xor    %r14d,%r14d
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,0x4(%rsp)
cmp    $0xffffffff,%eax
je     11b8 <currdatetime+0x68>
lea    0x4(%rsp),%rdi
call   1030 <localtime@plt>
lea    0xe67(%rip),%rdx
mov    %rbx,%rdi
mov    $0x14,%esi
mov    %rax,%rcx
call   1070 <strftime@plt>
test   %rax,%rax
cmove  %rax,%rbx
mov    %rbx,%r14
jmp    11b8 <currdatetime+0x68>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [15 x i8] c"%d_%m_%y_%H_%M\00"
define i8* @currdatetime() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.tm*
store i32 20, i32* %2
%6 = call i64 @malloc(i32 20)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %0
store i8* null, i8** %1
br label %27
11: ; preds = %0
%12 = load i8*, i8** %3
%13 = call i32 @memset(i8* %12, i32 0, i32 20)
%14 = call i32 @time(i32* null)
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %18
17: ; preds = %11
store i8* null, i8** %1
br label %27
18: ; preds = %11
%19 = call %struct.tm* @localtime(i32* %4)
store %struct.tm* %19, %struct.tm** %5
%20 = load i8*, i8** %3
%21 = load %struct.tm*, %struct.tm** %5
%22 = call i64 @strftime(i8* %20, i32 20, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %struct.tm* %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %18
store i8* null, i8** %1
br label %27
25: ; preds = %18
%26 = load i8*, i8** %3
store i8* %26, i8** %1
br label %27
27: ; preds = %25, %24, %17, %10
%28 = load i8*, i8** %1
ret i8* %28
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [15 x i8] c"%d_%m_%y_%H_%M\00"
define i8* @currdatetime() {
%1 = alloca i32
%2 = tail call i64 @malloc(i32 20)
%3 = inttoptr i64 %2 to i8*
%4 = icmp eq i64 %2, 0
br i1 %4, label %17, label %5
5: ; preds = %0
%6 = tail call i32 @memset(i8* %3, i32 0, i32 20)
%7 = bitcast i32* %1 to i8*
%8 = tail call i32 @time(i32* null)
store i32 %8, i32* %1
%9 = icmp eq i32 %8, -1
br i1 %9, label %15, label %10
10: ; preds = %5
%11 = call %struct.tm* @localtime(i32* %1)
%12 = call i64 @strftime(i8* %3, i32 20, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %struct.tm* %11)
%13 = icmp eq i64 %12, 0
%14 = select i1 %13, i8* null, i8* %3
br label %15
15: ; preds = %5, %10
%16 = phi i8* [ %14, %10 ], [ null, %5 ]
br label %17
17: ; preds = %0, %15
%18 = phi i8* [ %16, %15 ], [ null, %0 ]
ret i8* %18
}