#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;
typedef int /*<<< orphan*/ szDateBuff;
struct tm {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ localtime_r(int /*<<< orphan*/ const *, struct tm *);
int /*<<< orphan*/ strftime(char *, int, char const *, struct tm *);
char *formatDatetime(const time_t nTime, const char *szDateFormat, char *buff,
                     const int buff_size) {
  static char szDateBuff[128];
  struct tm tmTime;
  int size;
  localtime_r(&nTime, &tmTime);
  if (buff == NULL) {
    buff = szDateBuff;
    size = sizeof(szDateBuff);
  } else {
    size = buff_size;
  }
  *buff = '\0';
  strftime(buff, size, szDateFormat, &tmTime);
  return buff;
}


x86 assembly (clang, -O0):
<formatDatetime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
lea    -0x4(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <localtime_r@plt>
cmpq   $0x0,-0x18(%rbp)
jne    1165 <formatDatetime+0x45>
lea    0x2eeb(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x80,-0x24(%rbp)
jmp    116b <formatDatetime+0x4b>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1040 <strftime@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<formatDatetime>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r12d
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %edi,0x4(%rsp)
lea    0x4(%rsp),%rdi
lea    0x8(%rsp),%r15
mov    %r15,%rsi
call   1030 <localtime_r@plt>
test   %rbx,%rbx
lea    0x2eeb(%rip),%rbp
cmovne %rbx,%rbp
mov    $0x80,%esi
cmovne %r12d,%esi
movb   $0x0,0x0(%rbp)
mov    %rbp,%rdi
mov    %r14,%rdx
mov    %r15,%rcx
call   1040 <strftime@plt>
mov    %rbp,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@formatDatetime.szDateBuff = internal global [128 x i8] zeroinitializer
define i8* @formatDatetime(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca %struct.tm
%10 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%11 = call i32 @localtime_r(i32* %5, %struct.tm* %9)
%12 = load i8*, i8** %7
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %4
store i8* getelementptr inbounds ([128 x i8], [128 x i8]* @formatDatetime.szDateBuff, i64 0, i64 0), i8** %7
store i32 128, i32* %10
br label %17
15: ; preds = %4
%16 = load i32, i32* %8
store i32 %16, i32* %10
br label %17
17: ; preds = %15, %14
%18 = load i8*, i8** %7
store i8 0, i8* %18
%19 = load i8*, i8** %7
%20 = load i32, i32* %10
%21 = load i8*, i8** %6
%22 = call i32 @strftime(i8* %19, i32 %20, i8* %21, %struct.tm* %9)
%23 = load i8*, i8** %7
ret i8* %23
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@formatDatetime.szDateBuff = internal global [128 x i8] zeroinitializer
define i8* @formatDatetime(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca %struct.tm
store i32 %0, i32* %5
%7 = bitcast %struct.tm* %6 to i8*
%8 = call i32 @localtime_r(i32* %5, %struct.tm* %6)
%9 = icmp eq i8* %2, null
%10 = select i1 %9, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @formatDatetime.szDateBuff, i64 0, i64 0), i8* %2
%11 = select i1 %9, i32 128, i32 %3
store i8 0, i8* %10
%12 = call i32 @strftime(i8* %10, i32 %11, i8* %1, %struct.tm* %6)
ret i8* %10
}