#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);
int val2elapstr(int value, char *strvalue) {
  char *p = strvalue;
  if (value >= (24 * 60 * 60)) {
    p += sprintf(p, "%dd", value / (24 * 60 * 60));
  }
  if (value >= (60 * 60)) {
    p += sprintf(p, "%dh", (value % (24 * 60 * 60)) / (60 * 60));
  }
  if (value >= (60)) {
    p += sprintf(p, "%dm", (value % (60 * 60)) / (60));
  }
  p += sprintf(p, "%ds", (value % (60)));
  return p - strvalue;
}


x86 assembly (clang, -O0):
<val2elapstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x15180,-0x4(%rbp)
jl     1161 <val2elapstr+0x51>
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%eax
mov    $0x15180,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
lea    0xeb4(%rip),%rsi
call   1030 <sprintf@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
cmpl   $0xe10,-0x4(%rbp)
jl     11a5 <val2elapstr+0x95>
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%eax
mov    $0x15180,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
lea    0xe74(%rip),%rsi
call   1030 <sprintf@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x3c,-0x4(%rbp)
jl     11e6 <val2elapstr+0xd6>
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
lea    0xe37(%rip),%rsi
call   1030 <sprintf@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
lea    0xe10(%rip),%rsi
call   1030 <sprintf@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<val2elapstr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    %edi,%r12d
cmp    $0x15180,%edi
jl     114c <val2elapstr+0x3c>
mov    $0xc22e4507,%edx
imul   %r12,%rdx
shr    $0x30,%rdx
lea    0xec4(%rip),%rsi
mov    %r14,%rdi
call   1030 <sprintf@plt>
movslq %eax,%rbx
add    %r14,%rbx
jmp    115b <val2elapstr+0x4b>
mov    %r14,%rbx
cmp    $0xe10,%ebp
jl     1207 <val2elapstr+0xf7>
mov    $0xc22e4507,%eax
imul   %r12,%rax
shr    $0x30,%rax
imul   $0x15180,%eax,%eax
mov    %ebp,%ecx
sub    %eax,%ecx
mov    $0x91a2b3c5,%edx
imul   %rcx,%rdx
shr    $0x2b,%rdx
lea    0xe7e(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
movslq %eax,%r15
add    %rbx,%r15
mov    $0x91a2b3c5,%eax
imul   %r12,%rax
shr    $0x2b,%rax
imul   $0xe10,%eax,%eax
mov    %ebp,%ecx
sub    %eax,%ecx
imul   $0x8889,%ecx,%edx
shr    $0x15,%edx
lea    0xe4d(%rip),%rsi
mov    %r15,%rdi
call   1030 <sprintf@plt>
movslq %eax,%rbx
add    %r15,%rbx
movslq %ebp,%rax
imul   $0xffffffff88888889,%rax,%rax
shr    $0x20,%rax
add    %ebp,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x5,%eax
add    %ecx,%eax
imul   $0x3c,%eax,%eax
sub    %eax,%ebp
lea    0xe1d(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1030 <sprintf@plt>
add    %ebx,%eax
sub    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%r15
mov    %r14,%rbx
cmp    $0x3c,%ebp
jge    1194 <val2elapstr+0x84>
jmp    11c9 <val2elapstr+0xb9>

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

LLVM IR (-O2):
@.str = [4 x i8] c"%dd\00"
@.str.1 = [4 x i8] c"%dh\00"
@.str.2 = [4 x i8] c"%dm\00"
@.str.3 = [4 x i8] c"%ds\00"
define i32 @val2elapstr(i32 %0, i8* %1) {
%3 = icmp sgt i32 %0, 86399
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = udiv i32 %0, 86400
%6 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %1, i64 %7
br label %11
9: ; preds = %2
%10 = icmp sgt i32 %0, 3599
br i1 %10, label %11, label %18
11: ; preds = %9, %4
%12 = phi i8* [ %8, %4 ], [ %1, %9 ]
%13 = urem i32 %0, 86400
%14 = udiv i32 %13, 3600
%15 = tail call i32 @sprintf(i8* dereferenceable(1) %12, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %12, i64 %16
br label %20
18: ; preds = %9
%19 = icmp sgt i32 %0, 59
br i1 %19, label %20, label %29
20: ; preds = %11, %18
%21 = phi i8* [ %17, %11 ], [ %1, %18 ]
%22 = urem i32 %0, 3600
%23 = trunc i32 %22 to i16
%24 = udiv i16 %23, 60
%25 = zext i16 %24 to i32
%26 = tail call i32 @sprintf(i8* dereferenceable(1) %21, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %21, i64 %27
br label %29
29: ; preds = %20, %18
%30 = phi i8* [ %28, %20 ], [ %1, %18 ]
%31 = srem i32 %0, 60
%32 = tail call i32 @sprintf(i8* dereferenceable(1) %30, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %31)
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
%35 = ptrtoint i8* %34 to i64
%36 = ptrtoint i8* %1 to i64
%37 = sub i64 %35, %36
%38 = trunc i64 %37 to i32
ret i32 %38
}