void pay_amount(int dollars, int *twenties, int *tens, int *fives, int *toonies,
                int *loonie) {
  *twenties = dollars / 20;
  *tens = (dollars % 20) / 10;
  *fives = (dollars % 10) / 5;
  *toonies = (dollars % 5) / 2;
  *loonie = (dollars % 5) % 2;
}


x86 assembly (clang, -O0):
<pay_amount>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x14,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x4(%rbp),%eax
mov    $0x14,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x4(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x4(%rbp),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x30(%rbp),%rax
mov    %edx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<pay_amount>:
movslq %edi,%rax
imul   $0x66666667,%rax,%r11
mov    %r11,%rdi
sar    $0x23,%rdi
mov    %r11,%r10
shr    $0x3f,%r10
add    %r10d,%edi
mov    %edi,(%rsi)
shl    $0x2,%edi
lea    (%rdi,%rdi,4),%esi
mov    %eax,%edi
sub    %esi,%edi
movsbl %dil,%esi
imul   $0x67,%esi,%esi
movzwl %si,%esi
movswl %si,%edi
shr    $0xf,%esi
shr    $0xa,%edi
add    %sil,%dil
movsbl %dil,%esi
mov    %esi,(%rdx)
mov    %r11,%rdx
shr    $0x22,%rdx
add    %r10d,%edx
add    %edx,%edx
lea    (%rdx,%rdx,4),%edx
mov    %eax,%esi
sub    %edx,%esi
movsbl %sil,%edx
imul   $0x67,%edx,%edx
movzwl %dx,%edx
movswl %dx,%esi
shr    $0xf,%edx
shr    $0x9,%esi
add    %dl,%sil
movsbl %sil,%edx
mov    %edx,(%rcx)
shr    $0x21,%r11
add    %r10d,%r11d
lea    (%r11,%r11,4),%ecx
sub    %ecx,%eax
mov    %eax,%ecx
shr    $0x7,%cl
add    %al,%cl
mov    %ecx,%edx
sar    %dl
movsbl %dl,%edx
mov    %edx,(%r8)
and    $0xfe,%cl
sub    %cl,%al
movsbl %al,%eax
mov    %eax,(%r9)
ret

LLVM IR (-O0):
define void @pay_amount(i32 %0, i32* %1, i32* %2, i32* %3, i32* %4, i32* %5) {
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
store i32 %0, i32* %7
store i32* %1, i32** %8
store i32* %2, i32** %9
store i32* %3, i32** %10
store i32* %4, i32** %11
store i32* %5, i32** %12
%13 = load i32, i32* %7
%14 = sdiv i32 %13, 20
%15 = load i32*, i32** %8
store i32 %14, i32* %15
%16 = load i32, i32* %7
%17 = srem i32 %16, 20
%18 = sdiv i32 %17, 10
%19 = load i32*, i32** %9
store i32 %18, i32* %19
%20 = load i32, i32* %7
%21 = srem i32 %20, 10
%22 = sdiv i32 %21, 5
%23 = load i32*, i32** %10
store i32 %22, i32* %23
%24 = load i32, i32* %7
%25 = srem i32 %24, 5
%26 = sdiv i32 %25, 2
%27 = load i32*, i32** %11
store i32 %26, i32* %27
%28 = load i32, i32* %7
%29 = srem i32 %28, 5
%30 = srem i32 %29, 2
%31 = load i32*, i32** %12
store i32 %30, i32* %31
ret void
}

LLVM IR (-O2):
define void @pay_amount(i32 %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3, i32* nocapture writeonly %4, i32* nocapture writeonly %5) {
%7 = sdiv i32 %0, 20
store i32 %7, i32* %1
%8 = srem i32 %0, 20
%9 = trunc i32 %8 to i8
%10 = sdiv i8 %9, 10
%11 = sext i8 %10 to i32
store i32 %11, i32* %2
%12 = srem i32 %0, 10
%13 = trunc i32 %12 to i8
%14 = sdiv i8 %13, 5
%15 = sext i8 %14 to i32
store i32 %15, i32* %3
%16 = srem i32 %0, 5
%17 = trunc i32 %16 to i8
%18 = sdiv i8 %17, 2
%19 = sext i8 %18 to i32
store i32 %19, i32* %4
%20 = srem i8 %17, 2
%21 = sext i8 %20 to i32
store i32 %21, i32* %5
ret void
}