#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 snprintf(char *, int, char *, unsigned int, unsigned int, ...);
int rc_format_value_seconds(char *buffer, int size, unsigned seconds) {
  unsigned hours, minutes;
  minutes = seconds / 60;
  seconds -= minutes * 60;
  if (minutes < 60) {
    return snprintf(buffer, size, "%u:%02u", minutes, seconds);
  }
  hours = minutes / 60;
  minutes -= hours * 60;
  return snprintf(buffer, size, "%uh%02u:%02u", hours, minutes, seconds);
}


x86 assembly (clang, -O0):
<rc_format_value_seconds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x3c,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x20(%rbp)
imul   $0x3c,-0x20(%rbp),%ecx
mov    -0x18(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x3c,-0x20(%rbp)
jae    116b <rc_format_value_seconds+0x5b>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%r8d
lea    0xea4(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    %eax,-0x4(%rbp)
jmp    11a9 <rc_format_value_seconds+0x99>
mov    -0x20(%rbp),%eax
mov    $0x3c,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x1c(%rbp)
imul   $0x3c,-0x1c(%rbp),%ecx
mov    -0x20(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    -0x18(%rbp),%r9d
lea    0xe69(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rc_format_value_seconds>:
mov    %edx,%r8d
mov    $0x88888889,%ecx
imul   %r8,%rcx
shr    $0x25,%rcx
imul   $0xffffffc4,%ecx,%r9d
add    %edx,%r9d
cmp    $0xe0f,%edx
ja     1140 <rc_format_value_seconds+0x30>
lea    0xeca(%rip),%rdx
mov    %r9d,%r8d
xor    %eax,%eax
jmp    1030 <snprintf@plt>
mov    $0x91a2b3c5,%eax
imul   %r8,%rax
shr    $0x2b,%rax
imul   $0xffffffc4,%eax,%r8d
add    %ecx,%r8d
lea    0xead(%rip),%rdx
mov    %eax,%ecx
xor    %eax,%eax
jmp    1030 <snprintf@plt>

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

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