#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 int_to_words(int, char *, int);
int snprintf(char *, int, char *, char *, char *, ...);
int int_to_words_helper(int number, char *number_name, int number_value,
                        char *output, int outputlen) {
  char num[100];
  char rest[100];
  int rc;
  int n = number / number_value;
  int remaining = number - number_value * n;
  rc = int_to_words(n, num, 100);
  if (rc < 0)
    return rc;
  if (remaining != 0) {
    rc = int_to_words(remaining, rest, 100);
    if (rc < 0)
      return rc;
    rc = snprintf(output, outputlen, "%s %s %s", num, number_name, rest);
  } else {
    rc = snprintf(output, outputlen, "%s %s", num, number_name);
  }
  return rc;
}


x86 assembly (clang, -O0):
<int_to_words_helper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x8(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,-0x108(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x14(%rbp),%ecx
imul   -0x108(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x10c(%rbp)
mov    -0x108(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x64,%edx
call   1040 <int_to_words@plt>
mov    %eax,-0x104(%rbp)
cmpl   $0x0,-0x104(%rbp)
jge    1197 <int_to_words_helper+0x77>
mov    -0x104(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    123d <int_to_words_helper+0x11d>
cmpl   $0x0,-0x10c(%rbp)
je     120e <int_to_words_helper+0xee>
mov    -0x10c(%rbp),%edi
lea    -0x100(%rbp),%rsi
mov    $0x64,%edx
call   1040 <int_to_words@plt>
mov    %eax,-0x104(%rbp)
cmpl   $0x0,-0x104(%rbp)
jge    11dc <int_to_words_helper+0xbc>
mov    -0x104(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    123d <int_to_words_helper+0x11d>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
lea    -0x90(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    -0x100(%rbp),%r9
lea    0xe04(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    %eax,-0x104(%rbp)
jmp    1234 <int_to_words_helper+0x114>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
lea    -0x90(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xddc(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    %eax,-0x104(%rbp)
mov    -0x104(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int_to_words_helper>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xd8,%rsp
mov    %r8d,%r15d
mov    %rcx,%rbx
mov    %edx,%ecx
mov    %rsi,%r14
mov    %edi,%eax
cltd
idiv   %ecx
mov    %edx,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x64,%edx
call   1040 <int_to_words@plt>
test   %eax,%eax
js     11a6 <int_to_words_helper+0x86>
test   %ebp,%ebp
je     118c <int_to_words_helper+0x6c>
lea    0x70(%rsp),%rsi
mov    %ebp,%edi
mov    $0x64,%edx
call   1040 <int_to_words@plt>
test   %eax,%eax
js     11a6 <int_to_words_helper+0x86>
lea    0xe8e(%rip),%rdx
mov    %rsp,%rcx
lea    0x70(%rsp),%r9
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r14,%r8
xor    %eax,%eax
call   1030 <snprintf@plt>
jmp    11a6 <int_to_words_helper+0x86>
lea    0xe70(%rip),%rdx
mov    %rsp,%rcx
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r14,%r8
xor    %eax,%eax
call   1030 <snprintf@plt>
add    $0xd8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%s %s %s\00"
@.str.1 = [6 x i8] c"%s %s\00"
define i32 @int_to_words_helper(i32 %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca [100 x i8]
%13 = alloca [100 x i8]
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32 %0, i32* %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32 %4, i32* %11
%17 = load i32, i32* %7
%18 = load i32, i32* %9
%19 = sdiv i32 %17, %18
store i32 %19, i32* %15
%20 = load i32, i32* %7
%21 = load i32, i32* %9
%22 = load i32, i32* %15
%23 = mul nsw i32 %21, %22
%24 = sub nsw i32 %20, %23
store i32 %24, i32* %16
%25 = load i32, i32* %15
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%27 = call i32 @int_to_words(i32 %25, i8* %26, i32 100)
store i32 %27, i32* %14
%28 = load i32, i32* %14
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %5
%31 = load i32, i32* %14
store i32 %31, i32* %6
br label %58
32: ; preds = %5
%33 = load i32, i32* %16
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %50
35: ; preds = %32
%36 = load i32, i32* %16
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %13, i64 0, i64 0
%38 = call i32 @int_to_words(i32 %36, i8* %37, i32 100)
store i32 %38, i32* %14
%39 = load i32, i32* %14
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %35
%42 = load i32, i32* %14
store i32 %42, i32* %6
br label %58
43: ; preds = %35
%44 = load i8*, i8** %10
%45 = load i32, i32* %11
%46 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%47 = load i8*, i8** %8
%48 = getelementptr inbounds [100 x i8], [100 x i8]* %13, i64 0, i64 0
%49 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %44, i32 %45, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %46, i8* %47, i8* %48)
store i32 %49, i32* %14
br label %56
50: ; preds = %32
%51 = load i8*, i8** %10
%52 = load i32, i32* %11
%53 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%54 = load i8*, i8** %8
%55 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %51, i32 %52, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %53, i8* %54)
store i32 %55, i32* %14
br label %56
56: ; preds = %50, %43
%57 = load i32, i32* %14
store i32 %57, i32* %6
br label %58
58: ; preds = %56, %41, %30
%59 = load i32, i32* %6
ret i32 %59
}

LLVM IR (-O2):
@.str = [9 x i8] c"%s %s %s\00"
@.str.1 = [6 x i8] c"%s %s\00"
define i32 @int_to_words_helper(i32 %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca [100 x i8]
%7 = alloca [100 x i8]
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%10 = sdiv i32 %0, %2
%11 = mul nsw i32 %10, %2
%12 = srem i32 %0, %2
%13 = call i32 @int_to_words(i32 %10, i8* %8, i32 100)
%14 = icmp slt i32 %13, 0
br i1 %14, label %24, label %15
15: ; preds = %5
%16 = icmp eq i32 %12, 0
br i1 %16, label %22, label %17
17: ; preds = %15
%18 = call i32 @int_to_words(i32 %12, i8* %9, i32 100)
%19 = icmp slt i32 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %17
%21 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %3, i32 %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %8, i8* %1, i8* %9)
br label %24
22: ; preds = %15
%23 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %3, i32 %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %8, i8* %1)
br label %24
24: ; preds = %20, %22, %17, %5
%25 = phi i32 [ %13, %5 ], [ %18, %17 ], [ %21, %20 ], [ %23, %22 ]
ret i32 %25
}