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

/* Variables and functions */
int /*<<< orphan*/ *localtime_r(scalar_t__ *, struct tm *);
int /*<<< orphan*/ snprintf(char *, size_t, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strftime(char *, size_t, char *, struct tm *);
const char *fmttime(char *b, size_t l, time_t t) {
  struct tm tm;
  if (localtime_r(&t, &tm) == NULL)
    snprintf(b, l, "*%jd*", (intmax_t)t);
  else
    strftime(b, l, "%Y/%m/%d %H:%M:%S", &tm);
  return b;
}


x86 assembly (clang, -O0):
<fmttime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <localtime_r@plt>
cmp    $0x0,%rax
jne    117a <fmttime+0x4a>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    %eax,%ecx
lea    0xe90(%rip),%rdx
call   1040 <snprintf@plt>
jmp    1192 <fmttime+0x62>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xe7d(%rip),%rdx
lea    -0x20(%rbp),%rcx
call   1050 <strftime@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fmttime>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rdx,0x10(%rsp)
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1030 <localtime_r@plt>
test   %rax,%rax
je     116f <fmttime+0x3f>
lea    0xea9(%rip),%rdx
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strftime@plt>
jmp    1185 <fmttime+0x55>
mov    0x10(%rsp),%ecx
lea    0xe86(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <snprintf@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [6 x i8] c"*%jd*\00"
@.str.1 = [18 x i8] c"%Y/%m/%d %H:%M:%S\00"
define i8* @fmttime(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca %struct.tm
store i8* %0, i8** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%8 = call i32* @localtime_r(i64* %6, %struct.tm* %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %16
10: ; preds = %3
%11 = load i8*, i8** %4
%12 = load i64, i64* %5
%13 = load i64, i64* %6
%14 = trunc i64 %13 to i32
%15 = call i32 @snprintf(i8* %11, i64 %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %14)
br label %20
16: ; preds = %3
%17 = load i8*, i8** %4
%18 = load i64, i64* %5
%19 = call i32 @strftime(i8* %17, i64 %18, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %7)
br label %20
20: ; preds = %16, %10
%21 = load i8*, i8** %4
ret i8* %21
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [6 x i8] c"*%jd*\00"
@.str.1 = [18 x i8] c"%Y/%m/%d %H:%M:%S\00"
define i8* @fmttime(i8* returned %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = alloca %struct.tm
store i64 %2, i64* %4
%6 = bitcast %struct.tm* %5 to i8*
%7 = call i32* @localtime_r(i64* %4, %struct.tm* %5)
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %13
9: ; preds = %3
%10 = load i64, i64* %4
%11 = trunc i64 %10 to i32
%12 = call i32 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %11)
br label %15
13: ; preds = %3
%14 = call i32 @strftime(i8* %0, i64 %1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %5)
br label %15
15: ; preds = %13, %9
ret i8* %0
}