#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 */
typedef int uint;
typedef int time_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, int, ...);
const char *timedeltastr(time_t delta) {
  static char buf[256];
  uint d = (int)delta;
  if (delta < 60) {
    snprintf(buf, sizeof(buf) - 1, "   %02ds", d);
  } else if (delta < 60 * 60) {
    snprintf(buf, sizeof(buf) - 1, "%02dm%02ds", (d / 60), (d % 60));
  } else if (delta < 60 * 60 * 24) {
    snprintf(buf, sizeof(buf) - 1, "%02dh%02dm", (d / (60 * 60)),
             (d % (60 * 60)) / 60);
  } else {
    snprintf(buf, sizeof(buf) - 1, "%02dd%02dh", (d / (60 * 60 * 24)),
             (d % (60 * 60 * 24)) / (60 * 60));
  }
  buf[sizeof(buf) - 1] = 0;
  return buf;
}


x86 assembly (clang, -O0):
<timedeltastr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x3c,-0x4(%rbp)
jge    114d <timedeltastr+0x3d>
mov    -0x8(%rbp),%ecx
lea    0x2f0b(%rip),%rdi
mov    $0xff,%esi
lea    0xebf(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    122e <timedeltastr+0x11e>
cmpl   $0xe10,-0x4(%rbp)
jge    1194 <timedeltastr+0x84>
mov    -0x8(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x8(%rbp),%eax
mov    $0x3c,%esi
cltd
idiv   %esi
mov    %edx,%r8d
lea    0x2ec4(%rip),%rdi
mov    $0xff,%esi
lea    0xe81(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    1229 <timedeltastr+0x119>
cmpl   $0x15180,-0x4(%rbp)
jge    11e5 <timedeltastr+0xd5>
mov    -0x8(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x8(%rbp),%eax
mov    $0xe10,%esi
cltd
idiv   %esi
mov    %edx,%eax
mov    $0x3c,%esi
cltd
idiv   %esi
mov    %eax,%r8d
lea    0x2e73(%rip),%rdi
mov    $0xff,%esi
lea    0xe3b(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    1224 <timedeltastr+0x114>
mov    -0x8(%rbp),%eax
mov    $0x15180,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x8(%rbp),%eax
mov    $0x15180,%esi
cltd
idiv   %esi
mov    %edx,%eax
mov    $0xe10,%esi
cltd
idiv   %esi
mov    %eax,%r8d
lea    0x2e2f(%rip),%rdi
mov    $0xff,%esi
lea    0xe02(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    1229 <timedeltastr+0x119>
jmp    122e <timedeltastr+0x11e>
movb   $0x0,0x2f0a(%rip)
lea    0x2e04(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timedeltastr>:
push   %rax
mov    %edi,%eax
cmp    $0x3b,%edi
jg     1139 <timedeltastr+0x29>
lea    0x2f21(%rip),%rdi
lea    0xeda(%rip),%rdx
mov    $0xff,%esi
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <snprintf@plt>
jmp    11e5 <timedeltastr+0xd5>
cmp    $0xe0f,%eax
ja     116a <timedeltastr+0x5a>
movzwl %ax,%ecx
imul   $0x8889,%ecx,%ecx
shr    $0x15,%ecx
imul   $0x3c,%ecx,%edx
sub    %edx,%eax
movzwl %ax,%r8d
lea    0x2ee4(%rip),%rdi
lea    0xea6(%rip),%rdx
mov    $0xff,%esi
jmp    11de <timedeltastr+0xce>
mov    %eax,%edx
cmp    $0x1517f,%eax
ja     11a8 <timedeltastr+0x98>
mov    $0x91a2b3c5,%ecx
imul   %rdx,%rcx
shr    $0x2b,%rcx
imul   $0xe10,%ecx,%edx
sub    %edx,%eax
imul   $0x8889,%eax,%r8d
shr    $0x15,%r8d
lea    0x2ea6(%rip),%rdi
lea    0xe73(%rip),%rdx
mov    $0xff,%esi
jmp    11de <timedeltastr+0xce>
mov    $0xc22e4507,%ecx
imul   %rdx,%rcx
shr    $0x30,%rcx
imul   $0x15180,%ecx,%edx
sub    %edx,%eax
mov    $0x91a2b3c5,%r8d
imul   %rax,%r8
shr    $0x2b,%r8
lea    0x2e6e(%rip),%rdi
lea    0xe46(%rip),%rdx
mov    $0xff,%esi
xor    %eax,%eax
call   1030 <snprintf@plt>
movb   $0x0,0x2f53(%rip)
lea    0x2e4d(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@timedeltastr.buf = internal global [256 x i8] zeroinitializer
@.str = [9 x i8] c" %02ds\00"
@.str.1 = [11 x i8] c"%02dm%02ds\00"
@.str.2 = [11 x i8] c"%02dh%02dm\00"
@.str.3 = [11 x i8] c"%02dd%02dh\00"
define i8* @timedeltastr(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
store i32 %4, i32* %3
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 60
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* %3
%9 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @timedeltastr.buf, i64 0, i64 0), i32 255, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %38
10: ; preds = %1
%11 = load i32, i32* %2
%12 = icmp slt i32 %11, 3600
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = load i32, i32* %3
%15 = sdiv i32 %14, 60
%16 = load i32, i32* %3
%17 = srem i32 %16, 60
%18 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @timedeltastr.buf, i64 0, i64 0), i32 255, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %17)
br label %37
19: ; preds = %10
%20 = load i32, i32* %2
%21 = icmp slt i32 %20, 86400
br i1 %21, label %22, label %29
22: ; preds = %19
%23 = load i32, i32* %3
%24 = sdiv i32 %23, 3600
%25 = load i32, i32* %3
%26 = srem i32 %25, 3600
%27 = sdiv i32 %26, 60
%28 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @timedeltastr.buf, i64 0, i64 0), i32 255, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %24, i32 %27)
br label %36
29: ; preds = %19
%30 = load i32, i32* %3
%31 = sdiv i32 %30, 86400
%32 = load i32, i32* %3
%33 = srem i32 %32, 86400
%34 = sdiv i32 %33, 3600
%35 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @timedeltastr.buf, i64 0, i64 0), i32 255, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %31, i32 %34)
br label %36
36: ; preds = %29, %22
br label %37
37: ; preds = %36, %13
br label %38
38: ; preds = %37, %7
store i8 0, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @timedeltastr.buf, i64 0, i64 255)
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @timedeltastr.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@timedeltastr.buf = internal global [256 x i8] zeroinitializer
@.str = [9 x i8] c" %02ds\00"
@.str.1 = [11 x i8] c"%02dm%02ds\00"
@.str.2 = [11 x i8] c"%02dh%02dm\00"
@.str.3 = [11 x i8] c"%02dd%02dh\00"
define i8* @timedeltastr(i32 %0) {
%2 = icmp slt i32 %0, 60
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @timedeltastr.buf, i64 0, i64 0), i32 255, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %28
5: ; preds = %1
%6 = icmp ult i32 %0, 3600
br i1 %6, label %7, label %14
7: ; preds = %5
%8 = trunc i32 %0 to i16
%9 = udiv i16 %8, 60
%10 = zext i16 %9 to i32
%11 = urem i16 %8, 60
%12 = zext i16 %11 to i32
%13 = tail call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @timedeltastr.buf, i64 0, i64 0), i32 255, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 %12)
br label %28
14: ; preds = %5
%15 = icmp ult i32 %0, 86400
br i1 %15, label %16, label %23
16: ; preds = %14
%17 = udiv i32 %0, 3600
%18 = urem i32 %0, 3600
%19 = trunc i32 %18 to i16
%20 = udiv i16 %19, 60
%21 = zext i16 %20 to i32
%22 = tail call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @timedeltastr.buf, i64 0, i64 0), i32 255, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %17, i32 %21)
br label %28
23: ; preds = %14
%24 = udiv i32 %0, 86400
%25 = urem i32 %0, 86400
%26 = udiv i32 %25, 3600
%27 = tail call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @timedeltastr.buf, i64 0, i64 0), i32 255, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %24, i32 %26)
br label %28
28: ; preds = %7, %23, %16, %3
store i8 0, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @timedeltastr.buf, i64 0, i64 255)
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @timedeltastr.buf, i64 0, i64 0)
}