#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 centsFromCents(int);
int dollarsFromCents(int);
int /*<<< orphan*/ sprintf(char *, char *, int, int);
void dollarFormat(int cents, char *output) {
  if (centsFromCents(cents) < 10) {
    sprintf(output, "$%d.0%d", dollarsFromCents(cents), centsFromCents(cents));
  } else {
    sprintf(output, "$%d.%d", dollarsFromCents(cents), centsFromCents(cents));
  }
}


x86 assembly (clang, -O0):
<dollarFormat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <centsFromCents@plt>
cmp    $0xa,%eax
jge    1185 <dollarFormat+0x55>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <dollarsFromCents@plt>
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <centsFromCents@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    %eax,%ecx
lea    0xe85(%rip),%rsi
call   1050 <sprintf@plt>
jmp    11b5 <dollarFormat+0x85>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <dollarsFromCents@plt>
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <centsFromCents@plt>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    %eax,%ecx
lea    0xe58(%rip),%rsi
call   1050 <sprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dollarFormat>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebp
call   1040 <centsFromCents@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1030 <dollarsFromCents@plt>
mov    %eax,%r15d
mov    %ebp,%edi
call   1040 <centsFromCents@plt>
cmp    $0xa,%ebx
lea    0xea2(%rip),%rcx
lea    0xea3(%rip),%rsi
cmovl  %rcx,%rsi
mov    %r14,%rdi
mov    %r15d,%edx
mov    %eax,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <sprintf@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"$%d.0%d\00"
@.str.1 = [7 x i8] c"$%d.%d\00"
define void @dollarFormat(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%5 = load i32, i32* %3
%6 = call i32 @centsFromCents(i32 %5)
%7 = icmp slt i32 %6, 10
br i1 %7, label %8, label %15
8: ; preds = %2
%9 = load i8*, i8** %4
%10 = load i32, i32* %3
%11 = call i32 @dollarsFromCents(i32 %10)
%12 = load i32, i32* %3
%13 = call i32 @centsFromCents(i32 %12)
%14 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %13)
br label %22
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = load i32, i32* %3
%18 = call i32 @dollarsFromCents(i32 %17)
%19 = load i32, i32* %3
%20 = call i32 @centsFromCents(i32 %19)
%21 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %18, i32 %20)
br label %22
22: ; preds = %15, %8
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"$%d.0%d\00"
@.str.1 = [7 x i8] c"$%d.%d\00"
define void @dollarFormat(i32 %0, i8* nocapture writeonly %1) {
%3 = tail call i32 @centsFromCents(i32 %0)
%4 = icmp slt i32 %3, 10
%5 = tail call i32 @dollarsFromCents(i32 %0)
%6 = tail call i32 @centsFromCents(i32 %0)
%7 = select i1 %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0)
%8 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) %7, i32 %5, i32 %6)
ret void
}