#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, char *, ...);
void seconds_to_hms(long int time_in_seconds, char *time) {
  long hr, min, t;
  hr = time_in_seconds / 3600;
  t = time_in_seconds % 3600;
  min = t / 60;
  time_in_seconds = t % 60;
  if (hr > 0)
    sprintf(time, "%ld%s:%ld%s:%ld%s", hr, (hr > 1) ? "hrs" : "hr", min,
            (min > 1) ? "mins" : "min", time_in_seconds,
            (time_in_seconds > 1) ? "secs" : "sec");
  else if (min > 0)
    sprintf(time, "%ld%s:%ld%s", min, (min > 1) ? "mins" : "min",
            time_in_seconds, (time_in_seconds > 1) ? "secs" : "sec");
  else
    sprintf(time, "%ld%s", time_in_seconds,
            (time_in_seconds > 1) ? "secs" : "sec");
}


x86 assembly (clang, -O0):
<seconds_to_hms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
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,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    $0x3c,%ecx
cqto
idiv   %rcx
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    $0x3c,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x8(%rbp)
cmpq   $0x0,-0x18(%rbp)
jle    11ed <seconds_to_hms+0xdd>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x18(%rbp),%rsi
lea    0xe90(%rip),%rcx
lea    0xe85(%rip),%rax
cmp    $0x1,%rsi
cmovg  %rax,%rcx
mov    -0x20(%rbp),%r8
mov    -0x20(%rbp),%rsi
lea    0xe7a(%rip),%r9
lea    0xe6e(%rip),%rax
cmp    $0x1,%rsi
cmovg  %rax,%r9
mov    -0x8(%rbp),%r10
mov    -0x8(%rbp),%r11
lea    0xe65(%rip),%rax
lea    0xe59(%rip),%rsi
cmp    $0x1,%r11
cmovg  %rsi,%rax
lea    0xe28(%rip),%rsi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1280 <seconds_to_hms+0x170>
cmpq   $0x0,-0x20(%rbp)
jle    124b <seconds_to_hms+0x13b>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x20(%rbp),%rsi
lea    0xe13(%rip),%rcx
lea    0xe07(%rip),%rax
cmp    $0x1,%rsi
cmovg  %rax,%rcx
mov    -0x8(%rbp),%r8
mov    -0x8(%rbp),%rsi
lea    0xdfe(%rip),%r9
lea    0xdf2(%rip),%rax
cmp    $0x1,%rsi
cmovg  %rax,%r9
lea    0xdc7(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    127b <seconds_to_hms+0x16b>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x8(%rbp),%rsi
lea    0xdc9(%rip),%rcx
lea    0xdbd(%rip),%rax
cmp    $0x1,%rsi
cmovg  %rax,%rcx
lea    0xd98(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1280 <seconds_to_hms+0x170>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<seconds_to_hms>:
mov    %rdi,%rcx
movabs $0x48d159e26af37c05,%rdx
59 d1 48
mov    %rdi,%rax
imul   %rdx
mov    %rsi,%rdi
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0xa,%rdx
add    %rax,%rdx
imul   $0xe10,%rdx,%rax
mov    %rcx,%rsi
sub    %rax,%rsi
movswl %si,%eax
imul   $0xffff8889,%eax,%eax
shr    $0x10,%eax
add    %esi,%eax
movzwl %ax,%eax
movswl %ax,%edx
shr    $0xf,%eax
sar    $0x5,%edx
add    %eax,%edx
movswq %dx,%r8
imul   $0x3c,%edx,%eax
mov    %esi,%edx
sub    %eax,%edx
movswq %dx,%r10
cmp    $0xe10,%rcx
jl     11ec <seconds_to_hms+0xdc>
push   %rax
mov    %rcx,%rax
shr    $0x4,%rax
movabs $0x91a2b3c4d5e6f81,%rdx
2b 1a 09
mul    %rdx
shr    $0x3,%rdx
cmp    $0x1c20,%rcx
lea    0xe76(%rip),%rax
lea    0xe73(%rip),%rcx
cmovae %rax,%rcx
cmp    $0x78,%rsi
lea    0xe67(%rip),%rax
lea    0xe65(%rip),%r9
cmovge %rax,%r9
cmp    $0x2,%r10w
lea    0xe59(%rip),%rax
lea    0xe57(%rip),%r11
cmovge %rax,%r11
lea    0xe25(%rip),%rsi
xor    %eax,%eax
push   %r11
push   %r10
call   1030 <sprintf@plt>
add    $0x10,%rsp
pop    %rax
ret
cmp    $0x3c,%rsi
jl     1233 <seconds_to_hms+0x123>
cmp    $0x78,%rsi
lea    0xe1c(%rip),%rax
lea    0xe1a(%rip),%rcx
cmovae %rax,%rcx
cmp    $0x2,%r10w
lea    0xe0e(%rip),%rax
lea    0xe0c(%rip),%r9
cmovge %rax,%r9
lea    0xde0(%rip),%rsi
mov    %r8,%rdx
mov    %r10,%r8
xor    %eax,%eax
jmp    1030 <sprintf@plt>
cmp    $0x2,%r10w
lea    0xde3(%rip),%rax
lea    0xde1(%rip),%rcx
cmovge %rax,%rcx
lea    0xdbb(%rip),%rsi
mov    %r10,%rdx
xor    %eax,%eax
jmp    1030 <sprintf@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"%ld%s:%ld%s:%ld%s\00"
@.str.1 = [4 x i8] c"hrs\00"
@.str.2 = [3 x i8] c"hr\00"
@.str.3 = [5 x i8] c"mins\00"
@.str.4 = [4 x i8] c"min\00"
@.str.5 = [5 x i8] c"secs\00"
@.str.6 = [4 x i8] c"sec\00"
@.str.7 = [12 x i8] c"%ld%s:%ld%s\00"
@.str.8 = [6 x i8] c"%ld%s\00"
define void @seconds_to_hms(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i64 %0, i64* %3
store i8* %1, i8** %4
%8 = load i64, i64* %3
%9 = sdiv i64 %8, 3600
store i64 %9, i64* %5
%10 = load i64, i64* %3
%11 = srem i64 %10, 3600
store i64 %11, i64* %7
%12 = load i64, i64* %7
%13 = sdiv i64 %12, 60
store i64 %13, i64* %6
%14 = load i64, i64* %7
%15 = srem i64 %14, 60
store i64 %15, i64* %3
%16 = load i64, i64* %5
%17 = icmp sgt i64 %16, 0
br i1 %17, label %18, label %36
18: ; preds = %2
%19 = load i8*, i8** %4
%20 = load i64, i64* %5
%21 = load i64, i64* %5
%22 = icmp sgt i64 %21, 1
%23 = zext i1 %22 to i64
%24 = select i1 %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
%25 = load i64, i64* %6
%26 = load i64, i64* %6
%27 = icmp sgt i64 %26, 1
%28 = zext i1 %27 to i64
%29 = select i1 %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0)
%30 = load i64, i64* %3
%31 = load i64, i64* %3
%32 = icmp sgt i64 %31, 1
%33 = zext i1 %32 to i64
%34 = select i1 %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0)
%35 = call i32 (i8*, i8*, i64, i8*, ...) @sprintf(i8* %19, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i64 %20, i8* %24, i64 %25, i8* %29, i64 %30, i8* %34)
br label %61
36: ; preds = %2
%37 = load i64, i64* %6
%38 = icmp sgt i64 %37, 0
br i1 %38, label %39, label %52
39: ; preds = %36
%40 = load i8*, i8** %4
%41 = load i64, i64* %6
%42 = load i64, i64* %6
%43 = icmp sgt i64 %42, 1
%44 = zext i1 %43 to i64
%45 = select i1 %43, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0)
%46 = load i64, i64* %3
%47 = load i64, i64* %3
%48 = icmp sgt i64 %47, 1
%49 = zext i1 %48 to i64
%50 = select i1 %48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0)
%51 = call i32 (i8*, i8*, i64, i8*, ...) @sprintf(i8* %40, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i64 %41, i8* %45, i64 %46, i8* %50)
br label %60
52: ; preds = %36
%53 = load i8*, i8** %4
%54 = load i64, i64* %3
%55 = load i64, i64* %3
%56 = icmp sgt i64 %55, 1
%57 = zext i1 %56 to i64
%58 = select i1 %56, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0)
%59 = call i32 (i8*, i8*, i64, i8*, ...) @sprintf(i8* %53, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i64 %54, i8* %58)
br label %60
60: ; preds = %52, %39
br label %61
61: ; preds = %60, %18
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"%ld%s:%ld%s:%ld%s\00"
@.str.1 = [4 x i8] c"hrs\00"
@.str.2 = [3 x i8] c"hr\00"
@.str.3 = [5 x i8] c"mins\00"
@.str.4 = [4 x i8] c"min\00"
@.str.5 = [5 x i8] c"secs\00"
@.str.6 = [4 x i8] c"sec\00"
@.str.7 = [12 x i8] c"%ld%s:%ld%s\00"
@.str.8 = [6 x i8] c"%ld%s\00"
define void @seconds_to_hms(i64 %0, i8* nocapture writeonly %1) {
%3 = srem i64 %0, 3600
%4 = trunc i64 %3 to i16
%5 = sdiv i16 %4, 60
%6 = sext i16 %5 to i64
%7 = srem i16 %4, 60
%8 = sext i16 %7 to i64
%9 = icmp sgt i64 %0, 3599
br i1 %9, label %10, label %19
10: ; preds = %2
%11 = udiv i64 %0, 3600
%12 = icmp ugt i64 %0, 7199
%13 = select i1 %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
%14 = icmp sgt i64 %3, 119
%15 = select i1 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0)
%16 = icmp sgt i16 %7, 1
%17 = select i1 %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0)
%18 = tail call i32 (i8*, i8*, i64, i8*, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i64 %11, i8* %13, i64 %6, i8* %15, i64 %8, i8* %17)
br label %31
19: ; preds = %2
%20 = icmp sgt i64 %3, 59
br i1 %20, label %21, label %27
21: ; preds = %19
%22 = icmp ugt i64 %3, 119
%23 = select i1 %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0)
%24 = icmp sgt i16 %7, 1
%25 = select i1 %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0)
%26 = tail call i32 (i8*, i8*, i64, i8*, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i64 %6, i8* %23, i64 %8, i8* %25)
br label %31
27: ; preds = %19
%28 = icmp sgt i16 %7, 1
%29 = select i1 %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0)
%30 = tail call i32 (i8*, i8*, i64, i8*, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i64 %8, i8* %29)
br label %31
31: ; preds = %21, %27, %10
ret void
}