#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 */
float abs(int);
float fabsf(float);
int frac_to_words(float, char *, int, int);
int integer_to_words(int, char *, int);
int snprintf(char *, int, char *, char *, ...);
int trunc(float);
int numbers_to_words(float number, int max_decimal_places, char *buffer,
                     int buflen) {
  int i, rc;
  float f;
  char ipart[500], fpart[500];
  i = trunc(number);
  f = fabsf(number) - abs(i);
  rc = integer_to_words(i, ipart, 500);
  if (rc < 0)
    return rc;
  if (max_decimal_places > 0) {
    rc = frac_to_words(f, fpart, 500, max_decimal_places);
    if (rc < 0)
      return rc;
  }
  if ((f * 1000) >= 1.0 && max_decimal_places > 0)
    rc = snprintf(buffer, buflen, "%s %s", ipart, fpart);
  else
    rc = snprintf(buffer, buflen, "%s", ipart);
  return rc;
}


x86 assembly (clang, -O0):
<numbers_to_words>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movss  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movss  -0x8(%rbp),%xmm0
call   1060 <trunc@plt>
mov    %eax,-0x20(%rbp)
movss  -0x8(%rbp),%xmm0
movaps 0xe7d(%rip),%xmm1
pand   %xmm1,%xmm0
movss  %xmm0,-0x424(%rbp)
ff
mov    -0x20(%rbp),%edi
call   1030 <abs@plt>
movaps %xmm0,%xmm1
movss  -0x424(%rbp),%xmm0
ff
subss  %xmm1,%xmm0
movss  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x1f4,%edx
call   1050 <integer_to_words@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11d7 <numbers_to_words+0x87>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1294 <numbers_to_words+0x144>
cmpl   $0x0,-0xc(%rbp)
jle    1217 <numbers_to_words+0xc7>
movss  -0x28(%rbp),%xmm0
lea    -0x420(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    $0x1f4,%esi
call   1070 <frac_to_words@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1212 <numbers_to_words+0xc2>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1294 <numbers_to_words+0x144>
jmp    1217 <numbers_to_words+0xc7>
movss  0xdf9(%rip),%xmm0
mulss  -0x28(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xde0(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     126f <numbers_to_words+0x11f>
cmpl   $0x0,-0xc(%rbp)
jle    126f <numbers_to_words+0x11f>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
lea    -0x220(%rbp),%rcx
lea    -0x420(%rbp),%r8
lea    0xdbc(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    %eax,-0x24(%rbp)
jmp    128e <numbers_to_words+0x13e>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
lea    -0x220(%rbp),%rcx
lea    0xd9b(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<numbers_to_words>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x418,%rsp
mov    %edx,%r14d
mov    %rsi,%r15
mov    %edi,%ebp
movaps %xmm0,0x10(%rsp)
call   1060 <trunc@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1030 <abs@plt>
movss  %xmm0,0xc(%rsp)
lea    0x20(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1f4,%edx
call   1050 <integer_to_words@plt>
test   %eax,%eax
js     121c <numbers_to_words+0xcc>
test   %ebp,%ebp
jle    11e0 <numbers_to_words+0x90>
movaps 0x10(%rsp),%xmm0
andps  0xe59(%rip),%xmm0
subss  0xc(%rsp),%xmm0
lea    0x220(%rsp),%rdi
movaps %xmm0,0x10(%rsp)
mov    $0x1f4,%esi
mov    %ebp,%edx
call   1070 <frac_to_words@plt>
test   %eax,%eax
js     121c <numbers_to_words+0xcc>
movaps 0x10(%rsp),%xmm0
mulss  0xe39(%rip),%xmm0
ucomiss 0xe36(%rip),%xmm0
jae    11fb <numbers_to_words+0xab>
lea    0xe34(%rip),%rdx
lea    0x20(%rsp),%rcx
mov    %r15,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
jmp    121c <numbers_to_words+0xcc>
lea    0xe16(%rip),%rdx
lea    0x20(%rsp),%rcx
lea    0x220(%rsp),%r8
mov    %r15,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
add    $0x418,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s %s\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @numbers_to_words(float %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca float
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca float
%13 = alloca [500 x i8]
%14 = alloca [500 x i8]
store float %0, float* %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%15 = load float, float* %6
%16 = call i32 @trunc(float %15)
store i32 %16, i32* %10
%17 = load float, float* %6
%18 = call float @llvm.fabs.f32(float %17)
%19 = load i32, i32* %10
%20 = call float @abs(i32 %19)
%21 = fsub float %18, %20
store float %21, float* %12
%22 = load i32, i32* %10
%23 = getelementptr inbounds [500 x i8], [500 x i8]* %13, i64 0, i64 0
%24 = call i32 @integer_to_words(i32 %22, i8* %23, i32 500)
store i32 %24, i32* %11
%25 = load i32, i32* %11
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %4
%28 = load i32, i32* %11
store i32 %28, i32* %5
br label %63
29: ; preds = %4
%30 = load i32, i32* %7
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %42
32: ; preds = %29
%33 = load float, float* %12
%34 = getelementptr inbounds [500 x i8], [500 x i8]* %14, i64 0, i64 0
%35 = load i32, i32* %7
%36 = call i32 @frac_to_words(float %33, i8* %34, i32 500, i32 %35)
store i32 %36, i32* %11
%37 = load i32, i32* %11
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %32
%40 = load i32, i32* %11
store i32 %40, i32* %5
br label %63
41: ; preds = %32
br label %42
42: ; preds = %41, %29
%43 = load float, float* %12
%44 = fmul float %43, 1.000000e+03
%45 = fpext float %44 to double
%46 = fcmp oge double %45, 1.000000e+00
br i1 %46, label %47, label %56
47: ; preds = %42
%48 = load i32, i32* %7
%49 = icmp sgt i32 %48, 0
br i1 %49, label %50, label %56
50: ; preds = %47
%51 = load i8*, i8** %8
%52 = load i32, i32* %9
%53 = getelementptr inbounds [500 x i8], [500 x i8]* %13, i64 0, i64 0
%54 = getelementptr inbounds [500 x i8], [500 x i8]* %14, i64 0, i64 0
%55 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %51, i32 %52, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %53, i8* %54)
store i32 %55, i32* %11
br label %61
56: ; preds = %47, %42
%57 = load i8*, i8** %8
%58 = load i32, i32* %9
%59 = getelementptr inbounds [500 x i8], [500 x i8]* %13, i64 0, i64 0
%60 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %57, i32 %58, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %59)
store i32 %60, i32* %11
br label %61
61: ; preds = %56, %50
%62 = load i32, i32* %11
store i32 %62, i32* %5
br label %63
63: ; preds = %61, %39, %27
%64 = load i32, i32* %5
ret i32 %64
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s %s\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @numbers_to_words(float %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca [500 x i8]
%6 = alloca [500 x i8]
%7 = getelementptr inbounds [500 x i8], [500 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%9 = tail call i32 @trunc(float %0)
%10 = tail call float @llvm.fabs.f32(float %0)
%11 = tail call float @abs(i32 %9)
%12 = fsub float %10, %11
%13 = call i32 @integer_to_words(i32 %9, i8* %7, i32 500)
%14 = icmp slt i32 %13, 0
br i1 %14, label %27, label %15
15: ; preds = %4
%16 = icmp sgt i32 %1, 0
br i1 %16, label %17, label %25
17: ; preds = %15
%18 = call i32 @frac_to_words(float %12, i8* %8, i32 500, i32 %1)
%19 = icmp slt i32 %18, 0
br i1 %19, label %27, label %20
20: ; preds = %17
%21 = fmul float %12, 1.000000e+03
%22 = fcmp ult float %21, 1.000000e+00
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %2, i32 %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %7, i8* %8)
br label %27
25: ; preds = %15, %20
%26 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %2, i32 %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %7)
br label %27
27: ; preds = %23, %25, %17, %4
%28 = phi i32 [ %13, %4 ], [ %18, %17 ], [ %24, %23 ], [ %26, %25 ]
ret i32 %28
}