#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*/ printf(char *, ...);
void print_duration(int secs) {
  int hours = secs / 3600;
  secs -= (hours * 3600);
  int mins = secs / 60;
  secs -= (mins * 60);
  char *sep = "";
  if (hours > 0) {
    printf("%d hours", hours);
    sep = ", ";
  }
  if (mins > 0) {
    printf("%s%d minutes", sep, mins);
    sep = ", ";
  }
  printf("%s%d seconds", sep, secs);
}


x86 assembly (clang, -O0):
<print_duration>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
imul   $0xe10,-0x8(%rbp),%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
imul   $0x3c,-0xc(%rbp),%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
lea    0xeb2(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    1183 <print_duration+0x73>
mov    -0x8(%rbp),%esi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe8a(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    11ad <print_duration+0x9d>
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe60(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x4(%rbp),%edx
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_duration>:
push   %rbp
push   %r14
push   %rbx
movslq %edi,%rax
imul   $0xffffffff91a2b3c5,%rax,%rsi
shr    $0x20,%rsi
add    %eax,%esi
mov    %esi,%ecx
shr    $0x1f,%ecx
sar    $0xb,%esi
add    %ecx,%esi
imul   $0xfffff1f0,%esi,%ebp
add    %eax,%ebp
movslq %ebp,%rcx
imul   $0xffffffff88888889,%rcx,%rbx
shr    $0x20,%rbx
add    %ebp,%ebx
mov    %ebx,%r14d
shr    $0x1f,%r14d
sar    $0x5,%ebx
cmp    $0xe10,%eax
jl     116e <print_duration+0x5e>
lea    0xea2(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe9d(%rip),%rsi
jmp    1175 <print_duration+0x65>
lea    0xe96(%rip),%rsi
add    %r14d,%ebx
cmp    $0x3c,%ebp
jl     1194 <print_duration+0x84>
lea    0xe88(%rip),%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe75(%rip),%rsi
imul   $0xffffffc4,%ebx,%edx
add    %ebp,%edx
lea    0xe79(%rip),%rdi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [9 x i8] c"%d hours\00"
@.str.2 = [3 x i8] c", \00"
@.str.3 = [13 x i8] c"%s%d minutes\00"
@.str.4 = [13 x i8] c"%s%d seconds\00"
define void @print_duration(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = sdiv i32 %6, 3600
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = mul nsw i32 %8, 3600
%10 = load i32, i32* %2
%11 = sub nsw i32 %10, %9
store i32 %11, i32* %2
%12 = load i32, i32* %2
%13 = sdiv i32 %12, 60
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = mul nsw i32 %14, 60
%16 = load i32, i32* %2
%17 = sub nsw i32 %16, %15
store i32 %17, i32* %2
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %5
%18 = load i32, i32* %3
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %1
%21 = load i32, i32* %3
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %21)
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %5
br label %23
23: ; preds = %20, %1
%24 = load i32, i32* %4
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = load i8*, i8** %5
%28 = load i32, i32* %4
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %27, i32 %28)
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %5
br label %30
30: ; preds = %26, %23
%31 = load i8*, i8** %5
%32 = load i32, i32* %2
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %31, i32 %32)
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [9 x i8] c"%d hours\00"
@.str.2 = [3 x i8] c", \00"
@.str.3 = [13 x i8] c"%s%d minutes\00"
@.str.4 = [13 x i8] c"%s%d seconds\00"
define void @print_duration(i32 %0) {
%2 = sdiv i32 %0, 3600
%3 = mul nsw i32 %2, -3600
%4 = add i32 %3, %0
%5 = sdiv i32 %4, 60
%6 = icmp sgt i32 %0, 3599
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %2)
br label %9
9: ; preds = %7, %1
%10 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %7 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %1 ]
%11 = icmp sgt i32 %4, 59
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %10, i32 %5)
br label %14
14: ; preds = %12, %9
%15 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %12 ], [ %10, %9 ]
%16 = mul nsw i32 %5, -60
%17 = add i32 %16, %4
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* %15, i32 %17)
ret void
}