#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);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
char *elapsed_time(long sec) {
  static char tstr[256];
  char temp[256];
  if (sec <= 0)
    return "0s";
  tstr[0] = '\0';
  if (sec >= 86400) {
    sprintf(temp, "%ldD ", sec / 86400);
    strcat(tstr, temp);
    sec = sec % 86400;
  }
  if (sec >= 3600) {
    sprintf(temp, "%ldh ", sec / 3600);
    strcat(tstr, temp);
    sec = sec % 3600;
  }
  if (sec >= 60) {
    sprintf(temp, "%ldm ", sec / 60);
    strcat(tstr, temp);
    sec = sec % 60;
  }
  if (sec >= 1) {
    sprintf(temp, "%lds ", sec);
    strcat(tstr, temp);
  }
  tstr[strlen(tstr) - 1] = '\0';
  return tstr;
}


x86 assembly (clang, -O0):
<elapsed_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jg     115a <elapsed_time+0x2a>
lea    0xeaf(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12c0 <elapsed_time+0x190>
movb   $0x0,0x2eef(%rip)
cmpq   $0x15180,-0x10(%rbp)
jl     11b8 <elapsed_time+0x88>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    $0x15180,%ecx
cqto
idiv   %rcx
mov    %rax,%rdx
lea    0xe75(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x110(%rbp),%rsi
lea    0x2eaf(%rip),%rdi
call   1040 <strcat@plt>
mov    -0x10(%rbp),%rax
mov    $0x15180,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x10(%rbp)
cmpq   $0xe10,-0x10(%rbp)
jl     120f <elapsed_time+0xdf>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    $0xe10,%ecx
cqto
idiv   %rcx
mov    %rax,%rdx
lea    0xe24(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x110(%rbp),%rsi
lea    0x2e58(%rip),%rdi
call   1040 <strcat@plt>
mov    -0x10(%rbp),%rax
mov    $0xe10,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x10(%rbp)
cmpq   $0x3c,-0x10(%rbp)
jl     1263 <elapsed_time+0x133>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    $0x3c,%ecx
cqto
idiv   %rcx
mov    %rax,%rdx
lea    0xdd6(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x110(%rbp),%rsi
lea    0x2e04(%rip),%rdi
call   1040 <strcat@plt>
mov    -0x10(%rbp),%rax
mov    $0x3c,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x10(%rbp)
cmpq   $0x1,-0x10(%rbp)
jl     1298 <elapsed_time+0x168>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xd95(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x110(%rbp),%rsi
lea    0x2dbd(%rip),%rdi
call   1040 <strcat@plt>
lea    0x2db1(%rip),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2d9f(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2d94(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<elapsed_time>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
test   %rdi,%rdi
jle    11ac <elapsed_time+0x7c>
mov    %rdi,%rbx
movb   $0x0,0x2f05(%rip)
cmp    $0x15180,%rdi
jae    11c3 <elapsed_time+0x93>
cmp    $0xe10,%rbx
jae    1215 <elapsed_time+0xe5>
cmp    $0x3c,%rbx
jae    125c <elapsed_time+0x12c>
test   %rbx,%rbx
je     1194 <elapsed_time+0x64>
lea    0xe9e(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rbx,%rdx
call   1050 <sprintf@plt>
lea    0x2ec4(%rip),%rdi
mov    %r14,%rsi
call   1040 <strcat@plt>
lea    0x2eb5(%rip),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
jmp    11b3 <elapsed_time+0x83>
lea    0xe4d(%rip),%rbx
mov    %rbx,%rax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe39(%rip),%rsi
movabs $0xc22e450672894ab7,%rcx
45 2e c2
mov    %rbx,%rax
mul    %rcx
mov    %rdx,%r14
shr    $0x10,%r14
mov    %rsp,%r15
mov    %r15,%rdi
mov    %r14,%rdx
call   1050 <sprintf@plt>
lea    0x2e5a(%rip),%rdi
mov    %r15,%rsi
call   1040 <strcat@plt>
imul   $0x15180,%r14,%rax
sub    %rax,%rbx
cmp    $0xe10,%rbx
jb     1161 <elapsed_time+0x31>
lea    0xded(%rip),%rsi
mov    %ebx,%eax
mov    $0x91a2b3c5,%r14d
imul   %rax,%r14
shr    $0x2b,%r14
mov    %rsp,%r15
mov    %r15,%rdi
mov    %r14,%rdx
call   1050 <sprintf@plt>
lea    0x2e0f(%rip),%rdi
mov    %r15,%rsi
call   1040 <strcat@plt>
imul   $0xe10,%r14d,%eax
sub    %eax,%ebx
cmp    $0x3c,%rbx
jb     116b <elapsed_time+0x3b>
movzwl %bx,%eax
imul   $0x8889,%eax,%r14d
shr    $0x15,%r14d
lea    0xd9e(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
mov    %r14,%rdx
call   1050 <sprintf@plt>
lea    0x2dca(%rip),%rdi
mov    %r15,%rsi
call   1040 <strcat@plt>
imul   $0x3c,%r14d,%eax
sub    %eax,%ebx
movzwl %bx,%ebx
test   %rbx,%rbx
jne    1170 <elapsed_time+0x40>
jmp    1194 <elapsed_time+0x64>

LLVM IR (-O0):
@elapsed_time.tstr = internal global [256 x i8] zeroinitializer
@.str = [3 x i8] c"0s\00"
@.str.1 = [6 x i8] c"%ldD \00"
@.str.2 = [6 x i8] c"%ldh \00"
@.str.3 = [6 x i8] c"%ldm \00"
@.str.4 = [6 x i8] c"%lds \00"
define i8* @elapsed_time(i64 %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca [256 x i8]
store i64 %0, i64* %3
%5 = load i64, i64* %3
%6 = icmp sle i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %2
br label %58
8: ; preds = %1
store i8 0, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @elapsed_time.tstr, i64 0, i64 0)
%9 = load i64, i64* %3
%10 = icmp sge i64 %9, 86400
br i1 %10, label %11, label %20
11: ; preds = %8
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%13 = load i64, i64* %3
%14 = sdiv i64 %13, 86400
%15 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %14)
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%17 = call i32 @strcat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @elapsed_time.tstr, i64 0, i64 0), i8* %16)
%18 = load i64, i64* %3
%19 = srem i64 %18, 86400
store i64 %19, i64* %3
br label %20
20: ; preds = %11, %8
%21 = load i64, i64* %3
%22 = icmp sge i64 %21, 3600
br i1 %22, label %23, label %32
23: ; preds = %20
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%25 = load i64, i64* %3
%26 = sdiv i64 %25, 3600
%27 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %26)
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%29 = call i32 @strcat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @elapsed_time.tstr, i64 0, i64 0), i8* %28)
%30 = load i64, i64* %3
%31 = srem i64 %30, 3600
store i64 %31, i64* %3
br label %32
32: ; preds = %23, %20
%33 = load i64, i64* %3
%34 = icmp sge i64 %33, 60
br i1 %34, label %35, label %44
35: ; preds = %32
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%37 = load i64, i64* %3
%38 = sdiv i64 %37, 60
%39 = call i32 @sprintf(i8* %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i64 %38)
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%41 = call i32 @strcat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @elapsed_time.tstr, i64 0, i64 0), i8* %40)
%42 = load i64, i64* %3
%43 = srem i64 %42, 60
store i64 %43, i64* %3
br label %44
44: ; preds = %35, %32
%45 = load i64, i64* %3
%46 = icmp sge i64 %45, 1
br i1 %46, label %47, label %53
47: ; preds = %44
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%49 = load i64, i64* %3
%50 = call i32 @sprintf(i8* %48, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i64 %49)
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%52 = call i32 @strcat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @elapsed_time.tstr, i64 0, i64 0), i8* %51)
br label %53
53: ; preds = %47, %44
%54 = call i32 @strlen(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @elapsed_time.tstr, i64 0, i64 0))
%55 = sub nsw i32 %54, 1
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [256 x i8], [256 x i8]* @elapsed_time.tstr, i64 0, i64 %56
store i8 0, i8* %57
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @elapsed_time.tstr, i64 0, i64 0), i8** %2
br label %58
58: ; preds = %53, %7
%59 = load i8*, i8** %2
ret i8* %59
}

LLVM IR (-O2):
@elapsed_time.tstr = internal global [256 x i8] zeroinitializer
@.str = [3 x i8] c"0s\00"
@.str.1 = [6 x i8] c"%ldD \00"
@.str.2 = [6 x i8] c"%ldh \00"
@.str.3 = [6 x i8] c"%ldm \00"
@.str.4 = [6 x i8] c"%lds \00"
define i8* @elapsed_time(i64 %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = icmp slt i64 %0, 1
br i1 %4, label %45, label %5
5: ; preds = %1
store i8 0, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @elapsed_time.tstr, i64 0, i64 0)
%6 = icmp ugt i64 %0, 86399
br i1 %6, label %7, label %12
7: ; preds = %5
%8 = udiv i64 %0, 86400
%9 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %8)
%10 = call i32 @strcat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @elapsed_time.tstr, i64 0, i64 0), i8* %3)
%11 = urem i64 %0, 86400
br label %12
12: ; preds = %7, %5
%13 = phi i64 [ %11, %7 ], [ %0, %5 ]
%14 = icmp ugt i64 %13, 3599
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = trunc i64 %13 to i32
%17 = udiv i32 %16, 3600
%18 = zext i32 %17 to i64
%19 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %18)
%20 = call i32 @strcat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @elapsed_time.tstr, i64 0, i64 0), i8* %3)
%21 = urem i32 %16, 3600
%22 = zext i32 %21 to i64
br label %23
23: ; preds = %15, %12
%24 = phi i64 [ %22, %15 ], [ %13, %12 ]
%25 = icmp ugt i64 %24, 59
br i1 %25, label %26, label %34
26: ; preds = %23
%27 = trunc i64 %24 to i16
%28 = udiv i16 %27, 60
%29 = zext i16 %28 to i64
%30 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i64 %29)
%31 = call i32 @strcat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @elapsed_time.tstr, i64 0, i64 0), i8* %3)
%32 = urem i16 %27, 60
%33 = zext i16 %32 to i64
br label %34
34: ; preds = %26, %23
%35 = phi i64 [ %33, %26 ], [ %24, %23 ]
%36 = icmp eq i64 %35, 0
br i1 %36, label %40, label %37
37: ; preds = %34
%38 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i64 %35)
%39 = call i32 @strcat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @elapsed_time.tstr, i64 0, i64 0), i8* %3)
br label %40
40: ; preds = %37, %34
%41 = call i32 @strlen(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @elapsed_time.tstr, i64 0, i64 0))
%42 = add nsw i32 %41, -1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [256 x i8], [256 x i8]* @elapsed_time.tstr, i64 0, i64 %43
store i8 0, i8* %44
br label %45
45: ; preds = %1, %40
%46 = phi i8* [ getelementptr inbounds ([256 x i8], [256 x i8]* @elapsed_time.tstr, i64 0, i64 0), %40 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %1 ]
ret i8* %46
}