#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*/ sprintf(char *, char *, int, ...);
char *human_time(time_t t, char *text) {
  int h, m, s;
  h = (int)(t / (60 * 60));
  m = (int)((t % (60 * 60)) / 60);
  s = (int)(t % (60 * 60) % 60);
  if (h > 0) {
    sprintf(text, "%dh %dm %ds", h, m, s);
  } else if (m > 0) {
    sprintf(text, "%dm %ds", m, s);
  } else {
    sprintf(text, "%ds", s);
  }
  return text;
}


x86 assembly (clang, -O0):
<human_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1188 <human_time+0x78>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
lea    0xe84(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11c9 <human_time+0xb9>
cmpl   $0x0,-0x18(%rbp)
jle    11af <human_time+0x9f>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xe61(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11c4 <human_time+0xb4>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe4b(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11c9 <human_time+0xb9>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<human_time>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
movslq %edi,%rax
imul   $0xffffffff91a2b3c5,%rax,%rcx
shr    $0x20,%rcx
add    %edi,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0xb,%ecx
add    %edx,%ecx
imul   $0xe10,%ecx,%ecx
mov    %eax,%ebx
sub    %ecx,%ebx
movswl %bx,%ecx
imul   $0xffff8889,%ecx,%ecx
shr    $0x10,%ecx
add    %ebx,%ecx
movzwl %cx,%ecx
movswl %cx,%esi
shr    $0xf,%ecx
sar    $0x5,%esi
add    %ecx,%esi
movswl %si,%ecx
imul   $0x3c,%esi,%esi
mov    %ebx,%edx
sub    %esi,%edx
movswl %dx,%r8d
cmp    $0xe10,%eax
jl     118e <human_time+0x7e>
mov    %edi,%eax
mov    $0x91a2b3c5,%edx
imul   %rax,%rdx
shr    $0x2b,%rdx
lea    0xe7e(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <sprintf@plt>
jmp    11bf <human_time+0xaf>
cmp    $0x3c,%ebx
jl     11ab <human_time+0x9b>
lea    0xe6a(%rip),%rsi
mov    %r14,%rdi
mov    %ecx,%edx
mov    %r8d,%ecx
xor    %eax,%eax
call   1030 <sprintf@plt>
jmp    11bf <human_time+0xaf>
lea    0xe56(%rip),%rsi
mov    %r14,%rdi
mov    %r8d,%edx
xor    %eax,%eax
call   1030 <sprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [12 x i8] c"%dh %dm %ds\00"
@.str.1 = [8 x i8] c"%dm %ds\00"
@.str.2 = [4 x i8] c"%ds\00"
define i8* @human_time(i32 %0, i8* returned writeonly %1) {
%3 = srem i32 %0, 3600
%4 = trunc i32 %3 to i16
%5 = sdiv i16 %4, 60
%6 = sext i16 %5 to i32
%7 = srem i16 %4, 60
%8 = sext i16 %7 to i32
%9 = icmp sgt i32 %0, 3599
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = udiv i32 %0, 3600
%12 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %6, i32 %8)
br label %19
13: ; preds = %2
%14 = icmp sgt i32 %3, 59
br i1 %14, label %15, label %17
15: ; preds = %13
%16 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %6, i32 %8)
br label %19
17: ; preds = %13
%18 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %8)
br label %19
19: ; preds = %15, %17, %10
ret i8* %1
}