#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 EXIT_SUCCESS;
char *calloc(int, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ intToText(int, char *, int);
int letterCount(char *, int);
int /*<<< orphan*/ printf(char *, int, ...);
int main() {
  char *buffer;
  int i = 1;
  int total = 0;
  buffer = calloc(100, sizeof(char));
  for (i = 1; i <= 1000; i++) {
    buffer[0] = 0;
    intToText(i, buffer, 100);
    total += letterCount(buffer, (100));
    printf("%5d - %s\n", letterCount(buffer, 100), buffer);
  }
  free(buffer);
  printf("Solution : %d\n", total);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x64,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x3e8,-0x14(%rbp)
jg     11f0 <main+0xa0>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x64,%edx
call   1070 <intToText@plt>
mov    -0x10(%rbp),%rdi
mov    $0x64,%esi
call   1050 <letterCount@plt>
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x64,%esi
call   1050 <letterCount@plt>
mov    %eax,%esi
mov    -0x10(%rbp),%rdx
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1187 <main+0x37>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%esi
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dcf(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x1,%ebp
mov    $0x64,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%r14
lea    0xe8b(%rip),%r15
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movb   $0x0,(%r14)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x64,%edx
call   1070 <intToText@plt>
mov    %r14,%rdi
mov    $0x64,%esi
call   1050 <letterCount@plt>
add    %eax,%ebx
mov    %r14,%rdi
mov    $0x64,%esi
call   1050 <letterCount@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
cmp    $0x3e9,%ebp
jne    1180 <main+0x30>
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xe32(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"%5d - %s\0A\00"
@.str.1 = [15 x i8] c"Solution : %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %3
store i32 0, i32* %4
%5 = call i8* @calloc(i32 100, i32 1)
store i8* %5, i8** %2
store i32 1, i32* %3
br label %6
6: ; preds = %23, %0
%7 = load i32, i32* %3
%8 = icmp sle i32 %7, 1000
br i1 %8, label %9, label %26
9: ; preds = %6
%10 = load i8*, i8** %2
%11 = getelementptr inbounds i8, i8* %10, i64 0
store i8 0, i8* %11
%12 = load i32, i32* %3
%13 = load i8*, i8** %2
%14 = call i32 @intToText(i32 %12, i8* %13, i32 100)
%15 = load i8*, i8** %2
%16 = call i32 @letterCount(i8* %15, i32 100)
%17 = load i32, i32* %4
%18 = add nsw i32 %17, %16
store i32 %18, i32* %4
%19 = load i8*, i8** %2
%20 = call i32 @letterCount(i8* %19, i32 100)
%21 = load i8*, i8** %2
%22 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %20, i8* %21)
br label %23
23: ; preds = %9
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
store i32 %25, i32* %3
br label %6
26: ; preds = %6
%27 = load i8*, i8** %2
%28 = call i32 @free(i8* %27)
%29 = load i32, i32* %4
%30 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = load i32, i32* @EXIT_SUCCESS
ret i32 %31
}

LLVM IR (-O2):
@.str = [10 x i8] c"%5d - %s\0A\00"
@.str.1 = [15 x i8] c"Solution : %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call dereferenceable_or_null(100) i8* @calloc(i32 100, i32 1)
br label %2
2: ; preds = %0, %2
%3 = phi i32 [ 0, %0 ], [ %7, %2 ]
%4 = phi i32 [ 1, %0 ], [ %10, %2 ]
store i8 0, i8* %1
%5 = tail call i32 @intToText(i32 %4, i8* %1, i32 100)
%6 = tail call i32 @letterCount(i8* %1, i32 100)
%7 = add nsw i32 %6, %3
%8 = tail call i32 @letterCount(i8* %1, i32 100)
%9 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %8, i8* %1)
%10 = add nuw nsw i32 %4, 1
%11 = icmp eq i32 %10, 1001
br i1 %11, label %12, label %2
12: ; preds = %2
%13 = tail call i32 @free(i8* %1)
%14 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%15 = load i32, i32* @EXIT_SUCCESS
ret i32 %15
}