#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 dummy;
};
struct timeval {
  long tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ bcopy(int /*<<< orphan*/, struct tm *, int);
int /*<<< orphan*/ localtime(int /*<<< orphan*/ *);
char *stpcpy(char *, char *);
int strftime(char *, size_t, char *, struct tm *);
scalar_t__ strlen(char *);
size_t fmt_past_time(struct timeval *tv, struct timeval *now, size_t width,
                     char *buf, size_t buf_len) {
  static char *time_fmts[] = {"%-r", "%-l:%M%p", "%-l%p", 0};
  static char *week_fmts[] = {"%A", "%a", 0};
  static char *month_fmts[] = {"%A %-d", "%a %-d", "%a%-d", 0};
  static char *date_fmts[] = {"%A, %-d %B", "%a, %-d %b", "%-d %B",
                              "%-d %b",     "%-d%b",      0};
  static char *year_fmts[] = {"%A, %-d %B %Y", "%a, %-d %b %Y", "%a, %-d %b %y",
                              "%-d %b %y",     "%-d%b%y",       0};
  struct tm tm;
  int used = 0;
  long diff = now ? (now->tv_sec - tv->tv_sec) : tv->tv_sec;
  if (diff < 0)
    diff = -diff;
  bcopy(localtime((time_t *)&tv->tv_sec), &tm, sizeof tm);
  if (width <= 0 || width >= buf_len)
    width = buf_len - 1;
  if (diff < (24 * (60 * 60))) {
    char **fmt;
    for (fmt = time_fmts; *fmt && !used; fmt++)
      used = strftime(buf, width + 1, *fmt, &tm);
    if (!used)
      used = strftime(buf, buf_len, fmt[-1], &tm);
  } else {
    static char *seps[] = {", ", " ", "", 0};
    char **fmt, **dfmt, **dfmts, **sep;
    if (diff < (7 * (24 * (60 * 60))))
      dfmts = week_fmts;
    else if (diff < (31 * (24 * (60 * 60))))
      dfmts = month_fmts;
    else if (diff < (365 * (24 * (60 * 60))))
      dfmts = date_fmts;
    else
      dfmts = year_fmts;
    for (fmt = time_fmts; *fmt && !used; fmt++)
      for (sep = seps; *sep && !used; sep++)
        for (dfmt = dfmts; *dfmt && !used; dfmt++) {
          char whole_fmt[strlen(*dfmt) + strlen(*sep) + strlen(*fmt) + 1];
          char *end = whole_fmt;
          end = stpcpy(end, *dfmt);
          end = stpcpy(end, *sep);
          stpcpy(end, *fmt);
          used = strftime(buf, width + 1, whole_fmt, &tm);
        }
    if (!used)
      for (dfmt = dfmts; *dfmt && !used; dfmt++)
        used = strftime(buf, width + 1, *dfmt, &tm);
    if (!used)
      used = strftime(buf, buf_len, dfmt[-1], &tm);
  }
  return used;
}


x86 assembly (clang, -O0):
<fmt_past_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     119b <fmt_past_time+0x4b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x8(%rbp),%rcx
sub    (%rcx),%rax
mov    %rax,-0x88(%rbp)
jmp    11a9 <fmt_past_time+0x59>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jge    11c9 <fmt_past_time+0x79>
xor    %eax,%eax
sub    -0x40(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <localtime@plt>
mov    %eax,%edi
lea    -0x30(%rbp),%rsi
mov    $0x4,%edx
call   1060 <bcopy@plt>
cmpq   $0x0,-0x18(%rbp)
jbe    11fb <fmt_past_time+0xab>
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
jb     1207 <fmt_past_time+0xb7>
mov    -0x28(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x15180,-0x40(%rbp)
jge    12b3 <fmt_past_time+0x163>
lea    0x2e34(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rcx
xor    %eax,%eax
cmpq   $0x0,(%rcx)
mov    %al,-0x89(%rbp)
je     1245 <fmt_past_time+0xf5>
cmpl   $0x0,-0x34(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x89(%rbp)
mov    -0x89(%rbp),%al
test   $0x1,%al
jne    1258 <fmt_past_time+0x108>
jmp    1288 <fmt_past_time+0x138>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
mov    -0x48(%rbp),%rax
mov    (%rax),%rdx
lea    -0x30(%rbp),%rcx
call   1070 <strftime@plt>
mov    %eax,-0x34(%rbp)
mov    -0x48(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x48(%rbp)
jmp    1220 <fmt_past_time+0xd0>
cmpl   $0x0,-0x34(%rbp)
jne    12ae <fmt_past_time+0x15e>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x48(%rbp),%rax
mov    -0x8(%rax),%rdx
lea    -0x30(%rbp),%rcx
call   1070 <strftime@plt>
mov    %eax,-0x34(%rbp)
jmp    15a0 <fmt_past_time+0x450>
cmpq   $0x93a80,-0x40(%rbp)
jge    12d1 <fmt_past_time+0x181>
lea    0x2da8(%rip),%rax
mov    %rax,-0x60(%rbp)
jmp    1322 <fmt_past_time+0x1d2>
cmpq   $0x28de80,-0x40(%rbp)
jge    12ef <fmt_past_time+0x19f>
lea    0x2daa(%rip),%rax
mov    %rax,-0x60(%rbp)
jmp    131d <fmt_past_time+0x1cd>
cmpq   $0x1e13380,-0x40(%rbp)
01
jge    130d <fmt_past_time+0x1bd>
lea    0x2dac(%rip),%rax
mov    %rax,-0x60(%rbp)
jmp    1318 <fmt_past_time+0x1c8>
lea    0x2dcc(%rip),%rax
mov    %rax,-0x60(%rbp)
jmp    131d <fmt_past_time+0x1cd>
jmp    1322 <fmt_past_time+0x1d2>
lea    0x2d27(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rcx
xor    %eax,%eax
cmpq   $0x0,(%rcx)
mov    %al,-0x8a(%rbp)
je     1352 <fmt_past_time+0x202>
cmpl   $0x0,-0x34(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x8a(%rbp)
mov    -0x8a(%rbp),%al
test   $0x1,%al
jne    1365 <fmt_past_time+0x215>
jmp    14f6 <fmt_past_time+0x3a6>
lea    0x2da4(%rip),%rax
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rcx
xor    %eax,%eax
cmpq   $0x0,(%rcx)
mov    %al,-0x8b(%rbp)
je     1395 <fmt_past_time+0x245>
cmpl   $0x0,-0x34(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x8b(%rbp)
mov    -0x8b(%rbp),%al
test   $0x1,%al
jne    13a8 <fmt_past_time+0x258>
jmp    14e0 <fmt_past_time+0x390>
mov    -0x60(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rcx
xor    %eax,%eax
cmpq   $0x0,(%rcx)
mov    %al,-0x8c(%rbp)
je     13d5 <fmt_past_time+0x285>
cmpl   $0x0,-0x34(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x8c(%rbp)
mov    -0x8c(%rbp),%al
test   $0x1,%al
jne    13e8 <fmt_past_time+0x298>
jmp    14ca <fmt_past_time+0x37a>
mov    -0x58(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    %rax,-0xa8(%rbp)
mov    -0x68(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0xa8(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0xa0(%rbp)
mov    -0x50(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    -0xa0(%rbp),%rdx
lea    0x1(%rax,%rdx,1),%rcx
mov    %rsp,%rsi
mov    %rsi,-0x70(%rbp)
lea    0x10(%rax,%rdx,1),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rax
sub    %rdx,%rax
mov    %rax,-0x98(%rbp)
mov    %rax,%rsp
mov    %rcx,-0x78(%rbp)
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rdi
mov    -0x58(%rbp),%rax
mov    (%rax),%rsi
call   1040 <stpcpy@plt>
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rdi
mov    -0x68(%rbp),%rax
mov    (%rax),%rsi
call   1040 <stpcpy@plt>
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rdi
mov    -0x50(%rbp),%rax
mov    (%rax),%rsi
call   1040 <stpcpy@plt>
mov    -0x98(%rbp),%rdx
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
lea    -0x30(%rbp),%rcx
call   1070 <strftime@plt>
mov    %eax,-0x34(%rbp)
mov    -0x70(%rbp),%rax
mov    %rax,%rsp
mov    -0x58(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x58(%rbp)
jmp    13b0 <fmt_past_time+0x260>
jmp    14cf <fmt_past_time+0x37f>
mov    -0x68(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x68(%rbp)
jmp    1370 <fmt_past_time+0x220>
jmp    14e5 <fmt_past_time+0x395>
mov    -0x50(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x50(%rbp)
jmp    132d <fmt_past_time+0x1dd>
cmpl   $0x0,-0x34(%rbp)
jne    1575 <fmt_past_time+0x425>
mov    -0x60(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rcx
xor    %eax,%eax
cmpq   $0x0,(%rcx)
mov    %al,-0xa9(%rbp)
je     152d <fmt_past_time+0x3dd>
cmpl   $0x0,-0x34(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0xa9(%rbp)
mov    -0xa9(%rbp),%al
test   $0x1,%al
jne    1540 <fmt_past_time+0x3f0>
jmp    1570 <fmt_past_time+0x420>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
mov    -0x58(%rbp),%rax
mov    (%rax),%rdx
lea    -0x30(%rbp),%rcx
call   1070 <strftime@plt>
mov    %eax,-0x34(%rbp)
mov    -0x58(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x58(%rbp)
jmp    1508 <fmt_past_time+0x3b8>
jmp    1575 <fmt_past_time+0x425>
cmpl   $0x0,-0x34(%rbp)
jne    159b <fmt_past_time+0x44b>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x58(%rbp),%rax
mov    -0x8(%rax),%rdx
lea    -0x30(%rbp),%rcx
call   1070 <strftime@plt>
mov    %eax,-0x34(%rbp)
jmp    15a0 <fmt_past_time+0x450>
movslq -0x34(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fmt_past_time>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r8,-0x50(%rbp)
mov    %rcx,-0x38(%rbp)
mov    %rdx,%r12
test   %rsi,%rsi
je     1189 <fmt_past_time+0x29>
mov    (%rsi),%rax
sub    (%rdi),%rax
jmp    118c <fmt_past_time+0x2c>
mov    (%rdi),%rax
mov    %rax,%rbx
neg    %rbx
cmovs  %rax,%rbx
call   1030 <localtime@plt>
lea    -0x30(%rbp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1070 <bcopy@plt>
mov    -0x50(%rbp),%rcx
lea    -0x1(%rcx),%rax
cmp    %rcx,%r12
mov    %rax,%rcx
cmovb  %r12,%rcx
test   %r12,%r12
cmove  %rax,%rcx
cmp    $0x1517f,%rbx
ja     121d <fmt_past_time+0xbd>
add    $0x1,%rcx
mov    %rcx,%r14
lea    0xe25(%rip),%rdx
lea    0x2b56(%rip),%rbx
lea    -0x30(%rbp),%r12
cs nopw 0x0(%rax,%rax,1)
mov    -0x38(%rbp),%rdi
mov    %r14,%rsi
mov    %r12,%rcx
call   1080 <strftime@plt>
mov    0x10(%rbx),%rdx
add    $0x8,%rbx
test   %rdx,%rdx
je     1210 <fmt_past_time+0xb0>
test   %eax,%eax
je     11f0 <fmt_past_time+0x90>
test   %eax,%eax
jne    13c9 <fmt_past_time+0x269>
jmp    13b5 <fmt_past_time+0x255>
cmp    $0x93a80,%rbx
mov    %rcx,-0x48(%rbp)
jae    1233 <fmt_past_time+0xd3>
lea    0x2b2f(%rip),%rax
jmp    1261 <fmt_past_time+0x101>
cmp    $0x28de80,%rbx
jae    1245 <fmt_past_time+0xe5>
lea    0x2b3d(%rip),%rax
jmp    1261 <fmt_past_time+0x101>
cmp    $0x1e13380,%rbx
lea    0x2b4d(%rip),%rax
lea    0x2b76(%rip),%rcx
cmovb  %rax,%rcx
mov    %rcx,%rax
mov    (%rax),%rdx
addq   $0x1,-0x48(%rbp)
mov    %rax,-0x40(%rbp)
add    $0x8,%rax
mov    %rax,-0x60(%rbp)
lea    0x2ac4(%rip),%rcx
mov    %rdx,-0x68(%rbp)
mov    %rcx,-0x58(%rbp)
lea    0x2b75(%rip),%r12
nopl   0x0(%rax,%rax,1)
test   %rdx,%rdx
je     1340 <fmt_past_time+0x1e0>
mov    -0x60(%rbp),%r13
mov    %rdx,%rdi
call   1060 <strlen@plt>
mov    %rax,%r14
mov    (%r12),%rdi
call   1060 <strlen@plt>
mov    %r12,%rbx
mov    %rax,%r12
mov    -0x58(%rbp),%r15
mov    (%r15),%rdi
call   1060 <strlen@plt>
mov    %rsp,-0x70(%rbp)
add    %r14,%r12
add    %r12,%rax
add    $0x10,%rax
mov    %rbx,%r12
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    -0x8(%r13),%rsi
mov    %rbx,%rdi
call   1050 <stpcpy@plt>
mov    (%r12),%rsi
mov    %rax,%rdi
call   1050 <stpcpy@plt>
mov    (%r15),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
mov    -0x38(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %rbx,%rdx
lea    -0x30(%rbp),%rcx
call   1080 <strftime@plt>
mov    -0x70(%rbp),%rsp
mov    0x0(%r13),%rdi
test   %rdi,%rdi
je     1342 <fmt_past_time+0x1e2>
add    $0x8,%r13
test   %eax,%eax
je     12a0 <fmt_past_time+0x140>
jmp    1342 <fmt_past_time+0x1e2>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
cmpq   $0x0,0x8(%r12)
mov    -0x68(%rbp),%rdx
mov    -0x58(%rbp),%rcx
je     135e <fmt_past_time+0x1fe>
add    $0x8,%r12
test   %eax,%eax
je     1290 <fmt_past_time+0x130>
cmpq   $0x0,0x8(%rcx)
je     1371 <fmt_past_time+0x211>
add    $0x8,%rcx
test   %eax,%eax
je     1280 <fmt_past_time+0x120>
test   %eax,%eax
jne    13c9 <fmt_past_time+0x269>
test   %rdx,%rdx
je     13ad <fmt_past_time+0x24d>
lea    -0x30(%rbp),%r13
xchg   %ax,%ax
mov    -0x38(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %r13,%rcx
call   1080 <strftime@plt>
mov    -0x40(%rbp),%rcx
mov    0x8(%rcx),%rdx
add    $0x8,%rcx
mov    %rcx,-0x40(%rbp)
test   %rdx,%rdx
je     13a9 <fmt_past_time+0x249>
test   %eax,%eax
je     1380 <fmt_past_time+0x220>
test   %eax,%eax
jne    13c9 <fmt_past_time+0x269>
mov    -0x40(%rbp),%rbx
add    $0xfffffffffffffff8,%rbx
mov    (%rbx),%rdx
lea    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%rdi
mov    -0x50(%rbp),%rsi
call   1080 <strftime@plt>
cltq
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i64 }
%struct.tm = type { i32 }
@fmt_past_time.time_fmts = internal global [4 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i32 0, i32 0), i8* null]
@.str = [4 x i8] c"%-r\00"
@.str.1 = [9 x i8] c"%-l:%M%p\00"
@.str.2 = [6 x i8] c"%-l%p\00"
@fmt_past_time.week_fmts = internal global [3 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i32 0, i32 0), i8* null]
@.str.3 = [3 x i8] c"%A\00"
@.str.4 = [3 x i8] c"%a\00"
@fmt_past_time.month_fmts = internal global [4 x i8*] [i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i32 0, i32 0), i8* null]
@.str.5 = [7 x i8] c"%A %-d\00"
@.str.6 = [7 x i8] c"%a %-d\00"
@.str.7 = [6 x i8] c"%a%-d\00"
@fmt_past_time.date_fmts = internal global [6 x i8*] [i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i32 0, i32 0), i8* null]
@.str.8 = [11 x i8] c"%A, %-d %B\00"
@.str.9 = [11 x i8] c"%a, %-d %b\00"
@.str.10 = [7 x i8] c"%-d %B\00"
@.str.11 = [7 x i8] c"%-d %b\00"
@.str.12 = [6 x i8] c"%-d%b\00"
@fmt_past_time.year_fmts = internal global [6 x i8*] [i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.14, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.15, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.16, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.17, i32 0, i32 0), i8* null]
@.str.13 = [14 x i8] c"%A, %-d %B %Y\00"
@.str.14 = [14 x i8] c"%a, %-d %b %Y\00"
@.str.15 = [14 x i8] c"%a, %-d %b %y\00"
@.str.16 = [10 x i8] c"%-d %b %y\00"
@.str.17 = [8 x i8] c"%-d%b%y\00"
@fmt_past_time.seps = internal global [4 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.18, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.19, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.20, i32 0, i32 0), i8* null]
@.str.18 = [3 x i8] c", \00"
@.str.19 = [2 x i8] c" \00"
@.str.20 = [1 x i8] zeroinitializer
define i64 @fmt_past_time(%struct.timeval* %0, %struct.timeval* %1, i64 %2, i8* %3, i64 %4) {
%6 = alloca %struct.timeval*
%7 = alloca %struct.timeval*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
%11 = alloca %struct.tm
%12 = alloca i32
%13 = alloca i64
%14 = alloca i8**
%15 = alloca i8**
%16 = alloca i8**
%17 = alloca i8**
%18 = alloca i8**
%19 = alloca i8*
%20 = alloca i64
%21 = alloca i8*
store %struct.timeval* %0, %struct.timeval** %6
store %struct.timeval* %1, %struct.timeval** %7
store i64 %2, i64* %8
store i8* %3, i8** %9
store i64 %4, i64* %10
store i32 0, i32* %12
%22 = load %struct.timeval*, %struct.timeval** %7
%23 = icmp ne %struct.timeval* %22, null
br i1 %23, label %24, label %32
24: ; preds = %5
%25 = load %struct.timeval*, %struct.timeval** %7
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %25, i32 0, i32 0
%27 = load i64, i64* %26
%28 = load %struct.timeval*, %struct.timeval** %6
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %28, i32 0, i32 0
%30 = load i64, i64* %29
%31 = sub nsw i64 %27, %30
br label %36
32: ; preds = %5
%33 = load %struct.timeval*, %struct.timeval** %6
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %33, i32 0, i32 0
%35 = load i64, i64* %34
br label %36
36: ; preds = %32, %24
%37 = phi i64 [ %31, %24 ], [ %35, %32 ]
store i64 %37, i64* %13
%38 = load i64, i64* %13
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = load i64, i64* %13
%42 = sub nsw i64 0, %41
store i64 %42, i64* %13
br label %43
43: ; preds = %40, %36
%44 = load %struct.timeval*, %struct.timeval** %6
%45 = getelementptr inbounds %struct.timeval, %struct.timeval* %44, i32 0, i32 0
%46 = bitcast i64* %45 to i32*
%47 = call i32 @localtime(i32* %46)
%48 = call i32 @bcopy(i32 %47, %struct.tm* %11, i32 4)
%49 = load i64, i64* %8
%50 = icmp ule i64 %49, 0
br i1 %50, label %55, label %51
51: ; preds = %43
%52 = load i64, i64* %8
%53 = load i64, i64* %10
%54 = icmp uge i64 %52, %53
br i1 %54, label %55, label %58
55: ; preds = %51, %43
%56 = load i64, i64* %10
%57 = sub i64 %56, 1
store i64 %57, i64* %8
br label %58
58: ; preds = %55, %51
%59 = load i64, i64* %13
%60 = icmp slt i64 %59, 86400
br i1 %60, label %61, label %93
61: ; preds = %58
store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @fmt_past_time.time_fmts, i64 0, i64 0), i8*** %14
br label %62
62: ; preds = %79, %61
%63 = load i8**, i8*** %14
%64 = load i8*, i8** %63
%65 = icmp ne i8* %64, null
br i1 %65, label %66, label %70
66: ; preds = %62
%67 = load i32, i32* %12
%68 = icmp ne i32 %67, 0
%69 = xor i1 %68, true
br label %70
70: ; preds = %66, %62
%71 = phi i1 [ false, %62 ], [ %69, %66 ]
br i1 %71, label %72, label %82
72: ; preds = %70
%73 = load i8*, i8** %9
%74 = load i64, i64* %8
%75 = add i64 %74, 1
%76 = load i8**, i8*** %14
%77 = load i8*, i8** %76
%78 = call i32 @strftime(i8* %73, i64 %75, i8* %77, %struct.tm* %11)
store i32 %78, i32* %12
br label %79
79: ; preds = %72
%80 = load i8**, i8*** %14
%81 = getelementptr inbounds i8*, i8** %80, i32 1
store i8** %81, i8*** %14
br label %62
82: ; preds = %70
%83 = load i32, i32* %12
%84 = icmp ne i32 %83, 0
br i1 %84, label %92, label %85
85: ; preds = %82
%86 = load i8*, i8** %9
%87 = load i64, i64* %10
%88 = load i8**, i8*** %14
%89 = getelementptr inbounds i8*, i8** %88, i64 -1
%90 = load i8*, i8** %89
%91 = call i32 @strftime(i8* %86, i64 %87, i8* %90, %struct.tm* %11)
store i32 %91, i32* %12
br label %92
92: ; preds = %85, %82
br label %222
93: ; preds = %58
%94 = load i64, i64* %13
%95 = icmp slt i64 %94, 604800
br i1 %95, label %96, label %97
96: ; preds = %93
store i8** getelementptr inbounds ([3 x i8*], [3 x i8*]* @fmt_past_time.week_fmts, i64 0, i64 0), i8*** %17
br label %108
97: ; preds = %93
%98 = load i64, i64* %13
%99 = icmp slt i64 %98, 2678400
br i1 %99, label %100, label %101
100: ; preds = %97
store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @fmt_past_time.month_fmts, i64 0, i64 0), i8*** %17
br label %107
101: ; preds = %97
%102 = load i64, i64* %13
%103 = icmp slt i64 %102, 31536000
br i1 %103, label %104, label %105
104: ; preds = %101
store i8** getelementptr inbounds ([6 x i8*], [6 x i8*]* @fmt_past_time.date_fmts, i64 0, i64 0), i8*** %17
br label %106
105: ; preds = %101
store i8** getelementptr inbounds ([6 x i8*], [6 x i8*]* @fmt_past_time.year_fmts, i64 0, i64 0), i8*** %17
br label %106
106: ; preds = %105, %104
br label %107
107: ; preds = %106, %100
br label %108
108: ; preds = %107, %96
store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @fmt_past_time.time_fmts, i64 0, i64 0), i8*** %15
br label %109
109: ; preds = %182, %108
%110 = load i8**, i8*** %15
%111 = load i8*, i8** %110
%112 = icmp ne i8* %111, null
br i1 %112, label %113, label %117
113: ; preds = %109
%114 = load i32, i32* %12
%115 = icmp ne i32 %114, 0
%116 = xor i1 %115, true
br label %117
117: ; preds = %113, %109
%118 = phi i1 [ false, %109 ], [ %116, %113 ]
br i1 %118, label %119, label %185
119: ; preds = %117
store i8** getelementptr inbounds ([4 x i8*], [4 x i8*]* @fmt_past_time.seps, i64 0, i64 0), i8*** %18
br label %120
120: ; preds = %178, %119
%121 = load i8**, i8*** %18
%122 = load i8*, i8** %121
%123 = icmp ne i8* %122, null
br i1 %123, label %124, label %128
124: ; preds = %120
%125 = load i32, i32* %12
%126 = icmp ne i32 %125, 0
%127 = xor i1 %126, true
br label %128
128: ; preds = %124, %120
%129 = phi i1 [ false, %120 ], [ %127, %124 ]
br i1 %129, label %130, label %181
130: ; preds = %128
%131 = load i8**, i8*** %17
store i8** %131, i8*** %16
br label %132
132: ; preds = %174, %130
%133 = load i8**, i8*** %16
%134 = load i8*, i8** %133
%135 = icmp ne i8* %134, null
br i1 %135, label %136, label %140
136: ; preds = %132
%137 = load i32, i32* %12
%138 = icmp ne i32 %137, 0
%139 = xor i1 %138, true
br label %140
140: ; preds = %136, %132
%141 = phi i1 [ false, %132 ], [ %139, %136 ]
br i1 %141, label %142, label %177
142: ; preds = %140
%143 = load i8**, i8*** %16
%144 = load i8*, i8** %143
%145 = call i64 @strlen(i8* %144)
%146 = load i8**, i8*** %18
%147 = load i8*, i8** %146
%148 = call i64 @strlen(i8* %147)
%149 = add nsw i64 %145, %148
%150 = load i8**, i8*** %15
%151 = load i8*, i8** %150
%152 = call i64 @strlen(i8* %151)
%153 = add nsw i64 %149, %152
%154 = add nsw i64 %153, 1
%155 = call i8* @llvm.stacksave()
store i8* %155, i8** %19
%156 = alloca i8, i64 %154
store i64 %154, i64* %20
store i8* %156, i8** %21
%157 = load i8*, i8** %21
%158 = load i8**, i8*** %16
%159 = load i8*, i8** %158
%160 = call i8* @stpcpy(i8* %157, i8* %159)
store i8* %160, i8** %21
%161 = load i8*, i8** %21
%162 = load i8**, i8*** %18
%163 = load i8*, i8** %162
%164 = call i8* @stpcpy(i8* %161, i8* %163)
store i8* %164, i8** %21
%165 = load i8*, i8** %21
%166 = load i8**, i8*** %15
%167 = load i8*, i8** %166
%168 = call i8* @stpcpy(i8* %165, i8* %167)
%169 = load i8*, i8** %9
%170 = load i64, i64* %8
%171 = add i64 %170, 1
%172 = call i32 @strftime(i8* %169, i64 %171, i8* %156, %struct.tm* %11)
store i32 %172, i32* %12
%173 = load i8*, i8** %19
br label %174
174: ; preds = %142
%175 = load i8**, i8*** %16
%176 = getelementptr inbounds i8*, i8** %175, i32 1
store i8** %176, i8*** %16
br label %132
177: ; preds = %140
br label %178
178: ; preds = %177
%179 = load i8**, i8*** %18
%180 = getelementptr inbounds i8*, i8** %179, i32 1
store i8** %180, i8*** %18
br label %120
181: ; preds = %128
br label %182
182: ; preds = %181
%183 = load i8**, i8*** %15
%184 = getelementptr inbounds i8*, i8** %183, i32 1
store i8** %184, i8*** %15
br label %109
185: ; preds = %117
%186 = load i32, i32* %12
%187 = icmp ne i32 %186, 0
br i1 %187, label %211, label %188
188: ; preds = %185
%189 = load i8**, i8*** %17
store i8** %189, i8*** %16
br label %190
190: ; preds = %207, %188
%191 = load i8**, i8*** %16
%192 = load i8*, i8** %191
%193 = icmp ne i8* %192, null
br i1 %193, label %194, label %198
194: ; preds = %190
%195 = load i32, i32* %12
%196 = icmp ne i32 %195, 0
%197 = xor i1 %196, true
br label %198
198: ; preds = %194, %190
%199 = phi i1 [ false, %190 ], [ %197, %194 ]
br i1 %199, label %200, label %210
200: ; preds = %198
%201 = load i8*, i8** %9
%202 = load i64, i64* %8
%203 = add i64 %202, 1
%204 = load i8**, i8*** %16
%205 = load i8*, i8** %204
%206 = call i32 @strftime(i8* %201, i64 %203, i8* %205, %struct.tm* %11)
store i32 %206, i32* %12
br label %207
207: ; preds = %200
%208 = load i8**, i8*** %16
%209 = getelementptr inbounds i8*, i8** %208, i32 1
store i8** %209, i8*** %16
br label %190
210: ; preds = %198
br label %211
211: ; preds = %210, %185
%212 = load i32, i32* %12
%213 = icmp ne i32 %212, 0
br i1 %213, label %221, label %214
214: ; preds = %211
%215 = load i8*, i8** %9
%216 = load i64, i64* %10
%217 = load i8**, i8*** %16
%218 = getelementptr inbounds i8*, i8** %217, i64 -1
%219 = load i8*, i8** %218
%220 = call i32 @strftime(i8* %215, i64 %216, i8* %219, %struct.tm* %11)
store i32 %220, i32* %12
br label %221
221: ; preds = %214, %211
br label %222
222: ; preds = %221, %92
%223 = load i32, i32* %12
%224 = sext i32 %223 to i64
ret i64 %224
}

LLVM IR (-O2):
%struct.timeval = type { i64 }
%struct.tm = type { i32 }
@fmt_past_time.time_fmts = internal unnamed_addr constant [4 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i32 0, i32 0), i8* null]
@.str = [4 x i8] c"%-r\00"
@.str.1 = [9 x i8] c"%-l:%M%p\00"
@.str.2 = [6 x i8] c"%-l%p\00"
@fmt_past_time.week_fmts = internal unnamed_addr constant [3 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i32 0, i32 0), i8* null]
@.str.3 = [3 x i8] c"%A\00"
@.str.4 = [3 x i8] c"%a\00"
@fmt_past_time.month_fmts = internal unnamed_addr constant [4 x i8*] [i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i32 0, i32 0), i8* null]
@.str.5 = [7 x i8] c"%A %-d\00"
@.str.6 = [7 x i8] c"%a %-d\00"
@.str.7 = [6 x i8] c"%a%-d\00"
@fmt_past_time.date_fmts = internal unnamed_addr constant [6 x i8*] [i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.12, i32 0, i32 0), i8* null]
@.str.8 = [11 x i8] c"%A, %-d %B\00"
@.str.9 = [11 x i8] c"%a, %-d %b\00"
@.str.10 = [7 x i8] c"%-d %B\00"
@.str.11 = [7 x i8] c"%-d %b\00"
@.str.12 = [6 x i8] c"%-d%b\00"
@fmt_past_time.year_fmts = internal unnamed_addr constant [6 x i8*] [i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.14, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.15, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.16, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.17, i32 0, i32 0), i8* null]
@.str.13 = [14 x i8] c"%A, %-d %B %Y\00"
@.str.14 = [14 x i8] c"%a, %-d %b %Y\00"
@.str.15 = [14 x i8] c"%a, %-d %b %y\00"
@.str.16 = [10 x i8] c"%-d %b %y\00"
@.str.17 = [8 x i8] c"%-d%b%y\00"
@fmt_past_time.seps = internal unnamed_addr constant [4 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.18, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.19, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.20, i32 0, i32 0), i8* null]
@.str.18 = [3 x i8] c", \00"
@.str.19 = [2 x i8] c" \00"
@.str.20 = [1 x i8] zeroinitializer
define i64 @fmt_past_time(%struct.timeval* %0, %struct.timeval* %1, i64 %2, i8* %3, i64 %4) {
%6 = alloca %struct.tm
%7 = bitcast %struct.tm* %6 to i8*
%8 = icmp eq %struct.timeval* %1, null
br i1 %8, label %15, label %9
9: ; preds = %5
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%11 = load i64, i64* %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%13 = load i64, i64* %12
%14 = sub nsw i64 %11, %13
br label %18
15: ; preds = %5
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%17 = load i64, i64* %16
br label %18
18: ; preds = %15, %9
%19 = phi i64 [ %14, %9 ], [ %17, %15 ]
%20 = tail call i64 @llvm.abs.i64(i64 %19, i1 true)
%21 = bitcast %struct.timeval* %0 to i32*
%22 = tail call i32 @localtime(i32* %21)
%23 = call i32 @bcopy(i32 %22, %struct.tm* %6, i32 4)
%24 = icmp ne i64 %2, 0
%25 = icmp ult i64 %2, %4
%26 = and i1 %24, %25
%27 = add i64 %4, -1
%28 = select i1 %26, i64 %2, i64 %27
%29 = icmp ult i64 %20, 86400
br i1 %29, label %30, label %42
30: ; preds = %18
%31 = add i64 %28, 1
br label %32
32: ; preds = %30, %32
%33 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %30 ], [ %37, %32 ]
%34 = phi i8** [ getelementptr inbounds ([4 x i8*], [4 x i8*]* @fmt_past_time.time_fmts, i64 0, i64 0), %30 ], [ %36, %32 ]
%35 = call i32 @strftime(i8* %3, i64 %31, i8* %33, %struct.tm* %6)
%36 = getelementptr inbounds i8*, i8** %34, i64 1
%37 = load i8*, i8** %36
%38 = icmp ne i8* %37, null
%39 = icmp eq i32 %35, 0
%40 = select i1 %38, i1 %39, i1 false
br i1 %40, label %32, label %41
41: ; preds = %32
br i1 %39, label %111, label %115
42: ; preds = %18
%43 = icmp ult i64 %20, 604800
br i1 %43, label %49, label %44
44: ; preds = %42
%45 = icmp ult i64 %20, 2678400
br i1 %45, label %49, label %46
46: ; preds = %44
%47 = icmp ult i64 %20, 31536000
%48 = select i1 %47, i8** getelementptr inbounds ([6 x i8*], [6 x i8*]* @fmt_past_time.date_fmts, i64 0, i64 0), i8** getelementptr inbounds ([6 x i8*], [6 x i8*]* @fmt_past_time.year_fmts, i64 0, i64 0)
br label %49
49: ; preds = %46, %44, %42
%50 = phi i8** [ getelementptr inbounds ([3 x i8*], [3 x i8*]* @fmt_past_time.week_fmts, i64 0, i64 0), %42 ], [ getelementptr inbounds ([4 x i8*], [4 x i8*]* @fmt_past_time.month_fmts, i64 0, i64 0), %44 ], [ %48, %46 ]
%51 = load i8*, i8** %50
%52 = icmp eq i8* %51, null
%53 = add i64 %28, 1
br label %54
54: ; preds = %49, %90
%55 = phi i8** [ getelementptr inbounds ([4 x i8*], [4 x i8*]* @fmt_past_time.time_fmts, i64 0, i64 0), %49 ], [ %91, %90 ]
br label %56
56: ; preds = %54, %83
%57 = phi i8** [ getelementptr inbounds ([4 x i8*], [4 x i8*]* @fmt_past_time.seps, i64 0, i64 0), %54 ], [ %85, %83 ]
br i1 %52, label %83, label %58
58: ; preds = %56, %58
%59 = phi i8* [ %79, %58 ], [ %51, %56 ]
%60 = phi i8** [ %78, %58 ], [ %50, %56 ]
%61 = call i64 @strlen(i8* %59)
%62 = load i8*, i8** %57
%63 = call i64 @strlen(i8* dereferenceable(1) %62)
%64 = load i8*, i8** %55
%65 = call i64 @strlen(i8* dereferenceable(1) %64)
%66 = add i64 %61, 1
%67 = add i64 %66, %63
%68 = add i64 %67, %65
%69 = call i8* @llvm.stacksave()
%70 = alloca i8, i64 %68
%71 = load i8*, i8** %60
%72 = call i8* @stpcpy(i8* %70, i8* %71)
%73 = load i8*, i8** %57
%74 = call i8* @stpcpy(i8* %72, i8* %73)
%75 = load i8*, i8** %55
%76 = call i8* @strcpy(i8* dereferenceable(1) %74, i8* dereferenceable(1) %75)
%77 = call i32 @strftime(i8* %3, i64 %53, i8* %70, %struct.tm* %6)
%78 = getelementptr inbounds i8*, i8** %60, i64 1
%79 = load i8*, i8** %78
%80 = icmp ne i8* %79, null
%81 = icmp eq i32 %77, 0
%82 = select i1 %80, i1 %81, i1 false
br i1 %82, label %58, label %83
83: ; preds = %58, %56
%84 = phi i32 [ 0, %56 ], [ %77, %58 ]
%85 = getelementptr inbounds i8*, i8** %57, i64 1
%86 = load i8*, i8** %85
%87 = icmp ne i8* %86, null
%88 = icmp eq i32 %84, 0
%89 = select i1 %87, i1 %88, i1 false
br i1 %89, label %56, label %90
90: ; preds = %83
%91 = getelementptr inbounds i8*, i8** %55, i64 1
%92 = load i8*, i8** %91
%93 = icmp ne i8* %92, null
%94 = select i1 %93, i1 %88, i1 false
br i1 %94, label %54, label %95
95: ; preds = %90
br i1 %88, label %96, label %115
96: ; preds = %95
br i1 %52, label %108, label %97
97: ; preds = %96, %97
%98 = phi i8* [ %102, %97 ], [ %51, %96 ]
%99 = phi i8** [ %101, %97 ], [ %50, %96 ]
%100 = call i32 @strftime(i8* %3, i64 %53, i8* %98, %struct.tm* %6)
%101 = getelementptr inbounds i8*, i8** %99, i64 1
%102 = load i8*, i8** %101
%103 = icmp ne i8* %102, null
%104 = icmp eq i32 %100, 0
%105 = select i1 %103, i1 %104, i1 false
br i1 %105, label %97, label %106
106: ; preds = %97
%107 = icmp eq i32 %100, 0
br i1 %107, label %108, label %115
108: ; preds = %96, %106
%109 = phi i8** [ %101, %106 ], [ %50, %96 ]
%110 = getelementptr inbounds i8*, i8** %109, i64 -1
br label %111
111: ; preds = %41, %108
%112 = phi i8** [ %110, %108 ], [ %34, %41 ]
%113 = load i8*, i8** %112
%114 = call i32 @strftime(i8* %3, i64 %4, i8* %113, %struct.tm* %6)
br label %115
115: ; preds = %111, %95, %106, %41
%116 = phi i32 [ %35, %41 ], [ %100, %106 ], [ %84, %95 ], [ %114, %111 ]
%117 = sext i32 %116 to i64
ret i64 %117
}