#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 *const, size_t const, char *, int, int, ...);
char *ElapsedStr(double elap, char *const s, const size_t siz) {
  int ielap, day, sec, min, hr;
  ielap = (int)(elap + 0.5);
  if (ielap < 0)
    ielap = 0;
  sec = ielap % 60;
  min = (ielap / 60) % 60;
  hr = (ielap / 3600) % 24;
  day = (ielap / 86400);
  if (day > 0) {
    snprintf(s, siz, "%d:%02d:%02d:%02d", day, hr, min, sec);
  } else if (hr > 0) {
    snprintf(s, siz, "%d:%02d:%02d", hr, min, sec);
  } else {
    snprintf(s, siz, "%d:%02d", min, sec);
  }
  return (s);
}


x86 assembly (clang, -O0):
<ElapsedStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movsd  0xed3(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    114a <ElapsedStr+0x3a>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    $0x18,%ecx
cltd
idiv   %ecx
mov    %edx,-0x2c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x15180,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    11c8 <ElapsedStr+0xb8>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
mov    -0x28(%rbp),%r9d
mov    -0x24(%rbp),%eax
lea    0xe4f(%rip),%rdx
mov    %eax,(%rsp)
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    121a <ElapsedStr+0x10a>
cmpl   $0x0,-0x2c(%rbp)
jle    11f8 <ElapsedStr+0xe8>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x2c(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    -0x24(%rbp),%r9d
lea    0xe2e(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    1215 <ElapsedStr+0x105>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%ecx
mov    -0x24(%rbp),%r8d
lea    0xe19(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    121a <ElapsedStr+0x10a>
mov    -0x10(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ElapsedStr>:
push   %rbx
sub    $0x10,%rsp
addsd  0xee3(%rip),%xmm0
cvttsd2si %xmm0,%eax
xor    %ecx,%ecx
test   %eax,%eax
cmovns %eax,%ecx
mov    %rdi,%rbx
mov    $0x88888889,%edx
mov    %rcx,%r9
imul   %rdx,%r9
shr    $0x25,%r9
imul   $0x3c,%r9d,%edi
mov    %ecx,%eax
sub    %edi,%eax
mov    %r9,%rdi
imul   %rdx,%rdi
shr    $0x25,%rdi
imul   $0x3c,%edi,%edx
sub    %edx,%r9d
mov    $0x91a2b3c5,%r8d
imul   %rcx,%r8
shr    $0x2b,%r8
mov    $0xaaaaaaab,%edx
imul   %r8,%rdx
shr    $0x24,%rdx
shl    $0x3,%edx
lea    (%rdx,%rdx,2),%edx
sub    %edx,%r8d
cmp    $0x15180,%ecx
jae    119a <ElapsedStr+0x8a>
test   %r8d,%r8d
je     11bf <ElapsedStr+0xaf>
lea    0xe8e(%rip),%rdx
mov    %rbx,%rdi
mov    %r8d,%ecx
mov    %r9d,%r8d
mov    %eax,%r9d
jmp    11b6 <ElapsedStr+0xa6>
mov    %ecx,%edx
mov    $0xc22e4507,%ecx
imul   %rdx,%rcx
shr    $0x30,%rcx
mov    %eax,(%rsp)
lea    0xe55(%rip),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <snprintf@plt>
jmp    11d6 <ElapsedStr+0xc6>
lea    0xe61(%rip),%rdx
mov    %rbx,%rdi
mov    %r9d,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1030 <snprintf@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [18 x i8] c"%d:%02d:%02d:%02d\00"
@.str.1 = [13 x i8] c"%d:%02d:%02d\00"
@.str.2 = [8 x i8] c"%d:%02d\00"
define i8* @ElapsedStr(double %0, i8* returned %1, i64 %2) {
%4 = fadd double %0, 5.000000e-01
%5 = fptosi double %4 to i32
%6 = icmp sgt i32 %5, 0
%7 = select i1 %6, i32 %5, i32 0
%8 = urem i32 %7, 60
%9 = udiv i32 %7, 60
%10 = urem i32 %9, 60
%11 = udiv i32 %7, 3600
%12 = urem i32 %11, 24
%13 = icmp ult i32 %7, 86400
br i1 %13, label %17, label %14
14: ; preds = %3
%15 = udiv i32 %7, 86400
%16 = tail call i32 (i8*, i64, i8*, i32, i32, ...) @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %12, i32 %10, i32 %8)
br label %23
17: ; preds = %3
%18 = icmp eq i32 %12, 0
br i1 %18, label %21, label %19
19: ; preds = %17
%20 = tail call i32 (i8*, i64, i8*, i32, i32, ...) @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %12, i32 %10, i32 %8)
br label %23
21: ; preds = %17
%22 = tail call i32 (i8*, i64, i8*, i32, i32, ...) @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %10, i32 %8)
br label %23
23: ; preds = %19, %21, %14
ret i8* %1
}