#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);
  p = buf = mandoc_malloc(10 + 4 + 4 + 1);
  if (0 == (ssz = strftime(p, 10 + 1, "%B ", tm)))
    goto fail;
  p += (int)ssz;
  if (-1 == (isz = snprintf(p, 4 + 1, "%d, ", tm->tm_mday)))
    goto fail;
  p += isz;
  if (0 == strftime(p, 4 + 1, "%Y", tm))
    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)
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    0xe72(%rip),%rdx
call   1060 <strftime@plt>
mov    %rax,%rcx
mov    %rcx,-0x30(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    11aa <time2a+0x5a>
jmp    123a <time2a+0xea>
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    0xe30(%rip),%rdx
call   1050 <snprintf@plt>
mov    %eax,%ecx
mov    %ecx,-0x34(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11f0 <time2a+0xa0>
jmp    123a <time2a+0xea>
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    0xdf4(%rip),%rdx
call   1060 <strftime@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    122d <time2a+0xdd>
jmp    123a <time2a+0xea>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    124b <time2a+0xfb>
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>
mov    %rax,%r14
mov    $0x13,%edi
call   1070 <mandoc_malloc@plt>
mov    %rax,%rbx
mov    %rax,%r15
lea    0xe7f(%rip),%rdx
mov    %rax,%rdi
mov    $0xb,%esi
mov    %r14,%rcx
call   1060 <strftime@plt>
test   %rax,%rax
je     11d8 <time2a+0x88>
cltq
add    %rax,%rbx
mov    (%r14),%ecx
lea    0xe5f(%rip),%rdx
mov    %rbx,%rdi
mov    $0x5,%esi
call   1050 <snprintf@plt>
cmp    $0xffffffff,%eax
je     11d8 <time2a+0x88>
cltq
add    %rax,%rbx
lea    0xe46(%rip),%rdx
mov    %rbx,%rdi
mov    $0x5,%esi
mov    %r14,%rcx
call   1060 <strftime@plt>
test   %rax,%rax
jne    11e3 <time2a+0x93>
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 = call i8* @mandoc_malloc(i32 19)
store i8* %10, i8** %5
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = load %struct.tm*, %struct.tm** %4
%13 = call i64 @strftime(i8* %11, i32 11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %struct.tm* %12)
store i64 %13, i64* %7
%14 = icmp eq i64 0, %13
br i1 %14, label %15, label %16
15: ; preds = %1
br label %41
16: ; preds = %1
%17 = load i64, i64* %7
%18 = trunc i64 %17 to i32
%19 = load i8*, i8** %6
%20 = sext i32 %18 to i64
%21 = getelementptr inbounds i8, i8* %19, i64 %20
store i8* %21, i8** %6
%22 = load i8*, i8** %6
%23 = load %struct.tm*, %struct.tm** %4
%24 = getelementptr inbounds %struct.tm, %struct.tm* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = call i32 @snprintf(i8* %22, i32 5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %25)
store i32 %26, i32* %8
%27 = icmp eq i32 -1, %26
br i1 %27, label %28, label %29
28: ; preds = %16
br label %41
29: ; preds = %16
%30 = load i32, i32* %8
%31 = load i8*, i8** %6
%32 = sext i32 %30 to i64
%33 = getelementptr inbounds i8, i8* %31, i64 %32
store i8* %33, i8** %6
%34 = load i8*, i8** %6
%35 = load %struct.tm*, %struct.tm** %4
%36 = call i64 @strftime(i8* %34, i32 5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %35)
%37 = icmp eq i64 0, %36
br i1 %37, label %38, label %39
38: ; preds = %29
br label %41
39: ; preds = %29
%40 = load i8*, i8** %5
store i8* %40, i8** %2
br label %44
41: ; preds = %38, %28, %15
%42 = load i8*, i8** %5
%43 = call i32 @free(i8* %42)
store i8* null, i8** %2
br label %44
44: ; preds = %41, %39
%45 = load i8*, i8** %2
ret i8* %45
}

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 = call i8* @mandoc_malloc(i32 19)
%5 = call i64 @strftime(i8* %4, i32 11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %struct.tm* %3)
%6 = icmp eq i64 %5, 0
br i1 %6, label %20, label %7
7: ; preds = %1
%8 = shl i64 %5, 32
%9 = ashr exact i64 %8, 32
%10 = getelementptr inbounds i8, i8* %4, i64 %9
%11 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 0
%12 = load i32, i32* %11
%13 = call i32 @snprintf(i8* %10, i32 5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %20, label %15
15: ; preds = %7
%16 = sext i32 %13 to i64
%17 = getelementptr inbounds i8, i8* %10, i64 %16
%18 = call i64 @strftime(i8* %17, i32 5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %3)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %15, %7, %1
%21 = call i32 @free(i8* %4)
br label %22
22: ; preds = %15, %20
%23 = phi i8* [ null, %20 ], [ %4, %15 ]
ret i8* %23
}