#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*/ printNumberOfNotes(int, int);
int /*<<< orphan*/ printf(char *, ...);
void calculateSmallestMoney(int fullQuantity) {
  int remainder = 0;
  int previousRemainder = 0;
  int loopValue = 20;
  int numNotes = 0;
  printf("$%d consists of: ", fullQuantity);
  previousRemainder = fullQuantity;
  for (loopValue = 20; loopValue >= 5; loopValue /= 2) {
    if (previousRemainder % loopValue != 0) {
      remainder = (previousRemainder % loopValue);
      numNotes = ((previousRemainder - remainder) / loopValue);
      previousRemainder = remainder;
    } else {
      numNotes = (previousRemainder / loopValue);
      previousRemainder = 0;
    }
    printNumberOfNotes(loopValue, numNotes);
  }
  if (previousRemainder > 1)
    printf("%d $1 coins", previousRemainder);
  else if (previousRemainder == 1)
    printf("%d $1 coin", previousRemainder);
  printf("\n");
}


x86 assembly (clang, -O0):
<calculateSmallestMoney>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x14,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x4(%rbp),%esi
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
movl   $0x14,-0x10(%rbp)
cmpl   $0x5,-0x10(%rbp)
jl     11d0 <calculateSmallestMoney+0xb0>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x10(%rbp)
cmp    $0x0,%edx
je     11a1 <calculateSmallestMoney+0x81>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x10(%rbp)
mov    %edx,-0x8(%rbp)
mov    -0xc(%rbp),%eax
sub    -0x8(%rbp),%eax
cltd
idivl  -0x10(%rbp)
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    11b2 <calculateSmallestMoney+0x92>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x10(%rbp)
mov    %eax,-0x14(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <printNumberOfNotes@plt>
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
jmp    1165 <calculateSmallestMoney+0x45>
cmpl   $0x1,-0xc(%rbp)
jle    11f0 <calculateSmallestMoney+0xd0>
mov    -0xc(%rbp),%esi
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1210 <calculateSmallestMoney+0xf0>
cmpl   $0x1,-0xc(%rbp)
jne    120b <calculateSmallestMoney+0xeb>
mov    -0xc(%rbp),%esi
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1210 <calculateSmallestMoney+0xf0>
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculateSmallestMoney>:
push   %rbx
mov    %edi,%ebx
lea    0xec6(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movslq %ebx,%rbx
imul   $0x66666667,%rbx,%rsi
mov    %rsi,%rax
shr    $0x3f,%rax
sar    $0x23,%rsi
add    %eax,%esi
lea    0x0(,%rsi,4),%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebx
mov    $0x14,%edi
call   1050 <printNumberOfNotes@plt>
movsbl %bl,%eax
imul   $0x67,%eax,%eax
movzwl %ax,%eax
movswl %ax,%ecx
shr    $0xf,%eax
shr    $0xa,%ecx
add    %al,%cl
movzbl %cl,%eax
lea    (%rax,%rax,1),%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %cl,%bl
movsbl %al,%esi
mov    $0xa,%edi
call   1050 <printNumberOfNotes@plt>
movsbl %bl,%ebx
imul   $0x67,%ebx,%eax
movzwl %ax,%ecx
shr    $0x9,%eax
shr    $0xf,%ecx
add    %al,%cl
movzbl %cl,%eax
lea    (%rax,%rax,4),%ecx
sub    %cl,%bl
movsbl %al,%esi
mov    $0x5,%edi
call   1050 <printNumberOfNotes@plt>
cmp    $0x2,%bl
jl     11d3 <calculateSmallestMoney+0xa3>
movsbl %bl,%esi
lea    0xe41(%rip),%rdi
jmp    11e4 <calculateSmallestMoney+0xb4>
cmp    $0x1,%bl
jne    11eb <calculateSmallestMoney+0xbb>
lea    0xe3f(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
pop    %rbx
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"$%d consists of: \00"
@.str.1 = [12 x i8] c"%d $1 coins\00"
@.str.2 = [11 x i8] c"%d $1 coin\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @calculateSmallestMoney(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 20, i32* %5
store i32 0, i32* %6
%7 = load i32, i32* %2
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i32, i32* %2
store i32 %9, i32* %4
store i32 20, i32* %5
br label %10
10: ; preds = %36, %1
%11 = load i32, i32* %5
%12 = icmp sge i32 %11, 5
br i1 %12, label %13, label %39
13: ; preds = %10
%14 = load i32, i32* %4
%15 = load i32, i32* %5
%16 = srem i32 %14, %15
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %28
18: ; preds = %13
%19 = load i32, i32* %4
%20 = load i32, i32* %5
%21 = srem i32 %19, %20
store i32 %21, i32* %3
%22 = load i32, i32* %4
%23 = load i32, i32* %3
%24 = sub nsw i32 %22, %23
%25 = load i32, i32* %5
%26 = sdiv i32 %24, %25
store i32 %26, i32* %6
%27 = load i32, i32* %3
store i32 %27, i32* %4
br label %32
28: ; preds = %13
%29 = load i32, i32* %4
%30 = load i32, i32* %5
%31 = sdiv i32 %29, %30
store i32 %31, i32* %6
store i32 0, i32* %4
br label %32
32: ; preds = %28, %18
%33 = load i32, i32* %5
%34 = load i32, i32* %6
%35 = call i32 @printNumberOfNotes(i32 %33, i32 %34)
br label %36
36: ; preds = %32
%37 = load i32, i32* %5
%38 = sdiv i32 %37, 2
store i32 %38, i32* %5
br label %10
39: ; preds = %10
%40 = load i32, i32* %4
%41 = icmp sgt i32 %40, 1
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i32, i32* %4
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %43)
br label %52
45: ; preds = %39
%46 = load i32, i32* %4
%47 = icmp eq i32 %46, 1
br i1 %47, label %48, label %51
48: ; preds = %45
%49 = load i32, i32* %4
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %48, %45
br label %52
52: ; preds = %51, %42
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"$%d consists of: \00"
@.str.1 = [12 x i8] c"%d $1 coins\00"
@.str.2 = [11 x i8] c"%d $1 coin\00"
define void @calculateSmallestMoney(i32 %0) {
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %0)
%3 = srem i32 %0, 20
%4 = sdiv i32 %0, 20
%5 = tail call i32 @printNumberOfNotes(i32 20, i32 %4)
%6 = trunc i32 %3 to i8
%7 = srem i8 %6, 10
%8 = trunc i32 %3 to i8
%9 = sdiv i8 %8, 10
%10 = sext i8 %9 to i32
%11 = tail call i32 @printNumberOfNotes(i32 10, i32 %10)
%12 = srem i8 %7, 5
%13 = sdiv i8 %7, 5
%14 = sext i8 %13 to i32
%15 = tail call i32 @printNumberOfNotes(i32 5, i32 %14)
%16 = icmp sgt i8 %12, 1
br i1 %16, label %17, label %20
17: ; preds = %1
%18 = sext i8 %12 to i32
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %24
20: ; preds = %1
%21 = icmp eq i8 %12, 1
br i1 %21, label %22, label %24
22: ; preds = %20
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 1)
br label %24
24: ; preds = %20, %22, %17
%25 = tail call i32 @putchar(i32 10)
ret void
}