#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 sprintf(char *, char *, int);
char *statstr_dup(char *, int);
char *secs2str_short(int t) {
  char tstr[20];
  int len;
  int h, m, s;
  h = t / 3600;
  t = t % 3600;
  m = t / 60;
  s = t % 60;
  if (h > 99)
    h = 99;
  if (h)
    len = sprintf(tstr, "%dh", h);
  else if (m)
    len = sprintf(tstr, "%dm", m);
  else
    len = sprintf(tstr, "%ds", s);
  if (len < 0)
    len = 0;
  return statstr_dup(tstr, len);
}


x86 assembly (clang, -O0):
<secs2str_short>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x28(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %edx,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x2c(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,-0x30(%rbp)
cmpl   $0x63,-0x28(%rbp)
jle    1174 <secs2str_short+0x54>
movl   $0x63,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     1199 <secs2str_short+0x79>
lea    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%edx
lea    0xe74(%rip),%rsi
call   1040 <sprintf@plt>
mov    %eax,-0x24(%rbp)
jmp    11d9 <secs2str_short+0xb9>
cmpl   $0x0,-0x2c(%rbp)
je     11be <secs2str_short+0x9e>
lea    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%edx
lea    0xe53(%rip),%rsi
call   1040 <sprintf@plt>
mov    %eax,-0x24(%rbp)
jmp    11d4 <secs2str_short+0xb4>
lea    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%edx
lea    0xe3c(%rip),%rsi
call   1040 <sprintf@plt>
mov    %eax,-0x24(%rbp)
jmp    11d9 <secs2str_short+0xb9>
cmpl   $0x0,-0x24(%rbp)
jge    11ea <secs2str_short+0xca>
movl   $0x0,-0x24(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1030 <statstr_dup@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<secs2str_short>:
sub    $0x18,%rsp
movslq %edi,%rax
imul   $0xffffffff91a2b3c5,%rax,%rax
shr    $0x20,%rax
add    %edi,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0xb,%eax
add    %ecx,%eax
cmp    $0x63,%eax
mov    $0x63,%edx
cmovl  %eax,%edx
test   %edx,%edx
je     1156 <secs2str_short+0x36>
lea    0xeac(%rip),%rsi
jmp    119d <secs2str_short+0x7d>
imul   $0xe10,%eax,%eax
sub    %eax,%edi
movswl %di,%eax
imul   $0xffff8889,%eax,%eax
shr    $0x10,%eax
add    %edi,%eax
movzwl %ax,%ecx
movswl %cx,%eax
shr    $0xf,%ecx
sar    $0x5,%eax
add    %ecx,%eax
lea    0x3b(%rdi),%ecx
cmp    $0x77,%ecx
jae    1193 <secs2str_short+0x73>
imul   $0x3c,%eax,%eax
sub    %eax,%edi
movswl %di,%edx
lea    0xe77(%rip),%rsi
jmp    119d <secs2str_short+0x7d>
movswl %ax,%edx
lea    0xe67(%rip),%rsi
mov    %rsp,%rdi
call   1040 <sprintf@plt>
xor    %esi,%esi
test   %eax,%eax
cmovns %eax,%esi
mov    %rsp,%rdi
call   1030 <statstr_dup@plt>
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%dh\00"
@.str.1 = [4 x i8] c"%dm\00"
@.str.2 = [4 x i8] c"%ds\00"
define i8* @secs2str_short(i32 %0) {
%2 = alloca [20 x i8]
%3 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%4 = sdiv i32 %0, 3600
%5 = srem i32 %0, 3600
%6 = trunc i32 %5 to i16
%7 = sdiv i16 %6, 60
%8 = sext i16 %7 to i32
%9 = srem i16 %6, 60
%10 = sext i16 %9 to i32
%11 = icmp slt i32 %4, 99
%12 = select i1 %11, i32 %4, i32 99
%13 = icmp eq i32 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %1
%15 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %23
16: ; preds = %1
%17 = add nsw i32 %5, 59
%18 = icmp ult i32 %17, 119
br i1 %18, label %21, label %19
19: ; preds = %16
%20 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %8)
br label %23
21: ; preds = %16
%22 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %10)
br label %23
23: ; preds = %19, %21, %14
%24 = phi i32 [ %15, %14 ], [ %20, %19 ], [ %22, %21 ]
%25 = icmp sgt i32 %24, 0
%26 = select i1 %25, i32 %24, i32 0
%27 = call i8* @statstr_dup(i8* %3, i32 %26)
ret i8* %27
}