#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*/ snprintf(char *, unsigned int, char *, long, long, ...);
void format_seconds(char *buf, unsigned int n, long t) {
  if (t >= 24 * 60 * 60)
    snprintf(buf, n, "%ldd %ldh %ldm", t / 60 / 60 / 24, (t / 60 / 60) % 24,
             (t / 60) % 60);
  else if (t >= 60 * 60)
    snprintf(buf, n, "%ldh %ldm", (t / 60 / 60) % 24, (t / 60) % 60);
  else
    snprintf(buf, n, "%ldm %lds", t / 60, t % 60);
}


x86 assembly (clang, -O0):
<format_seconds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x15180,-0x18(%rbp)
jl     11b5 <format_seconds+0xa5>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rax
mov    $0x3c,%ecx
cqto
idiv   %rcx
mov    $0x3c,%ecx
cqto
idiv   %rcx
mov    $0x18,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    $0x3c,%r8d
cqto
idiv   %r8
mov    $0x3c,%r8d
cqto
idiv   %r8
mov    $0x18,%r8d
cqto
idiv   %r8
mov    %rdx,%r8
mov    -0x18(%rbp),%rax
mov    $0x3c,%r9d
cqto
idiv   %r9
mov    $0x3c,%r9d
cqto
idiv   %r9
mov    %rdx,%r9
lea    0xe57(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    125c <format_seconds+0x14c>
cmpq   $0xe10,-0x18(%rbp)
jl     121f <format_seconds+0x10f>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rax
mov    $0x3c,%ecx
cqto
idiv   %rcx
mov    $0x3c,%ecx
cqto
idiv   %rcx
mov    $0x18,%ecx
cqto
idiv   %rcx
mov    %rdx,%rcx
mov    -0x18(%rbp),%rax
mov    $0x3c,%r8d
cqto
idiv   %r8
mov    $0x3c,%r8d
cqto
idiv   %r8
mov    %rdx,%r8
lea    0xdf2(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    1257 <format_seconds+0x147>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rax
mov    $0x3c,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    $0x3c,%r8d
cqto
idiv   %r8
mov    %rdx,%r8
lea    0xdbf(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    125c <format_seconds+0x14c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_seconds>:
mov    %rdx,%r8
cmp    $0x15180,%rdx
jl     11a9 <format_seconds+0x99>
movabs $0x8888888888888889,%r11
88 88 88
mov    %r8,%rax
mul    %r11
mov    %rdx,%r9
mov    %r8,%rax
shr    $0x4,%rax
movabs $0x91a2b3c4d5e6f81,%rcx
2b 1a 09
mul    %rcx
mov    %rdx,%r10
shr    $0x5,%r9
movabs $0xc22e450672894ab7,%rcx
45 2e c2
mov    %r8,%rax
mul    %rcx
mov    %rdx,%rcx
shr    $0x3,%r10
movabs $0xaaaaaaaaaaaaaaab,%rdx
aa aa aa
mov    %r10,%rax
mul    %rdx
shr    $0x10,%rcx
shr    %rdx
and    $0xfffffffffffffff8,%rdx
lea    (%rdx,%rdx,2),%rax
sub    %rax,%r10
mov    %r9,%rax
mul    %r11
shr    $0x5,%rdx
imul   $0x3c,%rdx,%rax
sub    %rax,%r9
lea    0xe61(%rip),%rdx
mov    %r10,%r8
xor    %eax,%eax
jmp    1030 <snprintf@plt>
cmp    $0xe10,%r8
jl     1209 <format_seconds+0xf9>
mov    %r8d,%ecx
mov    $0x88888889,%eax
imul   %rcx,%rax
shr    $0x25,%rax
mov    $0x91a2b3c5,%edx
imul   %rcx,%rdx
shr    $0x2b,%rdx
movzbl %dl,%ecx
imul   $0xab,%ecx,%ecx
shr    $0x9,%ecx
and    $0xfffffff8,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %cl,%dl
movzbl %dl,%ecx
movzwl %ax,%edx
imul   $0x8889,%edx,%edx
shr    $0x15,%edx
imul   $0x3c,%edx,%edx
sub    %edx,%eax
movzwl %ax,%r8d
lea    0xe03(%rip),%rdx
xor    %eax,%eax
jmp    1030 <snprintf@plt>
movabs $0x8888888888888889,%rcx
88 88 88
mov    %r8,%rax
imul   %rcx
lea    (%rdx,%r8,1),%rcx
mov    %rcx,%rax
shr    $0x3f,%rax
sar    $0x5,%rcx
add    %rax,%rcx
imul   $0x3c,%rcx,%rax
sub    %rax,%r8
lea    0xdd6(%rip),%rdx
xor    %eax,%eax
jmp    1030 <snprintf@plt>

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

LLVM IR (-O2):
@.str = [15 x i8] c"%ldd %ldh %ldm\00"
@.str.1 = [10 x i8] c"%ldh %ldm\00"
@.str.2 = [10 x i8] c"%ldm %lds\00"
define void @format_seconds(i8* %0, i32 %1, i64 %2) {
%4 = icmp sgt i64 %2, 86399
br i1 %4, label %5, label %12
5: ; preds = %3
%6 = udiv i64 %2, 60
%7 = udiv i64 %2, 3600
%8 = udiv i64 %2, 86400
%9 = urem i64 %7, 24
%10 = urem i64 %6, 60
%11 = tail call i32 (i8*, i32, i8*, i64, i64, ...) @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i64 %8, i64 %9, i64 %10)
br label %29
12: ; preds = %3
%13 = icmp sgt i64 %2, 3599
br i1 %13, label %14, label %25
14: ; preds = %12
%15 = trunc i64 %2 to i32
%16 = udiv i32 %15, 60
%17 = udiv i32 %15, 3600
%18 = trunc i32 %17 to i8
%19 = urem i8 %18, 24
%20 = zext i8 %19 to i64
%21 = trunc i32 %16 to i16
%22 = urem i16 %21, 60
%23 = zext i16 %22 to i64
%24 = tail call i32 (i8*, i32, i8*, i64, i64, ...) @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64 %20, i64 %23)
br label %29
25: ; preds = %12
%26 = sdiv i64 %2, 60
%27 = srem i64 %2, 60
%28 = tail call i32 (i8*, i32, i8*, i64, i64, ...) @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i64 %26, i64 %27)
br label %29
29: ; preds = %14, %25, %5
ret void
}