#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 */
char *print_decimal(double);
int /*<<< orphan*/ sprintf(char *, char *, ...);
char *secs_to_human_time(double interval) {
  static char buf[32];
  int secs = (int)(interval + 0.5);
  int hours, mins, days;
  days = secs / 86400, secs %= 86400;
  hours = secs / 3600, secs %= 3600;
  mins = secs / 60, secs %= 60;
  if (days)
    sprintf(buf, "%dd %dh %dm %ds", days, hours, mins, secs);
  else if (hours)
    sprintf(buf, "%dh %dm %ds", hours, mins, secs);
  else if (mins)
    sprintf(buf, "%dm %ds", mins, secs);
  else
    sprintf(buf, "%ss", print_decimal(interval));
  return buf;
}


x86 assembly (clang, -O0):
<secs_to_human_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  0xecb(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x15180,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x15180,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11c7 <secs_to_human_time+0xa7>
mov    -0x18(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%r8d
mov    -0xc(%rbp),%r9d
lea    0x2e8c(%rip),%rdi
lea    0xe4d(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    124b <secs_to_human_time+0x12b>
cmpl   $0x0,-0x10(%rbp)
je     11f5 <secs_to_human_time+0xd5>
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0xc(%rbp),%r8d
lea    0x2e5e(%rip),%rdi
lea    0xe23(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    1246 <secs_to_human_time+0x126>
cmpl   $0x0,-0x14(%rbp)
je     121f <secs_to_human_time+0xff>
mov    -0x14(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0x2e34(%rip),%rdi
lea    0xdfd(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    1241 <secs_to_human_time+0x121>
movsd  -0x8(%rbp),%xmm0
call   1030 <print_decimal@plt>
mov    %rax,%rdx
lea    0x2e0d(%rip),%rdi
lea    0xdde(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    1246 <secs_to_human_time+0x126>
jmp    124b <secs_to_human_time+0x12b>
lea    0x2dee(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<secs_to_human_time>:
push   %rax
movsd  0xed7(%rip),%xmm1
addsd  %xmm0,%xmm1
cvttsd2si %xmm1,%eax
movslq %eax,%r10
imul   $0xffffffffc22e4507,%r10,%rdx
shr    $0x20,%rdx
add    %r10d,%edx
mov    %edx,%ecx
shr    $0x1f,%ecx
sar    $0x10,%edx
add    %ecx,%edx
imul   $0x15180,%edx,%ecx
mov    %r10d,%r11d
sub    %ecx,%r11d
movslq %r11d,%rsi
imul   $0xffffffff91a2b3c5,%rsi,%rcx
shr    $0x20,%rcx
add    %r11d,%ecx
mov    %ecx,%eax
shr    $0x1f,%eax
sar    $0xb,%ecx
add    %eax,%ecx
imul   $0xe10,%ecx,%eax
sub    %eax,%esi
movswl %si,%eax
imul   $0xffff8889,%eax,%eax
shr    $0x10,%eax
add    %esi,%eax
movzwl %ax,%eax
movswl %ax,%edi
shr    $0xf,%eax
sar    $0x5,%edi
add    %eax,%edi
movswl %di,%r8d
imul   $0x3c,%edi,%eax
mov    %esi,%edi
sub    %eax,%edi
movswl %di,%r9d
add    $0x1517f,%r10d
cmp    $0x2a2ff,%r10d
jae    11ed <secs_to_human_time+0xcd>
add    $0xe0f,%r11d
cmp    $0x1c1f,%r11d
jae    1204 <secs_to_human_time+0xe4>
add    $0x3b,%esi
cmp    $0x77,%esi
jae    1223 <secs_to_human_time+0x103>
call   1030 <print_decimal@plt>
lea    0x2e66(%rip),%rdi
lea    0xe37(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <sprintf@plt>
jmp    123e <secs_to_human_time+0x11e>
lea    0x2e4c(%rip),%rdi
lea    0xe0d(%rip),%rsi
xor    %eax,%eax
call   1040 <sprintf@plt>
jmp    123e <secs_to_human_time+0x11e>
lea    0x2e35(%rip),%rdi
lea    0xdfa(%rip),%rsi
mov    %ecx,%edx
mov    %r8d,%ecx
mov    %r9d,%r8d
xor    %eax,%eax
call   1040 <sprintf@plt>
jmp    123e <secs_to_human_time+0x11e>
lea    0x2e16(%rip),%rdi
lea    0xddf(%rip),%rsi
mov    %r8d,%edx
mov    %r9d,%ecx
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0x2dfb(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@secs_to_human_time.buf = internal global [32 x i8] zeroinitializer
@.str = [16 x i8] c"%dd %dh %dm %ds\00"
@.str.1 = [12 x i8] c"%dh %dm %ds\00"
@.str.2 = [8 x i8] c"%dm %ds\00"
@.str.3 = [4 x i8] c"%ss\00"
define i8* @secs_to_human_time(double %0) {
%2 = alloca double
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store double %0, double* %2
%7 = load double, double* %2
%8 = fadd double %7, 5.000000e-01
%9 = fptosi double %8 to i32
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = sdiv i32 %10, 86400
store i32 %11, i32* %6
%12 = load i32, i32* %3
%13 = srem i32 %12, 86400
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = sdiv i32 %14, 3600
store i32 %15, i32* %4
%16 = load i32, i32* %3
%17 = srem i32 %16, 3600
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = sdiv i32 %18, 60
store i32 %19, i32* %5
%20 = load i32, i32* %3
%21 = srem i32 %20, 60
store i32 %21, i32* %3
%22 = load i32, i32* %6
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %1
%25 = load i32, i32* %6
%26 = load i32, i32* %4
%27 = load i32, i32* %5
%28 = load i32, i32* %3
%29 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @secs_to_human_time.buf, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %25, i32 %26, i32 %27, i32 %28)
br label %51
30: ; preds = %1
%31 = load i32, i32* %4
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %30
%34 = load i32, i32* %4
%35 = load i32, i32* %5
%36 = load i32, i32* %3
%37 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @secs_to_human_time.buf, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %34, i32 %35, i32 %36)
br label %50
38: ; preds = %30
%39 = load i32, i32* %5
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %38
%42 = load i32, i32* %5
%43 = load i32, i32* %3
%44 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @secs_to_human_time.buf, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %42, i32 %43)
br label %49
45: ; preds = %38
%46 = load double, double* %2
%47 = call i8* @print_decimal(double %46)
%48 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @secs_to_human_time.buf, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %47)
br label %49
49: ; preds = %45, %41
br label %50
50: ; preds = %49, %33
br label %51
51: ; preds = %50, %24
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @secs_to_human_time.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@secs_to_human_time.buf = internal global [32 x i8] zeroinitializer
@.str = [16 x i8] c"%dd %dh %dm %ds\00"
@.str.1 = [12 x i8] c"%dh %dm %ds\00"
@.str.2 = [8 x i8] c"%dm %ds\00"
@.str.3 = [4 x i8] c"%ss\00"
define i8* @secs_to_human_time(double %0) {
%2 = fadd double %0, 5.000000e-01
%3 = fptosi double %2 to i32
%4 = srem i32 %3, 86400
%5 = sdiv i32 %3, 86400
%6 = sdiv i32 %4, 3600
%7 = srem i32 %4, 3600
%8 = trunc i32 %7 to i16
%9 = sdiv i16 %8, 60
%10 = sext i16 %9 to i32
%11 = srem i16 %8, 60
%12 = sext i16 %11 to i32
%13 = add i32 %3, 86399
%14 = icmp ult i32 %13, 172799
br i1 %14, label %17, label %15
15: ; preds = %1
%16 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @secs_to_human_time.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6, i32 %10, i32 %12)
br label %30
17: ; preds = %1
%18 = add nsw i32 %4, 3599
%19 = icmp ult i32 %18, 7199
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @secs_to_human_time.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %6, i32 %10, i32 %12)
br label %30
22: ; preds = %17
%23 = add nsw i32 %7, 59
%24 = icmp ult i32 %23, 119
br i1 %24, label %27, label %25
25: ; preds = %22
%26 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @secs_to_human_time.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %10, i32 %12)
br label %30
27: ; preds = %22
%28 = tail call i8* @print_decimal(double %0)
%29 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @secs_to_human_time.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %20, %27, %25, %15
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @secs_to_human_time.buf, i64 0, i64 0)
}