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

/* Variables and functions */
int to_bcd(int);
void adr_to_msf_bcd(uint32_t adr, uint8_t *msf) {
  uint8_t m = adr / 4500;
  uint8_t s = (adr % 4500) / 75;
  uint8_t f = adr % 75;
  msf[0] = to_bcd(m);
  msf[1] = to_bcd(s);
  msf[2] = to_bcd(f);
}


x86 assembly (clang, -O0):
<adr_to_msf_bcd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x1194,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x1194,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0x4b,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x4b,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <to_bcd@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%edi
call   1030 <to_bcd@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x1c(%rbp),%edi
call   1030 <to_bcd@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<adr_to_msf_bcd>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
movslq %edi,%rbx
imul   $0x7482296b,%rbx,%rdi
mov    %rdi,%rax
shr    $0x3f,%rax
sar    $0x2b,%rdi
add    %eax,%edi
imul   $0x1194,%edi,%eax
mov    %ebx,%ecx
sub    %eax,%ecx
movswl %cx,%eax
imul   $0xffffda75,%eax,%eax
shr    $0x10,%eax
add    %ecx,%eax
movzwl %ax,%eax
movswl %ax,%ecx
shr    $0xf,%eax
sar    $0x6,%ecx
add    %eax,%ecx
movswl %cx,%ebp
imul   $0x1b4e81b5,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x23,%rax
add    %ecx,%eax
imul   $0x4b,%eax,%eax
sub    %eax,%ebx
call   1030 <to_bcd@plt>
mov    %eax,(%r14)
mov    %ebp,%edi
call   1030 <to_bcd@plt>
mov    %eax,0x4(%r14)
mov    %ebx,%edi
call   1030 <to_bcd@plt>
mov    %eax,0x8(%r14)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @adr_to_msf_bcd(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
%8 = load i32, i32* %3
%9 = sdiv i32 %8, 4500
store i32 %9, i32* %5
%10 = load i32, i32* %3
%11 = srem i32 %10, 4500
%12 = sdiv i32 %11, 75
store i32 %12, i32* %6
%13 = load i32, i32* %3
%14 = srem i32 %13, 75
store i32 %14, i32* %7
%15 = load i32, i32* %5
%16 = call i32 @to_bcd(i32 %15)
%17 = load i32*, i32** %4
%18 = getelementptr inbounds i32, i32* %17, i64 0
store i32 %16, i32* %18
%19 = load i32, i32* %6
%20 = call i32 @to_bcd(i32 %19)
%21 = load i32*, i32** %4
%22 = getelementptr inbounds i32, i32* %21, i64 1
store i32 %20, i32* %22
%23 = load i32, i32* %7
%24 = call i32 @to_bcd(i32 %23)
%25 = load i32*, i32** %4
%26 = getelementptr inbounds i32, i32* %25, i64 2
store i32 %24, i32* %26
ret void
}

LLVM IR (-O2):
define void @adr_to_msf_bcd(i32 %0, i32* nocapture writeonly %1) {
%3 = sdiv i32 %0, 4500
%4 = srem i32 %0, 4500
%5 = trunc i32 %4 to i16
%6 = sdiv i16 %5, 75
%7 = sext i16 %6 to i32
%8 = srem i32 %0, 75
%9 = tail call i32 @to_bcd(i32 %3)
store i32 %9, i32* %1
%10 = tail call i32 @to_bcd(i32 %7)
%11 = getelementptr inbounds i32, i32* %1, i64 1
store i32 %10, i32* %11
%12 = tail call i32 @to_bcd(i32 %8)
%13 = getelementptr inbounds i32, i32* %1, i64 2
store i32 %12, i32* %13
ret void
}