#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 int32_t;

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, int, ...);
char *time_pretty(int32_t time, char *buffer, int32_t size) {
  int32_t days = 0, hours = 0, minutes = 0, seconds = 0;
  buffer[0] = '\0';
  if (time > (24 * 60 * 60)) {
    days = time / (24 * 60 * 60);
    time -= (days * 24 * 60 * 60);
  }
  if (time > (60 * 60)) {
    hours = time / (60 * 60);
    time -= (hours * 60 * 60);
  }
  if (time > 60) {
    minutes = time / 60;
    time -= (minutes * 60);
  }
  seconds = time;
  if (days) {
    sprintf(buffer, "%dd %dh %dm %ds", days, hours, minutes, seconds);
  } else if (hours) {
    sprintf(buffer, "%dh %dm %ds", hours, minutes, seconds);
  } else if (minutes) {
    sprintf(buffer, "%dm %ds", minutes, seconds);
  } else {
    sprintf(buffer, "%ds", seconds);
  }
  return buffer;
}


x86 assembly (clang, -O0):
<time_pretty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
cmpl   $0x15180,-0x4(%rbp)
jle    1172 <time_pretty+0x62>
mov    -0x4(%rbp),%eax
mov    $0x15180,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
imul   $0x18,-0x18(%rbp),%eax
imul   $0x3c,%eax,%eax
imul   $0x3c,%eax,%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
cmpl   $0xe10,-0x4(%rbp)
jle    119c <time_pretty+0x8c>
mov    -0x4(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
imul   $0x3c,-0x1c(%rbp),%eax
imul   $0x3c,%eax,%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x3c,-0x4(%rbp)
jle    11c0 <time_pretty+0xb0>
mov    -0x4(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
imul   $0x3c,-0x20(%rbp),%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11f5 <time_pretty+0xe5>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    -0x24(%rbp),%r9d
lea    0xe17(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1266 <time_pretty+0x156>
cmpl   $0x0,-0x1c(%rbp)
je     1220 <time_pretty+0x110>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
lea    0xdf0(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1261 <time_pretty+0x151>
cmpl   $0x0,-0x20(%rbp)
je     1247 <time_pretty+0x137>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
lea    0xdcd(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    125c <time_pretty+0x14c>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xdb7(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1261 <time_pretty+0x151>
jmp    1266 <time_pretty+0x156>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<time_pretty>:
push   %rbx
mov    %rsi,%rbx
mov    %edi,%r9d
movb   $0x0,(%rsi)
xor    %ecx,%ecx
cmp    $0x15181,%edi
jl     1148 <time_pretty+0x38>
mov    %r9d,%eax
mov    $0xc22e4507,%edx
imul   %rax,%rdx
shr    $0x30,%rdx
imul   $0xfffeae80,%edx,%eax
add    %eax,%r9d
cmp    $0xe11,%r9d
jge    1153 <time_pretty+0x43>
jmp    116c <time_pretty+0x5c>
xor    %edx,%edx
cmp    $0xe11,%r9d
jl     116c <time_pretty+0x5c>
mov    %r9d,%eax
mov    $0x91a2b3c5,%ecx
imul   %rax,%rcx
shr    $0x2b,%rcx
imul   $0xfffff1f0,%ecx,%eax
add    %eax,%r9d
xor    %r8d,%r8d
cmp    $0x3d,%r9d
jl     118d <time_pretty+0x7d>
mov    %r9d,%eax
mov    $0x88888889,%r8d
imul   %rax,%r8
shr    $0x25,%r8
imul   $0xffffffc4,%r8d,%eax
add    %eax,%r9d
test   %edx,%edx
je     11a4 <time_pretty+0x94>
lea    0xe68(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <sprintf@plt>
jmp    11f5 <time_pretty+0xe5>
test   %ecx,%ecx
je     11c3 <time_pretty+0xb3>
lea    0xe55(%rip),%rsi
mov    %rbx,%rdi
mov    %ecx,%edx
mov    %r8d,%ecx
mov    %r9d,%r8d
xor    %eax,%eax
call   1030 <sprintf@plt>
jmp    11f5 <time_pretty+0xe5>
test   %r8d,%r8d
je     11e1 <time_pretty+0xd1>
lea    0xe39(%rip),%rsi
mov    %rbx,%rdi
mov    %r8d,%edx
mov    %r9d,%ecx
xor    %eax,%eax
call   1030 <sprintf@plt>
jmp    11f5 <time_pretty+0xe5>
lea    0xe24(%rip),%rsi
mov    %rbx,%rdi
mov    %r9d,%edx
xor    %eax,%eax
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [16 x i8] c"%dd %dh %dm %ds\00"
@.str.1 = [12 x i8] c"%dh %dm %ds\00"
@.str.2 = [8 x i8] c"%dm %ds\00"
@.str.3 = [4 x i8] c"%ds\00"
define i8* @time_pretty(i32 %0, i8* returned writeonly %1, i32 %2) {
store i8 0, i8* %1
%4 = icmp sgt i32 %0, 86400
br i1 %4, label %5, label %9
5: ; preds = %3
%6 = udiv i32 %0, 86400
%7 = mul nsw i32 %6, -86400
%8 = add nsw i32 %7, %0
br label %9
9: ; preds = %5, %3
%10 = phi i32 [ %8, %5 ], [ %0, %3 ]
%11 = phi i32 [ %6, %5 ], [ 0, %3 ]
%12 = icmp sgt i32 %10, 3600
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = udiv i32 %10, 3600
%15 = mul nsw i32 %14, -3600
%16 = add nsw i32 %15, %10
br label %17
17: ; preds = %13, %9
%18 = phi i32 [ %16, %13 ], [ %10, %9 ]
%19 = phi i32 [ %14, %13 ], [ 0, %9 ]
%20 = icmp sgt i32 %18, 60
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = udiv i32 %18, 60
%23 = mul nsw i32 %22, -60
%24 = add nsw i32 %23, %18
br label %25
25: ; preds = %21, %17
%26 = phi i32 [ %24, %21 ], [ %18, %17 ]
%27 = phi i32 [ %22, %21 ], [ 0, %17 ]
%28 = icmp eq i32 %11, 0
br i1 %28, label %31, label %29
29: ; preds = %25
%30 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* %1, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %19, i32 %27, i32 %26)
br label %41
31: ; preds = %25
%32 = icmp eq i32 %19, 0
br i1 %32, label %35, label %33
33: ; preds = %31
%34 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* %1, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 %27, i32 %26)
br label %41
35: ; preds = %31
%36 = icmp eq i32 %27, 0
br i1 %36, label %39, label %37
37: ; preds = %35
%38 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* %1, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %27, i32 %26)
br label %41
39: ; preds = %35
%40 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* %1, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %26)
br label %41
41: ; preds = %33, %39, %37, %29
ret i8* %1
}