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

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, size_t, char *, int, int);
char *human_time(char *buf, size_t buf_len, time_t interval) {
  int days = (int)(interval / (24 * 60 * 60));
  int hours = (int)((interval % (24 * 60 * 60)) / (60 * 60));
  int minutes = (int)((interval % (60 * 60)) / 60);
  int seconds = (int)(interval % 60);
  if (days)
    snprintf(buf, buf_len, "%02dd %02dh", days, hours);
  else if (hours)
    snprintf(buf, buf_len, "%02dh %02dm", hours, minutes);
  else
    snprintf(buf, buf_len, "%02dm %02ds", minutes, seconds);
  return buf;
}


x86 assembly (clang, -O0):
<human_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x15180,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x15180,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,-0x24(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1199 <human_time+0x89>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
lea    0xe71(%rip),%rdx
call   1030 <snprintf@plt>
jmp    11e3 <human_time+0xd3>
cmpl   $0x0,-0x1c(%rbp)
je     11c3 <human_time+0xb3>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
lea    0xe53(%rip),%rdx
call   1030 <snprintf@plt>
jmp    11de <human_time+0xce>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
lea    0xe3f(%rip),%rdx
call   1030 <snprintf@plt>
jmp    11e3 <human_time+0xd3>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<human_time>:
push   %rbx
mov    %rdi,%rbx
movslq %edx,%r8
imul   $0xffffffffc22e4507,%r8,%rcx
shr    $0x20,%rcx
add    %r8d,%ecx
mov    %ecx,%eax
shr    $0x1f,%eax
sar    $0x10,%ecx
add    %eax,%ecx
imul   $0x15180,%ecx,%eax
mov    %r8d,%edx
sub    %eax,%edx
movslq %edx,%rax
imul   $0xffffffff91a2b3c5,%rax,%rax
shr    $0x20,%rax
add    %edx,%eax
mov    %eax,%edi
shr    $0x1f,%edi
sar    $0xb,%eax
add    %edi,%eax
lea    0x1517f(%r8),%edi
cmp    $0x2a2ff,%edi
jae    11e1 <human_time+0xd1>
imul   $0xffffffff91a2b3c5,%r8,%rcx
shr    $0x20,%rcx
add    %r8d,%ecx
mov    %ecx,%edi
shr    $0x1f,%edi
sar    $0xb,%ecx
add    %edi,%ecx
imul   $0xe10,%ecx,%ecx
mov    %r8d,%edi
sub    %ecx,%edi
movswl %di,%ecx
imul   $0xffff8889,%ecx,%ecx
shr    $0x10,%ecx
add    %edi,%ecx
movzwl %cx,%ecx
movswl %cx,%edi
shr    $0xf,%ecx
sar    $0x5,%edi
add    %ecx,%edi
movswl %di,%r9d
add    $0xe0f,%edx
cmp    $0x1c1f,%edx
jae    11f0 <human_time+0xe0>
imul   $0xffffffff88888889,%r8,%rax
shr    $0x20,%rax
add    %r8d,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x5,%eax
add    %ecx,%eax
imul   $0x3c,%eax,%eax
sub    %eax,%r8d
lea    0xe3f(%rip),%rdx
mov    %rbx,%rdi
mov    %r9d,%ecx
jmp    11ff <human_time+0xef>
lea    0xe18(%rip),%rdx
mov    %rbx,%rdi
mov    %eax,%r8d
jmp    11ff <human_time+0xef>
lea    0xe15(%rip),%rdx
mov    %rbx,%rdi
mov    %eax,%ecx
mov    %r9d,%r8d
call   1030 <snprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

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

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