#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 */
typedef int uint32_t;

/* Variables and functions */
int dec2bcd(int);
uint32_t ts_time_encode_bcd(int duration_sec) {
  int t_sec, t_min, t_hour, ret;
  t_sec = duration_sec % 60;
  t_min = (duration_sec - t_sec) / 60;
  t_hour = (t_min - t_min % 60) / 60;
  t_min = t_min - t_hour * 60;
  ret = dec2bcd(t_hour) << 16;
  ret |= dec2bcd(t_min) << 8;
  ret |= dec2bcd(t_sec);
  return ret;
}


x86 assembly (clang, -O0):
<ts_time_encode_bcd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
mov    -0x4(%rbp),%eax
sub    -0x8(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    -0x18(%rbp),%eax
sub    %edx,%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
imul   $0x3c,-0x10(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <dec2bcd@plt>
shl    $0x10,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <dec2bcd@plt>
shl    $0x8,%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <dec2bcd@plt>
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ts_time_encode_bcd>:
push   %rbp
push   %r14
push   %rbx
movslq %edi,%rbx
imul   $0xffffffff88888889,%rbx,%rax
shr    $0x20,%rax
add    %ebx,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x5,%eax
add    %ecx,%eax
imul   $0x3c,%eax,%ecx
imul   $0xffffffff91a2b3c5,%rbx,%rdi
shr    $0x20,%rdi
add    %ebx,%edi
sub    %ecx,%ebx
mov    %edi,%ecx
shr    $0x1f,%ecx
sar    $0xb,%edi
add    %ecx,%edi
imul   $0xffffffc4,%edi,%ebp
add    %eax,%ebp
call   1030 <dec2bcd@plt>
mov    %eax,%r14d
shl    $0x10,%r14d
mov    %ebp,%edi
call   1030 <dec2bcd@plt>
mov    %eax,%ebp
shl    $0x8,%ebp
mov    %ebx,%edi
call   1030 <dec2bcd@plt>
or     %r14d,%eax
or     %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ts_time_encode_bcd(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = srem i32 %7, 60
store i32 %8, i32* %3
%9 = load i32, i32* %2
%10 = load i32, i32* %3
%11 = sub nsw i32 %9, %10
%12 = sdiv i32 %11, 60
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = load i32, i32* %4
%15 = srem i32 %14, 60
%16 = sub nsw i32 %13, %15
%17 = sdiv i32 %16, 60
store i32 %17, i32* %5
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = mul nsw i32 %19, 60
%21 = sub nsw i32 %18, %20
store i32 %21, i32* %4
%22 = load i32, i32* %5
%23 = call i32 @dec2bcd(i32 %22)
%24 = shl i32 %23, 16
store i32 %24, i32* %6
%25 = load i32, i32* %4
%26 = call i32 @dec2bcd(i32 %25)
%27 = shl i32 %26, 8
%28 = load i32, i32* %6
%29 = or i32 %28, %27
store i32 %29, i32* %6
%30 = load i32, i32* %3
%31 = call i32 @dec2bcd(i32 %30)
%32 = load i32, i32* %6
%33 = or i32 %32, %31
store i32 %33, i32* %6
%34 = load i32, i32* %6
ret i32 %34
}

LLVM IR (-O2):
define i32 @ts_time_encode_bcd(i32 %0) {
%2 = srem i32 %0, 60
%3 = sdiv i32 %0, 60
%4 = sdiv i32 %0, 3600
%5 = mul nsw i32 %4, -60
%6 = add nsw i32 %5, %3
%7 = tail call i32 @dec2bcd(i32 %4)
%8 = shl i32 %7, 16
%9 = tail call i32 @dec2bcd(i32 %6)
%10 = shl i32 %9, 8
%11 = or i32 %10, %8
%12 = tail call i32 @dec2bcd(i32 %2)
%13 = or i32 %11, %12
ret i32 %13
}