#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*/ value;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *, long,
                            char const *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
const char *timestr_long(long dtime) {
  static char buf[100], value[100];
  const char *str[7] = {"year", "month",  "week",  "day",
                        "hour", "minute", "second"};
  int div[7] = {31556736, 2621376, 604800, 86400, 3600, 60, 1};
  *buf = *value = 0;
  for (int i = 0; i < 7; i++) {
    if (dtime >= div[i]) {
      long temp = dtime / div[i];
      snprintf(value, sizeof(value), "%s%s%ld %s%s", buf, (*buf ? ", " : ""),
               temp, str[i], temp != 1 ? "s" : "");
      strncpy(buf, value, sizeof(buf));
      dtime %= div[i];
    }
  }
  return buf;
}


x86 assembly (clang, -O0):
<timestr_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x40(%rbp),%rdi
lea    0x2c96(%rip),%rsi
mov    $0x38,%edx
call   1050 <memcpy@plt>
mov    0xee5(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0xee2(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    0xedf(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xedd(%rip),%eax
mov    %eax,-0x48(%rbp)
movb   $0x0,0x2f3b(%rip)
movb   $0x0,0x2ec4(%rip)
movl   $0x0,-0x64(%rbp)
cmpl   $0x7,-0x64(%rbp)
jge    1275 <timestr_long+0x145>
mov    -0x8(%rbp),%rax
movslq -0x64(%rbp),%rcx
movslq -0x60(%rbp,%rcx,4),%rcx
cmp    %rcx,%rax
jl     1262 <timestr_long+0x132>
mov    -0x8(%rbp),%rax
movslq -0x64(%rbp),%rcx
movslq -0x60(%rbp,%rcx,4),%rcx
cqto
idiv   %rcx
mov    %rax,-0x70(%rbp)
movsbl 0x2e80(%rip),%ecx
lea    0xe5f(%rip),%r8
lea    0xe56(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%r8
mov    -0x70(%rbp),%r9
movslq -0x64(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%r10
mov    -0x70(%rbp),%rdx
lea    0xe39(%rip),%rax
lea    0xe2e(%rip),%rcx
cmp    $0x1,%rdx
cmovne %rcx,%rax
lea    0x2ead(%rip),%rdi
mov    $0x64,%esi
lea    0xe08(%rip),%rdx
lea    0x2e2a(%rip),%rcx
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1040 <snprintf@plt>
lea    0x2e15(%rip),%rdi
lea    0x2e7e(%rip),%rsi
mov    $0x64,%edx
call   1030 <strncpy@plt>
movslq -0x64(%rbp),%rax
movslq -0x60(%rbp,%rax,4),%rcx
mov    -0x8(%rbp),%rax
cqto
idiv   %rcx
mov    %rdx,-0x8(%rbp)
jmp    1267 <timestr_long+0x137>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1193 <timestr_long+0x63>
lea    0x2dd4(%rip),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timestr_long>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
movb   $0x0,0x2f7b(%rip)
movb   $0x0,0x2f04(%rip)
xor    %ebx,%ebx
lea    0xf1b(%rip),%rax
lea    0x2ef4(%rip),%r14
lea    0xeed(%rip),%r12
lea    0x2f56(%rip),%r15
jmp    11db <timestr_long+0xbb>
nopl   0x0(%rax)
mov    %r13,%rax
cqto
idiv   %rcx
mov    %rax,%r9
mov    %rdx,%r13
cmpb   $0x0,0x2ecb(%rip)
lea    0xeb8(%rip),%r8
lea    0xeb3(%rip),%rcx
cmove  %rcx,%r8
movslq (%rbx,%r12,1),%rax
add    %r12,%rax
cmp    $0x1,%r9
lea    0xe99(%rip),%rbp
cmove  %rcx,%rbp
mov    %r15,%rdi
mov    $0x64,%esi
lea    0xe7b(%rip),%rdx
mov    %r14,%rcx
push   %rbp
push   %rax
call   1040 <snprintf@plt>
add    $0x10,%rsp
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x64,%edx
call   1030 <strncpy@plt>
lea    0xe8f(%rip),%rax
add    $0x4,%rbx
cmp    $0x1c,%rbx
je     1206 <timestr_long+0xe6>
movslq (%rbx,%rax,1),%rcx
cmp    %rcx,%r13
jl     11d1 <timestr_long+0xb1>
mov    %r13,%rax
or     %rcx,%rax
shr    $0x20,%rax
jne    1160 <timestr_long+0x40>
mov    %r13d,%eax
xor    %edx,%edx
div    %ecx
mov    %eax,%r9d
mov    %edx,%r13d
jmp    116e <timestr_long+0x4e>
lea    0x2e33(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@timestr_long.buf = internal global [100 x i8] zeroinitializer
@timestr_long.value = internal global [100 x i8] zeroinitializer
@.str = [5 x i8] c"year\00"
@.str.1 = [6 x i8] c"month\00"
@.str.2 = [5 x i8] c"week\00"
@.str.3 = [4 x i8] c"day\00"
@.str.4 = [5 x i8] c"hour\00"
@.str.5 = [7 x i8] c"minute\00"
@.str.6 = [7 x i8] c"second\00"
@__const.timestr_long.str = [7 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i32 0, i32 0), 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)]
@__const.timestr_long.div = [7 x i32] [i32 31556736, i32 2621376, i32 604800, i32 86400, i32 3600, i32 60, i32 1]
@.str.7 = [13 x i8] c"%s%s%ld %s%s\00"
@.str.8 = [3 x i8] c", \00"
@.str.9 = [1 x i8] zeroinitializer
@.str.10 = [2 x i8] c"s\00"
define i8* @timestr_long(i64 %0) {
%2 = alloca i64
%3 = alloca [7 x i8*]
%4 = alloca [7 x i32]
%5 = alloca i32
%6 = alloca i64
store i64 %0, i64* %2
%7 = bitcast [7 x i8*]* %3 to i8*
%8 = bitcast [7 x i32]* %4 to i8*
store i8 0, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @timestr_long.value, i64 0, i64 0)
store i8 0, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @timestr_long.buf, i64 0, i64 0)
store i32 0, i32* %5
br label %9
9: ; preds = %52, %1
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 7
br i1 %11, label %12, label %55
12: ; preds = %9
%13 = load i64, i64* %2
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [7 x i32], [7 x i32]* %4, i64 0, i64 %15
%17 = load i32, i32* %16
%18 = sext i32 %17 to i64
%19 = icmp sge i64 %13, %18
br i1 %19, label %20, label %51
20: ; preds = %12
%21 = load i64, i64* %2
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [7 x i32], [7 x i32]* %4, i64 0, i64 %23
%25 = load i32, i32* %24
%26 = sext i32 %25 to i64
%27 = sdiv i64 %21, %26
store i64 %27, i64* %6
%28 = load i8, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @timestr_long.buf, i64 0, i64 0)
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 0
%31 = zext i1 %30 to i64
%32 = select i1 %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.9, i64 0, i64 0)
%33 = load i64, i64* %6
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [7 x i8*], [7 x i8*]* %3, i64 0, i64 %35
%37 = load i8*, i8** %36
%38 = load i64, i64* %6
%39 = icmp ne i64 %38, 1
%40 = zext i1 %39 to i64
%41 = select i1 %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.9, i64 0, i64 0)
%42 = call i32 @snprintf(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @timestr_long.value, i64 0, i64 0), i32 100, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([100 x i8], [100 x i8]* @timestr_long.buf, i64 0, i64 0), i8* %32, i64 %33, i8* %37, i8* %41)
%43 = call i32 @strncpy(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @timestr_long.buf, i64 0, i64 0), i8* getelementptr inbounds ([100 x i8], [100 x i8]* @timestr_long.value, i64 0, i64 0), i32 100)
%44 = load i32, i32* %5
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [7 x i32], [7 x i32]* %4, i64 0, i64 %45
%47 = load i32, i32* %46
%48 = sext i32 %47 to i64
%49 = load i64, i64* %2
%50 = srem i64 %49, %48
store i64 %50, i64* %2
br label %51
51: ; preds = %20, %12
br label %52
52: ; preds = %51
%53 = load i32, i32* %5
%54 = add nsw i32 %53, 1
store i32 %54, i32* %5
br label %9
55: ; preds = %9
ret i8* getelementptr inbounds ([100 x i8], [100 x i8]* @timestr_long.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@timestr_long.buf = internal global [100 x i8] zeroinitializer
@timestr_long.value = internal global [100 x i8] zeroinitializer
@.str = [5 x i8] c"year\00"
@.str.1 = [6 x i8] c"month\00"
@.str.2 = [5 x i8] c"week\00"
@.str.3 = [4 x i8] c"day\00"
@.str.4 = [5 x i8] c"hour\00"
@.str.5 = [7 x i8] c"minute\00"
@.str.6 = [7 x i8] c"second\00"
@reltable.timestr_long = [7 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str to i64), i64 ptrtoint ([7 x i32]* @reltable.timestr_long to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.1 to i64), i64 ptrtoint ([7 x i32]* @reltable.timestr_long to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.2 to i64), i64 ptrtoint ([7 x i32]* @reltable.timestr_long to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.3 to i64), i64 ptrtoint ([7 x i32]* @reltable.timestr_long to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.4 to i64), i64 ptrtoint ([7 x i32]* @reltable.timestr_long to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.5 to i64), i64 ptrtoint ([7 x i32]* @reltable.timestr_long to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.6 to i64), i64 ptrtoint ([7 x i32]* @reltable.timestr_long to i64)) to i32)]
@__const.timestr_long.div = [7 x i32] [i32 31556736, i32 2621376, i32 604800, i32 86400, i32 3600, i32 60, i32 1]
@.str.7 = [13 x i8] c"%s%s%ld %s%s\00"
@.str.8 = [3 x i8] c", \00"
@.str.9 = [1 x i8] zeroinitializer
@.str.10 = [2 x i8] c"s\00"
define i8* @timestr_long(i64 %0) {
store i8 0, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @timestr_long.value, i64 0, i64 0)
store i8 0, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @timestr_long.buf, i64 0, i64 0)
br label %3
2: ; preds = %22
ret i8* getelementptr inbounds ([100 x i8], [100 x i8]* @timestr_long.buf, i64 0, i64 0)
3: ; preds = %1, %22
%4 = phi i64 [ 0, %1 ], [ %24, %22 ]
%5 = phi i64 [ %0, %1 ], [ %23, %22 ]
%6 = getelementptr inbounds [7 x i32], [7 x i32]* @__const.timestr_long.div, i64 0, i64 %4
%7 = load i32, i32* %6
%8 = sext i32 %7 to i64
%9 = icmp slt i64 %5, %8
br i1 %9, label %22, label %10
10: ; preds = %3
%11 = sdiv i64 %5, %8
%12 = load i8, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @timestr_long.buf, i64 0, i64 0)
%13 = icmp eq i8 %12, 0
%14 = select i1 %13, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0)
%15 = shl i64 %4, 2
%16 = call i8* @llvm.load.relative.i64(i8* bitcast ([7 x i32]* @reltable.timestr_long to i8*), i64 %15)
%17 = icmp eq i64 %11, 1
%18 = select i1 %17, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0)
%19 = tail call i32 @snprintf(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @timestr_long.value, i64 0, i64 0), i32 100, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([100 x i8], [100 x i8]* @timestr_long.buf, i64 0, i64 0), i8* %14, i64 %11, i8* %16, i8* %18)
%20 = tail call i32 @strncpy(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @timestr_long.buf, i64 0, i64 0), i8* getelementptr inbounds ([100 x i8], [100 x i8]* @timestr_long.value, i64 0, i64 0), i32 100)
%21 = srem i64 %5, %8
br label %22
22: ; preds = %3, %10
%23 = phi i64 [ %21, %10 ], [ %5, %3 ]
%24 = add nuw nsw i64 %4, 1
%25 = icmp eq i64 %24, 7
br i1 %25, label %2, label %3
}