#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, size_t, ...);
int print_human_readable_time(FILE *stream, size_t time) {
  size_t hr_ms = time % 1000;
  size_t hr_s = time / 1000;
  size_t hr_m = hr_s / 60;
  size_t hr_h = hr_m / 60;
  hr_m = hr_m % 60;
  hr_s = hr_s % 60;
  if (hr_h != 0) {
    fprintf(stream, "%zu hours, ", hr_h);
  }
  if (hr_m != 0) {
    fprintf(stream, "%zu minutes, ", hr_m);
  }
  if (hr_s != 0) {
    hr_ms = (hr_ms + 5) / 10;
    fprintf(stream, "%zu.%02zu seconds (%zu ms)", hr_s, hr_ms, time);
  } else {
    fprintf(stream, "%zu milliseconds (%zu ms)", hr_ms, time);
  }
  return (0);
}


x86 assembly (clang, -O0):
<print_human_readable_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    $0x3c,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    $0x3c,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    $0x3c,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    $0x3c,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11ad <print_human_readable_time+0x9d>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xe5a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
cmpq   $0x0,-0x28(%rbp)
je     11ce <print_human_readable_time+0xbe>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xe45(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
cmpq   $0x0,-0x20(%rbp)
je     1212 <print_human_readable_time+0x102>
mov    -0x18(%rbp),%rax
add    $0x5,%rax
mov    $0xa,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xe14(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    122c <print_human_readable_time+0x11c>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe10(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_human_readable_time>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rax
shr    $0x3,%rax
movabs $0x20c49ba5e353f7cf,%rcx
9b c4 20
mul    %rcx
mov    %rdx,%r12
shr    $0x4,%r12
mov    %rsi,%rax
shr    $0x5,%rax
movabs $0x45e7b272f608771,%rcx
7b 5e 04
mul    %rcx
mov    %rdx,%rbx
shr    $0x5,%rbx
movabs $0x8888888888888889,%rcx
88 88 88
mov    %rbx,%rax
mul    %rcx
shr    $0x5,%rdx
imul   $0x3c,%rdx,%rsi
mov    %r12,%rax
mul    %rcx
sub    %rsi,%rbx
shr    $0x5,%rdx
imul   $0x3c,%rdx,%r13
cmp    $0x36ee80,%r15
jb     11ae <print_human_readable_time+0x9e>
movabs $0x4a90be587de6e565,%rcx
be 90 4a
mov    %r15,%rax
mul    %rcx
shr    $0x14,%rdx
lea    0xe5c(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <fprintf@plt>
imul   $0x3e8,%r12,%rbp
sub    %r13,%r12
test   %rbx,%rbx
je     11d1 <print_human_readable_time+0xc1>
lea    0xe48(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %r15,%rdx
sub    %rbp,%rdx
test   %r12,%r12
je     1204 <print_human_readable_time+0xf4>
add    $0x5,%edx
movzwl %dx,%eax
imul   $0xcccd,%eax,%ecx
shr    $0x13,%ecx
lea    0xe28(%rip),%rsi
mov    %r14,%rdi
mov    %r12,%rdx
mov    %r15,%r8
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    1218 <print_human_readable_time+0x108>
lea    0xe2a(%rip),%rsi
mov    %r14,%rdi
mov    %r15,%rcx
xor    %eax,%eax
call   1030 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%zu hours, \00"
@.str.1 = [14 x i8] c"%zu minutes, \00"
@.str.2 = [27 x i8] c"%zu.%02zu seconds (%zu ms)\00"
@.str.3 = [26 x i8] c"%zu milliseconds (%zu ms)\00"
define i32 @print_human_readable_time(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i32* %0, i32** %3
store i64 %1, i64* %4
%9 = load i64, i64* %4
%10 = urem i64 %9, 1000
store i64 %10, i64* %5
%11 = load i64, i64* %4
%12 = udiv i64 %11, 1000
store i64 %12, i64* %6
%13 = load i64, i64* %6
%14 = udiv i64 %13, 60
store i64 %14, i64* %7
%15 = load i64, i64* %7
%16 = udiv i64 %15, 60
store i64 %16, i64* %8
%17 = load i64, i64* %7
%18 = urem i64 %17, 60
store i64 %18, i64* %7
%19 = load i64, i64* %6
%20 = urem i64 %19, 60
store i64 %20, i64* %6
%21 = load i64, i64* %8
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %2
%24 = load i32*, i32** %3
%25 = load i64, i64* %8
%26 = call i32 (i32*, i8*, i64, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i64 %25)
br label %27
27: ; preds = %23, %2
%28 = load i64, i64* %7
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = load i32*, i32** %3
%32 = load i64, i64* %7
%33 = call i32 (i32*, i8*, i64, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i64 %32)
br label %34
34: ; preds = %30, %27
%35 = load i64, i64* %6
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %46
37: ; preds = %34
%38 = load i64, i64* %5
%39 = add i64 %38, 5
%40 = udiv i64 %39, 10
store i64 %40, i64* %5
%41 = load i32*, i32** %3
%42 = load i64, i64* %6
%43 = load i64, i64* %5
%44 = load i64, i64* %4
%45 = call i32 (i32*, i8*, i64, ...) @fprintf(i32* %41, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i64 %42, i64 %43, i64 %44)
br label %51
46: ; preds = %34
%47 = load i32*, i32** %3
%48 = load i64, i64* %5
%49 = load i64, i64* %4
%50 = call i32 (i32*, i8*, i64, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i64 %48, i64 %49)
br label %51
51: ; preds = %46, %37
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"%zu hours, \00"
@.str.1 = [14 x i8] c"%zu minutes, \00"
@.str.2 = [27 x i8] c"%zu.%02zu seconds (%zu ms)\00"
@.str.3 = [26 x i8] c"%zu milliseconds (%zu ms)\00"
define i32 @print_human_readable_time(i32* nocapture %0, i64 %1) {
%3 = urem i64 %1, 1000
%4 = udiv i64 %1, 1000
%5 = udiv i64 %1, 60000
%6 = urem i64 %5, 60
%7 = urem i64 %4, 60
%8 = icmp ult i64 %1, 3600000
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = udiv i64 %1, 3600000
%11 = tail call i32 (i32*, i8*, i64, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i64 %10)
br label %12
12: ; preds = %9, %2
%13 = icmp eq i64 %6, 0
br i1 %13, label %16, label %14
14: ; preds = %12
%15 = tail call i32 (i32*, i8*, i64, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i64 %6)
br label %16
16: ; preds = %14, %12
%17 = icmp eq i64 %7, 0
br i1 %17, label %24, label %18
18: ; preds = %16
%19 = trunc i64 %3 to i16
%20 = add nuw nsw i16 %19, 5
%21 = udiv i16 %20, 10
%22 = zext i16 %21 to i64
%23 = tail call i32 (i32*, i8*, i64, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i64 %7, i64 %22, i64 %1)
br label %26
24: ; preds = %16
%25 = tail call i32 (i32*, i8*, i64, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i64 %3, i64 %1)
br label %26
26: ; preds = %24, %18
ret i32 0
}