#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*/ sprintf(char *, char *, int, ...);
void hms(char *str, int s) {
  int h = 0;
  int m = 0;
  if (s > 60.0) {
    if (s > 3600.0) {
      h = (int)s / 3600;
      s -= (int)h * 3600;
    }
    m = (int)s / 60;
    s -= (int)m * 60;
  }
  if (h)
    sprintf(str, "%dh %dm %ds", h, m, s);
  else if (m)
    sprintf(str, "%dm %ds", m, s);
  else
    sprintf(str, "%ds", s);
}


x86 assembly (clang, -O0):
<hms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  0xec6(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1192 <hms+0x82>
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  0xeb7(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1178 <hms+0x68>
mov    -0xc(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
imul   $0xe10,-0x10(%rbp),%ecx
mov    -0xc(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
imul   $0x3c,-0x14(%rbp),%ecx
mov    -0xc(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11bd <hms+0xad>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0xc(%rbp),%r8d
lea    0xe5f(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11fe <hms+0xee>
cmpl   $0x0,-0x14(%rbp)
je     11e4 <hms+0xd4>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xe3c(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11f9 <hms+0xe9>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe26(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11fe <hms+0xee>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hms>:
mov    %esi,%eax
cmp    $0x3d,%esi
jl     1164 <hms+0x54>
cmp    $0xe10,%eax
jbe    1174 <hms+0x64>
mov    %eax,%ecx
mov    $0x91a2b3c5,%edx
imul   %rcx,%rdx
shr    $0x2b,%rdx
imul   $0xfffff1f0,%edx,%ecx
add    %eax,%ecx
movslq %ecx,%rax
imul   $0xffffffff88888889,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%esi
shr    $0x1f,%esi
sar    $0x5,%ecx
add    %esi,%ecx
imul   $0xffffffc4,%ecx,%r8d
add    %eax,%r8d
lea    0xea3(%rip),%rsi
xor    %eax,%eax
jmp    1030 <sprintf@plt>
lea    0xe9d(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
jmp    1030 <sprintf@plt>
movzwl %ax,%ecx
imul   $0x8889,%ecx,%edx
shr    $0x15,%edx
imul   $0xffffffc4,%edx,%ecx
add    %eax,%ecx
lea    0xe78(%rip),%rsi
xor    %eax,%eax
jmp    1030 <sprintf@plt>

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 void @hms(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
%7 = load i32, i32* %4
%8 = sitofp i32 %7 to double
%9 = fcmp ogt double %8, 6.000000e+01
br i1 %9, label %10, label %28
10: ; preds = %2
%11 = load i32, i32* %4
%12 = sitofp i32 %11 to double
%13 = fcmp ogt double %12, 3.600000e+03
br i1 %13, label %14, label %21
14: ; preds = %10
%15 = load i32, i32* %4
%16 = sdiv i32 %15, 3600
store i32 %16, i32* %5
%17 = load i32, i32* %5
%18 = mul nsw i32 %17, 3600
%19 = load i32, i32* %4
%20 = sub nsw i32 %19, %18
store i32 %20, i32* %4
br label %21
21: ; preds = %14, %10
%22 = load i32, i32* %4
%23 = sdiv i32 %22, 60
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = mul nsw i32 %24, 60
%26 = load i32, i32* %4
%27 = sub nsw i32 %26, %25
store i32 %27, i32* %4
br label %28
28: ; preds = %21, %2
%29 = load i32, i32* %5
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %28
%32 = load i8*, i8** %3
%33 = load i32, i32* %5
%34 = load i32, i32* %6
%35 = load i32, i32* %4
%36 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %32, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %33, i32 %34, i32 %35)
br label %50
37: ; preds = %28
%38 = load i32, i32* %6
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %37
%41 = load i8*, i8** %3
%42 = load i32, i32* %6
%43 = load i32, i32* %4
%44 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %41, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %42, i32 %43)
br label %49
45: ; preds = %37
%46 = load i8*, i8** %3
%47 = load i32, i32* %4
%48 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %46, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %45, %40
br label %50
50: ; preds = %49, %31
ret void
}

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 void @hms(i8* nocapture writeonly %0, i32 %1) {
%3 = icmp sgt i32 %1, 60
br i1 %3, label %4, label %21
4: ; preds = %2
%5 = icmp ugt i32 %1, 3600
br i1 %5, label %13, label %6
6: ; preds = %4
%7 = trunc i32 %1 to i16
%8 = udiv i16 %7, 60
%9 = zext i16 %8 to i32
%10 = mul nsw i32 %9, -60
%11 = add nsw i32 %10, %1
%12 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 %11)
br label %23
13: ; preds = %4
%14 = udiv i32 %1, 3600
%15 = mul nsw i32 %14, -3600
%16 = add nsw i32 %15, %1
%17 = sdiv i32 %16, 60
%18 = mul nsw i32 %17, -60
%19 = add i32 %18, %16
%20 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %17, i32 %19)
br label %23
21: ; preds = %2
%22 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %1)
br label %23
23: ; preds = %6, %21, %13
ret void
}