#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*/ p;

/* Variables and functions */
int /*<<< orphan*/ _xstrcat(char **, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ localtime_r(scalar_t__ *, struct tm *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strftime(char *, int, char const *, struct tm *);
scalar_t__ time(scalar_t__ *);
void _xstrftimecat(char **buf, const char *fmt) {
  char p[256];
  time_t t;
  struct tm tm;
  const char default_fmt[] = "%m/%d/%Y %H:%M:%S %Z";
  if (fmt == NULL)
    fmt = default_fmt;
  if (time(&t) == (time_t)-1)
    fprintf(stderr, "time() failed\n");
  if (!localtime_r(&t, &tm))
    fprintf(stderr, "localtime_r() failed\n");
  strftime(p, sizeof(p), fmt, &tm);
  _xstrcat(buf, p);
}


x86 assembly (clang, -O0):
<_xstrftimecat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe96(%rip),%rax
mov    %rax,-0x140(%rbp)
mov    0xe90(%rip),%rax
mov    %rax,-0x138(%rbp)
mov    0xe8b(%rip),%eax
mov    %eax,-0x130(%rbp)
mov    0xe83(%rip),%al
mov    %al,-0x12c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ad <_xstrftimecat+0x5d>
lea    -0x140(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x118(%rbp),%rdi
call   1060 <time@plt>
cmp    $0xffffffffffffffff,%rax
jne    11d8 <_xstrftimecat+0x88>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
lea    0xe42(%rip),%rsi
call   1040 <fprintf@plt>
lea    -0x118(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   1030 <localtime_r@plt>
cmp    $0x0,%eax
jne    1209 <_xstrftimecat+0xb9>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
call   1040 <fprintf@plt>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x100,%esi
lea    -0x120(%rbp),%rcx
call   1070 <strftime@plt>
mov    -0x8(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   1050 <_xstrcat@plt>
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_xstrftimecat>:
push   %r14
push   %rbx
sub    $0x138,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
movaps 0xe99(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movabs $0x5a252053253a4d,%rax
mov    %rax,0x1d(%rsp)
lea    0x8(%rsp),%rdi
call   1060 <time@plt>
cmp    $0xffffffffffffffff,%rax
jne    11a0 <_xstrftimecat+0x50>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
lea    0xe7a(%rip),%rsi
call   1040 <fprintf@plt>
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
call   1030 <localtime_r@plt>
test   %eax,%eax
jne    11c6 <_xstrftimecat+0x76>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
lea    0xe63(%rip),%rsi
call   1040 <fprintf@plt>
test   %rbx,%rbx
lea    0x10(%rsp),%rdx
cmovne %rbx,%rdx
lea    0x30(%rsp),%rbx
mov    %rsp,%rcx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1070 <strftime@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <_xstrcat@plt>
add    $0x138,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@__const._xstrftimecat.default_fmt = [21 x i8] c"%m/%d/%Y %H:%M:%S %Z\00"
@stderr = global i32 0
@.str = [15 x i8] c"time() failed\0A\00"
@.str.1 = [22 x i8] c"localtime_r() failed\0A\00"
define void @_xstrftimecat(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca [256 x i8]
%6 = alloca i64
%7 = alloca %struct.tm
%8 = alloca [21 x i8]
store i8** %0, i8*** %3
store i8* %1, i8** %4
%9 = bitcast [21 x i8]* %8 to i8*
%10 = load i8*, i8** %4
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = getelementptr inbounds [21 x i8], [21 x i8]* %8, i64 0, i64 0
store i8* %13, i8** %4
br label %14
14: ; preds = %12, %2
%15 = call i64 @time(i64* %6)
%16 = icmp eq i64 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %17, %14
%21 = call i32 @localtime_r(i64* %6, %struct.tm* %7)
%22 = icmp ne i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %23, %20
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%28 = load i8*, i8** %4
%29 = call i32 @strftime(i8* %27, i32 256, i8* %28, %struct.tm* %7)
%30 = load i8**, i8*** %3
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%32 = call i32 @_xstrcat(i8** %30, i8* %31)
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@__const._xstrftimecat.default_fmt = [21 x i8] c"%m/%d/%Y %H:%M:%S %Z\00"
@stderr = global i32 0
@.str = [15 x i8] c"time() failed\0A\00"
@.str.1 = [22 x i8] c"localtime_r() failed\0A\00"
define void @_xstrftimecat(i8** %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = alloca i64
%5 = alloca %struct.tm
%6 = alloca [21 x i8]
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%8 = bitcast i64* %4 to i8*
%9 = bitcast %struct.tm* %5 to i8*
%10 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 0
%11 = call i64 @time(i64* %4)
%12 = icmp eq i64 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %13, %2
%17 = call i32 @localtime_r(i64* %4, %struct.tm* %5)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %19, %16
%23 = icmp eq i8* %1, null
%24 = select i1 %23, i8* %10, i8* %1
%25 = call i32 @strftime(i8* %7, i32 256, i8* %24, %struct.tm* %5)
%26 = call i32 @_xstrcat(i8** %0, i8* %7)
ret void
}