#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 tm_mday;
};

/* Variables and functions */
int /*<<< orphan*/ free(char *);
struct tm *localtime(int /*<<< orphan*/ *);
char *mandoc_malloc(int);
int snprintf(char *, int, char *, int);
size_t strftime(char *, int, char *, struct tm *);
char *time2a(time_t t) {
  struct tm *tm;
  char *buf, *p;
  size_t ssz;
  int isz;
  tm = localtime(&t);
  if (tm == NULL)
    return NULL;
  p = buf = mandoc_malloc(10 + 4 + 4 + 1);
  if ((ssz = strftime(p, 10 + 1, "%B ", tm)) == 0)
    goto fail;
  p += (int)ssz;
  if ((isz = snprintf(p, 4 + 1, "%d, ", tm->tm_mday)) == -1)
    goto fail;
  p += isz;
  if (strftime(p, 4 + 1, "%Y", tm) == 0)
    goto fail;
  return buf;
fail:
  free(buf);
  return NULL;
}


x86 assembly (clang, -O0):
<time2a>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
lea    -0xc(%rbp),%rdi
call   1040 <localtime@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1180 <time2a+0x30>
movq   $0x0,-0x8(%rbp)
jmp    1255 <time2a+0x105>
mov    $0x13,%edi
call   1070 <mandoc_malloc@plt>
mov    %rax,-0x20(%rbp)
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0xb,%esi
lea    0xe5a(%rip),%rdx
call   1060 <strftime@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11be <time2a+0x6e>
jmp    1244 <time2a+0xf4>
mov    -0x30(%rbp),%rax
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
mov    $0x5,%esi
lea    0xe1c(%rip),%rdx
call   1050 <snprintf@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
jne    11fe <time2a+0xae>
jmp    1244 <time2a+0xf4>
mov    -0x34(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x5,%esi
lea    0xde6(%rip),%rdx
call   1060 <strftime@plt>
cmp    $0x0,%rax
jne    1237 <time2a+0xe7>
jmp    1244 <time2a+0xf4>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1255 <time2a+0x105>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<time2a>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1040 <localtime@plt>
test   %rax,%rax
je     11e5 <time2a+0x95>
mov    %rax,%r14
mov    $0x13,%edi
call   1070 <mandoc_malloc@plt>
mov    %rax,%r15
lea    0xe7d(%rip),%rdx
mov    %rax,%rdi
mov    $0xb,%esi
mov    %r14,%rcx
call   1060 <strftime@plt>
test   %rax,%rax
je     11dd <time2a+0x8d>
cltq
mov    %r15,%rbx
add    %rax,%rbx
mov    (%r14),%ecx
lea    0xe5a(%rip),%rdx
mov    %rbx,%rdi
mov    $0x5,%esi
call   1050 <snprintf@plt>
cmp    $0xffffffff,%eax
je     11dd <time2a+0x8d>
cltq
add    %rax,%rbx
lea    0xe41(%rip),%rdx
mov    %rbx,%rdi
mov    $0x5,%esi
mov    %r14,%rcx
call   1060 <strftime@plt>
test   %rax,%rax
jne    11e8 <time2a+0x98>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [4 x i8] c"%B \00"
@.str.1 = [5 x i8] c"%d, \00"
@.str.2 = [3 x i8] c"%Y\00"
define i8* @time2a(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.tm*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i32 %0, i32* %3
%9 = call %struct.tm* @localtime(i32* %3)
store %struct.tm* %9, %struct.tm** %4
%10 = load %struct.tm*, %struct.tm** %4
%11 = icmp eq %struct.tm* %10, null
br i1 %11, label %12, label %13
12: ; preds = %1
store i8* null, i8** %2
br label %48
13: ; preds = %1
%14 = call i8* @mandoc_malloc(i32 19)
store i8* %14, i8** %5
store i8* %14, i8** %6
%15 = load i8*, i8** %6
%16 = load %struct.tm*, %struct.tm** %4
%17 = call i64 @strftime(i8* %15, i32 11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %struct.tm* %16)
store i64 %17, i64* %7
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %13
br label %45
20: ; preds = %13
%21 = load i64, i64* %7
%22 = trunc i64 %21 to i32
%23 = load i8*, i8** %6
%24 = sext i32 %22 to i64
%25 = getelementptr inbounds i8, i8* %23, i64 %24
store i8* %25, i8** %6
%26 = load i8*, i8** %6
%27 = load %struct.tm*, %struct.tm** %4
%28 = getelementptr inbounds %struct.tm, %struct.tm* %27, i32 0, i32 0
%29 = load i32, i32* %28
%30 = call i32 @snprintf(i8* %26, i32 5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %29)
store i32 %30, i32* %8
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %33
32: ; preds = %20
br label %45
33: ; preds = %20
%34 = load i32, i32* %8
%35 = load i8*, i8** %6
%36 = sext i32 %34 to i64
%37 = getelementptr inbounds i8, i8* %35, i64 %36
store i8* %37, i8** %6
%38 = load i8*, i8** %6
%39 = load %struct.tm*, %struct.tm** %4
%40 = call i64 @strftime(i8* %38, i32 5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %39)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %33
br label %45
43: ; preds = %33
%44 = load i8*, i8** %5
store i8* %44, i8** %2
br label %48
45: ; preds = %42, %32, %19
%46 = load i8*, i8** %5
%47 = call i32 @free(i8* %46)
store i8* null, i8** %2
br label %48
48: ; preds = %45, %43, %12
%49 = load i8*, i8** %2
ret i8* %49
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [4 x i8] c"%B \00"
@.str.1 = [5 x i8] c"%d, \00"
@.str.2 = [3 x i8] c"%Y\00"
define i8* @time2a(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = call %struct.tm* @localtime(i32* %2)
%4 = icmp eq %struct.tm* %3, null
br i1 %4, label %24, label %5
5: ; preds = %1
%6 = call i8* @mandoc_malloc(i32 19)
%7 = call i64 @strftime(i8* %6, i32 11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %struct.tm* %3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %22, label %9
9: ; preds = %5
%10 = shl i64 %7, 32
%11 = ashr exact i64 %10, 32
%12 = getelementptr inbounds i8, i8* %6, i64 %11
%13 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 0
%14 = load i32, i32* %13
%15 = call i32 @snprintf(i8* %12, i32 5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %22, label %17
17: ; preds = %9
%18 = sext i32 %15 to i64
%19 = getelementptr inbounds i8, i8* %12, i64 %18
%20 = call i64 @strftime(i8* %19, i32 5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %3)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %17, %9, %5
%23 = call i32 @free(i8* %6)
br label %24
24: ; preds = %17, %1, %22
%25 = phi i8* [ null, %22 ], [ null, %1 ], [ %6, %17 ]
ret i8* %25
}