#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 /*<<< orphan*/ tm_mday;
  scalar_t__ tm_mon;
  scalar_t__ tm_year;
};

/* Variables and functions */
struct tm *localtime_r(int /*<<< orphan*/ *, struct tm *);
scalar_t__ malloc(int);
int /*<<< orphan*/ px_set_date(char *, scalar_t__, scalar_t__,
                               int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *px_cur_date(char *cp) {
  struct tm *ctm, tmbuf;
  time_t c_time;
  c_time = time((time_t *)NULL);
  ctm = localtime_r(&c_time, &tmbuf);
  if (cp == NULL)
    cp = (char *)malloc(9);
  if (ctm == NULL || cp == NULL)
    return NULL;
  px_set_date(cp, tmbuf.tm_year + 1900, tmbuf.tm_mon + 1, tmbuf.tm_mday);
  return cp;
}


x86 assembly (clang, -O0):
<px_cur_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0x34(%rbp)
lea    -0x34(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <localtime_r@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1182 <px_cur_date+0x42>
mov    $0x9,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1198 <px_cur_date+0x58>
cmpq   $0x0,-0x10(%rbp)
jne    11a5 <px_cur_date+0x65>
movq   $0x0,-0x8(%rbp)
jmp    11cc <px_cur_date+0x8c>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x76c,%rsi
mov    -0x28(%rbp),%rdx
add    $0x1,%rdx
mov    -0x30(%rbp),%ecx
call   1060 <px_set_date@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<px_cur_date>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbx
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1030 <localtime_r@plt>
mov    %rax,%r14
test   %rbx,%rbx
jne    1179 <px_cur_date+0x39>
mov    $0x9,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
test   %r14,%r14
je     11a7 <px_cur_date+0x67>
test   %rbx,%rbx
je     11a7 <px_cur_date+0x67>
mov    $0x76c,%esi
add    0x20(%rsp),%rsi
mov    0x18(%rsp),%rdx
add    $0x1,%rdx
mov    0x10(%rsp),%ecx
mov    %rbx,%rdi
call   1060 <px_set_date@plt>
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32, i64, i64 }
define i8* @px_cur_date(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca %struct.tm*
%5 = alloca %struct.tm
%6 = alloca i32
store i8* %0, i8** %3
%7 = call i32 @time(i32* null)
store i32 %7, i32* %6
%8 = call %struct.tm* @localtime_r(i32* %6, %struct.tm* %5)
store %struct.tm* %8, %struct.tm** %4
%9 = load i8*, i8** %3
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = call i64 @malloc(i32 9)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %3
br label %14
14: ; preds = %11, %1
%15 = load %struct.tm*, %struct.tm** %4
%16 = icmp eq %struct.tm* %15, null
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = load i8*, i8** %3
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %21
20: ; preds = %17, %14
store i8* null, i8** %2
br label %33
21: ; preds = %17
%22 = load i8*, i8** %3
%23 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 2
%24 = load i64, i64* %23
%25 = add nsw i64 %24, 1900
%26 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 1
%27 = load i64, i64* %26
%28 = add nsw i64 %27, 1
%29 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 0
%30 = load i32, i32* %29
%31 = call i32 @px_set_date(i8* %22, i64 %25, i64 %28, i32 %30)
%32 = load i8*, i8** %3
store i8* %32, i8** %2
br label %33
33: ; preds = %21, %20
%34 = load i8*, i8** %2
ret i8* %34
}

LLVM IR (-O2):
%struct.tm = type { i32, i64, i64 }
define i8* @px_cur_date(i8* %0) {
%2 = alloca %struct.tm
%3 = alloca i32
%4 = bitcast %struct.tm* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = tail call i32 @time(i32* null)
store i32 %6, i32* %3
%7 = call %struct.tm* @localtime_r(i32* %3, %struct.tm* %2)
%8 = icmp eq i8* %0, null
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = call i64 @malloc(i32 9)
%11 = inttoptr i64 %10 to i8*
br label %12
12: ; preds = %9, %1
%13 = phi i8* [ %11, %9 ], [ %0, %1 ]
%14 = icmp eq %struct.tm* %7, null
%15 = icmp eq i8* %13, null
%16 = select i1 %14, i1 true, i1 %15
br i1 %16, label %27, label %17
17: ; preds = %12
%18 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 2
%19 = load i64, i64* %18
%20 = add nsw i64 %19, 1900
%21 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 1
%22 = load i64, i64* %21
%23 = add nsw i64 %22, 1
%24 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 0
%25 = load i32, i32* %24
%26 = call i32 @px_set_date(i8* %13, i64 %20, i64 %23, i32 %25)
br label %27
27: ; preds = %12, %17
%28 = phi i8* [ %13, %17 ], [ null, %12 ]
ret i8* %28
}