#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, ...);
char *small_duration(int duration) {
  static char dbuffer[20];
  int days = 0, hours = 0, mins = 0;
  dbuffer[0] = 0;
  days = (int)(duration / (24 * 60 * 60));
  duration %= (24 * 60 * 60);
  hours = (int)(duration / (60 * 60));
  duration %= (60 * 60);
  mins = (int)(duration / 60);
  if (days)
    sprintf(dbuffer, "%dd %dh %dm", days, hours, mins);
  else if (hours)
    sprintf(dbuffer, "%dh %dm", hours, mins);
  else
    sprintf(dbuffer, "%dm", mins);
  return dbuffer;
}


x86 assembly (clang, -O0):
<small_duration>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movb   $0x0,0x2f09(%rip)
mov    -0x4(%rbp),%eax
mov    $0x15180,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x15180,%ecx
cltd
idiv   %ecx
mov    %edx,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %edx,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11ab <small_duration+0x9b>
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
lea    0x2ea8(%rip),%rdi
lea    0xe61(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11f2 <small_duration+0xe2>
cmpl   $0x0,-0xc(%rbp)
je     11d5 <small_duration+0xc5>
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0x2e7e(%rip),%rdi
lea    0xe3b(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11ed <small_duration+0xdd>
mov    -0x10(%rbp),%edx
lea    0x2e61(%rip),%rdi
lea    0xe22(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11f2 <small_duration+0xe2>
lea    0x2e47(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<small_duration>:
push   %rax
movb   $0x0,0x2f28(%rip)
movslq %edi,%r9
imul   $0xffffffffc22e4507,%r9,%rdx
shr    $0x20,%rdx
add    %r9d,%edx
mov    %edx,%ecx
shr    $0x1f,%ecx
sar    $0x10,%edx
add    %ecx,%edx
imul   $0x15180,%edx,%ecx
mov    %r9d,%esi
sub    %ecx,%esi
movslq %esi,%rdi
imul   $0xffffffff91a2b3c5,%rdi,%rcx
shr    $0x20,%rcx
add    %esi,%ecx
mov    %ecx,%eax
shr    $0x1f,%eax
sar    $0xb,%ecx
add    %eax,%ecx
imul   $0xe10,%ecx,%eax
sub    %eax,%edi
movswl %di,%eax
imul   $0xffff8889,%eax,%eax
shr    $0x10,%eax
add    %edi,%eax
movzwl %ax,%eax
movswl %ax,%edi
shr    $0xf,%eax
sar    $0x5,%edi
add    %eax,%edi
movswl %di,%r8d
add    $0x1517f,%r9d
cmp    $0x2a2ff,%r9d
jae    11b8 <small_duration+0xa8>
add    $0xe0f,%esi
lea    0x2ea3(%rip),%rdi
cmp    $0x1c1f,%esi
jae    11cf <small_duration+0xbf>
lea    0xe5c(%rip),%rsi
mov    %r8d,%edx
xor    %eax,%eax
call   1030 <sprintf@plt>
jmp    11e2 <small_duration+0xd2>
lea    0x2e81(%rip),%rdi
lea    0xe3a(%rip),%rsi
xor    %eax,%eax
call   1030 <sprintf@plt>
jmp    11e2 <small_duration+0xd2>
lea    0xe2e(%rip),%rsi
mov    %ecx,%edx
mov    %r8d,%ecx
xor    %eax,%eax
call   1030 <sprintf@plt>
lea    0x2e57(%rip),%rax
pop    %rcx
ret

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

LLVM IR (-O2):
@small_duration.dbuffer = internal global [20 x i8] zeroinitializer
@.str = [12 x i8] c"%dd %dh %dm\00"
@.str.1 = [8 x i8] c"%dh %dm\00"
@.str.2 = [4 x i8] c"%dm\00"
define i8* @small_duration(i32 %0) {
store i8 0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @small_duration.dbuffer, i64 0, i64 0)
%2 = srem i32 %0, 86400
%3 = sdiv i32 %0, 86400
%4 = sdiv i32 %2, 3600
%5 = srem i32 %2, 3600
%6 = trunc i32 %5 to i16
%7 = sdiv i16 %6, 60
%8 = sext i16 %7 to i32
%9 = add i32 %0, 86399
%10 = icmp ult i32 %9, 172799
br i1 %10, label %13, label %11
11: ; preds = %1
%12 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @small_duration.dbuffer, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %4, i32 %8)
br label %20
13: ; preds = %1
%14 = add nsw i32 %2, 3599
%15 = icmp ult i32 %14, 7199
br i1 %15, label %18, label %16
16: ; preds = %13
%17 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @small_duration.dbuffer, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %4, i32 %8)
br label %20
18: ; preds = %13
%19 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @small_duration.dbuffer, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %8)
br label %20
20: ; preds = %16, %18, %11
ret i8* getelementptr inbounds ([20 x i8], [20 x i8]* @small_duration.dbuffer, i64 0, i64 0)
}