#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 *, int, ...);
void secondsToHuman(char *buffer, long elapsed) {
  int days;
  int hours;
  int minutes;
  int seconds;
  days = elapsed / 86400;
  elapsed = elapsed % 86400;
  hours = elapsed / 3600;
  elapsed = elapsed % 3600;
  minutes = elapsed / 60;
  seconds = elapsed % 60;
  if (days > 0) {
    sprintf(buffer, "%02dd%02dh%02dm%02ds", days, hours, minutes, seconds);
  } else if (hours > 0) {
    sprintf(buffer, "   %02dh%02dm%02ds", hours, minutes, seconds);
  } else if (minutes > 0) {
    sprintf(buffer, "      %02dm%02ds", minutes, seconds);
  } else {
    sprintf(buffer, "         %02ds", seconds);
  }
}


x86 assembly (clang, -O0):
<secondsToHuman>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x15180,%ecx
cqto
idiv   %rcx
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x15180,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    $0xe10,%ecx
cqto
idiv   %rcx
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    $0xe10,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x3c,%ecx
cqto
idiv   %rcx
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x3c,%ecx
cqto
idiv   %rcx
mov    %edx,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11b9 <secondsToHuman+0xa9>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
mov    -0x20(%rbp),%r9d
lea    0xe53(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    122a <secondsToHuman+0x11a>
cmpl   $0x0,-0x18(%rbp)
jle    11e4 <secondsToHuman+0xd4>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
lea    0xe3d(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1225 <secondsToHuman+0x115>
cmpl   $0x0,-0x1c(%rbp)
jle    120b <secondsToHuman+0xfb>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    0xe29(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1220 <secondsToHuman+0x110>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%edx
lea    0xe20(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1225 <secondsToHuman+0x115>
jmp    122a <secondsToHuman+0x11a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<secondsToHuman>:
mov    %rsi,%r10
movabs $0x1845c8a0ce512957,%rcx
c8 45 18
mov    %rsi,%rax
imul   %rcx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0xd,%rdx
add    %rax,%rdx
imul   $0x15180,%rdx,%rax
sub    %rax,%r10
movslq %r10d,%r11
imul   $0xffffffff91a2b3c5,%r11,%rcx
shr    $0x20,%rcx
add    %r10d,%ecx
mov    %ecx,%esi
shr    $0x1f,%esi
sar    $0xb,%ecx
add    %esi,%ecx
imul   $0xe10,%ecx,%esi
sub    %esi,%r11d
movswl %r11w,%esi
imul   $0xffff8889,%esi,%esi
shr    $0x10,%esi
add    %r11d,%esi
movzwl %si,%esi
movswl %si,%eax
shr    $0xf,%esi
sar    $0x5,%eax
add    %esi,%eax
movswl %ax,%r8d
imul   $0x3c,%eax,%eax
mov    %r11d,%esi
sub    %eax,%esi
movswl %si,%r9d
test   %edx,%edx
jle    119f <secondsToHuman+0x8f>
lea    0xe68(%rip),%rsi
xor    %eax,%eax
jmp    1030 <sprintf@plt>
cmp    $0xe10,%r10d
jl     11be <secondsToHuman+0xae>
lea    0xe66(%rip),%rsi
mov    %ecx,%edx
mov    %r8d,%ecx
mov    %r9d,%r8d
xor    %eax,%eax
jmp    1030 <sprintf@plt>
cmp    $0x3c,%r11w
jl     11d9 <secondsToHuman+0xc9>
lea    0xe5c(%rip),%rsi
mov    %r8d,%edx
mov    %r9d,%ecx
xor    %eax,%eax
jmp    1030 <sprintf@plt>
lea    0xe59(%rip),%rsi
mov    %r9d,%edx
xor    %eax,%eax
jmp    1030 <sprintf@plt>

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

LLVM IR (-O2):
@.str = [21 x i8] c"%02dd%02dh%02dm%02ds\00"
@.str.1 = [19 x i8] c" %02dh%02dm%02ds\00"
@.str.2 = [17 x i8] c" %02dm%02ds\00"
@.str.3 = [15 x i8] c" %02ds\00"
define void @secondsToHuman(i8* nocapture writeonly %0, i64 %1) {
%3 = sdiv i64 %1, 86400
%4 = trunc i64 %3 to i32
%5 = srem i64 %1, 86400
%6 = trunc i64 %5 to i32
%7 = sdiv i32 %6, 3600
%8 = srem i32 %6, 3600
%9 = trunc i32 %8 to i16
%10 = sdiv i16 %9, 60
%11 = sext i16 %10 to i32
%12 = srem i16 %9, 60
%13 = sext i16 %12 to i32
%14 = icmp sgt i32 %4, 0
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %7, i32 %11, i32 %13)
br label %27
17: ; preds = %2
%18 = icmp sgt i32 %6, 3599
br i1 %18, label %19, label %21
19: ; preds = %17
%20 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 %11, i32 %13)
br label %27
21: ; preds = %17
%22 = icmp sgt i16 %9, 59
br i1 %22, label %23, label %25
23: ; preds = %21
%24 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %11, i32 %13)
br label %27
25: ; preds = %21
%26 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %13)
br label %27
27: ; preds = %19, %25, %23, %15
ret void
}