#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*/ snprintf(char *, size_t, char *, unsigned int, ...);
char *str_seconds(unsigned int seconds, char *buf, size_t size) {
  unsigned int hours, minutes;
  hours = seconds / 60 / 60;
  minutes = seconds / 60 - hours * 60;
  seconds = seconds - minutes * 60 - hours * 60 * 60;
  if (hours)
    snprintf(buf, size, "%uh %um %us", hours, minutes, seconds);
  else if (minutes)
    snprintf(buf, size, "%um %us", minutes, seconds);
  else
    snprintf(buf, size, "%us", seconds);
  return buf;
}


x86 assembly (clang, -O0):
<str_seconds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3c,%ecx
xor    %edx,%edx
div    %ecx
mov    $0x3c,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3c,%ecx
xor    %edx,%edx
div    %ecx
imul   $0x3c,-0x1c(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
imul   $0x3c,-0x20(%rbp),%ecx
sub    %ecx,%eax
imul   $0x3c,-0x1c(%rbp),%ecx
imul   $0x3c,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1195 <str_seconds+0x85>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    -0x4(%rbp),%r9d
lea    0xe77(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    11df <str_seconds+0xcf>
cmpl   $0x0,-0x20(%rbp)
je     11c1 <str_seconds+0xb1>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%ecx
mov    -0x4(%rbp),%r8d
lea    0xe4f(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    11da <str_seconds+0xca>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x4(%rbp),%ecx
lea    0xe35(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    11df <str_seconds+0xcf>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_seconds>:
push   %rbx
mov    %rsi,%rbx
mov    %edi,%eax
mov    $0x88888889,%esi
imul   %rax,%rsi
shr    $0x25,%rsi
mov    $0x91a2b3c5,%ecx
imul   %rax,%rcx
shr    $0x2b,%rcx
imul   $0xffffffc4,%ecx,%r8d
add    %esi,%r8d
imul   $0xffffffc4,%r8d,%eax
imul   $0xfffff1f0,%ecx,%r9d
add    %edi,%r9d
add    %eax,%r9d
cmp    $0xe10,%edi
jae    1174 <str_seconds+0x64>
test   %r8d,%r8d
je     118d <str_seconds+0x7d>
lea    0xea8(%rip),%rax
mov    %rbx,%rdi
mov    %rdx,%rsi
mov    %rax,%rdx
mov    %r8d,%ecx
mov    %r9d,%r8d
xor    %eax,%eax
call   1030 <snprintf@plt>
jmp    11a7 <str_seconds+0x97>
lea    0xe85(%rip),%rax
mov    %rbx,%rdi
mov    %rdx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <snprintf@plt>
jmp    11a7 <str_seconds+0x97>
lea    0xe74(%rip),%rax
mov    %rbx,%rdi
mov    %rdx,%rsi
mov    %rax,%rdx
mov    %r9d,%ecx
xor    %eax,%eax
call   1030 <snprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [12 x i8] c"%uh %um %us\00"
@.str.1 = [8 x i8] c"%um %us\00"
@.str.2 = [4 x i8] c"%us\00"
define i8* @str_seconds(i32 %0, i8* returned %1, i64 %2) {
%4 = udiv i32 %0, 60
%5 = udiv i32 %0, 3600
%6 = mul nsw i32 %5, -60
%7 = add nsw i32 %6, %4
%8 = mul i32 %7, -60
%9 = mul i32 %5, -3600
%10 = add i32 %9, %0
%11 = add i32 %10, %8
%12 = icmp ult i32 %0, 3600
br i1 %12, label %15, label %13
13: ; preds = %3
%14 = tail call i32 (i8*, i64, i8*, i32, ...) @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %7, i32 %11)
br label %21
15: ; preds = %3
%16 = icmp eq i32 %7, 0
br i1 %16, label %19, label %17
17: ; preds = %15
%18 = tail call i32 (i8*, i64, i8*, i32, ...) @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 %11)
br label %21
19: ; preds = %15
%20 = tail call i32 (i8*, i64, i8*, i32, ...) @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %11)
br label %21
21: ; preds = %17, %19, %13
ret i8* %1
}