#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 *, unsigned int, ...);
void format_time(unsigned int sec, char output[64]) {
  if (sec >= 24 * 3600) {
    unsigned int days = sec / (24 * 3600);
    sec -= days * (24 * 3600);
    unsigned int hours = sec / 3600;
    sec -= hours * 3600;
    unsigned int minutes = sec / 60;
    sec -= minutes * 60;
    sprintf(output, "%ud%uh%um%us", days, hours, minutes, sec);
  } else if (sec >= 3600) {
    unsigned int hours = sec / 3600;
    sec -= hours * 3600;
    unsigned int minutes = sec / 60;
    sec -= minutes * 60;
    sprintf(output, "%uh%um%us", hours, minutes, sec);
  } else if (sec >= 60) {
    unsigned int minutes = sec / 60;
    sec -= minutes * 60;
    sprintf(output, "%um%us", minutes, sec);
  } else {
    sprintf(output, "%us", sec);
  }
}


x86 assembly (clang, -O0):
<format_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x15180,-0x4(%rbp)
jb     11a8 <format_time+0x98>
mov    -0x4(%rbp),%eax
mov    $0x15180,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x14(%rbp)
imul   $0x15180,-0x14(%rbp),%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xe10,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x18(%rbp)
imul   $0xe10,-0x18(%rbp),%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3c,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x1c(%rbp)
imul   $0x3c,-0x1c(%rbp),%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
mov    -0x4(%rbp),%r9d
lea    0xe64(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1270 <format_time+0x160>
cmpl   $0xe10,-0x4(%rbp)
jb     120f <format_time+0xff>
mov    -0x4(%rbp),%eax
mov    $0xe10,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x20(%rbp)
imul   $0xe10,-0x20(%rbp),%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3c,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x24(%rbp)
imul   $0x3c,-0x24(%rbp),%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x4(%rbp),%r8d
lea    0xe00(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    126b <format_time+0x15b>
cmpl   $0x3c,-0x4(%rbp)
jb     1251 <format_time+0x141>
mov    -0x4(%rbp),%eax
mov    $0x3c,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x28(%rbp)
imul   $0x3c,-0x28(%rbp),%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%edx
mov    -0x4(%rbp),%ecx
lea    0xdc1(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1266 <format_time+0x156>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xdaa(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    126b <format_time+0x15b>
jmp    1270 <format_time+0x160>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_time>:
mov    %rsi,%r10
mov    %edi,%eax
cmp    $0x15180,%edi
jb     116f <format_time+0x5f>
mov    %eax,%ecx
mov    $0xc22e4507,%edx
imul   %rcx,%rdx
shr    $0x30,%rdx
imul   $0xfffeae80,%edx,%esi
add    %eax,%esi
mov    $0x91a2b3c5,%ecx
imul   %rsi,%rcx
shr    $0x2b,%rcx
imul   $0xfffff1f0,%ecx,%eax
add    %esi,%eax
mov    $0x88888889,%r8d
imul   %rax,%r8
shr    $0x25,%r8
imul   $0xffffffc4,%r8d,%r9d
add    %eax,%r9d
lea    0xe9b(%rip),%rsi
mov    %r10,%rdi
xor    %eax,%eax
jmp    1030 <sprintf@plt>
cmp    $0xe10,%eax
jb     11b2 <format_time+0xa2>
mov    %eax,%ecx
mov    $0x91a2b3c5,%edx
imul   %rcx,%rdx
shr    $0x2b,%rdx
imul   $0xfffff1f0,%edx,%esi
add    %eax,%esi
mov    $0x88888889,%ecx
imul   %rsi,%rcx
shr    $0x25,%rcx
imul   $0xffffffc4,%ecx,%r8d
add    %esi,%r8d
lea    0xe5b(%rip),%rsi
mov    %r10,%rdi
xor    %eax,%eax
jmp    1030 <sprintf@plt>
cmp    $0x3c,%eax
jb     11d9 <format_time+0xc9>
movzwl %ax,%ecx
imul   $0x8889,%ecx,%edx
shr    $0x15,%edx
imul   $0xffffffc4,%edx,%ecx
add    %eax,%ecx
lea    0xe37(%rip),%rsi
mov    %r10,%rdi
xor    %eax,%eax
jmp    1030 <sprintf@plt>
lea    0xe29(%rip),%rsi
mov    %r10,%rdi
mov    %eax,%edx
xor    %eax,%eax
jmp    1030 <sprintf@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"%ud%uh%um%us\00"
@.str.1 = [10 x i8] c"%uh%um%us\00"
@.str.2 = [7 x i8] c"%um%us\00"
@.str.3 = [4 x i8] c"%us\00"
define void @format_time(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%11 = load i32, i32* %3
%12 = icmp uge i32 %11, 86400
br i1 %12, label %13, label %38
13: ; preds = %2
%14 = load i32, i32* %3
%15 = udiv i32 %14, 86400
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = mul i32 %16, 86400
%18 = load i32, i32* %3
%19 = sub i32 %18, %17
store i32 %19, i32* %3
%20 = load i32, i32* %3
%21 = udiv i32 %20, 3600
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = mul i32 %22, 3600
%24 = load i32, i32* %3
%25 = sub i32 %24, %23
store i32 %25, i32* %3
%26 = load i32, i32* %3
%27 = udiv i32 %26, 60
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = mul i32 %28, 60
%30 = load i32, i32* %3
%31 = sub i32 %30, %29
store i32 %31, i32* %3
%32 = load i8*, i8** %4
%33 = load i32, i32* %5
%34 = load i32, i32* %6
%35 = load i32, i32* %7
%36 = load i32, i32* %3
%37 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %32, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %33, i32 %34, i32 %35, i32 %36)
br label %79
38: ; preds = %2
%39 = load i32, i32* %3
%40 = icmp uge i32 %39, 3600
br i1 %40, label %41, label %59
41: ; preds = %38
%42 = load i32, i32* %3
%43 = udiv i32 %42, 3600
store i32 %43, i32* %8
%44 = load i32, i32* %8
%45 = mul i32 %44, 3600
%46 = load i32, i32* %3
%47 = sub i32 %46, %45
store i32 %47, i32* %3
%48 = load i32, i32* %3
%49 = udiv i32 %48, 60
store i32 %49, i32* %9
%50 = load i32, i32* %9
%51 = mul i32 %50, 60
%52 = load i32, i32* %3
%53 = sub i32 %52, %51
store i32 %53, i32* %3
%54 = load i8*, i8** %4
%55 = load i32, i32* %8
%56 = load i32, i32* %9
%57 = load i32, i32* %3
%58 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %54, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %55, i32 %56, i32 %57)
br label %78
59: ; preds = %38
%60 = load i32, i32* %3
%61 = icmp uge i32 %60, 60
br i1 %61, label %62, label %73
62: ; preds = %59
%63 = load i32, i32* %3
%64 = udiv i32 %63, 60
store i32 %64, i32* %10
%65 = load i32, i32* %10
%66 = mul i32 %65, 60
%67 = load i32, i32* %3
%68 = sub i32 %67, %66
store i32 %68, i32* %3
%69 = load i8*, i8** %4
%70 = load i32, i32* %10
%71 = load i32, i32* %3
%72 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %69, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %70, i32 %71)
br label %77
73: ; preds = %59
%74 = load i8*, i8** %4
%75 = load i32, i32* %3
%76 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %74, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %75)
br label %77
77: ; preds = %73, %62
br label %78
78: ; preds = %77, %41
br label %79
79: ; preds = %78, %13
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"%ud%uh%um%us\00"
@.str.1 = [10 x i8] c"%uh%um%us\00"
@.str.2 = [7 x i8] c"%um%us\00"
@.str.3 = [4 x i8] c"%us\00"
define void @format_time(i32 %0, i8* nocapture writeonly %1) {
%3 = icmp ugt i32 %0, 86399
br i1 %3, label %4, label %15
4: ; preds = %2
%5 = udiv i32 %0, 86400
%6 = mul i32 %5, -86400
%7 = add i32 %6, %0
%8 = udiv i32 %7, 3600
%9 = mul i32 %8, -3600
%10 = add i32 %9, %7
%11 = udiv i32 %10, 60
%12 = mul i32 %11, -60
%13 = add i32 %12, %10
%14 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %8, i32 %11, i32 %13)
br label %36
15: ; preds = %2
%16 = icmp ugt i32 %0, 3599
br i1 %16, label %17, label %25
17: ; preds = %15
%18 = udiv i32 %0, 3600
%19 = mul nsw i32 %18, -3600
%20 = add nsw i32 %19, %0
%21 = udiv i32 %20, 60
%22 = mul i32 %21, -60
%23 = add i32 %22, %20
%24 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %18, i32 %21, i32 %23)
br label %36
25: ; preds = %15
%26 = icmp ugt i32 %0, 59
br i1 %26, label %27, label %34
27: ; preds = %25
%28 = trunc i32 %0 to i16
%29 = udiv i16 %28, 60
%30 = zext i16 %29 to i32
%31 = mul nsw i32 %30, -60
%32 = add nsw i32 %31, %0
%33 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %30, i32 %32)
br label %36
34: ; preds = %25
%35 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %0)
br label %36
36: ; preds = %17, %34, %27, %4
ret void
}