#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 */

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, long, ...);
const char *FormatDuration(long seconds, char *buf) {
  if (seconds < (60 * 60)) {
    sprintf(buf, "%dm", seconds / 60);
  } else if (seconds < (24 * 60 * 60)) {
    sprintf(buf, "%dh%dm", seconds / (60 * 60), (seconds % (60 * 60)) / 60);
  } else if (seconds < (365 * 24 * 60 * 60)) {
    sprintf(buf, "%dd%dh", seconds / (24 * 60 * 60),
            (seconds % (24 * 60 * 60)) / (60 * 60));
  } else {
    sprintf(buf, "%dy%dd", seconds / (365 * 24 * 60 * 60),
            (seconds % (365 * 24 * 60 * 60)) / (24 * 60 * 60));
  }
  return buf;
}


x86 assembly (clang, -O0):
<FormatDuration>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0xe10,-0x8(%rbp)
jge    1156 <FormatDuration+0x46>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    $0x3c,%ecx
cqto
idiv   %rcx
mov    %rax,%rdx
lea    0xeb9(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1258 <FormatDuration+0x148>
cmpq   $0x15180,-0x8(%rbp)
jge    11af <FormatDuration+0x9f>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    $0xe10,%ecx
cqto
idiv   %rcx
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    $0xe10,%ecx
cqto
idiv   %rcx
mov    %rdx,%rax
mov    $0x3c,%ecx
cqto
idiv   %rcx
mov    -0x18(%rbp),%rdx
mov    %rax,%rcx
lea    0xe5d(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1253 <FormatDuration+0x143>
cmpq   $0x1e13380,-0x8(%rbp)
01
jge    1208 <FormatDuration+0xf8>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    $0x15180,%ecx
cqto
idiv   %rcx
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x15180,%ecx
cqto
idiv   %rcx
mov    %rdx,%rax
mov    $0xe10,%ecx
cqto
idiv   %rcx
mov    -0x20(%rbp),%rdx
mov    %rax,%rcx
lea    0xe0b(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    124e <FormatDuration+0x13e>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    $0x1e13380,%ecx
cqto
idiv   %rcx
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x1e13380,%ecx
cqto
idiv   %rcx
mov    %rdx,%rax
mov    $0x15180,%ecx
cqto
idiv   %rcx
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xdc7(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1253 <FormatDuration+0x143>
jmp    1258 <FormatDuration+0x148>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FormatDuration>:
push   %rbx
mov    %rsi,%rbx
cmp    $0xe0f,%rdi
jg     1154 <FormatDuration+0x44>
movabs $0x8888888888888889,%rcx
88 88 88
mov    %rdi,%rax
imul   %rcx
add    %rdi,%rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x5,%rdx
add    %rax,%rdx
lea    0xebe(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <sprintf@plt>
jmp    11fc <FormatDuration+0xec>
cmp    $0x1517f,%rdi
ja     1186 <FormatDuration+0x76>
mov    %edi,%eax
mov    $0x91a2b3c5,%edx
imul   %rax,%rdx
shr    $0x2b,%rdx
imul   $0xe10,%edx,%eax
sub    %eax,%edi
imul   $0x8889,%edi,%ecx
shr    $0x15,%ecx
lea    0xe7c(%rip),%rsi
jmp    11f2 <FormatDuration+0xe2>
cmp    $0x1e1337f,%rdi
ja     11bc <FormatDuration+0xac>
mov    %edi,%eax
mov    $0xc22e4507,%edx
imul   %rax,%rdx
shr    $0x30,%rdx
imul   $0x15180,%edx,%eax
sub    %eax,%edi
mov    $0x91a2b3c5,%ecx
imul   %rdi,%rcx
shr    $0x2b,%rcx
lea    0xe4d(%rip),%rsi
jmp    11f2 <FormatDuration+0xe2>
mov    %rdi,%rax
shr    $0x7,%rax
movabs $0x220c523d72c49c3,%rcx
c5 20 02
mul    %rcx
shr    $0xb,%rdx
imul   $0x1e13380,%rdx,%rax
sub    %rax,%rdi
mov    $0xc22e4507,%ecx
imul   %rdi,%rcx
shr    $0x30,%rcx
lea    0xe1c(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%dm\00"
@.str.1 = [7 x i8] c"%dh%dm\00"
@.str.2 = [7 x i8] c"%dd%dh\00"
@.str.3 = [7 x i8] c"%dy%dd\00"
define i8* @FormatDuration(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
store i64 %0, i64* %3
store i8* %1, i8** %4
%5 = load i64, i64* %3
%6 = icmp slt i64 %5, 3600
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load i8*, i8** %4
%9 = load i64, i64* %3
%10 = sdiv i64 %9, 60
%11 = call i32 (i8*, i8*, i64, ...) @sprintf(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %10)
br label %44
12: ; preds = %2
%13 = load i64, i64* %3
%14 = icmp slt i64 %13, 86400
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = load i8*, i8** %4
%17 = load i64, i64* %3
%18 = sdiv i64 %17, 3600
%19 = load i64, i64* %3
%20 = srem i64 %19, 3600
%21 = sdiv i64 %20, 60
%22 = call i32 (i8*, i8*, i64, ...) @sprintf(i8* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 %18, i64 %21)
br label %43
23: ; preds = %12
%24 = load i64, i64* %3
%25 = icmp slt i64 %24, 31536000
br i1 %25, label %26, label %34
26: ; preds = %23
%27 = load i8*, i8** %4
%28 = load i64, i64* %3
%29 = sdiv i64 %28, 86400
%30 = load i64, i64* %3
%31 = srem i64 %30, 86400
%32 = sdiv i64 %31, 3600
%33 = call i32 (i8*, i8*, i64, ...) @sprintf(i8* %27, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i64 %29, i64 %32)
br label %42
34: ; preds = %23
%35 = load i8*, i8** %4
%36 = load i64, i64* %3
%37 = sdiv i64 %36, 31536000
%38 = load i64, i64* %3
%39 = srem i64 %38, 31536000
%40 = sdiv i64 %39, 86400
%41 = call i32 (i8*, i8*, i64, ...) @sprintf(i8* %35, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i64 %37, i64 %40)
br label %42
42: ; preds = %34, %26
br label %43
43: ; preds = %42, %15
br label %44
44: ; preds = %43, %7
%45 = load i8*, i8** %4
ret i8* %45
}

LLVM IR (-O2):
@.str = [4 x i8] c"%dm\00"
@.str.1 = [7 x i8] c"%dh%dm\00"
@.str.2 = [7 x i8] c"%dd%dh\00"
@.str.3 = [7 x i8] c"%dy%dd\00"
define i8* @FormatDuration(i64 %0, i8* returned writeonly %1) {
%3 = icmp slt i64 %0, 3600
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = sdiv i64 %0, 60
%6 = tail call i32 (i8*, i8*, i64, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %5)
br label %35
7: ; preds = %2
%8 = icmp ult i64 %0, 86400
br i1 %8, label %9, label %18
9: ; preds = %7
%10 = trunc i64 %0 to i32
%11 = udiv i32 %10, 3600
%12 = zext i32 %11 to i64
%13 = urem i32 %10, 3600
%14 = trunc i32 %13 to i16
%15 = udiv i16 %14, 60
%16 = zext i16 %15 to i64
%17 = tail call i32 (i8*, i8*, i64, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 %12, i64 %16)
br label %35
18: ; preds = %7
%19 = icmp ult i64 %0, 31536000
br i1 %19, label %20, label %28
20: ; preds = %18
%21 = trunc i64 %0 to i32
%22 = udiv i32 %21, 86400
%23 = zext i32 %22 to i64
%24 = urem i32 %21, 86400
%25 = udiv i32 %24, 3600
%26 = zext i32 %25 to i64
%27 = tail call i32 (i8*, i8*, i64, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i64 %23, i64 %26)
br label %35
28: ; preds = %18
%29 = udiv i64 %0, 31536000
%30 = urem i64 %0, 31536000
%31 = trunc i64 %30 to i32
%32 = udiv i32 %31, 86400
%33 = zext i32 %32 to i64
%34 = tail call i32 (i8*, i8*, i64, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i64 %29, i64 %33)
br label %35
35: ; preds = %9, %28, %20, %4
ret i8* %1
}