char *seconds2string(unsigned long seconds) {
  int i;
  const unsigned long s = 1;
  const unsigned long m = 60 * s;
  const unsigned long h = 60 * m;
  const unsigned long d = 24 * h;
  const unsigned long w = 7 * d;
  const unsigned long y = 365 * d;
  const unsigned long coeff[6] = {y, w, d, h, m, s};
  const char units[6][7] = {"year", "week", "day", "hour", "minute", "second"};
  static char buffer[256];
  char *ptr = buffer;
  for (i = 0; i < 6; i++) {
    unsigned long value;
    value = seconds / coeff[i];
    seconds = seconds % coeff[i];
    if (value) {
      if (ptr != buffer)
        ptr += sprintf(ptr, ", ");
      ptr += sprintf(ptr, "%lu %s%s", value, units[i], (value > 1 ? "s" : ""));
    }
  }
  if (ptr == buffer)
    sprintf(ptr, "...");
  return buffer;
}


x86 assembly (clang, -O0):
<seconds2string>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x1,-0x18(%rbp)
movq   $0x3c,-0x20(%rbp)
movq   $0xe10,-0x28(%rbp)
movq   $0x15180,-0x30(%rbp)
movq   $0x93a80,-0x38(%rbp)
movq   $0x1e13380,-0x40(%rbp)
01
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1030 <memset@plt>
movq   $0x1e13380,-0x70(%rbp)
01
movq   $0x93a80,-0x68(%rbp)
movq   $0x15180,-0x60(%rbp)
movq   $0xe10,-0x58(%rbp)
movq   $0x3c,-0x50(%rbp)
movq   $0x1,-0x48(%rbp)
lea    -0xa0(%rbp),%rdi
lea    0xe43(%rip),%rsi
mov    $0x2a,%edx
call   1040 <memcpy@plt>
lea    0x2e82(%rip),%rax
mov    %rax,-0xa8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x6,-0xc(%rbp)
jge    12d0 <seconds2string+0x1a0>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
xor    %edx,%edx
divq   -0x70(%rbp,%rcx,8)
mov    %rax,-0xb0(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
xor    %edx,%edx
divq   -0x70(%rbp,%rcx,8)
mov    %rdx,-0x8(%rbp)
cmpq   $0x0,-0xb0(%rbp)
je     12bd <seconds2string+0x18d>
lea    0x2e2c(%rip),%rax
cmp    %rax,-0xa8(%rbp)
je     125c <seconds2string+0x12c>
mov    -0xa8(%rbp),%rdi
lea    0xdeb(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    %eax,%ecx
mov    -0xa8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0xa8(%rbp)
mov    -0xa8(%rbp),%rdi
mov    -0xb0(%rbp),%rdx
movslq -0xc(%rbp),%rax
lea    -0xa0(%rbp),%rcx
imul   $0x7,%rax,%rax
add    %rax,%rcx
mov    -0xb0(%rbp),%rsi
lea    0xda2(%rip),%r8
lea    0xda3(%rip),%rax
cmp    $0x1,%rsi
cmova  %rax,%r8
lea    0xd8d(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    %eax,%ecx
mov    -0xa8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0xa8(%rbp)
jmp    12c2 <seconds2string+0x192>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11dc <seconds2string+0xac>
lea    0x2d79(%rip),%rax
cmp    %rax,-0xa8(%rbp)
jne    12f9 <seconds2string+0x1c9>
mov    -0xa8(%rbp),%rdi
lea    0xd44(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
lea    0x2d50(%rip),%rax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<seconds2string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
movaps 0xedb(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xedf(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xee3(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movups 0xf01(%rip),%xmm0
movups %xmm0,0x1a(%rsp)
movaps 0xeeb(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xecf(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0x2ed4(%rip),%r13
mov    $0x1e13380,%esi
mov    %rsp,%r15
mov    $0x1,%ebp
lea    0xedd(%rip),%r14
mov    %r13,%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rdi,%rax
or     %rsi,%rax
shr    $0x20,%rax
je     11b0 <seconds2string+0xa0>
mov    %rdi,%rax
xor    %edx,%edx
div    %rsi
mov    %rdx,%r12
cmp    %rdi,%rsi
jbe    11be <seconds2string+0xae>
jmp    1205 <seconds2string+0xf5>
xchg   %ax,%ax
mov    %edi,%eax
xor    %edx,%edx
div    %esi
mov    %edx,%r12d
cmp    %rdi,%rsi
ja     1205 <seconds2string+0xf5>
mov    %r13,%rbx
cmp    %r13,%rcx
je     11d6 <seconds2string+0xc6>
movb   $0x0,0x2(%rcx)
movw   $0x202c,(%rcx)
add    $0x2,%rcx
mov    %rcx,%rbx
cmp    $0x2,%rax
lea    0xe7b(%rip),%r8
lea    0xe7c(%rip),%rcx
cmovae %rcx,%r8
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1030 <sprintf@plt>
movslq %eax,%rcx
add    %rbx,%rcx
cmp    $0x6,%rbp
je     1220 <seconds2string+0x110>
mov    0x30(%rsp,%rbp,8),%rsi
add    $0x7,%r15
add    $0x1,%rbp
mov    %r12,%rdi
jmp    1190 <seconds2string+0x80>
lea    0x2e19(%rip),%rax
cmp    %rax,%rcx
jne    1236 <seconds2string+0x126>
movl   $0x2e2e2e,0x2e0a(%rip)
lea    0x2e03(%rip),%rax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.seconds2string.units = [6 x [7 x i8]] [[7 x i8] c"year\00\00\00", [7 x i8] c"week\00\00\00", [7 x i8] c"day\00\00\00\00", [7 x i8] c"hour\00\00\00", [7 x i8] c"minute\00", [7 x i8] c"second\00"]
@seconds2string.buffer = internal global [256 x i8] zeroinitializer
@.str = [3 x i8] c", \00"
@.str.1 = [9 x i8] c"%lu %s%s\00"
@.str.2 = [2 x i8] c"s\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [4 x i8] c"...\00"
define i8* @seconds2string(i64 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca [6 x i64]
%11 = alloca [6 x [7 x i8]]
%12 = alloca i8*
%13 = alloca i64
store i64 %0, i64* %2
store i64 1, i64* %4
store i64 60, i64* %5
store i64 3600, i64* %6
store i64 86400, i64* %7
store i64 604800, i64* %8
store i64 31536000, i64* %9
%14 = bitcast [6 x i64]* %10 to i8*
%15 = bitcast i8* %14 to [6 x i64]*
%16 = getelementptr inbounds [6 x i64], [6 x i64]* %15, i32 0, i32 0
store i64 31536000, i64* %16
%17 = getelementptr inbounds [6 x i64], [6 x i64]* %15, i32 0, i32 1
store i64 604800, i64* %17
%18 = getelementptr inbounds [6 x i64], [6 x i64]* %15, i32 0, i32 2
store i64 86400, i64* %18
%19 = getelementptr inbounds [6 x i64], [6 x i64]* %15, i32 0, i32 3
store i64 3600, i64* %19
%20 = getelementptr inbounds [6 x i64], [6 x i64]* %15, i32 0, i32 4
store i64 60, i64* %20
%21 = getelementptr inbounds [6 x i64], [6 x i64]* %15, i32 0, i32 5
store i64 1, i64* %21
%22 = bitcast [6 x [7 x i8]]* %11 to i8*
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @seconds2string.buffer, i64 0, i64 0), i8** %12
store i32 0, i32* %3
br label %23
23: ; preds = %66, %1
%24 = load i32, i32* %3
%25 = icmp slt i32 %24, 6
br i1 %25, label %26, label %69
26: ; preds = %23
%27 = load i64, i64* %2
%28 = load i32, i32* %3
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [6 x i64], [6 x i64]* %10, i64 0, i64 %29
%31 = load i64, i64* %30
%32 = udiv i64 %27, %31
store i64 %32, i64* %13
%33 = load i64, i64* %2
%34 = load i32, i32* %3
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [6 x i64], [6 x i64]* %10, i64 0, i64 %35
%37 = load i64, i64* %36
%38 = urem i64 %33, %37
store i64 %38, i64* %2
%39 = load i64, i64* %13
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %65
41: ; preds = %26
%42 = load i8*, i8** %12
%43 = icmp ne i8* %42, getelementptr inbounds ([256 x i8], [256 x i8]* @seconds2string.buffer, i64 0, i64 0)
br i1 %43, label %44, label %50
44: ; preds = %41
%45 = load i8*, i8** %12
%46 = call i32 (i8*, i8*, ...) @sprintf(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%47 = load i8*, i8** %12
%48 = sext i32 %46 to i64
%49 = getelementptr inbounds i8, i8* %47, i64 %48
store i8* %49, i8** %12
br label %50
50: ; preds = %44, %41
%51 = load i8*, i8** %12
%52 = load i64, i64* %13
%53 = load i32, i32* %3
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [6 x [7 x i8]], [6 x [7 x i8]]* %11, i64 0, i64 %54
%56 = getelementptr inbounds [7 x i8], [7 x i8]* %55, i64 0, i64 0
%57 = load i64, i64* %13
%58 = icmp ugt i64 %57, 1
%59 = zext i1 %58 to i64
%60 = select i1 %58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0)
%61 = call i32 (i8*, i8*, ...) @sprintf(i8* %51, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i64 %52, i8* %56, i8* %60)
%62 = load i8*, i8** %12
%63 = sext i32 %61 to i64
%64 = getelementptr inbounds i8, i8* %62, i64 %63
store i8* %64, i8** %12
br label %65
65: ; preds = %50, %26
br label %66
66: ; preds = %65
%67 = load i32, i32* %3
%68 = add nsw i32 %67, 1
store i32 %68, i32* %3
br label %23
69: ; preds = %23
%70 = load i8*, i8** %12
%71 = icmp eq i8* %70, getelementptr inbounds ([256 x i8], [256 x i8]* @seconds2string.buffer, i64 0, i64 0)
br i1 %71, label %72, label %75
72: ; preds = %69
%73 = load i8*, i8** %12
%74 = call i32 (i8*, i8*, ...) @sprintf(i8* %73, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
br label %75
75: ; preds = %72, %69
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @seconds2string.buffer, i64 0, i64 0)
}

LLVM IR (-O2):
@__const.seconds2string.units = [6 x [7 x i8]] [[7 x i8] c"year\00\00\00", [7 x i8] c"week\00\00\00", [7 x i8] c"day\00\00\00\00", [7 x i8] c"hour\00\00\00", [7 x i8] c"minute\00", [7 x i8] c"second\00"]
@seconds2string.buffer = internal global [256 x i8] zeroinitializer
@.str = [3 x i8] c", \00"
@.str.1 = [9 x i8] c"%lu %s%s\00"
@.str.2 = [2 x i8] c"s\00"
@.str.3 = [1 x i8] zeroinitializer
define i8* @seconds2string(i64 %0) {
%2 = alloca [6 x i64]
%3 = alloca [6 x [7 x i8]]
%4 = bitcast [6 x i64]* %2 to i8*
%5 = bitcast [6 x i64]* %2 to <2 x i64>*
store <2 x i64> <i64 31536000, i64 604800>, <2 x i64>* %5
%6 = getelementptr inbounds [6 x i64], [6 x i64]* %2, i64 0, i64 2
%7 = bitcast i64* %6 to <2 x i64>*
store <2 x i64> <i64 86400, i64 3600>, <2 x i64>* %7
%8 = getelementptr inbounds [6 x i64], [6 x i64]* %2, i64 0, i64 4
%9 = bitcast i64* %8 to <2 x i64>*
store <2 x i64> <i64 60, i64 1>, <2 x i64>* %9
%10 = getelementptr inbounds [6 x [7 x i8]], [6 x [7 x i8]]* %3, i64 0, i64 0, i64 0
br label %11
11: ; preds = %35, %1
%12 = phi i64 [ 31536000, %1 ], [ %37, %35 ]
%13 = phi i64 [ 0, %1 ], [ %33, %35 ]
%14 = phi i64 [ %0, %1 ], [ %17, %35 ]
%15 = phi i8* [ getelementptr inbounds ([256 x i8], [256 x i8]* @seconds2string.buffer, i64 0, i64 0), %1 ], [ %32, %35 ]
%16 = udiv i64 %14, %12
%17 = urem i64 %14, %12
%18 = icmp ugt i64 %12, %14
br i1 %18, label %31, label %19
19: ; preds = %11
%20 = icmp eq i8* %15, getelementptr inbounds ([256 x i8], [256 x i8]* @seconds2string.buffer, i64 0, i64 0)
br i1 %20, label %23, label %21
21: ; preds = %19
%22 = getelementptr inbounds i8, i8* %15, i64 2
br label %23
23: ; preds = %21, %19
%24 = phi i8* [ %22, %21 ], [ getelementptr inbounds ([256 x i8], [256 x i8]* @seconds2string.buffer, i64 0, i64 0), %19 ]
%25 = getelementptr inbounds [6 x [7 x i8]], [6 x [7 x i8]]* %3, i64 0, i64 %13, i64 0
%26 = icmp ugt i64 %16, 1
%27 = select i1 %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0)
%28 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %24, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i64 %16, i8* %25, i8* %27)
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %24, i64 %29
br label %31
31: ; preds = %23, %11
%32 = phi i8* [ %30, %23 ], [ %15, %11 ]
%33 = add nuw nsw i64 %13, 1
%34 = icmp eq i64 %33, 6
br i1 %34, label %38, label %35
35: ; preds = %31
%36 = getelementptr inbounds [6 x i64], [6 x i64]* %2, i64 0, i64 %33
%37 = load i64, i64* %36
br label %11
38: ; preds = %31
%39 = icmp eq i8* %32, getelementptr inbounds ([256 x i8], [256 x i8]* @seconds2string.buffer, i64 0, i64 0)
br i1 %39, label %40, label %41
40: ; preds = %38
store i32 3026478, i32* bitcast ([256 x i8]* @seconds2string.buffer to i32*)
br label %41
41: ; preds = %40, %38
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @seconds2string.buffer, i64 0, i64 0)
}